diff --git a/res/values/strings.xml b/res/values/strings.xml index 012aadd661..71a424c084 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1118,8 +1118,14 @@ Help - Your build of Signal has expired! - Messages will no longer send successfully, please update to the most recent version. + Your version of Signal is outdated + + Your version of Signal will expire in 1 day. Tap to update to the most recent version. + Your version of Signal will expire in %d days. Tap to update to the most recent version. + + Your version of Signal will expire today. Tap to update to the most recent version. + Your version of Signal has expired! + Messages will no longer send successfully. Tap to update to the most recent version. UPDATE Use as default SMS app Tap to make Signal your default SMS app. diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index 1bc1e5a017..1d08005bb3 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -54,6 +54,7 @@ import android.view.ViewGroup; import org.thoughtcrime.securesms.ConversationListAdapter.ItemClickListener; import org.thoughtcrime.securesms.components.reminder.DefaultSmsReminder; import org.thoughtcrime.securesms.components.reminder.ExpiredBuildReminder; +import org.thoughtcrime.securesms.components.reminder.OutdatedBuildReminder; import org.thoughtcrime.securesms.components.reminder.PushRegistrationReminder; import org.thoughtcrime.securesms.components.reminder.Reminder; import org.thoughtcrime.securesms.components.reminder.ReminderView; @@ -166,8 +167,10 @@ public class ConversationListFragment extends Fragment new AsyncTask>() { @Override protected Optional doInBackground(Context... params) { final Context context = params[0]; - if (ExpiredBuildReminder.isEligible(context)) { + if (ExpiredBuildReminder.isEligible()) { return Optional.of(new ExpiredBuildReminder(context)); + } else if (OutdatedBuildReminder.isEligible()) { + return Optional.of(new OutdatedBuildReminder(context)); } else if (DefaultSmsReminder.isEligible(context)) { return Optional.of(new DefaultSmsReminder(context)); } else if (Util.isDefaultSmsProvider(context) && SystemSmsImportReminder.isEligible(context)) { diff --git a/src/org/thoughtcrime/securesms/components/reminder/ExpiredBuildReminder.java b/src/org/thoughtcrime/securesms/components/reminder/ExpiredBuildReminder.java index 7de9c41626..b74a93c76f 100644 --- a/src/org/thoughtcrime/securesms/components/reminder/ExpiredBuildReminder.java +++ b/src/org/thoughtcrime/securesms/components/reminder/ExpiredBuildReminder.java @@ -31,8 +31,8 @@ public class ExpiredBuildReminder extends Reminder { return false; } - public static boolean isEligible(Context context) { - return !Util.isBuildFresh(); + public static boolean isEligible() { + return Util.getDaysTillBuildExpiry() <= 0; } } diff --git a/src/org/thoughtcrime/securesms/components/reminder/OutdatedBuildReminder.java b/src/org/thoughtcrime/securesms/components/reminder/OutdatedBuildReminder.java new file mode 100644 index 0000000000..40a0c30fdf --- /dev/null +++ b/src/org/thoughtcrime/securesms/components/reminder/OutdatedBuildReminder.java @@ -0,0 +1,45 @@ +package org.thoughtcrime.securesms.components.reminder; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.view.View; + +import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.util.Util; + +public class OutdatedBuildReminder extends Reminder { + + public OutdatedBuildReminder(final Context context) { + super(context.getString(R.string.reminder_header_outdated_build), + getPluralsText(context)); + setOkListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + try { + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName()))); + } catch (android.content.ActivityNotFoundException anfe) { + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName()))); + } + } + }); + } + + private static CharSequence getPluralsText(final Context context) { + int days = Util.getDaysTillBuildExpiry() - 1; + if (days == 0) { + return context.getString(R.string.reminder_header_outdated_build_details_today); + } + return context.getResources().getQuantityString(R.plurals.reminder_header_outdated_build_details, days, days); + } + + @Override + public boolean isDismissable() { + return false; + } + + public static boolean isEligible() { + return Util.getDaysTillBuildExpiry() <= 10; + } + +} diff --git a/src/org/thoughtcrime/securesms/jobs/SendJob.java b/src/org/thoughtcrime/securesms/jobs/SendJob.java index 382dc59fcb..c0c632c8ac 100644 --- a/src/org/thoughtcrime/securesms/jobs/SendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/SendJob.java @@ -34,7 +34,7 @@ public abstract class SendJob extends MasterSecretJob { @Override public final void onRun(MasterSecret masterSecret) throws Exception { - if (!Util.isBuildFresh()) { + if (Util.getDaysTillBuildExpiry() <= 0) { throw new TextSecureExpiredException(String.format("TextSecure expired (build %d, now %d)", BuildConfig.BUILD_TIMESTAMP, System.currentTimeMillis())); diff --git a/src/org/thoughtcrime/securesms/util/Util.java b/src/org/thoughtcrime/securesms/util/Util.java index c25ffcab40..f0c40af315 100644 --- a/src/org/thoughtcrime/securesms/util/Util.java +++ b/src/org/thoughtcrime/securesms/util/Util.java @@ -327,8 +327,9 @@ public class Util { } } - public static boolean isBuildFresh() { - return BuildConfig.BUILD_TIMESTAMP + TimeUnit.DAYS.toMillis(90) > System.currentTimeMillis(); + public static int getDaysTillBuildExpiry() { + int age = (int)TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - BuildConfig.BUILD_TIMESTAMP); + return 90 - age; } @TargetApi(VERSION_CODES.LOLLIPOP)