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