Skip to content

Commit

Permalink
- Refactor: Update AppUpdate and Dependencies
Browse files Browse the repository at this point in the history
This commit refactors the `AppUpdate` object to use Ktor for network requests and Kotlin Serialization for JSON parsing.

- Updates dependencies to the latest versions.
- Replaces `getJsonApi` with a Ktor-based implementation in `AppUpdate`.
- Renames data class properties in `AppUpdates` to follow Kotlin coding conventions (e.g., `update_real_version` to `updateRealVersion`).
- Updates usages of `AppUpdates` properties throughout the project to reflect the new naming.
- Updates build files to include Ktor and Kotlin Serialization dependencies.
- Updates `apkString` to use the new property names.
- Refactors update checks to use the new `AppUpdates` properties.
- Updates `SettingsActivity` to use the new `AppUpdates` properties.
- Refactors `GenericAnime`, `GenericManga`, and `GenericNovel` to use the new `AppUpdates` properties.
- Updates `BaseMainActivity` to use the new `AppUpdates` properties.
- Refactors `UpdateChecker` to use the new `AppUpdates` properties.
- Refactors `NavGraph` to improve navigation transitions (TODO).
- Refactors `MainFragment` to use the new `AppUpdates` properties and uses a different random source.
- Refactors `InfoSettings` to use the new `AppUpdates` properties.
  • Loading branch information
jacobrein committed Dec 9, 2024
1 parent be49b42 commit b151a80
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ abstract class BaseMainActivity : AppCompatActivity() {
val appUpdate by updateAppCheck.collectAsState(null)
return AppUpdate.checkForUpdate(
appVersion(),
appUpdate?.update_real_version.orEmpty()
appUpdate?.updateRealVersion.orEmpty()
)
}

Expand Down
2 changes: 2 additions & 0 deletions UIViews/src/main/java/com/programmersbox/uiviews/NavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import com.programmersbox.uiviews.utils.Screen
import com.programmersbox.uiviews.utils.chromeCustomTabs
import com.programmersbox.uiviews.utils.sharedelements.animatedScopeComposable

//TODO: MAYBE give each screen an enum of where they are and the transitions are based off of that?

