mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Fix "select all" not working for apps not in the DB
- Now we store the "select all" as the default value for apps not in the DB - This also means new apps, which makes sense - We pre-fill the "select all" checkbox with the default value Also, now we store true/false as integers 1/0 instead of as string
This commit is contained in:
@@ -22,6 +22,7 @@ package org.kde.kdeconnect.Plugins.NotificationsPlugin;
|
|||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
@@ -31,23 +32,27 @@ import java.util.HashSet;
|
|||||||
class AppDatabase {
|
class AppDatabase {
|
||||||
|
|
||||||
static final private HashSet<String> disabledByDefault = new HashSet<>();
|
static final private HashSet<String> disabledByDefault = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
disabledByDefault.add("com.google.android.googlequicksearchbox"); //Google Now notifications re-spawn every few minutes
|
disabledByDefault.add("com.google.android.googlequicksearchbox"); //Google Now notifications re-spawn every few minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String SETTINGS_NAME = "app_database";
|
||||||
|
private static final String SETTINGS_KEY_ALL_ENABLED = "all_enabled";
|
||||||
|
|
||||||
|
private static final int DATABASE_VERSION = 4;
|
||||||
|
private static final String DATABASE_NAME = "Applications";
|
||||||
|
private static final String DATABASE_TABLE = "Applications";
|
||||||
private static final String KEY_PACKAGE_NAME = "packageName";
|
private static final String KEY_PACKAGE_NAME = "packageName";
|
||||||
private static final String KEY_IS_ENABLED = "isEnabled";
|
private static final String KEY_IS_ENABLED = "isEnabled";
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "Applications";
|
|
||||||
private static final String DATABASE_TABLE = "Applications";
|
|
||||||
private static final int DATABASE_VERSION = 2;
|
|
||||||
|
|
||||||
private SQLiteDatabase ourDatabase;
|
private SQLiteDatabase ourDatabase;
|
||||||
private DbHelper ourHelper;
|
private DbHelper ourHelper;
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
AppDatabase(Context context, boolean readonly) {
|
AppDatabase(Context context, boolean readonly) {
|
||||||
ourHelper = new DbHelper(context);
|
ourHelper = new DbHelper(context);
|
||||||
|
prefs = context.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
if (readonly) {
|
if (readonly) {
|
||||||
ourDatabase = ourHelper.getReadableDatabase();
|
ourDatabase = ourHelper.getReadableDatabase();
|
||||||
} else {
|
} else {
|
||||||
@@ -69,7 +74,7 @@ class AppDatabase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
db.execSQL("CREATE TABLE " + DATABASE_TABLE + "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + KEY_IS_ENABLED + " TEXT NOT NULL); ");
|
db.execSQL("CREATE TABLE " + DATABASE_TABLE + "(" + KEY_PACKAGE_NAME + " TEXT PRIMARY KEY NOT NULL, " + KEY_IS_ENABLED + " INTEGER NOT NULL); ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,7 +89,7 @@ class AppDatabase {
|
|||||||
String[] columns = new String[]{KEY_IS_ENABLED};
|
String[] columns = new String[]{KEY_IS_ENABLED};
|
||||||
try (Cursor res = ourDatabase.query(DATABASE_TABLE, columns, KEY_PACKAGE_NAME + " =? ", new String[]{packageName}, null, null, null)) {
|
try (Cursor res = ourDatabase.query(DATABASE_TABLE, columns, KEY_PACKAGE_NAME + " =? ", new String[]{packageName}, null, null, null)) {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(KEY_IS_ENABLED, isEnabled ? "true" : "false");
|
cv.put(KEY_IS_ENABLED, isEnabled ? 1 : 0);
|
||||||
if (res.getCount() > 0) {
|
if (res.getCount() > 0) {
|
||||||
ourDatabase.update(DATABASE_TABLE, cv, KEY_PACKAGE_NAME + "=?", new String[]{packageName});
|
ourDatabase.update(DATABASE_TABLE, cv, KEY_PACKAGE_NAME + "=?", new String[]{packageName});
|
||||||
} else {
|
} else {
|
||||||
@@ -94,8 +99,13 @@ class AppDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean getAllEnabled() {
|
||||||
|
return prefs.getBoolean(SETTINGS_KEY_ALL_ENABLED, true);
|
||||||
|
}
|
||||||
|
|
||||||
void setAllEnabled(boolean enabled) {
|
void setAllEnabled(boolean enabled) {
|
||||||
ourDatabase.execSQL("UPDATE " + DATABASE_TABLE + " SET " + KEY_IS_ENABLED + "='" + enabled + "'");
|
prefs.edit().putBoolean(SETTINGS_KEY_ALL_ENABLED, enabled).apply();
|
||||||
|
ourDatabase.execSQL("UPDATE " + DATABASE_TABLE + " SET " + KEY_IS_ENABLED + "=" + (enabled? "1" : "0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isEnabled(String packageName) {
|
boolean isEnabled(String packageName) {
|
||||||
@@ -104,7 +114,7 @@ class AppDatabase {
|
|||||||
boolean result;
|
boolean result;
|
||||||
if (res.getCount() > 0) {
|
if (res.getCount() > 0) {
|
||||||
res.moveToFirst();
|
res.moveToFirst();
|
||||||
result = (res.getString(res.getColumnIndex(KEY_IS_ENABLED))).equals("true");
|
result = (res.getInt(res.getColumnIndex(KEY_IS_ENABLED)) != 0);
|
||||||
} else {
|
} else {
|
||||||
result = getDefaultStatus(packageName);
|
result = getDefaultStatus(packageName);
|
||||||
}
|
}
|
||||||
@@ -113,7 +123,10 @@ class AppDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getDefaultStatus(String packageName) {
|
private boolean getDefaultStatus(String packageName) {
|
||||||
return !disabledByDefault.contains(packageName);
|
if (disabledByDefault.contains(packageName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return getAllEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -148,6 +148,7 @@ public class NotificationFilterActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
listView.setItemChecked(0, appDatabase.getAllEnabled()); //"Select all" button
|
||||||
for (int i = 0; i < apps.length; i++) {
|
for (int i = 0; i < apps.length; i++) {
|
||||||
listView.setItemChecked(i + 1, apps[i].isEnabled);
|
listView.setItemChecked(i + 1, apps[i].isEnabled);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user