From f3b5b09ed01bf6c1f3e4e2e1a78c04336e362b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 4 Nov 2020 10:08:06 +0100 Subject: [PATCH] A few code fixes --- .../model/SCNSettings.java | 20 +++++++++---------- .../view/MainActivity.java | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java index e4f6fd9..59ea5ae 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java @@ -10,7 +10,7 @@ import com.blackforestbytes.simplecloudnotifier.SCNApp; import com.blackforestbytes.simplecloudnotifier.lib.datatypes.Tuple3; import com.blackforestbytes.simplecloudnotifier.lib.string.Str; import com.blackforestbytes.simplecloudnotifier.service.IABService; -import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.installations.FirebaseInstallations; public class SCNSettings { @@ -182,13 +182,13 @@ public class SCNSettings return base + "index.php?preset_user_id="+user_id+"&preset_user_key="+user_key; } - public void setServerToken(String token, View loader) + public void setServerToken(String token, View loader, boolean force) { if (isConnected()) { fcm_token_local = token; save(); - if (!fcm_token_local.equals(fcm_token_server)) ServerCommunication.updateFCMToken(user_id, user_key, fcm_token_local, loader); + if (!fcm_token_local.equals(fcm_token_server) || force) ServerCommunication.updateFCMToken(user_id, user_key, fcm_token_local, loader); } else { @@ -200,13 +200,12 @@ public class SCNSettings } // called at app start - public void work(Activity a) + public void work(Activity a, boolean force) { - FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(a, instanceIdResult -> + FirebaseInstallations.getInstance().getId().addOnSuccessListener(a, newToken -> { - String newToken = instanceIdResult.getToken(); Log.d("FB::GetInstanceId", newToken); - SCNSettings.inst().setServerToken(newToken, null); + SCNSettings.inst().setServerToken(newToken, null, force); }).addOnCompleteListener(r -> { if (isConnected()) ServerCommunication.info(user_id, user_key, null); @@ -232,16 +231,15 @@ public class SCNSettings if (promode_server != promode_local) updateProState(loader); - if (!Str.equals(fcm_token_local, fcm_token_server)) work(a); + if (!Str.equals(fcm_token_local, fcm_token_server)) work(a, false); } else { // get token then register - FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(a, instanceIdResult -> + FirebaseInstallations.getInstance().getId().addOnSuccessListener(a, newToken -> { - String newToken = instanceIdResult.getToken(); Log.d("FB::GetInstanceId", newToken); - SCNSettings.inst().setServerToken(newToken, loader); // does register in here + SCNSettings.inst().setServerToken(newToken, loader, false); // does register in here }).addOnCompleteListener(r -> { if (isConnected()) ServerCommunication.info(user_id, user_key, null); // info again for safety diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java index 0ef5547..33e1a0d 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MainActivity.java @@ -79,7 +79,7 @@ public class MainActivity extends AppCompatActivity SCNApp.register(this); IABService.startup(this); - SCNSettings.inst().work(this); + SCNSettings.inst().work(this, true); } @Override @@ -207,7 +207,7 @@ public class MainActivity extends AppCompatActivity tabLayout.setupWithViewPager(viewPager); - SCNSettings.inst().work(this); + SCNSettings.inst().work(this, true); SCNApp.showToast("Backup imported", Toast.LENGTH_LONG);