refactor: implement singelton instance of intent-action
This commit is contained in:
parent
7d3b7a4fa5
commit
cb1fffa421
11 changed files with 43 additions and 41 deletions
|
@ -14,4 +14,15 @@
|
|||
<natures>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1675831639778</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
|
|
@ -20,4 +20,15 @@
|
|||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1675831639783</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
|
|
@ -79,10 +79,7 @@ android {
|
|||
fdroid {
|
||||
dimension "default"
|
||||
applicationIdSuffix ".fdroid"
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// signingConfig null
|
||||
>>>>>>> 4615956c (feat[gallery_extention]: integrate handler for gallery pick intent)
|
||||
signingConfig null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,15 +68,7 @@
|
|||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.file_provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data android:name="flutterEmbedding" android:value="2"/>
|
||||
|
|
|
@ -2,7 +2,6 @@ buildscript {
|
|||
ext.kotlin_version = '1.6.21'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral() //add this line
|
||||
jcenter()
|
||||
}
|
||||
|
||||
|
|
13
lib/app.dart
13
lib/app.dart
|
@ -40,7 +40,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
|
|||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
Future<IntentAction> initIntentAction() async {
|
||||
Future<bool> initIntentAction() async {
|
||||
IntentAction intentAction = IntentAction.main;
|
||||
try {
|
||||
final actionResult = await _mediaExtensionPlugin.getIntentAction();
|
||||
|
@ -51,7 +51,8 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
|
|||
if (intentAction == IntentAction.main) {
|
||||
_configureBackgroundFetch();
|
||||
}
|
||||
return intentAction;
|
||||
AppLifecycleService.instance.setIntentAction(intentAction);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -59,8 +60,8 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
|
|||
if (Platform.isAndroid || kDebugMode) {
|
||||
return FutureBuilder(
|
||||
future: initIntentAction(),
|
||||
builder: (BuildContext context, AsyncSnapshot<IntentAction> snapshot) {
|
||||
return snapshot.data != null
|
||||
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
|
||||
return snapshot.data != null && snapshot.data == true
|
||||
? AdaptiveTheme(
|
||||
light: lightThemeData,
|
||||
dark: darkThemeData,
|
||||
|
@ -70,7 +71,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
|
|||
themeMode: ThemeMode.system,
|
||||
theme: lightTheme,
|
||||
darkTheme: dartTheme,
|
||||
home: HomeWidget(intentAction: snapshot.data!),
|
||||
home: const HomeWidget(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
builder: EasyLoading.init(),
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
|
@ -87,7 +88,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
|
|||
themeMode: ThemeMode.system,
|
||||
theme: lightThemeData,
|
||||
darkTheme: darkThemeData,
|
||||
home: const HomeWidget(intentAction: IntentAction.main),
|
||||
home: const HomeWidget(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
builder: EasyLoading.init(),
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:media_extension/media_extension_action_types.dart';
|
||||
|
||||
class AppLifecycleService {
|
||||
final _logger = Logger("AppLifecycleService");
|
||||
|
||||
bool isForeground = false;
|
||||
IntentAction intentAction = IntentAction.main;
|
||||
|
||||
static final AppLifecycleService instance =
|
||||
AppLifecycleService._privateConstructor();
|
||||
|
||||
AppLifecycleService._privateConstructor();
|
||||
|
||||
void setIntentAction(IntentAction intentAction) {
|
||||
this.intentAction = intentAction;
|
||||
}
|
||||
|
||||
void onAppInForeground(String reason) {
|
||||
_logger.info("App in foreground via $reason");
|
||||
isForeground = true;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:media_extension/media_extension_action_types.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
|
@ -19,13 +18,11 @@ class HomeGalleryWidget extends StatelessWidget {
|
|||
final Widget? header;
|
||||
final Widget? footer;
|
||||
final SelectedFiles selectedFiles;
|
||||
final IntentAction intentAction;
|
||||
|
||||
const HomeGalleryWidget({
|
||||
Key? key,
|
||||
this.header,
|
||||
this.footer,
|
||||
required this.intentAction,
|
||||
required this.selectedFiles,
|
||||
}) : super(key: key);
|
||||
|
||||
|
@ -33,7 +30,6 @@ class HomeGalleryWidget extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
final double bottomSafeArea = MediaQuery.of(context).padding.bottom;
|
||||
final gallery = Gallery(
|
||||
intentAction: intentAction,
|
||||
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
|
||||
final ownerID = Configuration.instance.getUserID();
|
||||
final hasSelectedAllForBackup =
|
||||
|
|
|
@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:media_extension/media_extension_action_types.dart';
|
||||
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
||||
import 'package:move_to_background/move_to_background.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
|
@ -49,12 +48,9 @@ import 'package:uni_links/uni_links.dart';
|
|||
|
||||
class HomeWidget extends StatefulWidget {
|
||||
const HomeWidget({
|
||||
this.intentAction = IntentAction.main,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
final IntentAction intentAction;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HomeWidgetState();
|
||||
}
|
||||
|
@ -368,7 +364,6 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
showBackupFolderHook
|
||||
? const StartBackupHookWidget(headerWidget: _headerWidget)
|
||||
: HomeGalleryWidget(
|
||||
intentAction: widget.intentAction,
|
||||
header: _headerWidget,
|
||||
footer: const PreserveFooterWidget(),
|
||||
selectedFiles: _selectedFiles,
|
||||
|
|
|
@ -15,6 +15,7 @@ import 'package:photos/events/files_updated_event.dart';
|
|||
import 'package:photos/extensions/string_ext.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/services/app_lifecycle_service.dart';
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/huge_listview/place_holder_widget.dart';
|
||||
import 'package:photos/ui/viewer/file/detail_page.dart';
|
||||
|
@ -36,7 +37,6 @@ class LazyLoadingGallery extends StatefulWidget {
|
|||
final String? logTag;
|
||||
final Stream<int> currentIndexStream;
|
||||
final int photoGirdSize;
|
||||
final IntentAction intentAction;
|
||||
LazyLoadingGallery(
|
||||
this.files,
|
||||
this.index,
|
||||
|
@ -48,7 +48,6 @@ class LazyLoadingGallery extends StatefulWidget {
|
|||
this.currentIndexStream, {
|
||||
this.logTag = "",
|
||||
this.photoGirdSize = photoGridSizeDefault,
|
||||
this.intentAction = IntentAction.main,
|
||||
Key? key,
|
||||
}) : super(key: key ?? UniqueKey());
|
||||
|
||||
|
@ -262,7 +261,6 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
|
|||
_toggleSelectAllFromDay,
|
||||
_areAllFromDaySelected,
|
||||
widget.photoGirdSize,
|
||||
intentAction: widget.intentAction,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -291,7 +289,6 @@ class LazyLoadingGridView extends StatefulWidget {
|
|||
final ValueNotifier toggleSelectAllFromDay;
|
||||
final ValueNotifier areAllFilesSelected;
|
||||
final int? photoGridSize;
|
||||
final IntentAction intentAction;
|
||||
|
||||
LazyLoadingGridView(
|
||||
this.tag,
|
||||
|
@ -303,7 +300,6 @@ class LazyLoadingGridView extends StatefulWidget {
|
|||
this.toggleSelectAllFromDay,
|
||||
this.areAllFilesSelected,
|
||||
this.photoGridSize, {
|
||||
this.intentAction = IntentAction.main,
|
||||
Key? key,
|
||||
}) : super(key: key ?? UniqueKey());
|
||||
|
||||
|
@ -430,7 +426,7 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
|||
if (widget.selectedFiles.files.isNotEmpty) {
|
||||
_selectFile(file);
|
||||
} else {
|
||||
if (widget.intentAction == IntentAction.pick) {
|
||||
if (AppLifecycleService.instance.intentAction == IntentAction.pick) {
|
||||
final ioFile = await getFile(file);
|
||||
_mediaExtensionPlugin.setResult("file://${ioFile!.path}");
|
||||
} else {
|
||||
|
@ -439,8 +435,10 @@ class _LazyLoadingGridViewState extends State<LazyLoadingGridView> {
|
|||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
if (AppLifecycleService.instance.intentAction == IntentAction.main) {
|
||||
HapticFeedback.lightImpact();
|
||||
_selectFile(file);
|
||||
}
|
||||
},
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'dart:async';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:media_extension/media_extension_action_types.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/ente_theme_data.dart';
|
||||
|
@ -29,7 +28,6 @@ typedef GalleryLoader = Future<FileLoadResult> Function(
|
|||
});
|
||||
|
||||
class Gallery extends StatefulWidget {
|
||||
final IntentAction intentAction;
|
||||
final GalleryLoader asyncLoader;
|
||||
final List<File>? initialFiles;
|
||||
final Stream<FilesUpdatedEvent>? reloadEvent;
|
||||
|
@ -44,7 +42,6 @@ class Gallery extends StatefulWidget {
|
|||
final double scrollBottomSafeArea;
|
||||
|
||||
const Gallery({
|
||||
this.intentAction = IntentAction.main,
|
||||
required this.asyncLoader,
|
||||
required this.selectedFiles,
|
||||
required this.tagPrefix,
|
||||
|
@ -251,7 +248,6 @@ class _GalleryState extends State<Gallery> {
|
|||
.map((event) => event.index),
|
||||
logTag: _logTag,
|
||||
photoGirdSize: _photoGridSize,
|
||||
intentAction: widget.intentAction,
|
||||
);
|
||||
if (widget.header != null && index == 0) {
|
||||
gallery = Column(children: [widget.header!, gallery]);
|
||||
|
|
Loading…
Reference in a new issue