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