Skip to content

Commit

Permalink
Merge pull request #67 from damontecres/dev/version-tracking
Browse files Browse the repository at this point in the history
Store changed version
  • Loading branch information
damontecres authored Jan 25, 2024
2 parents ff9a048 + be0cba7 commit 1c0f04c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.StashAppAndroidTV"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
android:name=".StashApplication">
<activity
android:name=".MainActivity"
android:banner="@mipmap/stash_logo"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.damontecres.stashapp

import android.app.Application
import android.util.Log
import androidx.core.content.edit
import androidx.preference.PreferenceManager

class StashApplication : Application() {
override fun onCreate() {
super.onCreate()

val pkgInfo = packageManager.getPackageInfo(packageName, 0)

val prefs = PreferenceManager.getDefaultSharedPreferences(this)
val currentVersion = prefs.getString(VERSION_NAME_CURRENT_KEY, null)
val currentVersionCode = prefs.getLong(VERSION_CODE_CURRENT_KEY, -1)
if (pkgInfo.versionName != currentVersion || pkgInfo.versionCode.toLong() != currentVersionCode) {
Log.i(TAG, "App installed: $currentVersion=>${pkgInfo.versionName} ($currentVersionCode=>${pkgInfo.versionCode})")
prefs.edit(true) {
putString(VERSION_NAME_PREVIOUS_KEY, currentVersion)
putLong(VERSION_CODE_PREVIOUS_KEY, currentVersionCode)
putString(VERSION_NAME_CURRENT_KEY, pkgInfo.versionName)
putLong(VERSION_CODE_CURRENT_KEY, pkgInfo.versionCode.toLong())
}
}
}

companion object {
private const val TAG = "StashApplication"
const val VERSION_NAME_PREVIOUS_KEY = "VERSION_NAME_PREVIOUS_NAME"
const val VERSION_CODE_PREVIOUS_KEY = "VERSION_CODE_PREVIOUS_NAME"
const val VERSION_NAME_CURRENT_KEY = "VERSION_CURRENT_KEY"
const val VERSION_CODE_CURRENT_KEY = "VERSION_CODE_CURRENT_KEY"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ class QueryEngine(private val context: Context, private val showToasts: Boolean

private suspend fun <D : Operation.Data> executeQuery(query: ApolloCall<D>): ApolloResponse<D> {
val queryName = query.operation.name()
Log.d(TAG, "executeQuery $queryName: ${query.operation}")
Log.v(
TAG,
"executeQuery $queryName",
)
try {
val response = query.execute()
if (response.errors.isNullOrEmpty()) {
Log.d(TAG, "executeQuery $queryName successful")
Log.v(TAG, "executeQuery $queryName successful")
return response
} else {
val errorMsgs = response.errors!!.map { it.message }.joinToString("\n")
Expand Down

0 comments on commit 1c0f04c

Please sign in to comment.