Skip to content

Commit

Permalink
add a notification with the new brand name
Browse files Browse the repository at this point in the history
  • Loading branch information
BLeQuerrec committed Apr 20, 2016
1 parent 03c3e9b commit f6b7dc4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
7 changes: 7 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,12 @@
</intent-filter>
</receiver>

<receiver android:name=".IntroScreenActivity$AppUpgradeReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>

</application>
</manifest>
4 changes: 3 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@
<string name="ShareActivity_share_with">Share with</string>

<!-- IntroScreenActivity -->
<string name="IntroScreenActivity_welcome_to_smssecure">Welcome to SMSSecure!</string>
<string name="IntroScreenActivity_welcome_to_newappname">Welcome to NewAppName!</string>
<string name="IntroScreenActivity_smssecure_description">SMSSecure allows you to protect your privacy while communicating with friends.</string>
<string name="IntroScreenActivity_encrypt_your_messages">Encrypt your messages</string>
<string name="IntroScreenActivity_encrypt_your_messages_description">SMSSecure will encrypt messages with other SMSSecure users automatically.</string>
<string name="IntroScreenActivity_talk_to_everyone">Talk to everyone</string>
<string name="IntroScreenActivity_talk_to_everyone_description">SMSSecure can use unencrypted messages to chat with non-SMSSecure users.</string>
<string name="IntroScreenActivity_smssecure_is_now_newappname">SMSSecure is now NewAppName.</string>
<string name="IntroScreenActivity_your_messages_are_still_here">SMSSecure is now NewAppName. Your messages are still here and new features are coming.</string>

<!-- ExportFragment -->
<string name="ExportFragment_export">Export</string>
Expand Down
34 changes: 33 additions & 1 deletion src/org/smssecure/smssecure/IntroScreenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
public class IntroScreenActivity extends BaseActionBarActivity {
private static final String TAG = IntroScreenActivity.class.getSimpleName();

private static final int NOTIFICATION_ID = 1339;

private enum IntroScreen {
INTRO(new ArrayList<IntroPage>() {
{
add(new IntroPage(0xFF7568AE,
BasicIntroFragment.newInstance(R.drawable.splash_logo,
R.string.IntroScreenActivity_welcome_to_smssecure,
R.string.IntroScreenActivity_welcome_to_newappname,
R.string.IntroScreenActivity_smssecure_description)));
add(new IntroPage(0xFF7568AE,
BasicIntroFragment.newInstance(R.drawable.splash_padlock,
Expand Down Expand Up @@ -139,6 +141,7 @@ private void onContinue() {
}

public static Optional<IntroScreen> getIntroScreen(Context context) {
SMSSecurePreferences.setBrandNameUpdateAsSeen(context);
if (!SMSSecurePreferences.isFirstRun(context)) return Optional.absent();

Optional<IntroScreen> introScreen = Optional.absent();
Expand Down Expand Up @@ -174,4 +177,33 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
setStatusBarColor(color);
}
}

public static class AppUpgradeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction()) &&
intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
{
Log.w(TAG, "Displaying upgrade notification...");
if (SMSSecurePreferences.isFirstRun(context) || SMSSecurePreferences.seenBrandNameUpdate(context)) return;

Intent targetIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon_notification)
.setColor(context.getResources().getColor(R.color.smssecure_primary))
.setContentTitle(context.getString(R.string.IntroScreenActivity_welcome_to_newappname))
.setContentText(context.getString(R.string.IntroScreenActivity_smssecure_is_now_newappname))
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.IntroScreenActivity_your_messages_are_still_here)))
.setAutoCancel(true)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(PendingIntent.getActivity(context, 0,
targetIntent,
PendingIntent.FLAG_UPDATE_CURRENT))
.build();
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
SMSSecurePreferences.setBrandNameUpdateAsSeen(context);
}
}
}

}
9 changes: 9 additions & 0 deletions src/org/smssecure/smssecure/util/SMSSecurePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SMSSecurePreferences {

private static final String LAST_VERSION_CODE_PREF = "last_version_code";
private static final String IS_FIRST_RUN = "is_first_run";
private static final String SEEN_BRAND_NAME_UPDATE = "seen_brand_name_update";
public static final String RINGTONE_PREF = "pref_key_ringtone";
private static final String VIBRATE_PREF = "pref_key_vibrate";
private static final String NOTIFICATION_PREF = "pref_key_enable_notifications";
Expand Down Expand Up @@ -378,6 +379,14 @@ public static void setFirstRun(Context context) {
setBooleanPreference(context, IS_FIRST_RUN, false);
}

public static boolean seenBrandNameUpdate(Context context) {
return getBooleanPreference(context, SEEN_BRAND_NAME_UPDATE, false);
}

public static void setBrandNameUpdateAsSeen(Context context) {
setBooleanPreference(context, SEEN_BRAND_NAME_UPDATE, true);
}

public static String getTheme(Context context) {
return getStringPreference(context, THEME_PREF, "light");
}
Expand Down

0 comments on commit f6b7dc4

Please sign in to comment.