mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Implement new client deprecation UI.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package org.thoughtcrime.securesms.megaphone;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.PlayStoreUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
/**
|
||||
* Shown when a users build fully expires. Controlled by {@link Megaphones.Event#CLIENT_DEPRECATED}.
|
||||
*/
|
||||
public class ClientDeprecatedActivity extends PassphraseRequiredActivity {
|
||||
|
||||
private final DynamicTheme theme = new DynamicNoActionBarTheme();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState, boolean ready) {
|
||||
setContentView(R.layout.client_deprecated_activity);
|
||||
|
||||
findViewById(R.id.client_deprecated_update_button).setOnClickListener(v -> onUpdateClicked());
|
||||
findViewById(R.id.client_deprecated_dont_update_button).setOnClickListener(v -> onDontUpdateClicked());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
theme.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
theme.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Disabled
|
||||
}
|
||||
|
||||
private void onUpdateClicked() {
|
||||
PlayStoreUtil.openPlayStoreOrOurApkDownloadPage(this);
|
||||
}
|
||||
|
||||
private void onDontUpdateClicked() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.ClientDeprecatedActivity_warning)
|
||||
.setMessage(R.string.ClientDeprecatedActivity_your_version_of_signal_has_expired_you_can_view_your_message_history)
|
||||
.setPositiveButton(R.string.ClientDeprecatedActivity_dont_update, (dialog, which) -> {
|
||||
ApplicationDependencies.getMegaphoneRepository().markFinished(Megaphones.Event.CLIENT_DEPRECATED, () -> {
|
||||
Util.runOnMain(this::finish);
|
||||
});
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
|
||||
.show();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class Megaphone {
|
||||
|
||||
private final Event event;
|
||||
private final Style style;
|
||||
private final boolean mandatory;
|
||||
private final Priority priority;
|
||||
private final boolean canSnooze;
|
||||
private final int titleRes;
|
||||
private final int bodyRes;
|
||||
@@ -33,7 +33,7 @@ public class Megaphone {
|
||||
private Megaphone(@NonNull Builder builder) {
|
||||
this.event = builder.event;
|
||||
this.style = builder.style;
|
||||
this.mandatory = builder.mandatory;
|
||||
this.priority = builder.priority;
|
||||
this.canSnooze = builder.canSnooze;
|
||||
this.titleRes = builder.titleRes;
|
||||
this.bodyRes = builder.bodyRes;
|
||||
@@ -48,8 +48,8 @@ public class Megaphone {
|
||||
return event;
|
||||
}
|
||||
|
||||
public boolean isMandatory() {
|
||||
return mandatory;
|
||||
public @NonNull Priority getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public boolean canSnooze() {
|
||||
@@ -97,7 +97,7 @@ public class Megaphone {
|
||||
private final Event event;
|
||||
private final Style style;
|
||||
|
||||
private boolean mandatory;
|
||||
private Priority priority;
|
||||
private boolean canSnooze;
|
||||
private int titleRes;
|
||||
private int bodyRes;
|
||||
@@ -111,13 +111,14 @@ public class Megaphone {
|
||||
public Builder(@NonNull Event event, @NonNull Style style) {
|
||||
this.event = event;
|
||||
this.style = style;
|
||||
this.priority = Priority.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prioritizes this megaphone over others that do not set this flag.
|
||||
*/
|
||||
public @NonNull Builder setMandatory(boolean mandatory) {
|
||||
this.mandatory = mandatory;
|
||||
public @NonNull Builder setPriority(@NonNull Priority priority) {
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -192,6 +193,20 @@ public class Megaphone {
|
||||
POPUP
|
||||
}
|
||||
|
||||
enum Priority {
|
||||
DEFAULT(0), HIGH(1), CLIENT_EXPIRATION(1000);
|
||||
|
||||
int priorityValue;
|
||||
|
||||
Priority(int priorityValue) {
|
||||
this.priorityValue = priorityValue;
|
||||
}
|
||||
|
||||
public int getPriorityValue() {
|
||||
return priorityValue;
|
||||
}
|
||||
}
|
||||
|
||||
public interface EventListener {
|
||||
void onEvent(@NonNull Megaphone megaphone, @NonNull MegaphoneActionController listener);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Collectors;
|
||||
@@ -100,6 +101,11 @@ public class MegaphoneRepository {
|
||||
|
||||
@AnyThread
|
||||
public void markFinished(@NonNull Event event) {
|
||||
markFinished(event, null);
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
public void markFinished(@NonNull Event event, @Nullable Runnable onComplete) {
|
||||
executor.execute(() -> {
|
||||
MegaphoneRecord record = databaseCache.get(event);
|
||||
if (record != null && record.isFinished()) {
|
||||
@@ -108,6 +114,10 @@ public class MegaphoneRepository {
|
||||
|
||||
database.markFinished(event);
|
||||
resetDatabaseCache();
|
||||
|
||||
if (onComplete != null) {
|
||||
onComplete.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ import java.util.Objects;
|
||||
* Creating a new megaphone:
|
||||
* - Add an enum to {@link Event}
|
||||
* - Return a megaphone in {@link #forRecord(Context, MegaphoneRecord)}
|
||||
* - Include the event in {@link #buildDisplayOrder()}
|
||||
* - Include the event in {@link #buildDisplayOrder(Context)}
|
||||
*
|
||||
* Common patterns:
|
||||
* - For events that have a snooze-able recurring display schedule, use a {@link RecurringSchedule}.
|
||||
* - For events guarded by feature flags, set a {@link ForeverSchedule} with false in
|
||||
* {@link #buildDisplayOrder()}.
|
||||
* {@link #buildDisplayOrder(Context)}.
|
||||
* - For events that change, return different megaphones in {@link #forRecord(Context, MegaphoneRecord)}
|
||||
* based on whatever properties you're interested in.
|
||||
*/
|
||||
@@ -65,15 +65,9 @@ public final class Megaphones {
|
||||
.map(Map.Entry::getKey)
|
||||
.map(records::get)
|
||||
.map(record -> Megaphones.forRecord(context, record))
|
||||
.sortBy(m -> -m.getPriority().getPriorityValue())
|
||||
.toList();
|
||||
|
||||
boolean hasOptional = Stream.of(megaphones).anyMatch(m -> !m.isMandatory());
|
||||
boolean hasMandatory = Stream.of(megaphones).anyMatch(Megaphone::isMandatory);
|
||||
|
||||
if (hasOptional && hasMandatory) {
|
||||
megaphones = Stream.of(megaphones).filter(Megaphone::isMandatory).toList();
|
||||
}
|
||||
|
||||
if (megaphones.size() > 0) {
|
||||
return megaphones.get(0);
|
||||
} else {
|
||||
@@ -93,6 +87,7 @@ public final class Megaphones {
|
||||
put(Event.MESSAGE_REQUESTS, shouldShowMessageRequestsMegaphone() ? ALWAYS : NEVER);
|
||||
put(Event.MENTIONS, shouldShowMentionsMegaphone() ? ALWAYS : NEVER);
|
||||
put(Event.LINK_PREVIEWS, shouldShowLinkPreviewsMegaphone(context) ? ALWAYS : NEVER);
|
||||
put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER);
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -110,6 +105,8 @@ public final class Megaphones {
|
||||
return buildMentionsMegaphone();
|
||||
case LINK_PREVIEWS:
|
||||
return buildLinkPreviewsMegaphone();
|
||||
case CLIENT_DEPRECATED:
|
||||
return buildClientDeprecatedMegaphone(context);
|
||||
default:
|
||||
throw new IllegalArgumentException("Event not handled!");
|
||||
}
|
||||
@@ -117,14 +114,14 @@ public final class Megaphones {
|
||||
|
||||
private static @NonNull Megaphone buildReactionsMegaphone() {
|
||||
return new Megaphone.Builder(Event.REACTIONS, Megaphone.Style.REACTIONS)
|
||||
.setMandatory(false)
|
||||
.setPriority(Megaphone.Priority.DEFAULT)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull Megaphone buildPinsForAllMegaphone(@NonNull MegaphoneRecord record) {
|
||||
if (PinsForAllSchedule.shouldDisplayFullScreen(record.getFirstVisible(), System.currentTimeMillis())) {
|
||||
return new Megaphone.Builder(Event.PINS_FOR_ALL, Megaphone.Style.FULLSCREEN)
|
||||
.setMandatory(true)
|
||||
.setPriority(Megaphone.Priority.HIGH)
|
||||
.enableSnooze(null)
|
||||
.setOnVisibleListener((megaphone, listener) -> {
|
||||
if (new NetworkConstraint.Factory(ApplicationDependencies.getApplication()).create().isMet()) {
|
||||
@@ -134,7 +131,7 @@ public final class Megaphones {
|
||||
.build();
|
||||
} else {
|
||||
return new Megaphone.Builder(Event.PINS_FOR_ALL, Megaphone.Style.BASIC)
|
||||
.setMandatory(true)
|
||||
.setPriority(Megaphone.Priority.HIGH)
|
||||
.setImage(R.drawable.kbs_pin_megaphone)
|
||||
.setTitle(R.string.KbsMegaphone__create_a_pin)
|
||||
.setBody(R.string.KbsMegaphone__pins_keep_information_thats_stored_with_signal_encrytped)
|
||||
@@ -184,7 +181,7 @@ public final class Megaphones {
|
||||
private static @NonNull Megaphone buildMessageRequestsMegaphone(@NonNull Context context) {
|
||||
return new Megaphone.Builder(Event.MESSAGE_REQUESTS, Megaphone.Style.FULLSCREEN)
|
||||
.disableSnooze()
|
||||
.setMandatory(true)
|
||||
.setPriority(Megaphone.Priority.HIGH)
|
||||
.setOnVisibleListener(((megaphone, listener) -> {
|
||||
listener.onMegaphoneNavigationRequested(new Intent(context, MessageRequestMegaphoneActivity.class),
|
||||
ConversationListFragment.MESSAGE_REQUESTS_REQUEST_CODE_CREATE_NAME);
|
||||
@@ -202,7 +199,17 @@ public final class Megaphones {
|
||||
|
||||
private static @NonNull Megaphone buildLinkPreviewsMegaphone() {
|
||||
return new Megaphone.Builder(Event.LINK_PREVIEWS, Megaphone.Style.LINK_PREVIEWS)
|
||||
.setMandatory(true)
|
||||
.setPriority(Megaphone.Priority.HIGH)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull Megaphone buildClientDeprecatedMegaphone(@NonNull Context context) {
|
||||
return new Megaphone.Builder(Event.CLIENT_DEPRECATED, Megaphone.Style.FULLSCREEN)
|
||||
.disableSnooze()
|
||||
.setPriority(Megaphone.Priority.HIGH)
|
||||
.setOnVisibleListener((megaphone, listener) -> {
|
||||
listener.onMegaphoneNavigationRequested(new Intent(context, ClientDeprecatedActivity.class));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -224,7 +231,8 @@ public final class Megaphones {
|
||||
PIN_REMINDER("pin_reminder"),
|
||||
MESSAGE_REQUESTS("message_requests"),
|
||||
MENTIONS("mentions"),
|
||||
LINK_PREVIEWS("link_previews");
|
||||
LINK_PREVIEWS("link_previews"),
|
||||
CLIENT_DEPRECATED("client_deprecated");
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user