Skip to content

Commit

Permalink
Add banner warning about API 19 deprecation.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal authored and alex-signal committed Jan 12, 2023
1 parent 7617a16 commit 564b9f4
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.components.reminder

import android.content.Context
import android.os.Build
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.util.Util
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

/**
* Shown when a user has API 19.
*/
class Api19Reminder(context: Context) : Reminder(null, context.getString(R.string.API19Reminder_banner_message, getExpireDate())) {

init {
addAction(
Action(
context.getString(R.string.API19Reminder_learn_more),
R.id.reminder_action_api_19_learn_more
)
)
}

override fun isDismissable(): Boolean {
return false
}

override fun getImportance(): Importance {
return Importance.TERMINAL
}

companion object {
@JvmStatic
fun isEligible(): Boolean {
return Build.VERSION.SDK_INT < 21 && !ExpiredBuildReminder.isEligible()
}

fun getExpireDate(): String {
val formatter = SimpleDateFormat("MMMM d", Locale.getDefault())
val expireDate = Date(System.currentTimeMillis() + Util.getTimeUntilBuildExpiry())
return formatter.format(expireDate)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.thoughtcrime.securesms.components.reminder;

import android.content.Context;
import android.os.Build;

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.PlayStoreUtil;

import java.util.List;
Expand All @@ -17,10 +19,15 @@
public class ExpiredBuildReminder extends Reminder {

public ExpiredBuildReminder(final Context context) {
super(null, context.getString(R.string.ExpiredBuildReminder_this_version_of_signal_has_expired));

setOkListener(v -> PlayStoreUtil.openPlayStoreOrOurApkDownloadPage(context));
addAction(new Action(context.getString(R.string.ExpiredBuildReminder_update_now), R.id.reminder_action_update_now));
super(null, Build.VERSION.SDK_INT < 21
? context.getString(R.string.ExpiredBuildReminder_api_19_message)
: context.getString(R.string.ExpiredBuildReminder_this_version_of_signal_has_expired));

if (Build.VERSION.SDK_INT < 21) {
addAction(new Action(context.getString(R.string.API19Reminder_learn_more), R.id.reminder_action_api_19_learn_more));
} else {
addAction(new Action(context.getString(R.string.ExpiredBuildReminder_update_now), R.id.reminder_action_update_now));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public Action(CharSequence title, @IdRes int actionId) {
this.actionId = actionId;
}

CharSequence getTitle() {
public CharSequence getTitle() {
return title;
}

int getActionId() {
public int getActionId() {
return actionId;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,8 @@ private void handleReminderAction(@IdRes int reminderActionId) {
InsightsLauncher.showInsightsDashboard(getChildFragmentManager());
} else if (reminderActionId == R.id.reminder_action_update_now) {
PlayStoreUtil.openPlayStoreOrOurApkDownloadPage(requireContext());
} else if (reminderActionId == R.id.reminder_action_api_19_learn_more) {
CommunicationActions.openBrowserLink(requireContext(), "https://support.signal.org/hc/articles/5109141421850");
} else {
throw new IllegalArgumentException("Unknown ID: " + reminderActionId);
}
Expand Down Expand Up @@ -2974,6 +2976,11 @@ private void sendMessage(@Nullable String metricId) {
}

private void sendMediaMessage(@NonNull MediaSendActivityResult result) {
if (ExpiredBuildReminder.isEligible()) {
showExpiredDialog();
return;
}

long thread = this.threadId;
long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
QuoteModel quote = result.isViewOnce() ? null : inputPanel.getQuote().orElse(null);
Expand Down Expand Up @@ -3052,6 +3059,11 @@ private ListenableFuture<Void> sendMediaMessage(@NonNull RecipientId recipientId
final boolean clearComposeBox,
final @Nullable String metricId)
{
if (ExpiredBuildReminder.isEligible()) {
showExpiredDialog();
return new SettableFuture<>(null);
}

if (!viewModel.isDefaultSmsApplication() && sendType.usesSmsTransport() && recipient.get().hasSmsAddress()) {
showDefaultSmsPrompt();
return new SettableFuture<>(null);
Expand Down Expand Up @@ -3130,6 +3142,11 @@ private ListenableFuture<Void> sendMediaMessage(@NonNull RecipientId recipientId
private void sendTextMessage(@NonNull MessageSendType sendType, final long expiresIn, final boolean initiating, final @Nullable String metricId)
throws InvalidMessageException
{
if (ExpiredBuildReminder.isEligible()) {
showExpiredDialog();
return;
}

if (!viewModel.isDefaultSmsApplication() && sendType.usesSmsTransport() && recipient.get().hasSmsAddress()) {
showDefaultSmsPrompt();
return;
Expand Down Expand Up @@ -3172,6 +3189,29 @@ private void showDefaultSmsPrompt() {
.show();
}

private void showExpiredDialog() {
Reminder reminder = new ExpiredBuildReminder(requireContext());

MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext())
.setMessage(reminder.getText())
.setPositiveButton(android.R.string.ok, (d, w) -> d.dismiss());

List<Reminder.Action> actions = reminder.getActions();
if (actions.size() == 1) {
Reminder.Action action = actions.get(0);

builder.setNeutralButton(action.getTitle(), (d, i) -> {
if (action.getActionId() == R.id.reminder_action_update_now) {
PlayStoreUtil.openPlayStoreOrOurApkDownloadPage(requireContext());
} else if (action.getActionId() == R.id.reminder_action_api_19_learn_more) {
CommunicationActions.openBrowserLink(requireContext(), "https://support.signal.org/hc/articles/5109141421850");
}
});
}

builder.show();
}

private void updateToggleButtonState() {
if (inputPanel.isRecordingInLockedMode()) {
buttonToggle.display(sendButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.thoughtcrime.securesms.components.menu.SignalBottomActionBar;
import org.thoughtcrime.securesms.components.menu.SignalContextMenu;
import org.thoughtcrime.securesms.components.registration.PulsingFloatingActionButton;
import org.thoughtcrime.securesms.components.reminder.Api19Reminder;
import org.thoughtcrime.securesms.components.reminder.CdsPermanentErrorReminder;
import org.thoughtcrime.securesms.components.reminder.CdsTemporyErrorReminder;
import org.thoughtcrime.securesms.components.reminder.DozeReminder;
Expand Down Expand Up @@ -158,6 +159,7 @@
import org.thoughtcrime.securesms.util.AppForegroundObserver;
import org.thoughtcrime.securesms.util.AppStartup;
import org.thoughtcrime.securesms.util.BottomSheetUtil;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.ConversationUtil;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.LifecycleDisposable;
Expand Down Expand Up @@ -681,6 +683,8 @@ private void onReminderAction(@IdRes int reminderActionId) {
CdsTemporaryErrorBottomSheet.show(getChildFragmentManager());
} else if (reminderActionId == R.id.reminder_action_cds_permanent_error_learn_more) {
CdsPermanentErrorBottomSheet.show(getChildFragmentManager());
} else if (reminderActionId == R.id.reminder_action_api_19_learn_more) {
CommunicationActions.openBrowserLink(requireContext(), "https://support.signal.org/hc/articles/5109141421850");
}
}

Expand Down Expand Up @@ -942,6 +946,8 @@ private void updateReminders() {
} else if (ServiceOutageReminder.isEligible(context)) {
ApplicationDependencies.getJobManager().add(new ServiceOutageDetectionJob());
return Optional.of(new ServiceOutageReminder(context));
} else if (Api19Reminder.isEligible()) {
return Optional.of(new Api19Reminder(context));
} else if (OutdatedBuildReminder.isEligible()) {
return Optional.of(new OutdatedBuildReminder(context));
} else if (PushRegistrationReminder.isEligible(context)) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<item name="reminder_action_cds_temporary_error_learn_more" type="id" />
<item name="reminder_action_cds_permanent_error_learn_more" type="id" />

<item name="reminder_action_api_19_learn_more" type="id" />

<item name="status_bar_guideline" type="id" />
<item name="navigation_bar_guideline" type="id" />

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@
<string name="ExpiredBuildReminder_this_version_of_signal_has_expired">This version of Signal has expired. Update now to send and receive messages.</string>
<string name="ExpiredBuildReminder_update_now">Update now</string>

<!-- A message in a banner shown at the top of the screen indicating that the user must upgrade their device to use signal. -->
<string name="ExpiredBuildReminder_api_19_message">Signal no longer works on this device. To use Signal again, update your device to a newer version of Android or switch to a newer device.</string>

<!-- PendingGroupJoinRequestsReminder -->
<plurals name="PendingGroupJoinRequestsReminder_d_pending_member_requests">
<item quantity="one">%d pending member request.</item>
Expand Down Expand Up @@ -5482,4 +5485,10 @@
<!-- Displayed in the "clear filter" item in the chat feed if the user opened the filter from the overflow menu -->
<string name="ChatFilter__tip_pull_down">Tip: Pull down on the chat list to filter</string>

<!-- Text for a banner that is shown at the top of the screen letting users know that they're version of signal will soon expire. The placeholder is a date. -->
<string name="API19Reminder_banner_message">Signal will no longer support your device\'s version of Android soon. To keep using Signal, update your device, or switch to a newer device by %1$s.</string>

<!-- Text for a button in a banner shown at the top of the screen that users can click on to get more information. -->
<string name="API19Reminder_learn_more">Learn more</string>

</resources>

0 comments on commit 564b9f4

Please sign in to comment.