From 9b6552cb4383af582147286864a16d85c6f67dd3 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 7 Nov 2020 08:27:43 +0100 Subject: [PATCH] separate App-ID for PS Builds and show popup for users having PAM installed --- build.gradle | 4 ++ .../java/eu/siacs/conversations/Config.java | 1 + .../conversations/ui/WelcomeActivity.java | 3 + .../conversations/ui/util/UpdateHelper.java | 68 ++++++++++++++++--- src/main/res/values/strings.xml | 2 + 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index d330587ef..61203742f 100644 --- a/build.gradle +++ b/build.gradle @@ -153,9 +153,13 @@ android { playstore { dimension "distribution" versionNameSuffix "-playstore" + applicationId "im.blabber.messenger" + buildConfigField("boolean", "SHOW_MIGRATION_INFO", 'false') + resValue "string", "applicationId", applicationId } git { dimension "distribution" + buildConfigField("boolean", "SHOW_MIGRATION_INFO", 'true') } } if (project.hasProperty('mStoreFile') && diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index cf333bc63..b0d322b50 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -58,6 +58,7 @@ public final class Config { public static final String CHANNEL_DISCOVERY = "https://search.jabber.network"; public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox public static final boolean SHOW_INTRO = BuildConfig.SHOW_INTRO; + public static final boolean SHOW_MIGRATION_INFO = BuildConfig.SHOW_MIGRATION_INFO; public static final boolean USE_RANDOM_RESOURCE_ON_EVERY_BIND = false; diff --git a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java index a205ebd10..38d4b7136 100644 --- a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.ui; import android.Manifest; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -29,6 +30,7 @@ import eu.siacs.conversations.databinding.WelcomeBinding; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.ui.util.IntroHelper; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.ui.util.UpdateHelper; import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.InstallReferrerUtils; import eu.siacs.conversations.utils.SignupUtils; @@ -124,6 +126,7 @@ public class WelcomeActivity extends XmppActivity implements XmppConnectionServi ab.setDisplayHomeAsUpEnabled(false); } IntroHelper.showIntro(this, false); + UpdateHelper.showPopup(this); if (hasStoragePermission(REQUEST_IMPORT_BACKUP)) { binding.importDatabase.setVisibility(View.VISIBLE); binding.importText.setVisibility(View.VISIBLE); diff --git a/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java b/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java index 66795bf67..7cbe00bcf 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java +++ b/src/main/java/eu/siacs/conversations/ui/util/UpdateHelper.java @@ -1,17 +1,13 @@ package eu.siacs.conversations.ui.util; import android.app.Activity; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; -import android.os.Build; import android.preference.PreferenceManager; -import android.provider.Settings; -import android.util.Log; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; @@ -23,15 +19,11 @@ import java.util.Locale; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; -import eu.siacs.conversations.ui.IntroActivity; import me.drakeet.support.toast.ToastCompat; -import static eu.siacs.conversations.ui.IntroActivity.ACTIVITY; -import static eu.siacs.conversations.ui.IntroActivity.MULTICHAT; - public class UpdateHelper { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); - private static final String UPDATE_DATE = "2020-11-01"; + private static final String INSTALL_DATE = "2020-11-01"; public static void showPopup(Activity activity) { Thread t = new Thread(() -> { @@ -40,7 +32,7 @@ public class UpdateHelper { String Message = "message_shown_" + blabber_message; boolean SHOW_MESSAGE = getPrefs.getBoolean(Message, true); - if (SHOW_MESSAGE && updateInstalled(activity)) { + if (SHOW_MESSAGE && updateInstalled(activity) && Config.SHOW_MIGRATION_INFO) { activity.runOnUiThread(() -> { final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(activity.getString(R.string.title_activity_updater)); @@ -50,6 +42,27 @@ public class UpdateHelper { ); builder.create().show(); }); + } else if (SHOW_MESSAGE && newInstalled(activity) && !Config.SHOW_MIGRATION_INFO && PAMInstalled(activity)) { + activity.runOnUiThread(() -> { + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(activity.getString(R.string.title_activity_updater)); + builder.setMessage(activity.getString(R.string.updated_to_blabber_google)); + builder.setCancelable(false); + builder.setPositiveButton(R.string.link, (dialog, which) -> { + SaveMessageShown(activity, blabber_message); + try { + final Uri uri = Uri.parse(Config.migrationURL); + Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); + activity.startActivity(browserIntent); + } catch (Exception e) { + ToastCompat.makeText(activity, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show(); + } + } + ); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> SaveMessageShown(activity, blabber_message) + ); + builder.create().show(); + }); } }); t.start(); @@ -70,7 +83,7 @@ public class UpdateHelper { e.printStackTrace(); } try { - updateDate = DATE_FORMAT.parse(UPDATE_DATE); + updateDate = DATE_FORMAT.parse(INSTALL_DATE); if (lastUpdate != null) { lastUpdateDate = DATE_FORMAT.parse(lastUpdate); } @@ -80,6 +93,39 @@ public class UpdateHelper { return updateDate != null && lastUpdateDate != null && !firstInstalled.equals(lastUpdate) && lastUpdateDate.getTime() >= updateDate.getTime(); } + private static boolean newInstalled(Activity activity) { + PackageManager pm = activity.getPackageManager(); + PackageInfo packageInfo; + String firstInstalled = null; + Date installDate = null; + Date firstInstalledDate = null; + try { + packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES); + firstInstalled = DATE_FORMAT.format(new Date(packageInfo.firstInstallTime)); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + try { + installDate = DATE_FORMAT.parse(INSTALL_DATE); + if (firstInstalled != null) { + firstInstalledDate = DATE_FORMAT.parse(firstInstalled); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return installDate != null && firstInstalledDate != null && firstInstalledDate.getTime() >= installDate.getTime(); + } + + private static boolean PAMInstalled(Activity activity) { + PackageManager pm = activity.getPackageManager(); + try { + pm.getPackageInfo("de.pixart.messenger", 0); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + public static void SaveMessageShown(Context context, String message) { SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(context); String Message = "message_shown_" + message; diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e16aedfc1..c1b1f5833 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1067,4 +1067,6 @@ Use a custom invidious host Invidious host We have successfully updated Pix-Art Messenger to blabber.im\n\nThe cooperation of the two projects blabber.im and Pix-Art Messenger was expanded in November 2020. In the future, the Android app Pix-Art Messenger will be continued under the name blabber.im.\n\nWhat you can expect:\n- Range of functions remains the same\n- Support chat rooms are merged\n- Colors and logos are adapted to blabber.im\n- App is still available for free in Google Play Store and F-Droid Store\n\nYour blabber.im Team + We have to apologize that we could not update directly to blabber.im. Under the following link you will receive instructions on how to transfer all your profiles from Pix-Art Messenger to blabber.im. + Link