WIP Share media refactoring
This commit is contained in:
		| @@ -48,6 +48,7 @@ | ||||
|                 <action android:name="android.intent.action.MAIN"/> | ||||
|                 <category android:name="android.intent.category.LAUNCHER"/> | ||||
|             </intent-filter> | ||||
|  | ||||
|             <intent-filter android:autoVerify="true"> | ||||
|                 <action android:name="android.intent.action.VIEW" /> | ||||
|                 <category android:name="android.intent.category.DEFAULT" /> | ||||
| @@ -56,6 +57,11 @@ | ||||
|                 android:scheme="haclient" | ||||
|                 android:host="auth" /> | ||||
|             </intent-filter> | ||||
|             <intent-filter> | ||||
|                 <action android:name="android.intent.action.SEND"/> | ||||
|                 <category android:name="android.intent.category.DEFAULT"/> | ||||
|                 <data android:mimeType="text/plain"/> | ||||
|             </intent-filter> | ||||
|         </activity> | ||||
|  | ||||
|         <service | ||||
|   | ||||
| @@ -3,9 +3,8 @@ package com.keyboardcrumbs.hassclient; | ||||
| import android.os.Bundle; | ||||
| import io.flutter.app.FlutterActivity; | ||||
| import io.flutter.plugins.GeneratedPluginRegistrant; | ||||
| import io.flutter.plugins.share.FlutterShareReceiverActivity; | ||||
|  | ||||
| public class MainActivity extends FlutterShareReceiverActivity { | ||||
| public class MainActivity extends FlutterActivity { | ||||
|    | ||||
|   @Override | ||||
|   protected void onCreate(Bundle savedInstanceState) { | ||||
|   | ||||
| @@ -22,8 +22,7 @@ import 'package:device_info/device_info.dart'; | ||||
| import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||||
| import 'package:in_app_purchase/in_app_purchase.dart'; | ||||
| import 'plugins/circular_slider/single_circular_slider.dart'; | ||||
| import 'package:share/receive_share_state.dart'; | ||||
| import 'package:share/share.dart'; | ||||
| import 'package:receive_sharing_intent/receive_sharing_intent.dart'; | ||||
| import 'plugins/dynamic_multi_column_layout.dart'; | ||||
| import 'plugins/spoiler_card.dart'; | ||||
| import 'package:uni_links/uni_links.dart'; | ||||
|   | ||||
| @@ -9,7 +9,7 @@ class MainPage extends StatefulWidget { | ||||
|   _MainPageState createState() => new _MainPageState(); | ||||
| } | ||||
|  | ||||
| class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObserver, TickerProviderStateMixin { | ||||
| class _MainPageState extends State<MainPage> with WidgetsBindingObserver, TickerProviderStateMixin { | ||||
|  | ||||
|   StreamSubscription<List<PurchaseDetails>> _subscription; | ||||
|   StreamSubscription _stateSubscription; | ||||
| @@ -22,6 +22,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | ||||
|   StreamSubscription _showPopupMessageSubscription; | ||||
|   StreamSubscription _reloadUISubscription; | ||||
|   StreamSubscription _showPageSubscription; | ||||
|   StreamSubscription _intentDataStreamSubscription; | ||||
|   int _previousViewCount; | ||||
|   bool _showLoginButton = false; | ||||
|   bool _preventAppRefresh = false; | ||||
| @@ -40,7 +41,6 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | ||||
|       updateDeviceLocationIsolate, | ||||
|       isInDebugMode: false | ||||
|     ); | ||||
|     enableShareReceiving(); | ||||
|     WidgetsBinding.instance.addObserver(this); | ||||
|  | ||||
|     _firebaseMessaging.configure( | ||||
| @@ -60,6 +60,13 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | ||||
|  | ||||
|     _firebaseMessaging.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true)); | ||||
|  | ||||
|     _intentDataStreamSubscription = ReceiveSharingIntent.getTextStream().listen((String value) { | ||||
|       Logger.d("[SHARED] Got share from stream: $value"); | ||||
|       _handleShare(value); | ||||
|     }, onError: (err) { | ||||
|       Logger.w("[SHARE] getLinkStream error: $err"); | ||||
|     }); | ||||
|  | ||||
|     // initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project | ||||
|     var initializationSettingsAndroid = | ||||
|     new AndroidInitializationSettings('mini_icon'); | ||||
| @@ -81,12 +88,6 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | ||||
|     _fullLoad(); | ||||
|   } | ||||
|  | ||||
|   @override void receiveShare(Share shared) { | ||||
|     if (shared.mimeType == ShareType.TYPE_PLAIN_TEXT) { | ||||
|       _savedSharedText = shared.text; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   Future onSelectNotification(String payload) async { | ||||
|     if (payload != null) { | ||||
|       Logger.d('Notification clicked: ' + payload); | ||||
| @@ -131,12 +132,17 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   _fetchData() async { | ||||
|     if (_savedSharedText != null && !HomeAssistant().isNoEntities) { | ||||
|       Logger.d("Got shared text: $_savedSharedText"); | ||||
|       Navigator.pushNamed(context, "/play-media", arguments: {"url": _savedSharedText}); | ||||
|       _savedSharedText = null; | ||||
|   _handleShare(String text) { | ||||
|     if (text != null && !HomeAssistant().isNoEntities) { | ||||
|       Navigator.pushNamed(context, "/play-media", arguments: {"url": text}); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   _fetchData() async { | ||||
|     ReceiveSharingIntent.getInitialText().then((String value) { | ||||
|       Logger.d("[SHARED] Got initial share: $value"); | ||||
|       _handleShare(value); | ||||
|     }); | ||||
|     await HomeAssistant().fetchData().then((_) { | ||||
|       _hideBottomBar(); | ||||
|       if (_entityToShow != null) { | ||||
| @@ -918,6 +924,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | ||||
|     _subscription?.cancel(); | ||||
|     _showPageSubscription?.cancel(); | ||||
|     _reloadUISubscription?.cancel(); | ||||
|     _intentDataStreamSubscription?.cancel(); | ||||
|     //TODO disconnect | ||||
|     //widget.homeAssistant?.disconnect(); | ||||
|     super.dispose(); | ||||
|   | ||||
| @@ -30,9 +30,8 @@ dependencies: | ||||
|   workmanager: ^0.1.5 | ||||
|   battery: ^0.3.1+1 | ||||
|   sentry: ^2.3.1 | ||||
|   share: | ||||
|     git: | ||||
|       url: https://github.com/d-silveira/flutter-share.git | ||||
|   receive_sharing_intent: ^1.3.2 | ||||
|    | ||||
|  | ||||
| dev_dependencies: | ||||
|   flutter_test: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user