Compare commits
	
		
			6 Commits
		
	
	
		
			1.1.0-beta
			...
			1.1.0-beta
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | f0090d522d | ||
|  | edbfd8359b | ||
|  | 2702bb254a | ||
|  | ca7b6ed550 | ||
|  | fb00b5d9ff | ||
|  | 7ffba397ce | 
| @@ -16,6 +16,8 @@ import io.flutter.plugin.common.MethodChannel; | |||||||
|  |  | ||||||
| import com.google.android.gms.tasks.OnCompleteListener; | import com.google.android.gms.tasks.OnCompleteListener; | ||||||
| import com.google.android.gms.tasks.Task; | import com.google.android.gms.tasks.Task; | ||||||
|  | import com.google.android.gms.common.GoogleApiAvailability; | ||||||
|  | import com.google.android.gms.common.ConnectionResult; | ||||||
| import com.google.firebase.iid.FirebaseInstanceId; | import com.google.firebase.iid.FirebaseInstanceId; | ||||||
| import com.google.firebase.iid.InstanceIdResult; | import com.google.firebase.iid.InstanceIdResult; | ||||||
| import com.google.firebase.messaging.FirebaseMessaging; | import com.google.firebase.messaging.FirebaseMessaging; | ||||||
| @@ -31,13 +33,14 @@ public class MainActivity extends FlutterActivity { | |||||||
|             new MethodChannel.MethodCallHandler() { |             new MethodChannel.MethodCallHandler() { | ||||||
|                 @Override |                 @Override | ||||||
|                 public void onMethodCall(MethodCall call, MethodChannel.Result result) { |                 public void onMethodCall(MethodCall call, MethodChannel.Result result) { | ||||||
|  |                     Context context = getActivity(); | ||||||
|                     if (call.method.equals("getFCMToken")) { |                     if (call.method.equals("getFCMToken")) { | ||||||
|  |                         if (checkPlayServices()) { | ||||||
|                             FirebaseInstanceId.getInstance().getInstanceId() |                             FirebaseInstanceId.getInstance().getInstanceId() | ||||||
|                             .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { |                             .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { | ||||||
|                                 @Override |                                 @Override | ||||||
|                                 public void onComplete(@NonNull Task<InstanceIdResult> task) { |                                 public void onComplete(@NonNull Task<InstanceIdResult> task) { | ||||||
|                                     if (task.isSuccessful()) { |                                     if (task.isSuccessful()) { | ||||||
|                                         Context context = getActivity(); |  | ||||||
|                                         String token = task.getResult().getToken(); |                                         String token = task.getResult().getToken(); | ||||||
|                                         UpdateTokenTask updateTokenTask = new UpdateTokenTask(context); |                                         UpdateTokenTask updateTokenTask = new UpdateTokenTask(context); | ||||||
|                                         updateTokenTask.execute(token); |                                         updateTokenTask.execute(token); | ||||||
| @@ -47,12 +50,19 @@ public class MainActivity extends FlutterActivity { | |||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
|                             }); |                             }); | ||||||
|  |                         } else { | ||||||
|  |                             result.error("google_play_service_error", "Google Play Services unavailable", null); | ||||||
|  |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private boolean checkPlayServices() { | ||||||
|  |         return (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected void onCreate(Bundle savedInstanceState) { |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|         super.onCreate(savedInstanceState); |         super.onCreate(savedInstanceState); | ||||||
|   | |||||||
| @@ -38,6 +38,15 @@ class CardData { | |||||||
|           case CardType.LIGHT: |           case CardType.LIGHT: | ||||||
|             return LightCardData(rawData); |             return LightCardData(rawData); | ||||||
|             break; |             break; | ||||||
|  |           case CardType.PICTURE_ELEMENTS: | ||||||
|  |             //TODO temporary solution  | ||||||
|  |             if (rawData.containsKey('camera_image')) { | ||||||
|  |               rawData['entity'] = rawData['camera_image']; | ||||||
|  |               return ButtonCardData(rawData); | ||||||
|  |             } else { | ||||||
|  |               return CardData(null); | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|           case CardType.ENTITY_BUTTON: |           case CardType.ENTITY_BUTTON: | ||||||
|           case CardType.BUTTON: |           case CardType.BUTTON: | ||||||
|           case CardType.PICTURE_ENTITY: |           case CardType.PICTURE_ENTITY: | ||||||
|   | |||||||
| @@ -16,7 +16,8 @@ import 'package:http/http.dart' as http; | |||||||
| import 'package:charts_flutter/flutter.dart' as charts; | import 'package:charts_flutter/flutter.dart' as charts; | ||||||
| import 'package:flutter_markdown/flutter_markdown.dart'; | import 'package:flutter_markdown/flutter_markdown.dart'; | ||||||
| import 'package:flutter_custom_tabs/flutter_custom_tabs.dart'; | import 'package:flutter_custom_tabs/flutter_custom_tabs.dart'; | ||||||
| import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | import 'package:hive/hive.dart'; | ||||||
|  | import 'package:hive_flutter/hive_flutter.dart'; | ||||||
| import 'package:device_info/device_info.dart'; | import 'package:device_info/device_info.dart'; | ||||||
| import 'package:in_app_purchase/in_app_purchase.dart'; | import 'package:in_app_purchase/in_app_purchase.dart'; | ||||||
| import 'plugins/dynamic_multi_column_layout.dart'; | import 'plugins/dynamic_multi_column_layout.dart'; | ||||||
| @@ -184,7 +185,8 @@ void main() async { | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   WidgetsFlutterBinding.ensureInitialized(); |   WidgetsFlutterBinding.ensureInitialized(); | ||||||
|   AppSettings().loadAppTheme(); |   await AppSettings().loadAppTheme(); | ||||||
|  |   await Hive.initFlutter(); | ||||||
|  |  | ||||||
|   runZoned(() { |   runZoned(() { | ||||||
|       runApp(new HAClientApp( |       runApp(new HAClientApp( | ||||||
|   | |||||||
| @@ -2,6 +2,10 @@ part of '../main.dart'; | |||||||
|  |  | ||||||
| class AppSettings { | class AppSettings { | ||||||
|  |  | ||||||
|  |   static const DEFAULT_HIVE_BOX = 'defaultSettingsBox'; | ||||||
|  |  | ||||||
|  |   static const AUTH_TOKEN_KEY = 'llt'; | ||||||
|  |  | ||||||
|   static final AppSettings _instance = AppSettings._internal(); |   static final AppSettings _instance = AppSettings._internal(); | ||||||
|  |  | ||||||
|   factory AppSettings() { |   factory AppSettings() { | ||||||
| @@ -37,6 +41,7 @@ class AppSettings { | |||||||
|  |  | ||||||
|   Future load(bool full) async { |   Future load(bool full) async { | ||||||
|     if (full) { |     if (full) { | ||||||
|  |       await Hive.openBox(DEFAULT_HIVE_BOX); | ||||||
|       Logger.d('Loading settings...'); |       Logger.d('Loading settings...'); | ||||||
|       SharedPreferences prefs = await SharedPreferences.getInstance(); |       SharedPreferences prefs = await SharedPreferences.getInstance(); | ||||||
|       _domain = prefs.getString('hassio-domain'); |       _domain = prefs.getString('hassio-domain'); | ||||||
| @@ -52,18 +57,11 @@ class AppSettings { | |||||||
|       locationUpdateInterval = Duration(minutes: prefs.getInt("location-interval") ?? |       locationUpdateInterval = Duration(minutes: prefs.getInt("location-interval") ?? | ||||||
|         defaultLocationUpdateIntervalMinutes); |         defaultLocationUpdateIntervalMinutes); | ||||||
|       locationTrackingEnabled = prefs.getBool("location-enabled") ?? false; |       locationTrackingEnabled = prefs.getBool("location-enabled") ?? false; | ||||||
|       Logger.d('Done. $_domain:$_port'); |       longLivedToken = Hive.box(DEFAULT_HIVE_BOX).get(AUTH_TOKEN_KEY); | ||||||
|       try { |  | ||||||
|         final storage = new FlutterSecureStorage(); |  | ||||||
|         longLivedToken = await storage.read(key: "hacl_llt"); |  | ||||||
|         Logger.d("Long-lived token read successful"); |  | ||||||
|       oauthUrl = "$httpWebHost/auth/authorize?client_id=${Uri.encodeComponent( |       oauthUrl = "$httpWebHost/auth/authorize?client_id=${Uri.encodeComponent( | ||||||
|           'https://ha-client.app')}&redirect_uri=${Uri |           'https://ha-client.app')}&redirect_uri=${Uri | ||||||
|           .encodeComponent( |           .encodeComponent( | ||||||
|           'https://ha-client.app/service/auth_callback.html')}"; |           'https://ha-client.app/service/auth_callback.html')}"; | ||||||
|       } catch (e, stacktrace) { |  | ||||||
|         Logger.e("Error reading secure storage: $e", stacktrace: stacktrace); |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -103,25 +101,13 @@ class AppSettings { | |||||||
|   Future clearTokens() async { |   Future clearTokens() async { | ||||||
|     longLivedToken = null; |     longLivedToken = null; | ||||||
|     tempToken = null; |     tempToken = null; | ||||||
|     try { |     Hive.box(DEFAULT_HIVE_BOX).delete(AUTH_TOKEN_KEY); | ||||||
|       final storage = new FlutterSecureStorage(); |  | ||||||
|       await storage.delete(key: "hacl_llt"); |  | ||||||
|     } catch(e, stacktrace) { |  | ||||||
|       Logger.e("Error clearing tokens: $e", stacktrace: stacktrace); |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Future saveLongLivedToken(token) async { |   Future saveLongLivedToken(token) async { | ||||||
|     longLivedToken = token; |     longLivedToken = token; | ||||||
|     tempToken = null; |     tempToken = null; | ||||||
|     try { |     Hive.box(DEFAULT_HIVE_BOX).put(AUTH_TOKEN_KEY, longLivedToken); | ||||||
|       final storage = new FlutterSecureStorage(); |  | ||||||
|       await storage.write(key: "hacl_llt", value: "$longLivedToken"); |  | ||||||
|       SharedPreferences prefs = await SharedPreferences.getInstance(); |  | ||||||
|       prefs.setBool("oauth-used", true); |  | ||||||
|     } catch(e, stacktrace) { |  | ||||||
|       Logger.e("Error saving long-lived token: $e", stacktrace: stacktrace); |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   bool isNotConfigured() { |   bool isNotConfigured() { | ||||||
|   | |||||||
| @@ -654,6 +654,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker | |||||||
|   @override |   @override | ||||||
|   void dispose() { |   void dispose() { | ||||||
|     WidgetsBinding.instance.removeObserver(this); |     WidgetsBinding.instance.removeObserver(this); | ||||||
|  |     Hive.close(); | ||||||
|     //final flutterWebviewPlugin = new FlutterWebviewPlugin(); |     //final flutterWebviewPlugin = new FlutterWebviewPlugin(); | ||||||
|     //flutterWebviewPlugin.dispose(); |     //flutterWebviewPlugin.dispose(); | ||||||
|     _viewsTabController?.dispose(); |     _viewsTabController?.dispose(); | ||||||
|   | |||||||
| @@ -73,11 +73,9 @@ class TokenLoginPopup extends Popup { | |||||||
|                     padding: EdgeInsets.all(20), |                     padding: EdgeInsets.all(20), | ||||||
|                       child: TextFormField( |                       child: TextFormField( | ||||||
|                       onSaved: (newValue) { |                       onSaved: (newValue) { | ||||||
|                         final storage = new FlutterSecureStorage(); |                         Hive.box(AppSettings.DEFAULT_HIVE_BOX).put(AppSettings.AUTH_TOKEN_KEY, newValue.trim()); | ||||||
|                         storage.write(key: "hacl_llt", value: newValue.trim()).then((_) { |  | ||||||
|                         Navigator.of(context).pop(); |                         Navigator.of(context).pop(); | ||||||
|                         eventBus.fire(SettingsChangedEvent(true)); |                         eventBus.fire(SettingsChangedEvent(true)); | ||||||
|                         }); |  | ||||||
|                       }, |                       }, | ||||||
|                       decoration: InputDecoration( |                       decoration: InputDecoration( | ||||||
|                         hintText: 'Please enter long-lived token', |                         hintText: 'Please enter long-lived token', | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| name: hass_client | name: hass_client | ||||||
| description: Home Assistant Android Client | description: Home Assistant Android Client | ||||||
|  |  | ||||||
| version: 0.0.0+1151 | version: 1.1.0+1153 | ||||||
|  |  | ||||||
|  |  | ||||||
| environment: | environment: | ||||||
| @@ -23,7 +23,8 @@ dependencies: | |||||||
|   flutter_custom_tabs: ^0.6.0 |   flutter_custom_tabs: ^0.6.0 | ||||||
|   flutter_webview_plugin: ^0.3.10+1 |   flutter_webview_plugin: ^0.3.10+1 | ||||||
|   webview_flutter: ^0.3.19+7 |   webview_flutter: ^0.3.19+7 | ||||||
|   flutter_secure_storage: ^3.3.3 |   hive: ^1.4.1+1 | ||||||
|  |   hive_flutter: ^0.3.0+2 | ||||||
|   device_info: ^0.4.1+4 |   device_info: ^0.4.1+4 | ||||||
|   geolocator: ^5.3.1 |   geolocator: ^5.3.1 | ||||||
|   workmanager: ^0.2.2 |   workmanager: ^0.2.2 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user