summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-03-06 23:38:27 (GMT)
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-03-11 15:32:52 (GMT)
commit4938b49e080438be59fe8d4dcd7ff10a7ba279ed (patch)
tree5713f73ec648901851345432d1207c37f0922825 /src
parentd61bdb03364a481b56972b200bec41a410e33fb5 (diff)
downloadandroid_packages_providers_ThemesProvider-4938b49e080438be59fe8d4dcd7ff10a7ba279ed.zip
android_packages_providers_ThemesProvider-4938b49e080438be59fe8d4dcd7ff10a7ba279ed.tar.gz
android_packages_providers_ThemesProvider-4938b49e080438be59fe8d4dcd7ff10a7ba279ed.tar.bz2
Themes: Add previous value and update time to mixnmatch [2/2]
Change-Id: I6b4224e9416e61ce7792e608bd4fd602a9b34e47
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java28
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesProvider.java11
-rw-r--r--src/org/cyanogenmod/themes/provider/util/ProviderUtils.java23
3 files changed, 58 insertions, 4 deletions
diff --git a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
index b065f79..b0835de 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
@@ -36,7 +36,7 @@ import android.util.Log;
public class ThemesOpenHelper extends SQLiteOpenHelper {
private static final String TAG = ThemesOpenHelper.class.getName();
- private static final int DATABASE_VERSION = 13;
+ private static final int DATABASE_VERSION = 14;
private static final String DATABASE_NAME = "themes.db";
private static final String SYSTEM_THEME_PKG_NAME = ThemeConfig.SYSTEM_DEFAULT;
@@ -110,6 +110,10 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
upgradeToVersion13(db);
oldVersion = 13;
}
+ if (oldVersion == 13) {
+ upgradeToVersion14(db);
+ oldVersion = 14;
+ }
if (oldVersion != DATABASE_VERSION) {
Log.e(TAG, "Recreating db because unknown database version: " + oldVersion);
dropTables(db);
@@ -396,6 +400,18 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
ThemesColumns.INSTALL_STATE, ThemesColumns.InstallState.INSTALLED));
}
+ private void upgradeToVersion14(SQLiteDatabase db) {
+ // add previous_value column to mixnmatch db
+ String sql = String.format("ALTER TABLE %s ADD COLUMN %s TEXT",
+ MixnMatchTable.TABLE_NAME, MixnMatchColumns.COL_PREV_VALUE);
+ db.execSQL(sql);
+
+ // add update_time column to mixnmatch db
+ sql = String.format("ALTER TABLE %s ADD COLUMN %s INTEGER DEFAULT 0",
+ MixnMatchTable.TABLE_NAME, MixnMatchColumns.COL_UPDATE_TIME);
+ db.execSQL(sql);
+ }
+
private void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + ThemesTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + MixnMatchTable.TABLE_NAME);
@@ -474,18 +490,22 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
}
public static class MixnMatchTable {
- protected static final String TABLE_NAME = "mixnmatch";
+ public static final String TABLE_NAME = "mixnmatch";
private static final String MIXNMATCH_TABLE_CREATE =
"CREATE TABLE " + TABLE_NAME + " (" +
MixnMatchColumns.COL_KEY + " TEXT PRIMARY KEY," +
- MixnMatchColumns.COL_VALUE + " TEXT" +
+ MixnMatchColumns.COL_VALUE + " TEXT," +
+ MixnMatchColumns.COL_PREV_VALUE + " TEXT," +
+ MixnMatchColumns.COL_UPDATE_TIME + " INTEGER DEFAULT 0" +
")";
public static void insertDefaults(SQLiteDatabase db) {
ContentValues values = new ContentValues();
+ long updateTime = System.currentTimeMillis();
+ values.put(MixnMatchColumns.COL_VALUE, SYSTEM_THEME_PKG_NAME);
+ values.put(MixnMatchColumns.COL_UPDATE_TIME, updateTime);
for(String key : MixnMatchColumns.ROWS) {
values.put(MixnMatchColumns.COL_KEY, key);
- values.put(MixnMatchColumns.COL_VALUE, SYSTEM_THEME_PKG_NAME);
db.insert(TABLE_NAME, null, values);
}
}
diff --git a/src/org/cyanogenmod/themes/provider/ThemesProvider.java b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
index 966a18f..ed9025c 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesProvider.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
@@ -305,6 +305,17 @@ public class ThemesProvider extends ContentProvider {
getContext().getContentResolver().notifyChange(uri, null);
break;
case MIXNMATCH:
+ // Make the current value the previous value
+ String prevValue = ProviderUtils.getCurrentThemeForComponent(getContext(),
+ selection, selectionArgs);
+ String newValue = values.getAsString(MixnMatchColumns.COL_VALUE);
+ if (prevValue != null &&
+ prevValue.equals(newValue)) {
+ // Component re-applied? Most likely so remove the update time
+ values.remove(MixnMatchColumns.COL_UPDATE_TIME);
+ } else if (prevValue != null) {
+ values.put(MixnMatchColumns.COL_PREV_VALUE, prevValue);
+ }
rowsUpdated = sqlDB.update(MixnMatchTable.TABLE_NAME, values, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
break;
diff --git a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
index a07d0ba..2feeb07 100644
--- a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
+++ b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
@@ -20,9 +20,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.ThemeManager;
import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.provider.ThemesContract;
+import android.provider.ThemesContract.MixnMatchColumns;
import android.provider.ThemesContract.ThemesColumns;
+import org.cyanogenmod.themes.provider.ThemesOpenHelper;
public class ProviderUtils {
/**
@@ -81,6 +84,26 @@ public class ProviderUtils {
return state;
}
+ public static String getCurrentThemeForComponent(Context context, String selection,
+ String[] selectionArgs) {
+ if (context == null || selection == null || selectionArgs == null) {
+ return null;
+ }
+
+ String[] projection = new String[] {MixnMatchColumns.COL_VALUE};
+ Cursor c = context.getContentResolver().query(MixnMatchColumns.CONTENT_URI,
+ projection, selection, selectionArgs, null);
+
+ String themePkgName = null;
+ if (c != null) {
+ if (c.moveToFirst()) {
+ themePkgName = c.getString(c.getColumnIndex(MixnMatchColumns.COL_VALUE));
+ }
+ c.close();
+ }
+ return themePkgName;
+ }
+
/**
* Sends the {@link android.provider.ThemesContract.Intent#ACTION_THEME_INSTALLED} action
* @param context