ui: Fix background images not appearing

This commit is contained in:
2022-04-10 18:42:10 +02:00
parent 4e2761a7b8
commit 3daa290d64
6 changed files with 88 additions and 40 deletions

View File

@@ -45,6 +45,7 @@ class ConversationBloc extends Bloc<ConversationEvent, ConversationState> {
on<MessageUpdatedEvent>(_onMessageUpdated);
on<ConversationUpdatedEvent>(_onConversationUpdated);
on<AppStateChanged>(_onAppStateChanged);
on<BackgroundChangedEvent>(_onBackgroundChanged);
}
void _setLastChangeTimestamp() {
@@ -269,4 +270,8 @@ class ConversationBloc extends Bloc<ConversationEvent, ConversationState> {
_updateChatState(ChatState.gone);
}
}
Future<void> _onBackgroundChanged(BackgroundChangedEvent event, Emitter<ConversationState> emit) async {
return emit(state.copyWith(backgroundPath: event.backgroundPath));
}
}

View File

@@ -6,7 +6,14 @@ abstract class ConversationEvent {}
class InitConversationEvent extends ConversationEvent {
final String backgroundPath;
InitConversationEvent (this.backgroundPath);
InitConversationEvent(this.backgroundPath);
}
/// Triggered when the background image changed
class BackgroundChangedEvent extends ConversationEvent {
final String backgroundPath;
BackgroundChangedEvent(this.backgroundPath);
}
/// Triggered when the content of the input field changed.

View File

@@ -1,3 +1,4 @@
import "package:moxxyv2/ui/bloc/conversation_bloc.dart";
import "package:moxxyv2/shared/preferences.dart";
import "package:moxxyv2/shared/commands.dart";
import "package:moxxyv2/shared/backgroundsender.dart";
@@ -16,12 +17,19 @@ class PreferencesBloc extends Bloc<PreferencesEvent, PreferencesState> {
if (event.notify) {
GetIt.I.get<BackgroundServiceDataSender>().sendData(
SetPreferencesCommand(
preferences: state
preferences: event.preferences
),
awaitable: false
);
}
// Notify the conversation UI if we changed the background
if (event.preferences.backgroundPath != state.backgroundPath) {
GetIt.I.get<ConversationBloc>().add(
BackgroundChangedEvent(event.preferences.backgroundPath)
);
}
emit(event.preferences);
}
}

View File

@@ -9,5 +9,7 @@ class PreferencesChangedEvent extends PreferencesEvent {
final PreferencesState preferences;
final bool notify;
PreferencesChangedEvent(this.preferences, { this.notify = true });
PreferencesChangedEvent(this.preferences, {
this.notify = true,
});
}