Skip to content

Commit

Permalink
Add update info & localization support for changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
B1ays committed Jun 24, 2024
1 parent 779c058 commit b9332c9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ internal const val VIBRATION_LENGTH = 300L

const val APK_MIME_TYPE = "application/vnd.android.package-archive"

internal const val UPDATES_SOURCE_URL_STABLE = "" // TODO replace with real url
internal const val UPDATES_SOURCE_URL_BETA = "" // TODO replace with real url
internal const val UPDATES_SOURCE_URL_STABLE = "https://raw.githubusercontent.com/B1ays/BHub/main/update/update_stable.json"
internal const val UPDATES_SOURCE_URL_BETA = "https://raw.githubusercontent.com/B1ays/BHub/main/update/update_beta.json"
internal const val UPDATES_SOURCE_URL_NIGHTLY = "" // TODO replace with real url
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import ru.blays.hub.core.downloader.DownloadMode
import ru.blays.hub.core.downloader.DownloadRequest
import ru.blays.hub.core.logger.Logger
import ru.blays.hub.core.logic.R
import ru.blays.hub.core.logic.data.LocalizedMessage
import ru.blays.hub.core.logic.data.getUpdateChannelUrl
import ru.blays.hub.core.logic.data.models.AppUpdateInfoModel
import ru.blays.hub.core.logic.data.realType
import ru.blays.hub.core.logic.data.toDownloaderType
import ru.blays.hub.core.logic.utils.currentLanguage
import ru.blays.hub.core.logic.utils.downloadsFolder
import ru.blays.hub.core.logic.workers.DownloadAndInstallWorker
import ru.blays.hub.core.network.NetworkResult
Expand Down Expand Up @@ -90,12 +92,30 @@ class SelfUpdateComponent(
}
is NetworkResult.Success -> {
val resultModel = result.data
val changelogResult: NetworkResult<String> = networkRepository.getString(resultModel.changelogUrl)
val updateInfo = resultModel.toUIModel(
changelogResult.getOrDefault(
defaultValue = context.getString(R.string.error_changelog_not_found)
)
)
val changelogResult = networkRepository
.openStream(resultModel.changelogUrl)

val updateInfo = when(changelogResult) {
is NetworkResult.Failure -> {
resultModel.toUIModel(
context.getString(R.string.error_changelog_not_found)
)
}
is NetworkResult.Success -> {
val localizedMessage = LocalizedMessage(changelogResult.data)
if(localizedMessage.isValid) {
val changelog = localizedMessage.getForLanguageOrDefault(
context.currentLanguage
) ?: context.getString(R.string.error_changelog_not_found)
resultModel.toUIModel(changelog)
} else {
resultModel.toUIModel(
context.getString(R.string.error_changelog_not_found)
)
}
}
}

if(checkUpdateAvailable(resultModel.versionCode)) {
dialogNavigation.activate(
SelfUpdateDialogConfig(updateInfo)
Expand Down
3 changes: 3 additions & 0 deletions update/changelog_beta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<messages>
<en default="true">Initial commit</en>
</messages>
3 changes: 3 additions & 0 deletions update/changelog_stable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<messages>
<en default="true">Initial commit</en>
</messages>
Empty file added update/update_beta.json
Empty file.
7 changes: 7 additions & 0 deletions update/update_stable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Version name": "1.0",
"Version code": 1,
"Build date": "24.06.2024",
"Changelog url": "https://raw.githubusercontent.com/B1ays/BHub/main/update/changelog_stable.xml",
"Apk url": "https://github.com/B1ays/BHub/releases/download/1.0/app-release.apk"
}

0 comments on commit b9332c9

Please sign in to comment.