2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.table
|
|
|
|
|
|
|
|
import android.content.ContentValues
|
|
|
|
import android.database.Cursor
|
|
|
|
import android.database.sqlite.SQLiteDatabase
|
|
|
|
|
|
|
|
import java.util.HashSet
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.App1
|
2018-12-01 00:02:18 +01:00
|
|
|
import jp.juggler.util.LogCategory
|
2021-06-24 06:49:27 +02:00
|
|
|
import jp.juggler.util.TableCompanion
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-09-17 20:06:15 +02:00
|
|
|
object MutedApp : TableCompanion {
|
2021-06-20 15:12:25 +02:00
|
|
|
|
|
|
|
private val log = LogCategory("MutedApp")
|
|
|
|
|
2021-10-28 01:37:39 +02:00
|
|
|
override val table = "app_mute"
|
2021-06-20 15:12:25 +02:00
|
|
|
const val COL_ID = "_id"
|
|
|
|
const val COL_NAME = "name"
|
|
|
|
private const val COL_TIME_SAVE = "time_save"
|
|
|
|
|
|
|
|
override fun onDBCreate(db: SQLiteDatabase) {
|
|
|
|
log.d("onDBCreate!")
|
|
|
|
db.execSQL(
|
|
|
|
"""create table if not exists $table
|
2018-09-17 20:06:15 +02:00
|
|
|
($COL_ID INTEGER PRIMARY KEY
|
|
|
|
,$COL_NAME text not null
|
|
|
|
,$COL_TIME_SAVE integer not null
|
|
|
|
)"""
|
2021-06-20 15:12:25 +02:00
|
|
|
)
|
|
|
|
db.execSQL(
|
|
|
|
"create unique index if not exists ${table}_name on $table($COL_NAME)"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDBUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
|
|
|
if (oldVersion < 6 && newVersion >= 6) {
|
|
|
|
onDBCreate(db)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun save(appName: String?) {
|
|
|
|
if (appName == null) return
|
|
|
|
try {
|
|
|
|
val now = System.currentTimeMillis()
|
|
|
|
|
|
|
|
val cv = ContentValues()
|
|
|
|
cv.put(COL_NAME, appName)
|
|
|
|
cv.put(COL_TIME_SAVE, now)
|
|
|
|
App1.database.replace(table, null, cv)
|
|
|
|
} catch (ex: Throwable) {
|
|
|
|
log.e(ex, "save failed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun createCursor(): Cursor {
|
|
|
|
return App1.database.query(table, null, null, null, null, null, "$COL_NAME asc")
|
|
|
|
}
|
|
|
|
|
|
|
|
fun delete(name: String) {
|
|
|
|
try {
|
|
|
|
App1.database.delete(table, "$COL_NAME=?", arrayOf(name))
|
|
|
|
} catch (ex: Throwable) {
|
|
|
|
log.e(ex, "delete failed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// private static final String[] isMuted_projection = new String[]{COL_NAME};
|
|
|
|
// private static final String isMuted_where = COL_NAME+"=?";
|
|
|
|
// private static final ThreadLocal<String[]> isMuted_where_arg = new ThreadLocal<String[]>() {
|
|
|
|
// @Override protected String[] initialValue() {
|
|
|
|
// return new String[1];
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// public static boolean isMuted( String app_name ){
|
|
|
|
// if( app_name == null ) return false;
|
|
|
|
// try{
|
|
|
|
// String[] where_arg = isMuted_where_arg.get();
|
|
|
|
// where_arg[0] = app_name;
|
|
|
|
// Cursor cursor = App1.getDB().query( table, isMuted_projection,isMuted_where , where_arg, null, null, null );
|
|
|
|
// try{
|
|
|
|
// if( cursor.moveToFirst() ){
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// }finally{
|
|
|
|
// cursor.close();
|
|
|
|
// }
|
|
|
|
// }catch( Throwable ex ){
|
|
|
|
// warning.e( ex, "load failed." );
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
val nameSet: HashSet<String>
|
|
|
|
get() {
|
|
|
|
val dst = HashSet<String>()
|
|
|
|
try {
|
|
|
|
App1.database.query(table, null, null, null, null, null, null)
|
|
|
|
.use { cursor ->
|
|
|
|
val idx_name = cursor.getColumnIndex(COL_NAME)
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
val s = cursor.getString(idx_name)
|
|
|
|
dst.add(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ex: Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|