ui: Move chat background into chat
This commit is contained in:
parent
fdbf2534b7
commit
0d8bf8dd12
@ -40,7 +40,6 @@ import 'package:moxxyv2/ui/pages/profile/profile.dart';
|
|||||||
import 'package:moxxyv2/ui/pages/sendfiles.dart';
|
import 'package:moxxyv2/ui/pages/sendfiles.dart';
|
||||||
import 'package:moxxyv2/ui/pages/server_info.dart';
|
import 'package:moxxyv2/ui/pages/server_info.dart';
|
||||||
import 'package:moxxyv2/ui/pages/settings/about.dart';
|
import 'package:moxxyv2/ui/pages/settings/about.dart';
|
||||||
import 'package:moxxyv2/ui/pages/settings/appearance/appearance.dart';
|
|
||||||
import 'package:moxxyv2/ui/pages/settings/appearance/cropbackground.dart';
|
import 'package:moxxyv2/ui/pages/settings/appearance/cropbackground.dart';
|
||||||
import 'package:moxxyv2/ui/pages/settings/conversation.dart';
|
import 'package:moxxyv2/ui/pages/settings/conversation.dart';
|
||||||
import 'package:moxxyv2/ui/pages/settings/debugging.dart';
|
import 'package:moxxyv2/ui/pages/settings/debugging.dart';
|
||||||
@ -305,7 +304,6 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
case settingsRoute: return SettingsPage.route;
|
case settingsRoute: return SettingsPage.route;
|
||||||
case aboutRoute: return SettingsAboutPage.route;
|
case aboutRoute: return SettingsAboutPage.route;
|
||||||
case licensesRoute: return SettingsLicensesPage.route;
|
case licensesRoute: return SettingsLicensesPage.route;
|
||||||
case appearanceRoute: return AppearancePage.route;
|
|
||||||
case networkRoute: return NetworkPage.route;
|
case networkRoute: return NetworkPage.route;
|
||||||
case privacyRoute: return PrivacyPage.route;
|
case privacyRoute: return PrivacyPage.route;
|
||||||
case debuggingRoute: return DebuggingPage.route;
|
case debuggingRoute: return DebuggingPage.route;
|
||||||
|
@ -51,7 +51,6 @@ const String aboutRoute = '$settingsRoute/about';
|
|||||||
const String debuggingRoute = '$settingsRoute/debugging';
|
const String debuggingRoute = '$settingsRoute/debugging';
|
||||||
const String privacyRoute = '$settingsRoute/privacy';
|
const String privacyRoute = '$settingsRoute/privacy';
|
||||||
const String networkRoute = '$settingsRoute/network';
|
const String networkRoute = '$settingsRoute/network';
|
||||||
const String appearanceRoute = '$settingsRoute/appearance';
|
|
||||||
const String backgroundCroppingRoute = '$settingsRoute/appearance/background';
|
const String backgroundCroppingRoute = '$settingsRoute/appearance/background';
|
||||||
const String conversationSettingsRoute = '$settingsRoute/conversation';
|
const String conversationSettingsRoute = '$settingsRoute/conversation';
|
||||||
const String blocklistRoute = '/blocklist';
|
const String blocklistRoute = '/blocklist';
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:get_it/get_it.dart';
|
|
||||||
import 'package:moxxyv2/shared/preferences.dart';
|
|
||||||
import 'package:moxxyv2/ui/bloc/cropbackground_bloc.dart';
|
|
||||||
import 'package:moxxyv2/ui/bloc/preferences_bloc.dart';
|
|
||||||
import 'package:moxxyv2/ui/constants.dart';
|
|
||||||
import 'package:moxxyv2/ui/helpers.dart';
|
|
||||||
import 'package:moxxyv2/ui/service/thumbnail.dart';
|
|
||||||
import 'package:moxxyv2/ui/widgets/topbar.dart';
|
|
||||||
import 'package:path/path.dart' as path;
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
import 'package:settings_ui/settings_ui.dart';
|
|
||||||
|
|
||||||
class AppearancePage extends StatelessWidget {
|
|
||||||
const AppearancePage({ Key? key }): super(key: key);
|
|
||||||
|
|
||||||
static MaterialPageRoute<dynamic> get route => MaterialPageRoute<dynamic>(
|
|
||||||
builder: (_) => const AppearancePage(),
|
|
||||||
settings: const RouteSettings(
|
|
||||||
name: appearanceRoute,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO(Unknown): Move this somewhere else to not mix UI and application logic
|
|
||||||
Future<String?> _pickBackgroundImage() async {
|
|
||||||
final result = await FilePicker.platform.pickFiles(
|
|
||||||
type: FileType.image,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == null) return null;
|
|
||||||
|
|
||||||
final appDir = await getApplicationDocumentsDirectory();
|
|
||||||
final backgroundPath = path.join(appDir.path, result.files.single.name);
|
|
||||||
await File(result.files.single.path!).copy(backgroundPath);
|
|
||||||
|
|
||||||
return backgroundPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _removeBackgroundImage(BuildContext context, PreferencesState state) async {
|
|
||||||
final backgroundPath = state.backgroundPath;
|
|
||||||
if (backgroundPath.isEmpty) return;
|
|
||||||
|
|
||||||
// TODO(Unknown): Move this into the [PreferencesBloc]
|
|
||||||
final file = File(backgroundPath);
|
|
||||||
if (file.existsSync()) {
|
|
||||||
await file.delete();
|
|
||||||
}
|
|
||||||
// TODO(Unknown): END
|
|
||||||
|
|
||||||
// Remove from the cache
|
|
||||||
unawaited(GetIt.I.get<ThumbnailCacheService>().invalidateEntry(backgroundPath));
|
|
||||||
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
context.read<PreferencesBloc>().add(
|
|
||||||
PreferencesChangedEvent(
|
|
||||||
state.copyWith(backgroundPath: ''),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: BorderlessTopbar.simple('Appearance'),
|
|
||||||
body: BlocBuilder<PreferencesBloc, PreferencesState>(
|
|
||||||
builder: (context, state) => SettingsList(
|
|
||||||
sections: [
|
|
||||||
SettingsSection(
|
|
||||||
title: const Text('Conversation Background'),
|
|
||||||
tiles: [
|
|
||||||
SettingsTile(
|
|
||||||
title: const Text('Select background image'),
|
|
||||||
description: const Text('This image will be the background of all your chats'),
|
|
||||||
onPressed: (context) async {
|
|
||||||
final backgroundPath = await _pickBackgroundImage();
|
|
||||||
|
|
||||||
if (backgroundPath != null) {
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
context.read<CropBackgroundBloc>().add(
|
|
||||||
CropBackgroundRequestedEvent(backgroundPath),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
SettingsTile(
|
|
||||||
title: const Text('Remove background image'),
|
|
||||||
onPressed: (context) {
|
|
||||||
showConfirmationDialog(
|
|
||||||
'Are you sure?',
|
|
||||||
'Are you sure you want to remove your conversation background image?',
|
|
||||||
context,
|
|
||||||
() async {
|
|
||||||
await _removeBackgroundImage(context, state);
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,16 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:moxxyv2/shared/preferences.dart';
|
import 'package:moxxyv2/shared/preferences.dart';
|
||||||
|
import 'package:moxxyv2/ui/bloc/cropbackground_bloc.dart';
|
||||||
import 'package:moxxyv2/ui/bloc/preferences_bloc.dart';
|
import 'package:moxxyv2/ui/bloc/preferences_bloc.dart';
|
||||||
import 'package:moxxyv2/ui/constants.dart';
|
import 'package:moxxyv2/ui/constants.dart';
|
||||||
|
import 'package:moxxyv2/ui/helpers.dart';
|
||||||
import 'package:moxxyv2/ui/widgets/topbar.dart';
|
import 'package:moxxyv2/ui/widgets/topbar.dart';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:settings_ui/settings_ui.dart';
|
import 'package:settings_ui/settings_ui.dart';
|
||||||
|
|
||||||
class ConversationSettingsPage extends StatelessWidget {
|
class ConversationSettingsPage extends StatelessWidget {
|
||||||
@ -17,13 +24,84 @@ class ConversationSettingsPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO(Unknown): Move this somewhere else to not mix UI and application logic
|
||||||
|
Future<String?> _pickBackgroundImage() async {
|
||||||
|
final result = await FilePicker.platform.pickFiles(
|
||||||
|
type: FileType.image,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result == null) return null;
|
||||||
|
|
||||||
|
final appDir = await getApplicationDocumentsDirectory();
|
||||||
|
final backgroundPath = path.join(appDir.path, result.files.single.name);
|
||||||
|
await File(result.files.single.path!).copy(backgroundPath);
|
||||||
|
|
||||||
|
return backgroundPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _removeBackgroundImage(BuildContext context, PreferencesState state) async {
|
||||||
|
final backgroundPath = state.backgroundPath;
|
||||||
|
if (backgroundPath.isEmpty) return;
|
||||||
|
|
||||||
|
// TODO(Unknown): Move this into the [PreferencesBloc]
|
||||||
|
final file = File(backgroundPath);
|
||||||
|
if (file.existsSync()) {
|
||||||
|
await file.delete();
|
||||||
|
}
|
||||||
|
// TODO(Unknown): END
|
||||||
|
|
||||||
|
// Remove from the cache
|
||||||
|
// TODO(PapaTutuWawa): Invalidate the cache
|
||||||
|
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
context.read<PreferencesBloc>().add(
|
||||||
|
PreferencesChangedEvent(
|
||||||
|
state.copyWith(backgroundPath: ''),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: BorderlessTopbar.simple('Conversation'),
|
appBar: BorderlessTopbar.simple('Chat'),
|
||||||
body: BlocBuilder<PreferencesBloc, PreferencesState>(
|
body: BlocBuilder<PreferencesBloc, PreferencesState>(
|
||||||
builder: (context, state) => SettingsList(
|
builder: (context, state) => SettingsList(
|
||||||
sections: [
|
sections: [
|
||||||
|
SettingsSection(
|
||||||
|
title: const Text('Appearance'),
|
||||||
|
tiles: [
|
||||||
|
SettingsTile(
|
||||||
|
title: const Text('Select background image'),
|
||||||
|
description: const Text('This image will be the background of all your chats'),
|
||||||
|
onPressed: (context) async {
|
||||||
|
final backgroundPath = await _pickBackgroundImage();
|
||||||
|
|
||||||
|
if (backgroundPath != null) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
context.read<CropBackgroundBloc>().add(
|
||||||
|
CropBackgroundRequestedEvent(backgroundPath),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SettingsTile(
|
||||||
|
title: const Text('Remove background image'),
|
||||||
|
onPressed: (context) {
|
||||||
|
showConfirmationDialog(
|
||||||
|
'Are you sure?',
|
||||||
|
'Are you sure you want to remove your conversation background image?',
|
||||||
|
context,
|
||||||
|
() async {
|
||||||
|
await _removeBackgroundImage(context, state);
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
SettingsSection(
|
SettingsSection(
|
||||||
title: const Text('New Conversations'),
|
title: const Text('New Conversations'),
|
||||||
tiles: [
|
tiles: [
|
||||||
@ -37,7 +115,7 @@ class ConversationSettingsPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -27,15 +27,10 @@ class SettingsPage extends StatelessWidget {
|
|||||||
title: const Text('Conversations'),
|
title: const Text('Conversations'),
|
||||||
tiles: [
|
tiles: [
|
||||||
SettingsTile(
|
SettingsTile(
|
||||||
title: const Text('Conversation'),
|
title: const Text('Chat'),
|
||||||
leading: const Icon(Icons.chat_bubble),
|
leading: const Icon(Icons.chat_bubble),
|
||||||
onPressed: (context) => Navigator.pushNamed(context, conversationSettingsRoute),
|
onPressed: (context) => Navigator.pushNamed(context, conversationSettingsRoute),
|
||||||
),
|
),
|
||||||
SettingsTile(
|
|
||||||
title: const Text('Appearance'),
|
|
||||||
leading: const Icon(Icons.brush),
|
|
||||||
onPressed: (context) => Navigator.pushNamed(context, appearanceRoute),
|
|
||||||
),
|
|
||||||
SettingsTile(
|
SettingsTile(
|
||||||
title: const Text('Network'),
|
title: const Text('Network'),
|
||||||
leading: const Icon(Icons.network_wifi),
|
leading: const Icon(Icons.network_wifi),
|
||||||
|
Loading…
Reference in New Issue
Block a user