@OptIn(
ExperimentalAnimationApi::class, ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AppCheckWorker(

override suspend fun doWork(): Result {
return try {
val f = withTimeoutOrNull(60000) { AppUpdate.getUpdate()?.update_real_version.orEmpty() }
val f = withTimeoutOrNull(60000) { AppUpdate.getUpdate()?.updateRealVersion.orEmpty() }
logFirebaseMessage("Current Version: $f")
val appVersion = applicationContext.appVersion
if (f != null && AppUpdate.checkForUpdate(appVersion, f)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ fun InfoSettings(
val downloadInstaller = remember { DownloadAndInstaller(context) }

ShowWhen(
visibility = AppUpdate.checkForUpdate(appVersion(), appUpdate?.update_real_version.orEmpty())
visibility = AppUpdate.checkForUpdate(appVersion(), appUpdate?.updateRealVersion.orEmpty())
) {
var showDialog by remember { mutableStateOf(false) }

if (showDialog) {
AlertDialog(
onDismissRequest = { showDialog = false },
title = { Text(stringResource(R.string.updateTo, appUpdate?.update_real_version.orEmpty())) },
title = { Text(stringResource(R.string.updateTo, appUpdate?.updateRealVersion.orEmpty())) },
text = { Text(stringResource(R.string.please_update_for_latest_features)) },
confirmButton = {
TextButton(
Expand Down Expand Up @@ -171,7 +171,7 @@ fun InfoSettings(

PreferenceSetting(
settingTitle = { Text(stringResource(R.string.update_available)) },
summaryValue = { Text(stringResource(R.string.updateTo, appUpdate?.update_real_version.orEmpty())) },
summaryValue = { Text(stringResource(R.string.updateTo, appUpdate?.updateRealVersion.orEmpty())) },
modifier = Modifier.clickable(
indication = ripple(),
interactionSource = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class GenericAnime(
val storageHolder: StorageHolder,
) : GenericInfo {

override val apkString: AppUpdate.AppUpdates.() -> String? get() = { if (BuildConfig.FLAVOR == "noFirebase") anime_no_firebase_file else anime_file }
override val apkString: AppUpdate.AppUpdates.() -> String? get() = { if (BuildConfig.FLAVOR == "noFirebase") animeNoFirebaseFile else animeFile }
override val deepLinkUri: String get() = "animeworld://"

override val sourceType: String get() = "anime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MainActivity : FragmentActivity() {

lifecycleScope.launch {
if (currentService == null) {
val s = Sources.values().filterNot(Sources::notWorking).random()
val s = Sources.entries.filterNot(Sources::notWorking).random()
//sourceFlow.emit(s)
currentService = s.serviceName
} else if (currentService != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class MainFragment : BrowseSupportFragment() {
.filterNotNull()
.map {
val appVersion = context?.packageManager?.getPackageInfo(requireContext().packageName, 0)?.versionName.orEmpty()
AppUpdate.checkForUpdate(appVersion, it.update_real_version.orEmpty())
AppUpdate.checkForUpdate(appVersion, it.updateRealVersion.orEmpty())
}
.onEach {
if (it) gridRowAdapter.add(resources.getString(R.string.update_available))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class SettingsFragment : LeanbackSettingsFragmentCompat(), DialogPreference.Targ
.flowOn(Dispatchers.Main)
.onEach {
val appVersion = context?.packageManager?.getPackageInfo(requireContext().packageName, 0)?.versionName.orEmpty()
p.summary = if (AppUpdate.checkForUpdate(appVersion, it.update_real_version.orEmpty()))
getString(R.string.updateVersionAvailable, it.update_real_version.orEmpty())
p.summary = if (AppUpdate.checkForUpdate(appVersion, it.updateRealVersion.orEmpty()))
getString(R.string.updateVersionAvailable, it.updateRealVersion.orEmpty())
else ""
}
.collect()
Expand All @@ -136,9 +136,9 @@ class SettingsFragment : LeanbackSettingsFragmentCompat(), DialogPreference.Targ
.filterNotNull()
.flowOn(Dispatchers.Main)
.onEach {
p.summary = getString(R.string.currentVersion, it.update_real_version.orEmpty())
p.summary = getString(R.string.currentVersion, it.updateRealVersion.orEmpty())
val appVersion = context?.packageManager?.getPackageInfo(requireContext().packageName, 0)?.versionName.orEmpty()
p.isVisible = AppUpdate.checkForUpdate(appVersion, it.update_real_version.orEmpty())
p.isVisible = AppUpdate.checkForUpdate(appVersion, it.updateRealVersion.orEmpty())
}
.collect()
}
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
biometricVersion = "1.4.0-alpha02"
blurhash = "0.4.0-SNAPSHOT"
generativeai = "0.9.0"
gradle = "8.7.2"
gradle = "8.7.3"

kotlin = "2.1.0"
kspVersion = "2.1.0-1.0.29"
Expand All @@ -13,7 +13,7 @@ dragselect = "2.4.1"
easylauncher = "6.4.0"
firebaseCrashlyticsGradle = "3.0.2"
googleServices = "4.4.2"
haze = "1.1.0"
haze = "1.1.1"
kamelImage = "1.0.2"
latestAboutLibsRelease = "11.2.3"
coroutinesVersion = "1.9.0"
Expand All @@ -32,7 +32,7 @@ jetpackCompiler = "1.5.11"
jetbrainsCompiler = "1.5.1"
accompanist = "0.36.0"
okhttpVersion = "4.12.0"
ktorVersion = "3.0.1"
ktorVersion = "3.0.2"
workVersion = "2.10.0"
ziplineVersion = "1.1.0"
landscapist = "2.4.4"
Expand Down Expand Up @@ -306,7 +306,7 @@ androidxWebkit = "androidx.webkit:webkit:1.12.1"

mlkitTranslate = "com.google.mlkit:translate:17.0.3"
mlkitLanguage = "com.google.mlkit:language-id:17.0.6"
firebasePlatform = "com.google.firebase:firebase-bom:33.6.0"
firebasePlatform = "com.google.firebase:firebase-bom:33.7.0"
firebaseDatabase = { group = "com.google.firebase", name = "firebase-database" }
firebaseFirestore = { group = "com.google.firebase", name = "firebase-firestore" }
firebaseAuth = { group = "com.google.firebase", name = "firebase-auth" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class GenericManga(

override val deepLinkUri: String get() = "mangaworld://"

override val apkString: AppUpdate.AppUpdates.() -> String? get() = { if (BuildConfig.FLAVOR == "noFirebase") manga_no_firebase_file else manga_file }
override val apkString: AppUpdate.AppUpdates.() -> String? get() = { if (BuildConfig.FLAVOR == "noFirebase") mangaNoFirebaseFile else mangaFile }
override val scrollBuffer: Int = 4

override fun chapterOnClick(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class GenericNovel(val context: Context) : GenericInfo {
) {
}

override val apkString: AppUpdate.AppUpdates.() -> String? get() = { if (BuildConfig.FLAVOR == "noFirebase") novel_no_firebase_file else novel_file }
override val apkString: AppUpdate.AppUpdates.() -> String? get() = { if (BuildConfig.FLAVOR == "noFirebase") novelNoFirebaseFile else novelFile }

@Composable
override fun ComposeShimmerItem() {
Expand Down
3 changes: 3 additions & 0 deletions sharedutils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import plugins.ProductFlavorTypes

plugins {
id("otaku-library")
id("kotlinx-serialization")
}

android {
Expand Down Expand Up @@ -47,6 +48,8 @@ dependencies {
implementation(libs.coroutinesCore)
implementation(libs.coroutinesAndroid)

implementation(libs.bundles.ktorLibs)

implementation(projects.models)
implementation(projects.favoritesdatabase)
implementation(platform(libs.koin.bom))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
package com.programmersbox.sharedutils

import com.programmersbox.gsonutils.getJsonApi
import io.ktor.client.HttpClient
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import io.ktor.serialization.kotlinx.json.json
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json

object AppUpdate {
private const val url = "https://raw.githubusercontent.com/jakepurple13/OtakuWorld/master/update.json"
fun getUpdate() = getJsonApi<AppUpdates>(url)

private val client = HttpClient {
install(ContentNegotiation) {
json()
}
}

suspend fun getUpdate() = runCatching {
client.get(url)
.bodyAsText()
.let { Json.decodeFromString<AppUpdates>(it) }
}
.onSuccess { println(it) }
.onFailure { it.printStackTrace() }
.getOrNull()

@Serializable
data class AppUpdates(
val update_version: Double?,
val update_real_version: String?,
val update_url: String?,
val manga_file: String?,
val anime_file: String?,
val novel_file: String?,
val animetv_file: String?,
val otakumanager_file: String?,
val manga_no_firebase_file: String?,
val anime_no_firebase_file: String?,
val novel_no_firebase_file: String?,
val animetv_no_firebase_file: String?,
@SerialName("update_version")
val updateVersion: Double?,
@SerialName("update_real_version")
val updateRealVersion: String?,
@SerialName("update_url")
val updateUrl: String?,
@SerialName("manga_file")
val mangaFile: String?,
@SerialName("anime_file")
val animeFile: String?,
@SerialName("novel_file")
val novelFile: String?,
@SerialName("animetv_file")
val animetvFile: String?,
@SerialName("otakumanager_file")
val otakumanagerFile: String?,
@SerialName("manga_no_firebase_file")
val mangaNoFirebaseFile: String?,
@SerialName("anime_no_firebase_file")
val animeNoFirebaseFile: String?,
@SerialName("novel_no_firebase_file")
val novelNoFirebaseFile: String?,
@SerialName("animetv_no_firebase_file")
val animetvNoFirebaseFile: String?,
) {
fun downloadUrl(url: AppUpdates.() -> String?) = "$update_url${url()}"
fun downloadUrl(url: AppUpdates.() -> String?) = "$updateUrl${url()}"
}

private fun String.removeVariantSuffix() = removeSuffix("-noFirebase")
Expand All @@ -42,6 +77,7 @@ object AppUpdate {
major.second.toInt() == major.first.toInt()
&& minor.second.toInt() == minor.first.toInt()
&& patch.second.removeVariantSuffix().toInt() > patch.first.removeVariantSuffix().toInt() -> true

else -> false
}
} catch (e: Exception) {
Expand Down

0 comments on commit b151a80

Please sign in to comment.