2015-09-29 13:14:22 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.drawable.ColorDrawable;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.NonNull;
|
2017-09-03 19:44:33 -07:00
|
|
|
import android.support.annotation.Nullable;
|
2015-09-29 13:14:22 -07:00
|
|
|
import android.support.annotation.StringRes;
|
|
|
|
import android.support.v4.app.NotificationCompat;
|
|
|
|
import android.support.v4.view.ViewPager;
|
2018-11-27 17:45:58 -08:00
|
|
|
import android.view.View;
|
2015-09-29 13:14:22 -07:00
|
|
|
|
|
|
|
import com.melnykov.fab.FloatingActionButton;
|
|
|
|
import com.nineoldandroids.animation.ArgbEvaluator;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.IntroPagerAdapter.IntroPage;
|
2018-10-29 15:14:31 -07:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2018-08-06 12:20:24 -04:00
|
|
|
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
2015-09-29 13:14:22 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2015-09-29 13:14:22 -07:00
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2019-01-15 00:41:05 -08:00
|
|
|
public class ExperienceUpgradeActivity extends BaseActionBarActivity implements TypingIndicatorIntroFragment.Controller, LinkPreviewsIntroFragment.Controller {
|
2015-09-29 13:14:22 -07:00
|
|
|
private static final String TAG = ExperienceUpgradeActivity.class.getSimpleName();
|
2017-09-03 19:44:33 -07:00
|
|
|
private static final String DISMISS_ACTION = "org.thoughtcrime.securesms.ExperienceUpgradeActivity.DISMISS_ACTION";
|
2015-09-29 13:14:22 -07:00
|
|
|
private static final int NOTIFICATION_ID = 1339;
|
|
|
|
|
|
|
|
private enum ExperienceUpgrade {
|
2015-10-01 15:21:21 -07:00
|
|
|
SIGNAL_REBRANDING(157,
|
2015-09-29 13:14:22 -07:00
|
|
|
new IntroPage(0xFF2090EA,
|
|
|
|
BasicIntroFragment.newInstance(R.drawable.splash_logo,
|
|
|
|
R.string.ExperienceUpgradeActivity_welcome_to_signal_dgaf,
|
|
|
|
R.string.ExperienceUpgradeActivity_textsecure_is_now_called_signal)),
|
|
|
|
R.string.ExperienceUpgradeActivity_welcome_to_signal_excited,
|
|
|
|
R.string.ExperienceUpgradeActivity_textsecure_is_now_signal,
|
2017-09-03 19:44:33 -07:00
|
|
|
R.string.ExperienceUpgradeActivity_textsecure_is_now_signal_long,
|
2018-11-27 17:45:58 -08:00
|
|
|
null,
|
|
|
|
false),
|
2017-03-06 12:32:09 -08:00
|
|
|
VIDEO_CALLS(245,
|
|
|
|
new IntroPage(0xFF2090EA,
|
|
|
|
BasicIntroFragment.newInstance(R.drawable.video_splash,
|
|
|
|
R.string.ExperienceUpgradeActivity_say_hello_to_video_calls,
|
|
|
|
R.string.ExperienceUpgradeActivity_signal_now_supports_secure_video_calls)),
|
|
|
|
R.string.ExperienceUpgradeActivity_say_hello_to_video_calls,
|
|
|
|
R.string.ExperienceUpgradeActivity_signal_now_supports_secure_video_calling,
|
2017-09-03 19:44:33 -07:00
|
|
|
R.string.ExperienceUpgradeActivity_signal_now_supports_secure_video_calling_long,
|
2018-11-27 17:45:58 -08:00
|
|
|
null,
|
|
|
|
false),
|
2017-09-03 19:44:33 -07:00
|
|
|
PROFILES(286,
|
|
|
|
new IntroPage(0xFF2090EA,
|
|
|
|
BasicIntroFragment.newInstance(R.drawable.profile_splash,
|
|
|
|
R.string.ExperienceUpgradeActivity_ready_for_your_closeup,
|
|
|
|
R.string.ExperienceUpgradeActivity_now_you_can_share_a_profile_photo_and_name_with_friends_on_signal)),
|
|
|
|
R.string.ExperienceUpgradeActivity_signal_profiles_are_here,
|
|
|
|
R.string.ExperienceUpgradeActivity_now_you_can_share_a_profile_photo_and_name_with_friends_on_signal,
|
|
|
|
R.string.ExperienceUpgradeActivity_now_you_can_share_a_profile_photo_and_name_with_friends_on_signal,
|
2018-11-27 17:45:58 -08:00
|
|
|
CreateProfileActivity.class,
|
|
|
|
false),
|
2017-09-27 15:11:44 -07:00
|
|
|
READ_RECEIPTS(299,
|
|
|
|
new IntroPage(0xFF2090EA,
|
|
|
|
ReadReceiptsIntroFragment.newInstance()),
|
2017-10-02 10:45:43 -07:00
|
|
|
R.string.experience_upgrade_preference_fragment__read_receipts_are_here,
|
|
|
|
R.string.experience_upgrade_preference_fragment__optionally_see_and_share_when_messages_have_been_read,
|
|
|
|
R.string.experience_upgrade_preference_fragment__optionally_see_and_share_when_messages_have_been_read,
|
2018-11-27 17:45:58 -08:00
|
|
|
null,
|
|
|
|
false),
|
2018-11-28 09:21:19 -08:00
|
|
|
TYPING_INDICATORS(432,
|
2018-10-29 15:14:31 -07:00
|
|
|
new IntroPage(0xFF2090EA,
|
|
|
|
TypingIndicatorIntroFragment.newInstance()),
|
|
|
|
R.string.ExperienceUpgradeActivity_introducing_typing_indicators,
|
|
|
|
R.string.ExperienceUpgradeActivity_now_you_can_optionally_see_and_share_when_messages_are_being_typed,
|
|
|
|
R.string.ExperienceUpgradeActivity_now_you_can_optionally_see_and_share_when_messages_are_being_typed,
|
2018-11-27 17:45:58 -08:00
|
|
|
null,
|
2019-01-15 00:41:05 -08:00
|
|
|
true),
|
|
|
|
LINK_PREVIEWS(449,
|
|
|
|
new IntroPage(0xFF2090EA, LinkPreviewsIntroFragment.newInstance()),
|
|
|
|
R.string.ExperienceUpgradeActivity_introducing_link_previews,
|
|
|
|
R.string.ExperienceUpgradeActivity_optional_link_previews_are_now_supported,
|
|
|
|
R.string.ExperienceUpgradeActivity_optional_link_previews_are_now_supported,
|
|
|
|
null,
|
|
|
|
true);
|
2015-09-29 13:14:22 -07:00
|
|
|
|
|
|
|
private int version;
|
|
|
|
private List<IntroPage> pages;
|
|
|
|
private @StringRes int notificationTitle;
|
|
|
|
private @StringRes int notificationText;
|
|
|
|
private @StringRes int notificationBigText;
|
2017-09-03 19:44:33 -07:00
|
|
|
private @Nullable Class nextIntent;
|
2018-11-27 17:45:58 -08:00
|
|
|
private boolean handlesNavigation;
|
2015-09-29 13:14:22 -07:00
|
|
|
|
|
|
|
ExperienceUpgrade(int version,
|
|
|
|
@NonNull List<IntroPage> pages,
|
|
|
|
@StringRes int notificationTitle,
|
|
|
|
@StringRes int notificationText,
|
2017-09-03 19:44:33 -07:00
|
|
|
@StringRes int notificationBigText,
|
2018-11-27 17:45:58 -08:00
|
|
|
@Nullable Class nextIntent,
|
|
|
|
boolean handlesNavigation)
|
2015-09-29 13:14:22 -07:00
|
|
|
{
|
2017-09-03 19:44:33 -07:00
|
|
|
this.version = version;
|
|
|
|
this.pages = pages;
|
|
|
|
this.notificationTitle = notificationTitle;
|
|
|
|
this.notificationText = notificationText;
|
2015-09-29 13:14:22 -07:00
|
|
|
this.notificationBigText = notificationBigText;
|
2017-09-03 19:44:33 -07:00
|
|
|
this.nextIntent = nextIntent;
|
2018-11-27 17:45:58 -08:00
|
|
|
this.handlesNavigation = handlesNavigation;
|
2015-09-29 13:14:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ExperienceUpgrade(int version,
|
|
|
|
@NonNull IntroPage page,
|
|
|
|
@StringRes int notificationTitle,
|
|
|
|
@StringRes int notificationText,
|
2017-09-03 19:44:33 -07:00
|
|
|
@StringRes int notificationBigText,
|
2018-11-27 17:45:58 -08:00
|
|
|
@Nullable Class nextIntent,
|
|
|
|
boolean handlesNavigation)
|
2015-09-29 13:14:22 -07:00
|
|
|
{
|
2018-11-27 17:45:58 -08:00
|
|
|
this(version, Collections.singletonList(page), notificationTitle, notificationText, notificationBigText, nextIntent, handlesNavigation);
|
2015-09-29 13:14:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<IntroPage> getPages() {
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntroPage getPage(int i) {
|
|
|
|
return pages.get(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNotificationTitle() {
|
|
|
|
return notificationTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNotificationText() {
|
|
|
|
return notificationText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNotificationBigText() {
|
|
|
|
return notificationBigText;
|
|
|
|
}
|
2018-11-27 17:45:58 -08:00
|
|
|
|
|
|
|
public boolean handlesNavigation() {
|
|
|
|
return handlesNavigation;
|
|
|
|
}
|
2015-09-29 13:14:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setStatusBarColor(getResources().getColor(R.color.signal_primary_dark));
|
|
|
|
|
2015-10-01 15:21:21 -07:00
|
|
|
final Optional<ExperienceUpgrade> upgrade = getExperienceUpgrade(this);
|
2015-09-29 13:14:22 -07:00
|
|
|
if (!upgrade.isPresent()) {
|
2015-10-01 15:21:21 -07:00
|
|
|
onContinue(upgrade);
|
2015-09-29 13:14:22 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setContentView(R.layout.experience_upgrade_activity);
|
2015-11-05 10:45:39 -08:00
|
|
|
final ViewPager pager = ViewUtil.findById(this, R.id.pager);
|
|
|
|
final FloatingActionButton fab = ViewUtil.findById(this, R.id.fab);
|
2015-09-29 13:14:22 -07:00
|
|
|
|
|
|
|
pager.setAdapter(new IntroPagerAdapter(getSupportFragmentManager(), upgrade.get().getPages()));
|
|
|
|
|
2018-11-27 17:45:58 -08:00
|
|
|
if (upgrade.get().handlesNavigation()) {
|
|
|
|
fab.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
fab.setVisibility(View.VISIBLE);
|
|
|
|
fab.setOnClickListener(v -> onContinue(upgrade));
|
|
|
|
}
|
2015-09-29 13:14:22 -07:00
|
|
|
|
|
|
|
getWindow().setBackgroundDrawable(new ColorDrawable(upgrade.get().getPage(0).backgroundColor));
|
|
|
|
ServiceUtil.getNotificationManager(this).cancel(NOTIFICATION_ID);
|
|
|
|
}
|
|
|
|
|
2015-10-01 15:21:21 -07:00
|
|
|
private void onContinue(Optional<ExperienceUpgrade> seenUpgrade) {
|
|
|
|
ServiceUtil.getNotificationManager(this).cancel(NOTIFICATION_ID);
|
|
|
|
int latestVersion = seenUpgrade.isPresent() ? seenUpgrade.get().getVersion()
|
2019-05-28 19:57:06 -03:00
|
|
|
: Util.getCanonicalVersionCode();
|
2015-10-01 15:21:21 -07:00
|
|
|
TextSecurePreferences.setLastExperienceVersionCode(this, latestVersion);
|
2017-09-03 19:44:33 -07:00
|
|
|
if (seenUpgrade.isPresent() && seenUpgrade.get().nextIntent != null) {
|
|
|
|
Intent intent = new Intent(this, seenUpgrade.get().nextIntent);
|
|
|
|
Intent nextIntent = new Intent(this, ConversationListActivity.class);
|
|
|
|
intent.putExtra("next_intent", nextIntent);
|
|
|
|
startActivity(intent);
|
|
|
|
} else {
|
2018-02-21 18:49:08 -08:00
|
|
|
startActivity(getIntent().getParcelableExtra("next_intent"));
|
2017-09-03 19:44:33 -07:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:14:22 -07:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isUpdate(Context context) {
|
|
|
|
return getExperienceUpgrade(context).isPresent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Optional<ExperienceUpgrade> getExperienceUpgrade(Context context) {
|
2019-05-28 19:57:06 -03:00
|
|
|
final int currentVersionCode = Util.getCanonicalVersionCode();
|
2015-09-29 13:14:22 -07:00
|
|
|
final int lastSeenVersion = TextSecurePreferences.getLastExperienceVersionCode(context);
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "getExperienceUpgrade(" + lastSeenVersion + ")");
|
2015-09-29 13:14:22 -07:00
|
|
|
|
2015-10-01 15:21:21 -07:00
|
|
|
if (lastSeenVersion >= currentVersionCode) {
|
2015-09-29 13:14:22 -07:00
|
|
|
TextSecurePreferences.setLastExperienceVersionCode(context, currentVersionCode);
|
|
|
|
return Optional.absent();
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<ExperienceUpgrade> eligibleUpgrade = Optional.absent();
|
|
|
|
for (ExperienceUpgrade upgrade : ExperienceUpgrade.values()) {
|
|
|
|
if (lastSeenVersion < upgrade.getVersion()) eligibleUpgrade = Optional.of(upgrade);
|
|
|
|
}
|
|
|
|
|
|
|
|
return eligibleUpgrade;
|
|
|
|
}
|
|
|
|
|
2018-11-27 17:45:58 -08:00
|
|
|
@Override
|
2019-01-15 00:41:05 -08:00
|
|
|
public void onTypingIndicatorsFinished() {
|
2018-11-27 17:45:58 -08:00
|
|
|
onContinue(Optional.of(ExperienceUpgrade.TYPING_INDICATORS));
|
|
|
|
}
|
|
|
|
|
2019-01-15 00:41:05 -08:00
|
|
|
@Override
|
|
|
|
public void onLinkPreviewsFinished() {
|
|
|
|
onContinue(Optional.of(ExperienceUpgrade.LINK_PREVIEWS));
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:14:22 -07:00
|
|
|
private final class OnPageChangeListener implements ViewPager.OnPageChangeListener {
|
|
|
|
private final ArgbEvaluator evaluator = new ArgbEvaluator();
|
|
|
|
private final ExperienceUpgrade upgrade;
|
|
|
|
|
|
|
|
public OnPageChangeListener(ExperienceUpgrade upgrade) {
|
|
|
|
this.upgrade = upgrade;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageScrollStateChanged(int state) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
final int nextPosition = (position + 1) % upgrade.getPages().size();
|
|
|
|
|
|
|
|
final int color = (Integer)evaluator.evaluate(positionOffset,
|
|
|
|
upgrade.getPage(position).backgroundColor,
|
|
|
|
upgrade.getPage(nextPosition).backgroundColor);
|
|
|
|
getWindow().setBackgroundDrawable(new ColorDrawable(color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class AppUpgradeReceiver extends BroadcastReceiver {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2017-11-26 20:21:29 -08:00
|
|
|
if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()) &&
|
2017-09-03 19:44:33 -07:00
|
|
|
intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
|
2015-09-29 13:14:22 -07:00
|
|
|
{
|
2018-02-21 18:49:08 -08:00
|
|
|
if (TextSecurePreferences.getLastExperienceVersionCode(context) < 339 &&
|
|
|
|
!TextSecurePreferences.isPasswordDisabled(context))
|
|
|
|
{
|
2018-08-06 12:20:24 -04:00
|
|
|
Notification notification = new NotificationCompat.Builder(context, NotificationChannels.OTHER)
|
2019-07-24 09:51:09 +10:00
|
|
|
.setSmallIcon(R.drawable.ic_notification)
|
2018-02-21 18:49:08 -08:00
|
|
|
.setColor(context.getResources().getColor(R.color.signal_primary))
|
|
|
|
.setContentTitle(context.getString(R.string.ExperienceUpgradeActivity_unlock_to_complete_update))
|
|
|
|
.setContentText(context.getString(R.string.ExperienceUpgradeActivity_please_unlock_signal_to_complete_update))
|
|
|
|
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.ExperienceUpgradeActivity_please_unlock_signal_to_complete_update)))
|
|
|
|
.setAutoCancel(true)
|
|
|
|
.setContentIntent(PendingIntent.getActivity(context, 0,
|
|
|
|
context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()),
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:14:22 -07:00
|
|
|
Optional<ExperienceUpgrade> experienceUpgrade = getExperienceUpgrade(context);
|
|
|
|
|
2017-09-03 19:44:33 -07:00
|
|
|
if (!experienceUpgrade.isPresent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (experienceUpgrade.get().getVersion() == TextSecurePreferences.getExperienceDismissedVersionCode(context)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Intent targetIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
|
|
Intent dismissIntent = new Intent(context, AppUpgradeReceiver.class);
|
|
|
|
dismissIntent.setAction(DISMISS_ACTION);
|
|
|
|
|
2018-08-06 12:20:24 -04:00
|
|
|
Notification notification = new NotificationCompat.Builder(context, NotificationChannels.OTHER)
|
2019-07-24 09:51:09 +10:00
|
|
|
.setSmallIcon(R.drawable.ic_notification)
|
2015-09-29 13:14:22 -07:00
|
|
|
.setColor(context.getResources().getColor(R.color.signal_primary))
|
|
|
|
.setContentTitle(context.getString(experienceUpgrade.get().getNotificationTitle()))
|
|
|
|
.setContentText(context.getString(experienceUpgrade.get().getNotificationText()))
|
|
|
|
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(experienceUpgrade.get().getNotificationBigText())))
|
|
|
|
.setAutoCancel(true)
|
|
|
|
.setContentIntent(PendingIntent.getActivity(context, 0,
|
|
|
|
targetIntent,
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT))
|
2017-09-03 19:44:33 -07:00
|
|
|
|
|
|
|
.setDeleteIntent(PendingIntent.getBroadcast(context, 0,
|
|
|
|
dismissIntent,
|
|
|
|
PendingIntent.FLAG_UPDATE_CURRENT))
|
2015-09-29 13:14:22 -07:00
|
|
|
.build();
|
|
|
|
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
|
2017-09-03 19:44:33 -07:00
|
|
|
} else if (DISMISS_ACTION.equals(intent.getAction())) {
|
2019-05-28 19:57:06 -03:00
|
|
|
TextSecurePreferences.setExperienceDismissedVersionCode(context, Util.getCanonicalVersionCode());
|
2015-09-29 13:14:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|