-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GrindrPlus: Introduce block/unblock notifications
- Loading branch information
Showing
5 changed files
with
243 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.grindrplus.core | ||
|
||
import android.content.ContentValues | ||
import android.content.Context | ||
import android.database.Cursor | ||
import android.database.sqlite.SQLiteDatabase | ||
import com.grindrplus.GrindrPlus | ||
|
||
object DatabaseHelper { | ||
private fun getDatabase(): SQLiteDatabase { | ||
val context = GrindrPlus.context | ||
val databases = context.databaseList() | ||
val grindrUserDb = databases.firstOrNull { it.contains("grindr_user") } | ||
?: throw IllegalStateException("No database matching 'grindr_user' found") | ||
return context.openOrCreateDatabase(grindrUserDb, Context.MODE_PRIVATE, null) | ||
} | ||
|
||
fun query(query: String, args: Array<String>? = null): List<Map<String, Any>> { | ||
val database = getDatabase() | ||
val cursor = database.rawQuery(query, args) | ||
val results = mutableListOf<Map<String, Any>>() | ||
|
||
try { | ||
if (cursor.moveToFirst()) { | ||
do { | ||
val row = mutableMapOf<String, Any>() | ||
cursor.columnNames.forEach { column -> | ||
row[column] = when (cursor.getType(cursor.getColumnIndexOrThrow(column))) { | ||
Cursor.FIELD_TYPE_INTEGER -> cursor.getInt(cursor.getColumnIndexOrThrow(column)) | ||
Cursor.FIELD_TYPE_FLOAT -> cursor.getFloat(cursor.getColumnIndexOrThrow(column)) | ||
Cursor.FIELD_TYPE_STRING -> cursor.getString(cursor.getColumnIndexOrThrow(column)) | ||
Cursor.FIELD_TYPE_BLOB -> cursor.getBlob(cursor.getColumnIndexOrThrow(column)) | ||
Cursor.FIELD_TYPE_NULL -> "NULL" | ||
else -> "UNKNOWN" | ||
} | ||
} | ||
results.add(row) | ||
} while (cursor.moveToNext()) | ||
} | ||
} finally { | ||
cursor.close() | ||
database.close() | ||
} | ||
|
||
return results | ||
} | ||
|
||
fun insert(table: String, values: ContentValues): Long { | ||
val database = getDatabase() | ||
val rowId = database.insert(table, null, values) | ||
database.close() | ||
return rowId | ||
} | ||
|
||
fun update(table: String, values: ContentValues, whereClause: String?, whereArgs: Array<String>?): Int { | ||
val database = getDatabase() | ||
val rowsAffected = database.update(table, values, whereClause, whereArgs) | ||
database.close() | ||
return rowsAffected | ||
} | ||
|
||
fun delete(table: String, whereClause: String?, whereArgs: Array<String>?): Int { | ||
val database = getDatabase() | ||
val rowsDeleted = database.delete(table, whereClause, whereArgs) | ||
database.close() | ||
return rowsDeleted | ||
} | ||
|
||
fun execute(sql: String) { | ||
val database = getDatabase() | ||
database.execSQL(sql) | ||
database.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters