refactor
This commit is contained in:
parent
4ee646687a
commit
448b542f82
|
@ -83,7 +83,6 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
const val EXTRA_TASK_ID = "task_id"
|
||||
const val EXTRA_NOTIFICATION_TYPE = "notification_type"
|
||||
|
||||
|
||||
const val APP_SERVER = "https://mastodon-msg.juggler.jp"
|
||||
|
||||
internal val inject_queue = ConcurrentLinkedQueue<InjectData>()
|
||||
|
@ -904,7 +903,8 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
|
||||
TASK_NOTIFICATION_DELETE -> {
|
||||
val db_id = taskData.parseLong(EXTRA_DB_ID)
|
||||
val type = when(TrackingType.parseStr(taskData.parseString(EXTRA_NOTIFICATION_TYPE))){
|
||||
val type =
|
||||
when(TrackingType.parseStr(taskData.parseString(EXTRA_NOTIFICATION_TYPE))) {
|
||||
TrackingType.Reply -> NotificationHelper.TRACKING_NAME_REPLY
|
||||
else -> NotificationHelper.TRACKING_NAME_DEFAULT
|
||||
}
|
||||
|
@ -917,7 +917,8 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
|
||||
TASK_NOTIFICATION_CLICK -> {
|
||||
val db_id = taskData.parseLong(EXTRA_DB_ID)
|
||||
val type = when(TrackingType.parseStr(taskData.parseString(EXTRA_NOTIFICATION_TYPE))){
|
||||
val type =
|
||||
when(TrackingType.parseStr(taskData.parseString(EXTRA_NOTIFICATION_TYPE))) {
|
||||
TrackingType.Reply -> NotificationHelper.TRACKING_NAME_REPLY
|
||||
else -> NotificationHelper.TRACKING_NAME_DEFAULT
|
||||
}
|
||||
|
@ -1150,11 +1151,6 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// 種別チェックより先に、cache中の最新のIDを「最後に表示した通知」に指定する
|
||||
// nid_show は通知タップ時に参照されるので、通知を表示する際は必ず更新・保存する必要がある
|
||||
// 種別チェックより優先する
|
||||
if(cache.sinceId != null ) nr.nid_show = cache.sinceId
|
||||
|
||||
// 新しい順に並んでいる。先頭から10件までを処理する。ただし処理順序は古い方から
|
||||
val size = min(10, jsonList.size)
|
||||
for(i in (0 until size).reversed()) {
|
||||
|
@ -1163,18 +1159,16 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
}
|
||||
if(job.isJobCancelled) return
|
||||
|
||||
// 種別チェックより先に、cache中の最新のIDを「最後に表示した通知」に指定する
|
||||
// nid_show は通知タップ時に参照されるので、通知を表示する際は必ず更新・保存する必要がある
|
||||
// 種別チェックより優先する
|
||||
if(cache.sinceId != null) nr.nid_show = cache.sinceId
|
||||
nr.save()
|
||||
}
|
||||
|
||||
private fun update_sub(src : JSONObject) {
|
||||
|
||||
// null値が残ってたらログをとる
|
||||
if(nr.nid_read == null || nr.nid_show == null) {
|
||||
log.d("update_sub[${account.db_id}], nid_read=${nr.nid_read}, nid_show=${nr.nid_show}")
|
||||
}
|
||||
|
||||
val id = getEntityOrderId(account, src)
|
||||
|
||||
if(id.isDefault || duplicate_check.contains(id)) return
|
||||
duplicate_check.add(id)
|
||||
|
||||
|
@ -1274,6 +1268,7 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
TrackingType.Reply -> {
|
||||
midInt - account.db_id.toInt()
|
||||
}
|
||||
|
||||
else -> {
|
||||
Integer.MAX_VALUE - account.db_id.toInt()
|
||||
}
|
||||
|
@ -1287,7 +1282,11 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
val builder = if(Build.VERSION.SDK_INT >= 26) {
|
||||
// Android 8 から、通知のスタイルはユーザが管理することになった
|
||||
// NotificationChannel を端末に登録しておけば、チャネルごとに管理画面が作られる
|
||||
val channel = NotificationHelper.createNotificationChannel(context, account,trackingName)
|
||||
val channel = NotificationHelper.createNotificationChannel(
|
||||
context,
|
||||
account,
|
||||
trackingName
|
||||
)
|
||||
NotificationCompat.Builder(context, channel.id)
|
||||
} else {
|
||||
NotificationCompat.Builder(context, "not_used")
|
||||
|
@ -1463,7 +1462,6 @@ class PollingWorker private constructor(contextArg : Context) {
|
|||
NotificationCache.deleteCache(db_id)
|
||||
}
|
||||
|
||||
|
||||
private fun createErrorNotification(error_instance : ArrayList<String>) {
|
||||
if(error_instance.isEmpty()) {
|
||||
return
|
||||
|
|
|
@ -26,6 +26,7 @@ class NotificationCache(private val account_db_id : Long) {
|
|||
// 通知のリスト
|
||||
var data = ArrayList<JSONObject>()
|
||||
|
||||
// 次回以降の読み込み位置
|
||||
var sinceId : EntityId? = null
|
||||
|
||||
companion object : TableCompanion {
|
||||
|
@ -77,58 +78,6 @@ class NotificationCache(private val account_db_id : Long) {
|
|||
|
||||
private const val KEY_TIME_CREATED_AT = "<>KEY_TIME_CREATED_AT"
|
||||
|
||||
// fun updateRead(account_db_id : Long) {
|
||||
// try {
|
||||
// val where_args = arrayOf(account_db_id.toString())
|
||||
// App1.database.query(
|
||||
// table,
|
||||
// arrayOf(COL_NID_SHOW, COL_NID_READ),
|
||||
// WHERE_AID,
|
||||
// where_args,
|
||||
// null,
|
||||
// null,
|
||||
// null
|
||||
// )?.use { cursor ->
|
||||
// when {
|
||||
// ! cursor.moveToFirst() -> log.e("updateRead[${account_db_id}]: can't find the data row.")
|
||||
//
|
||||
// else -> {
|
||||
// val nid_show = EntityId.from(cursor, COL_NID_SHOW)
|
||||
// val nid_read = EntityId.from(cursor, COL_NID_READ)
|
||||
// when {
|
||||
// nid_show == null ->
|
||||
// log.w("updateRead[${account_db_id}]: nid_show is null.")
|
||||
// nid_read != null && nid_read >= nid_show ->
|
||||
// log.d("updateRead[${account_db_id}]: nid_read already updated.")
|
||||
//
|
||||
// else -> {
|
||||
// log.w("updateRead[${account_db_id}]: update nid_read as ${nid_show}...")
|
||||
// val cv = ContentValues()
|
||||
// nid_show.putTo(cv, COL_NID_READ) //変数名とキー名が異なるのに注意
|
||||
// App1.database.update(table, cv, WHERE_AID, where_args)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch(ex : Throwable) {
|
||||
// log.e(ex, "updateRead[${account_db_id}] failed.")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun resetPostAll() {
|
||||
// try {
|
||||
// val cv = ContentValues()
|
||||
// cv.putNull(COL_POST_ID)
|
||||
// cv.put(COL_POST_TIME, 0)
|
||||
// App1.database.update(table, cv, null, null)
|
||||
//
|
||||
// } catch(ex : Throwable) {
|
||||
// log.e(ex, "resetPostAll failed.")
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
fun resetLastLoad(db_id : Long) {
|
||||
try {
|
||||
val cv = ContentValues()
|
||||
|
@ -251,11 +200,9 @@ class NotificationCache(private val account_db_id : Long) {
|
|||
cv.put(COL_LAST_LOAD, last_load)
|
||||
cv.put(COL_DATA, data.toJsonArray().toString())
|
||||
|
||||
val sinceId = sinceId
|
||||
if(sinceId == null) {
|
||||
cv.putNull(COL_SINCE_ID)
|
||||
} else {
|
||||
sinceId.putTo(cv, COL_SINCE_ID)
|
||||
when(val sinceId = sinceId) {
|
||||
null -> cv.putNull(COL_SINCE_ID)
|
||||
else -> sinceId.putTo(cv, COL_SINCE_ID)
|
||||
}
|
||||
|
||||
val rv = App1.database.replaceOrThrow(table, null, cv)
|
||||
|
|
|
@ -11,14 +11,12 @@ fun Boolean.b2i() = if(this) 1 else 0
|
|||
// integer to boolean
|
||||
fun Int.i2b() = this != 0
|
||||
|
||||
|
||||
fun Cursor.getBoolean(keyIdx : Int) =
|
||||
getInt(keyIdx).i2b()
|
||||
|
||||
fun Cursor.getBoolean(key : String) =
|
||||
getBoolean(getColumnIndex(key))
|
||||
|
||||
|
||||
interface TableCompanion {
|
||||
fun onDBCreate(db : SQLiteDatabase)
|
||||
fun onDBUpgrade(db : SQLiteDatabase, oldVersion : Int, newVersion : Int)
|
||||
|
|
Loading…
Reference in New Issue