summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClark Scheff <clark@cyngn.com>2014-08-25 09:38:26 -0700
committerClark Scheff <clark@cyngn.com>2014-08-25 09:55:44 -0700
commit09b5b00e2f8952630f799cef5854b87ca223eea9 (patch)
treee2505c3c69927a51675a7d79dd6b922e2023f02f /src
parent12d5cf211d9a5246258a05d9097824b62df12399 (diff)
downloadpackages_apps_ThemeChooser-09b5b00e2f8952630f799cef5854b87ca223eea9.zip
packages_apps_ThemeChooser-09b5b00e2f8952630f799cef5854b87ca223eea9.tar.gz
packages_apps_ThemeChooser-09b5b00e2f8952630f799cef5854b87ca223eea9.tar.bz2
Collapse notifications when multiple themes installed
Rather than flood the users notification drawer with every theme installed, we can consolidate theme into one notification if more than one theme was recently installed. This will come in handy when people restore backups from google play and all their themes are installed. Change-Id: I00c676769115a1cf44b22a138b32287c3794b9ca
Diffstat (limited to 'src')
-rw-r--r--src/com/cyngn/theme/chooser/ChooserActivity.java3
-rw-r--r--src/com/cyngn/theme/util/NotificationHelper.java28
-rw-r--r--src/com/cyngn/theme/util/PreferenceUtils.java15
3 files changed, 42 insertions, 4 deletions
diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java
index 567cb85..6d08104 100644
--- a/src/com/cyngn/theme/chooser/ChooserActivity.java
+++ b/src/com/cyngn/theme/chooser/ChooserActivity.java
@@ -433,6 +433,9 @@ public class ChooserActivity extends FragmentActivity
IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
registerReceiver(mWallpaperChangeReceiver, filter);
+
+ // clear out the newly installed themes count
+ PreferenceUtils.setNewlyInstalledThemeCount(this, 0);
}
@Override
diff --git a/src/com/cyngn/theme/util/NotificationHelper.java b/src/com/cyngn/theme/util/NotificationHelper.java
index bd022cd..2a83478 100644
--- a/src/com/cyngn/theme/util/NotificationHelper.java
+++ b/src/com/cyngn/theme/util/NotificationHelper.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
@@ -29,6 +30,8 @@ import com.cyngn.theme.chooser.ChooserActivity;
import com.cyngn.theme.chooser.R;
public class NotificationHelper {
+ private static final int NOTIFICATION_ID = 0x434D5443;
+
public static void postThemeInstalledNotification(Context context, String pkgName) {
String themeName = null;
try {
@@ -46,27 +49,44 @@ public class NotificationHelper {
return;
}
+ int themeCount = PreferenceUtils.getNewlyInstalledThemeCount(context) + 1;
+
Intent intent = new Intent(context, ChooserActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.putExtra("pkgName", pkgName);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
+ String title = null;
+ String content = null;
+ final Resources res = context.getResources();
+ if (themeCount == 1) {
+ title = String.format(res.getString(
+ R.string.theme_installed_notification_title), themeName);
+ content = res.getString(R.string.theme_installed_notification_text);
+ } else {
+ title = String.format(res.getString(R.string.themes_installed_notification_title),
+ themeCount);
+ content = String.format(res.getQuantityString(
+ R.plurals.themes_installed_notification_text, themeCount -1),
+ themeName, themeCount - 1);
+ }
NotificationManager nm =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notice = new Notification.Builder(context)
.setAutoCancel(true)
.setOngoing(false)
- .setContentTitle(String.format(
- context.getString(R.string.theme_installed_notification_title), themeName))
- .setContentText(context.getString(R.string.theme_installed_notification_text))
+ .setContentTitle(title)
+ .setContentText(content)
.setContentIntent(pi)
.setSmallIcon(R.drawable.ic_notifiy)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.drawable.ic_app_themes))
.setWhen(System.currentTimeMillis())
.build();
- nm.notify(pkgName.hashCode(), notice);
+ if (themeCount > 1) notice.number = themeCount;
+ nm.notify(NOTIFICATION_ID, notice);
+ PreferenceUtils.setNewlyInstalledThemeCount(context, themeCount);
}
public static void cancelNotificationForPackage(Context context, String pkgName) {
diff --git a/src/com/cyngn/theme/util/PreferenceUtils.java b/src/com/cyngn/theme/util/PreferenceUtils.java
index edbf017..6486a03 100644
--- a/src/com/cyngn/theme/util/PreferenceUtils.java
+++ b/src/com/cyngn/theme/util/PreferenceUtils.java
@@ -13,6 +13,7 @@ import java.util.Set;
public class PreferenceUtils {
public static final String PREF_APPLIED_BASE_THEME = "applied_base_theme";
public static final String PREF_UPDATED_THEMES = "updated_themes";
+ public static final String PREF_NEWLY_INSTALLED_THEME_COUNT = "newly_installed_theme_count";
public static SharedPreferences getSharedPreferences(Context context) {
if (context == null) return null;
@@ -73,4 +74,18 @@ public class PreferenceUtils {
Set<String> updatedThemes = getUpdatedThemes(context);
return updatedThemes != null && updatedThemes.contains(pkgName);
}
+
+ public static int getNewlyInstalledThemeCount(Context context) {
+ SharedPreferences prefs = getSharedPreferences(context);
+ if (prefs == null) return 0;
+
+ return prefs.getInt(PREF_NEWLY_INSTALLED_THEME_COUNT, 0);
+ }
+
+ public static void setNewlyInstalledThemeCount(Context context, int count) {
+ SharedPreferences prefs = getSharedPreferences(context);
+ if (prefs != null) {
+ prefs.edit().putInt(PREF_NEWLY_INSTALLED_THEME_COUNT, count).apply();
+ }
+ }
}