mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 10:28:50 +01:00
Open enhanced photo browser from notification
This commit is contained in:
parent
ef4daf552b
commit
80689fa431
4 changed files with 100 additions and 12 deletions
|
@ -1,12 +1,35 @@
|
|||
package com.nkming.nc_photos
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.annotation.NonNull
|
||||
import com.nkming.nc_photos.plugin.NcPhotosPlugin
|
||||
import com.nkming.nc_photos.plugin.UriUtil
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.EventChannel
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import java.net.URLEncoder
|
||||
|
||||
class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler {
|
||||
companion object {
|
||||
private const val METHOD_CHANNEL = "com.nkming.nc_photos/activity"
|
||||
|
||||
private const val TAG = "MainActivity"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (intent.action == NcPhotosPlugin.ACTION_SHOW_IMAGE_PROCESSOR_RESULT) {
|
||||
val route = getRouteFromImageProcessorResult(intent) ?: return
|
||||
Log.i(TAG, "Initial route: $route")
|
||||
_initialRoute = route
|
||||
}
|
||||
}
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
MethodChannel(
|
||||
|
@ -21,6 +44,9 @@ class MainActivity : FlutterActivity() {
|
|||
).setMethodCallHandler(
|
||||
ShareChannelHandler(this)
|
||||
)
|
||||
MethodChannel(
|
||||
flutterEngine.dartExecutor.binaryMessenger, METHOD_CHANNEL
|
||||
).setMethodCallHandler(this)
|
||||
|
||||
EventChannel(
|
||||
flutterEngine.dartExecutor.binaryMessenger,
|
||||
|
@ -29,4 +55,45 @@ class MainActivity : FlutterActivity() {
|
|||
DownloadEventCancelChannelHandler(this)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
if (intent.action == NcPhotosPlugin.ACTION_SHOW_IMAGE_PROCESSOR_RESULT) {
|
||||
val route = getRouteFromImageProcessorResult(intent) ?: return
|
||||
Log.i(TAG, "Navigate to route: $route")
|
||||
flutterEngine?.navigationChannel?.pushRoute(route)
|
||||
} else {
|
||||
super.onNewIntent(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||
when (call.method) {
|
||||
"consumeInitialRoute" -> {
|
||||
result.success(_initialRoute)
|
||||
_initialRoute = null
|
||||
}
|
||||
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getRouteFromImageProcessorResult(intent: Intent): String? {
|
||||
val resultUri =
|
||||
intent.getParcelableExtra<Uri>(
|
||||
NcPhotosPlugin.EXTRA_IMAGE_RESULT_URI
|
||||
)
|
||||
if (resultUri == null) {
|
||||
Log.e(TAG, "Image result uri == null")
|
||||
return null
|
||||
}
|
||||
val filename = UriUtil.resolveFilename(this, resultUri)?.let {
|
||||
URLEncoder.encode(it, Charsets.UTF_8.toString())
|
||||
}
|
||||
return StringBuilder().apply {
|
||||
append("/enhanced-photo-browser?")
|
||||
if (filename != null) append("filename=$filename")
|
||||
}.toString()
|
||||
}
|
||||
|
||||
private var _initialRoute: String? = null
|
||||
}
|
||||
|
|
8
app/lib/mobile/android/activity.dart
Normal file
8
app/lib/mobile/android/activity.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
import 'package:flutter/services.dart';
|
||||
|
||||
class Activity {
|
||||
static Future<String?> consumeInitialRoute() =>
|
||||
_methodChannel.invokeMethod("consumeInitialRoute");
|
||||
|
||||
static const _methodChannel = MethodChannel("com.nkming.nc_photos/activity");
|
||||
}
|
|
@ -508,6 +508,12 @@ class _MyAppState extends State<MyApp>
|
|||
settings.arguments != null) {
|
||||
final args = settings.arguments as EnhancedPhotoBrowserArguments;
|
||||
return EnhancedPhotoBrowser.buildRoute(args);
|
||||
} else if (settings.name
|
||||
?.startsWith("${EnhancedPhotoBrowser.routeName}?") ==
|
||||
true) {
|
||||
final queries = Uri.parse(settings.name!).queryParameters;
|
||||
final args = EnhancedPhotoBrowserArguments(queries["filename"]);
|
||||
return EnhancedPhotoBrowser.buildRoute(args);
|
||||
}
|
||||
} catch (e) {
|
||||
_log.severe(
|
||||
|
|
|
@ -7,6 +7,8 @@ import 'package:nc_photos/app_localizations.dart';
|
|||
import 'package:nc_photos/changelog.dart' as changelog;
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/mobile/android/activity.dart';
|
||||
import 'package:nc_photos/platform/k.dart' as platform_k;
|
||||
import 'package:nc_photos/pref.dart';
|
||||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:nc_photos/theme.dart';
|
||||
|
@ -80,18 +82,23 @@ class _SplashState extends State<Splash> {
|
|||
);
|
||||
}
|
||||
|
||||
void _initTimedExit() {
|
||||
Future.delayed(const Duration(seconds: 1)).then((_) {
|
||||
final account = Pref().getCurrentAccount();
|
||||
if (isNeedSetup()) {
|
||||
Navigator.pushReplacementNamed(context, Setup.routeName);
|
||||
} else if (account == null) {
|
||||
Navigator.pushReplacementNamed(context, SignIn.routeName);
|
||||
} else {
|
||||
Navigator.pushReplacementNamed(context, Home.routeName,
|
||||
arguments: HomeArguments(account));
|
||||
Future<void> _initTimedExit() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
final account = Pref().getCurrentAccount();
|
||||
if (isNeedSetup()) {
|
||||
Navigator.pushReplacementNamed(context, Setup.routeName);
|
||||
} else if (account == null) {
|
||||
Navigator.pushReplacementNamed(context, SignIn.routeName);
|
||||
} else {
|
||||
Navigator.pushReplacementNamed(context, Home.routeName,
|
||||
arguments: HomeArguments(account));
|
||||
if (platform_k.isAndroid) {
|
||||
final initialRoute = await Activity.consumeInitialRoute();
|
||||
if (initialRoute != null) {
|
||||
Navigator.pushNamed(context, initialRoute);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool _shouldUpgrade() {
|
||||
|
|
Loading…
Reference in a new issue