From aac13c125a1a44ffe774a210c29ce14fce63b080 Mon Sep 17 00:00:00 2001 From: Alex Gavrishev Date: Mon, 19 Feb 2018 14:28:38 +0200 Subject: [PATCH] Show recently updates for 3 days --- playstore/playstore.iml | 77 +++++++------------ .../anod/appwatcher/backup/AppJsonObject.kt | 18 +++-- .../anod/appwatcher/content/AppListCursor.kt | 5 +- .../content/DbContentProviderClient.kt | 27 ------- .../anod/appwatcher/details/AppDetailsView.kt | 6 ++ .../java/com/anod/appwatcher/model/AppInfo.kt | 29 ++++--- .../appwatcher/model/AppListCursorLoader.kt | 12 ++- .../anod/appwatcher/model/AppListFilter.kt | 11 ++- .../anod/appwatcher/model/DbSchemaManager.kt | 12 +-- .../appwatcher/model/schema/AppListTable.kt | 71 ++++++++++------- .../com/anod/appwatcher/sync/UpdateCheck.kt | 7 +- .../watchlist/AppListCursorAdapter.kt | 4 +- .../appwatcher/watchlist/AppViewHolder.kt | 17 ++-- .../appwatcher/watchlist/AppViewHolderBase.kt | 1 + .../watchlist/AppViewHolderDataProvider.kt | 5 +- .../appwatcher/watchlist/WatchListFragment.kt | 7 +- 16 files changed, 156 insertions(+), 153 deletions(-) diff --git a/playstore/playstore.iml b/playstore/playstore.iml index 8fd5241c..637c1c0d 100644 --- a/playstore/playstore.iml +++ b/playstore/playstore.iml @@ -24,11 +24,11 @@ - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -101,21 +87,16 @@ - - - - - @@ -123,9 +104,7 @@ - - diff --git a/src/main/java/com/anod/appwatcher/backup/AppJsonObject.kt b/src/main/java/com/anod/appwatcher/backup/AppJsonObject.kt index ec0dc217..4f7ae94f 100644 --- a/src/main/java/com/anod/appwatcher/backup/AppJsonObject.kt +++ b/src/main/java/com/anod/appwatcher/backup/AppJsonObject.kt @@ -3,6 +3,7 @@ package com.anod.appwatcher.backup import android.text.TextUtils import com.anod.appwatcher.model.AppInfo import com.anod.appwatcher.model.Tag +import com.anod.appwatcher.model.schema.AppListTable import info.anodsplace.framework.AppLog import info.anodsplace.framework.json.JsonReader import info.anodsplace.framework.json.JsonToken @@ -36,9 +37,9 @@ class AppJsonObject(val app: AppInfo?, val tags: List) { writer.name("status").value(app.status.toLong()) writer.name("detailsUrl").value(app.detailsUrl) writer.name("iconUrl").value(app.iconUrl) - writer.name("refreshTime").value(app.refreshTime) + writer.name("uploadTime").value(app.uploadTime) writer.name("appType").value(app.appType) - writer.name("syncVersion").value(app.syncVersion.toLong()) + writer.name("refreshTimestamp").value(app.refreshTime.toLong()) val tagsWriter = writer.name("tags") tagsWriter.beginArray() @@ -62,9 +63,10 @@ class AppJsonObject(val app: AppInfo?, val tags: List) { var appType = "" var versionNumber = 0 var status = 0 - var syncVersion = 0 var refreshTime: Long = 0 + var uploadTime: Long = 0 val tags = mutableListOf() + val recentTime = AppListTable.recentTime reader.beginObject() while (reader.hasNext()) { @@ -91,12 +93,12 @@ class AppJsonObject(val app: AppInfo?, val tags: List) { detailsUrl = if (isNull) "" else reader.nextString() } else if (name == "iconUrl") { iconUrl = if (isNull) "" else reader.nextString() - } else if (name == "refreshTime") { - refreshTime = reader.nextLong() + } else if (name == "uploadTime") { + uploadTime = reader.nextLong() } else if (name == "appType") { appType = if (isNull) "" else reader.nextString() - } else if (name == "syncVersion") { - syncVersion = if (isNull) 0 else reader.nextInt() + } else if (name == "refreshTimestamp") { + refreshTime = if (isNull) 0 else reader.nextLong() } else if (name == "tags") { reader.beginArray() while (reader.hasNext()) { @@ -116,7 +118,7 @@ class AppJsonObject(val app: AppInfo?, val tags: List) { if (appId != null && pname != null) { val info = AppInfo(0, appId, pname, versionNumber, versionName, title, creator, iconUrl, status, uploadDate, null, null, null, - detailsUrl, refreshTime, appType, syncVersion) + detailsUrl, uploadTime, appType, refreshTime, uploadTime > recentTime) onUpgrade(info) return Pair(info, tags) } diff --git a/src/main/java/com/anod/appwatcher/content/AppListCursor.kt b/src/main/java/com/anod/appwatcher/content/AppListCursor.kt index 7fd8bed6..bfda63c3 100644 --- a/src/main/java/com/anod/appwatcher/content/AppListCursor.kt +++ b/src/main/java/com/anod/appwatcher/content/AppListCursor.kt @@ -31,9 +31,10 @@ class AppListCursor(cursor: Cursor?) : CursorIterator(cursor) { getString(AppListTable.Projection.priceCurrency), getInt(AppListTable.Projection.priceMicros), getString(AppListTable.Projection.detailsUrl), - getLong(AppListTable.Projection.refreshTime), + getLong(AppListTable.Projection.uploadTime), getString(AppListTable.Projection.appType), - getInt(AppListTable.Projection.syncVersion) + getLong(AppListTable.Projection.refreshTime), + getInt(AppListTable.Projection.recentFlag) == 1 ) } diff --git a/src/main/java/com/anod/appwatcher/content/DbContentProviderClient.kt b/src/main/java/com/anod/appwatcher/content/DbContentProviderClient.kt index 0d09c46b..298502d1 100644 --- a/src/main/java/com/anod/appwatcher/content/DbContentProviderClient.kt +++ b/src/main/java/com/anod/appwatcher/content/DbContentProviderClient.kt @@ -53,33 +53,6 @@ class DbContentProviderClient(private val contentProviderClient: ContentProvider return queryApps(sortOrder, selection, selectionArgs) } - fun queryUpdated(tag: Tag?): AppListCursor { - val selc = ArrayList(2) - val args = ArrayList(2) - - selc.add(AppListTable.Columns.status + " = ?") - args.add(AppInfoMetadata.STATUS_UPDATED.toString()) - - if (tag != null) { - selc.add(AppTagsTable.TableColumns.tagId + " = ?") - args.add(tag.id.toString()) - selc.add(AppTagsTable.TableColumns.appId + " = " + AppListTable.TableColumns.appId) - } - - val selection = TextUtils.join(" AND ", selc) - val selectionArgs = args.toTypedArray() - - var cr: Cursor? = null - try { - cr = contentProviderClient.query(DbContentProvider.appsContentUri(tag), - AppListTable.projection, selection, selectionArgs, null - ) - } catch (e: RemoteException) { - AppLog.e(e) - } - return AppListCursor(cr) - } - fun getCount(includeDeleted: Boolean): Int { val cr = queryAll(includeDeleted) return cr.count diff --git a/src/main/java/com/anod/appwatcher/details/AppDetailsView.kt b/src/main/java/com/anod/appwatcher/details/AppDetailsView.kt index e4c1549f..a9017132 100644 --- a/src/main/java/com/anod/appwatcher/details/AppDetailsView.kt +++ b/src/main/java/com/anod/appwatcher/details/AppDetailsView.kt @@ -69,6 +69,12 @@ class AppDetailsView(view: View, private val dataProvider: AppViewHolderBase.Dat val appChange = dataProvider.appChangeContentProvider.query(app.appId, app.versionNumber) this.recentChanges?.text = if (appChange?.details?.isBlank() != false) dataProvider.noRecentChangesText else Html.parse(appChange.details) } + app.recentFlag -> { + version?.text = dataProvider.formatVersionText(app.versionName, app.versionNumber) + this.recentChanges?.visibility = View.VISIBLE + val appChange = dataProvider.appChangeContentProvider.query(app.appId, app.versionNumber) + this.recentChanges?.text = if (appChange?.details?.isBlank() != false) dataProvider.noRecentChangesText else Html.parse(appChange.details) + } else -> { version?.text = dataProvider.formatVersionText(app.versionName, app.versionNumber) this.recentChanges?.visibility = View.GONE diff --git a/src/main/java/com/anod/appwatcher/model/AppInfo.kt b/src/main/java/com/anod/appwatcher/model/AppInfo.kt index d2a83b36..6bf8cef5 100644 --- a/src/main/java/com/anod/appwatcher/model/AppInfo.kt +++ b/src/main/java/com/anod/appwatcher/model/AppInfo.kt @@ -37,18 +37,19 @@ class AppInfo : AppInfoMetadata, Parcelable { val priceCur: String val priceMicros: Int? val iconUrl: String - val refreshTime: Long + val uploadTime: Long val appType: String - val syncVersion: Int + val refreshTime: Long + val recentFlag: Boolean private constructor(rowId: Int, packageName: String, versionCode: Int, versionName: String, title: String, iconUrl: String, status: Int, uploadDate: String) : this(rowId, packageName, packageName, versionCode, versionName, title, null, iconUrl, - status, uploadDate, null, null, 0, createDetailsUrl(packageName), 0, "", 0) + status, uploadDate, null, null, 0, createDetailsUrl(packageName), 0, "", 0, false) constructor(rowId: Int, appId: String, pname: String, versionNumber: Int, versionName: String, title: String, creator: String?, iconUrl: String, status: Int, uploadDate: String, priceText: String?, priceCur: String?, priceMicros: Int?, detailsUrl: String, - refreshTime: Long, appType: String, syncVersion: Int) : super(appId, status) { + uploadTime: Long, appType: String, refreshTime: Long, recentFlag: Boolean) : super(appId, status) { this.rowId = rowId this.packageName = pname this.versionNumber = versionNumber @@ -63,9 +64,10 @@ class AppInfo : AppInfoMetadata, Parcelable { this.detailsUrl = detailsUrl this.iconUrl = iconUrl - this.refreshTime = refreshTime + this.uploadTime = uploadTime this.appType = appType - this.syncVersion = syncVersion + this.refreshTime = refreshTime + this.recentFlag = recentFlag } constructor(doc: Document) : this(0, AppInfoMetadata.STATUS_NORMAL, doc) @@ -90,8 +92,9 @@ class AppInfo : AppInfoMetadata, Parcelable { this.priceCur = offer.currencyCode ?: "" this.iconUrl = doc.iconUrl ?: "" - this.refreshTime = doc.extractUploadDate() - this.syncVersion = 0 + this.uploadTime = doc.extractUploadDate() + this.refreshTime = System.currentTimeMillis() + this.recentFlag = true } constructor(`in`: Parcel) : super(`in`.readString(), `in`.readInt()) { @@ -109,9 +112,10 @@ class AppInfo : AppInfoMetadata, Parcelable { detailsUrl = `in`.readString() iconUrl = `in`.readString() - refreshTime = `in`.readLong() + uploadTime = `in`.readLong() appType = `in`.readString() - syncVersion = `in`.readInt() + refreshTime = `in`.readLong() + recentFlag = `in`.readInt() == 1 } override fun describeContents(): Int { @@ -135,9 +139,10 @@ class AppInfo : AppInfoMetadata, Parcelable { dest.writeString(detailsUrl) dest.writeString(iconUrl) - dest.writeLong(refreshTime) + dest.writeLong(uploadTime) dest.writeString(appType) - dest.writeInt(syncVersion) + dest.writeLong(refreshTime) + dest.writeInt(if (recentFlag) 1 else 0) } companion object { diff --git a/src/main/java/com/anod/appwatcher/model/AppListCursorLoader.kt b/src/main/java/com/anod/appwatcher/model/AppListCursorLoader.kt index d2ac3f16..9b5e4374 100644 --- a/src/main/java/com/anod/appwatcher/model/AppListCursorLoader.kt +++ b/src/main/java/com/anod/appwatcher/model/AppListCursorLoader.kt @@ -60,22 +60,26 @@ open class AppListCursorLoader(context: Context, return AppListCursor(FilterCursor(cr, cursorFilter)) } - val newCountFiltered: Int + val newCount: Int get() = cursorFilter.newCount - val updatableCountFiltered: Int + val updatableCount: Int get() = cursorFilter.updatableNewCount + val recentlyUpdatedCount: Int + get() = cursorFilter.recentlyUpdatedCount + companion object { private fun createSortOrder(sortId: Int): String { val filter = ArrayList() filter.add(AppListTable.Columns.status + " DESC") + filter.add(AppListTable.Columns.recentFlag + " DESC") if (sortId == Preferences.SORT_NAME_DESC) { filter.add(AppListTable.Columns.title + " COLLATE NOCASE DESC") } else if (sortId == Preferences.SORT_DATE_ASC) { - filter.add(AppListTable.Columns.refreshTimestamp + " ASC") + filter.add(AppListTable.Columns.uploadTimestamp + " ASC") } else if (sortId == Preferences.SORT_DATE_DESC) { - filter.add(AppListTable.Columns.refreshTimestamp + " DESC") + filter.add(AppListTable.Columns.uploadTimestamp + " DESC") } else { filter.add(AppListTable.Columns.title + " COLLATE NOCASE ASC") } diff --git a/src/main/java/com/anod/appwatcher/model/AppListFilter.kt b/src/main/java/com/anod/appwatcher/model/AppListFilter.kt index 5fdeac28..d2758445 100644 --- a/src/main/java/com/anod/appwatcher/model/AppListFilter.kt +++ b/src/main/java/com/anod/appwatcher/model/AppListFilter.kt @@ -1,10 +1,10 @@ package com.anod.appwatcher.model import android.database.Cursor -import com.anod.appwatcher.content.DbContentProviderClient import com.anod.appwatcher.model.schema.AppListTable import info.anodsplace.framework.database.FilterCursor import info.anodsplace.framework.content.InstalledApps +import java.util.concurrent.TimeUnit /** * @author alex @@ -15,6 +15,7 @@ import info.anodsplace.framework.content.InstalledApps interface CountableFilter { val newCount: Int val updatableNewCount: Int + val recentlyUpdatedCount: Int fun resetNewCount() } @@ -55,6 +56,8 @@ class AppListFilterInclusion(private val inclusion: Inclusion, private val insta private set override var updatableNewCount: Int = 0 private set + override var recentlyUpdatedCount: Int = 0 + private set override fun filterRecord(cursor: Cursor): Boolean { val packageName = cursor.getString(AppListTable.Projection.packageName) @@ -73,7 +76,10 @@ class AppListFilterInclusion(private val inclusion: Inclusion, private val insta updatableNewCount++ } } else if (status == AppInfoMetadata.STATUS_NORMAL) { - val refreshTime = cursor.getLong(AppListTable.Projection.refreshTime) + val isRecent = cursor.getInt(AppListTable.Projection.recentFlag) == 1 + if (isRecent) { + recentlyUpdatedCount++ + } } return false } @@ -81,5 +87,6 @@ class AppListFilterInclusion(private val inclusion: Inclusion, private val insta override fun resetNewCount() { newCount = 0 updatableNewCount = 0 + recentlyUpdatedCount = 0 } } diff --git a/src/main/java/com/anod/appwatcher/model/DbSchemaManager.kt b/src/main/java/com/anod/appwatcher/model/DbSchemaManager.kt index c7aa55ad..3b159d6d 100644 --- a/src/main/java/com/anod/appwatcher/model/DbSchemaManager.kt +++ b/src/main/java/com/anod/appwatcher/model/DbSchemaManager.kt @@ -42,7 +42,7 @@ class DbSchemaManager(context: Context) db.execSQL(AppTagsTable.sqlCreate) db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.iconUrl + " TEXT") db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.appType + " TEXT") - db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.syncVersion + " INTEGER") + db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.refreshTimestamp + " INTEGER") } 2, 3 -> { db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.priceText + " TEXT") @@ -56,7 +56,7 @@ class DbSchemaManager(context: Context) db.execSQL(AppTagsTable.sqlCreate) db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.iconUrl + " TEXT") db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.appType + " TEXT") - db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.syncVersion + " INTEGER") + db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.refreshTimestamp + " INTEGER") } 4 -> { db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.uploadDate + " TEXT") @@ -67,23 +67,23 @@ class DbSchemaManager(context: Context) db.execSQL(AppTagsTable.sqlCreate) db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.iconUrl + " TEXT") db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.appType + " TEXT") - db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.syncVersion + " INTEGER") + db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.refreshTimestamp + " INTEGER") } 5 -> { db.execSQL(TagsTable.sqlCreate) db.execSQL(AppTagsTable.sqlCreate) db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.iconUrl + " TEXT") db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.appType + " TEXT") - db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.syncVersion + " INTEGER") + db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.refreshTimestamp + " INTEGER") } 6, 7 -> { db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.iconUrl + " TEXT") db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.appType + " TEXT") - db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.syncVersion + " INTEGER") + db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.refreshTimestamp + " INTEGER") } 8 -> { db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.appType + " TEXT") - db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.syncVersion + " INTEGER") + db.execSQL("ALTER TABLE " + AppListTable.table + " ADD COLUMN " + AppListTable.Columns.refreshTimestamp + " INTEGER") } 9,10,11 -> { db.execSQL(ChangelogTable.sqlCreate) diff --git a/src/main/java/com/anod/appwatcher/model/schema/AppListTable.kt b/src/main/java/com/anod/appwatcher/model/schema/AppListTable.kt index 0f452aa5..58632f4a 100644 --- a/src/main/java/com/anod/appwatcher/model/schema/AppListTable.kt +++ b/src/main/java/com/anod/appwatcher/model/schema/AppListTable.kt @@ -3,6 +3,7 @@ package com.anod.appwatcher.model.schema import android.content.ContentValues import android.provider.BaseColumns import com.anod.appwatcher.model.AppInfo +import java.util.concurrent.TimeUnit class AppListTable { @@ -17,14 +18,15 @@ class AppListTable { const val iconCache = "icon" const val iconUrl = "iconUrl" const val status = "status" - const val refreshTimestamp = "update_date" + const val uploadTimestamp = "update_date" const val priceText = "price_text" const val priceCurrency = "price_currency" const val priceMicros = "price_micros" const val uploadDate = "upload_date" const val detailsUrl = "details_url" const val appType = "app_type" - const val syncVersion = "sync_version" + const val refreshTimestamp = "sync_version" + const val recentFlag = "recent_flag" } } @@ -42,7 +44,7 @@ class AppListTable { const val title = 5 const val creator = 6 const val status = 7 - const val refreshTime = 8 + const val uploadTime = 8 const val priceText = 9 const val priceCurrency = 10 const val priceMicros = 11 @@ -50,31 +52,48 @@ class AppListTable { const val detailsUrl = 13 const val iconUrl = 14 const val appType = 15 - const val syncVersion = 16 + const val refreshTime = 16 + const val recentFlag = 17 } companion object { const val table = "app_list" + const val recentDays: Long = 3 - val projection = arrayOf( - TableColumns._ID, - TableColumns.appId, - Columns.packageName, - Columns.versionNumber, - Columns.versionName, - Columns.title, - Columns.creator, - Columns.status, - Columns.refreshTimestamp, - Columns.priceText, - Columns.priceCurrency, - Columns.priceMicros, - Columns.uploadDate, - Columns.detailsUrl, - Columns.iconUrl, - Columns.appType, - Columns.syncVersion) + val recentTime: Long + get() { + val timestamp = System.currentTimeMillis() + // https://stackoverflow.com/questions/13892163/get-timestamp-for-start-of-day + // val dayEnd = dayStart + 86399999 + val dayStart = timestamp - (timestamp%86400000) + return dayStart - TimeUnit.DAYS.toMillis(recentDays) + } + + val projection: Array + get() = projection(recentTime) + + private fun projection(recentTime: Long): Array { + return arrayOf( + TableColumns._ID, + TableColumns.appId, + Columns.packageName, + Columns.versionNumber, + Columns.versionName, + Columns.title, + Columns.creator, + Columns.status, + Columns.uploadTimestamp, + Columns.priceText, + Columns.priceCurrency, + Columns.priceMicros, + Columns.uploadDate, + Columns.detailsUrl, + Columns.iconUrl, + Columns.appType, + Columns.refreshTimestamp, + "case when ${Columns.uploadTimestamp} > $recentTime then 1 else 0 end ${Columns.recentFlag}") + } val sqlCreate = "CREATE TABLE " + table + " (" + @@ -86,7 +105,7 @@ class AppListTable { Columns.title + " TEXT not null," + Columns.creator + " TEXT," + Columns.status + " INTEGER," + - Columns.refreshTimestamp + " INTEGER," + + Columns.uploadTimestamp + " INTEGER," + Columns.priceText + " TEXT," + Columns.priceCurrency + " TEXT," + Columns.priceMicros + " INTEGER," + @@ -94,7 +113,7 @@ class AppListTable { Columns.detailsUrl + " TEXT," + Columns.iconUrl + " TEXT," + Columns.appType + " TEXT," + - Columns.syncVersion + " INTEGER" + + Columns.refreshTimestamp + " INTEGER" + ") " } } @@ -122,9 +141,9 @@ val AppInfo.contentValues: ContentValues values.put(AppListTable.Columns.detailsUrl, detailsUrl) values.put(AppListTable.Columns.iconUrl, iconUrl) - values.put(AppListTable.Columns.refreshTimestamp, refreshTime) + values.put(AppListTable.Columns.uploadTimestamp, uploadTime) values.put(AppListTable.Columns.appType, appType) - values.put(AppListTable.Columns.syncVersion, syncVersion) + values.put(AppListTable.Columns.refreshTimestamp, refreshTime) return values } diff --git a/src/main/java/com/anod/appwatcher/sync/UpdateCheck.kt b/src/main/java/com/anod/appwatcher/sync/UpdateCheck.kt index dcbd0cb0..98b39ae5 100644 --- a/src/main/java/com/anod/appwatcher/sync/UpdateCheck.kt +++ b/src/main/java/com/anod/appwatcher/sync/UpdateCheck.kt @@ -3,7 +3,6 @@ package com.anod.appwatcher.sync import android.accounts.Account import android.content.ContentProviderClient import android.content.ContentValues -import android.content.Context import android.content.Intent import android.os.Bundle import android.os.RemoteException @@ -25,7 +24,6 @@ import com.anod.appwatcher.model.schema.AppListTable import com.anod.appwatcher.model.schema.ChangelogTable import com.anod.appwatcher.model.schema.contentValues import com.anod.appwatcher.userLog.UserLogger -import com.anod.appwatcher.utils.date.CustomParserFactory import com.anod.appwatcher.utils.extractUploadDate import finsky.api.model.DfeModel import finsky.api.model.Document @@ -34,7 +32,6 @@ import info.anodsplace.framework.app.ApplicationContext import info.anodsplace.framework.content.InstalledApps import info.anodsplace.playstore.BulkDetailsEndpoint import info.anodsplace.playstore.PlayStoreEndpoint -import java.text.ParseException import java.util.* /** @@ -114,7 +111,7 @@ class UpdateCheck(private val context: ApplicationContext): PlayStoreEndpoint.Li AppLog.e(e) } - if (updatedApps.isNotEmpty() && updatedApps.first().app.refreshTime == 0.toLong()) { + if (updatedApps.isNotEmpty() && updatedApps.first().app.uploadTime == 0.toLong()) { val uploadDate = updatedApps.first().app.uploadDate val locale = Locale.getDefault() userLogger.error("Cannot parse date '$uploadDate' for locale '$locale'") @@ -376,7 +373,7 @@ class UpdateCheck(private val context: ApplicationContext): PlayStoreEndpoint.Li private fun fillMissingData(marketApp: Document, localApp: AppInfo, values: ContentValues) { val refreshTime = marketApp.extractUploadDate() - values.put(AppListTable.Columns.refreshTimestamp, refreshTime) + values.put(AppListTable.Columns.uploadTimestamp, refreshTime) values.put(AppListTable.Columns.uploadDate, marketApp.appDetails.uploadDate) if (TextUtils.isEmpty(localApp.versionName)) { values.put(AppListTable.Columns.versionName, marketApp.appDetails.versionString) diff --git a/src/main/java/com/anod/appwatcher/watchlist/AppListCursorAdapter.kt b/src/main/java/com/anod/appwatcher/watchlist/AppListCursorAdapter.kt index 04a0fe0f..7d50517f 100644 --- a/src/main/java/com/anod/appwatcher/watchlist/AppListCursorAdapter.kt +++ b/src/main/java/com/anod/appwatcher/watchlist/AppListCursorAdapter.kt @@ -41,7 +41,7 @@ class AppListCursorAdapter( super.swapData(newCursor) } - fun setNewAppsCount(newCount: Int, updatableCount: Int) { - dataProvider.setNewAppsCount(newCount, updatableCount) + fun setNewAppsCount(newCount: Int, updatableCount: Int, recentlyUpdatedCount: Int) { + dataProvider.setNewAppsCount(newCount, updatableCount, recentlyUpdatedCount) } } diff --git a/src/main/java/com/anod/appwatcher/watchlist/AppViewHolder.kt b/src/main/java/com/anod/appwatcher/watchlist/AppViewHolder.kt index ea79004b..ba88045b 100644 --- a/src/main/java/com/anod/appwatcher/watchlist/AppViewHolder.kt +++ b/src/main/java/com/anod/appwatcher/watchlist/AppViewHolder.kt @@ -70,12 +70,7 @@ open class AppViewHolder( } open fun bindSectionView() { - if (location == dataProvider.newAppsCount) { - sectionText.setText(R.string.watching) - sectionCount.text = (dataProvider.totalAppsCount - dataProvider.newAppsCount).toString() - section.visibility = View.VISIBLE - actionButton.visibility = View.GONE - } else if (location == 0 && dataProvider.newAppsCount > 0) { + if (location == 0 && dataProvider.newAppsCount > 0) { sectionText.setText(R.string.new_updates) section.visibility = View.VISIBLE if (dataProvider.updatableAppsCount > 0) { @@ -86,6 +81,16 @@ open class AppViewHolder( sectionCount.text = dataProvider.newAppsCount.toString() sectionCount.visibility = View.VISIBLE } + } else if (location == dataProvider.newAppsCount && dataProvider.recentlyUpdatedCount > 0) { + sectionText.setText(R.string.recently_updated) + sectionCount.text = dataProvider.recentlyUpdatedCount.toString() + section.visibility = View.VISIBLE + actionButton.visibility = View.GONE + } else if (location == (dataProvider.recentlyUpdatedCount + dataProvider.newAppsCount)) { + sectionText.setText(R.string.watching) + sectionCount.text = (dataProvider.totalAppsCount - dataProvider.recentlyUpdatedCount - dataProvider.newAppsCount).toString() + section.visibility = View.VISIBLE + actionButton.visibility = View.GONE } else if (section.visibility == View.VISIBLE) { section.visibility = View.GONE } diff --git a/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderBase.kt b/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderBase.kt index f40649a4..f93978b5 100644 --- a/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderBase.kt +++ b/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderBase.kt @@ -35,6 +35,7 @@ abstract class AppViewHolderBase( fun getColor(@ColorRes colorRes: Int): Int val updatableAppsCount: Int + val recentlyUpdatedCount: Int } abstract fun bindView(location: Int, app: AppInfo) diff --git a/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderDataProvider.kt b/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderDataProvider.kt index 2378fbe8..a1e02998 100644 --- a/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderDataProvider.kt +++ b/src/main/java/com/anod/appwatcher/watchlist/AppViewHolderDataProvider.kt @@ -28,10 +28,13 @@ open class AppViewHolderDataProvider( private set final override var updatableAppsCount = 0 private set + final override var recentlyUpdatedCount = 0 + private set - internal fun setNewAppsCount(newAppsCount: Int, updatableAppsCount: Int) { + internal fun setNewAppsCount(newAppsCount: Int, updatableAppsCount: Int, recentlyUpdatedCount: Int) { this.newAppsCount = newAppsCount this.updatableAppsCount = updatableAppsCount + this.recentlyUpdatedCount = recentlyUpdatedCount } override fun getString(@StringRes resId: Int): String { diff --git a/src/main/java/com/anod/appwatcher/watchlist/WatchListFragment.kt b/src/main/java/com/anod/appwatcher/watchlist/WatchListFragment.kt index 3b793533..52302397 100644 --- a/src/main/java/com/anod/appwatcher/watchlist/WatchListFragment.kt +++ b/src/main/java/com/anod/appwatcher/watchlist/WatchListFragment.kt @@ -77,10 +77,11 @@ open class WatchListFragment : Fragment(), LoaderManager.LoaderCallbacks val watchlistAdapter = getInnerAdapter(ADAPTER_WATCHLIST) watchlistAdapter.swapData(data as AppListCursor) - val newCount = (loader as AppListCursorLoader).newCountFiltered - val updatableCount = loader.updatableCountFiltered + val newCount = (loader as AppListCursorLoader).newCount + val updatableCount = loader.updatableCount + val recentlyUpdatedCount = loader.recentlyUpdatedCount - watchlistAdapter.setNewAppsCount(newCount, updatableCount) + watchlistAdapter.setNewAppsCount(newCount, updatableCount, recentlyUpdatedCount) } override fun loaderReset() {