mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-05-25 02:52:11 +02:00
feat: use revanced api for changelogs
This commit is contained in:
parent
ffe5c058e0
commit
c2c4895a29
@ -11,7 +11,6 @@ import org.koin.dsl.module
|
||||
|
||||
val repositoryModule = module {
|
||||
singleOf(::ReVancedAPI)
|
||||
singleOf(::GithubRepository)
|
||||
singleOf(::Filesystem) {
|
||||
createdAtStart()
|
||||
}
|
||||
|
@ -1,21 +1,11 @@
|
||||
package app.revanced.manager.di
|
||||
|
||||
import app.revanced.manager.network.service.GithubService
|
||||
import app.revanced.manager.network.service.HttpService
|
||||
import app.revanced.manager.network.service.ReVancedService
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.module
|
||||
|
||||
val serviceModule = module {
|
||||
fun provideReVancedService(
|
||||
client: HttpService,
|
||||
): ReVancedService {
|
||||
return ReVancedService(
|
||||
client = client,
|
||||
)
|
||||
}
|
||||
|
||||
single { provideReVancedService(get()) }
|
||||
singleOf(::ReVancedService)
|
||||
singleOf(::HttpService)
|
||||
singleOf(::GithubService)
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package app.revanced.manager.domain.repository
|
||||
|
||||
import app.revanced.manager.network.service.GithubService
|
||||
|
||||
// TODO: delete this when the revanced api adds download count.
|
||||
class GithubRepository(private val service: GithubService) {
|
||||
suspend fun getChangelog(repo: String) = service.getChangelog(repo)
|
||||
}
|
@ -21,7 +21,8 @@ data class ReVancedReleaseMeta(
|
||||
val draft: Boolean,
|
||||
val prerelease: Boolean,
|
||||
@SerialName("created_at") val createdAt: String,
|
||||
@SerialName("published_at") val publishedAt: String
|
||||
@SerialName("published_at") val publishedAt: String,
|
||||
val body: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -1,15 +0,0 @@
|
||||
package app.revanced.manager.network.service
|
||||
|
||||
import app.revanced.manager.network.dto.GithubChangelog
|
||||
import app.revanced.manager.network.utils.APIResponse
|
||||
import io.ktor.client.request.url
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class GithubService(private val client: HttpService) {
|
||||
suspend fun getChangelog(repo: String): APIResponse<GithubChangelog> = withContext(Dispatchers.IO) {
|
||||
client.request {
|
||||
url("https://api.github.com/repos/revanced/$repo/releases/latest")
|
||||
}
|
||||
}
|
||||
}
|
@ -91,21 +91,6 @@ fun ManagerUpdateChangelog(
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
}
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.FileDownload,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
Text(
|
||||
vm.formattedDownloadCount,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
}
|
||||
}
|
||||
Markdown(
|
||||
vm.changelogHtml,
|
||||
|
@ -8,8 +8,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import app.revanced.manager.R
|
||||
import app.revanced.manager.domain.repository.GithubRepository
|
||||
import app.revanced.manager.network.dto.GithubChangelog
|
||||
import app.revanced.manager.network.api.ReVancedAPI
|
||||
import app.revanced.manager.network.utils.getOrThrow
|
||||
import app.revanced.manager.util.uiSafe
|
||||
import kotlinx.coroutines.launch
|
||||
@ -18,30 +17,19 @@ import org.intellij.markdown.html.HtmlGenerator
|
||||
import org.intellij.markdown.parser.MarkdownParser
|
||||
|
||||
class ManagerUpdateChangelogViewModel(
|
||||
private val githubRepository: GithubRepository,
|
||||
private val api: ReVancedAPI,
|
||||
private val app: Application,
|
||||
) : ViewModel() {
|
||||
private val markdownFlavour = GFMFlavourDescriptor()
|
||||
private val markdownParser = MarkdownParser(flavour = markdownFlavour)
|
||||
|
||||
var changelog by mutableStateOf(
|
||||
GithubChangelog(
|
||||
Changelog(
|
||||
"...",
|
||||
app.getString(R.string.changelog_loading),
|
||||
emptyList()
|
||||
)
|
||||
)
|
||||
private set
|
||||
val formattedDownloadCount by derivedStateOf {
|
||||
val downloadCount = changelog.assets.firstOrNull()?.downloadCount?.toDouble() ?: 0.0
|
||||
if (downloadCount > 1000) {
|
||||
val roundedValue =
|
||||
(downloadCount / 100).toInt() / 10.0 // Divide by 100 and round to one decimal place
|
||||
"${roundedValue}k"
|
||||
} else {
|
||||
downloadCount.toString()
|
||||
}
|
||||
}
|
||||
val changelogHtml by derivedStateOf {
|
||||
val markdown = changelog.body
|
||||
val parsedTree = markdownParser.buildMarkdownTreeFromString(markdown)
|
||||
@ -51,8 +39,15 @@ class ManagerUpdateChangelogViewModel(
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
uiSafe(app, R.string.changelog_download_fail, "Failed to download changelog") {
|
||||
changelog = githubRepository.getChangelog("revanced-manager").getOrThrow()
|
||||
changelog = api.getRelease("revanced-manager").getOrThrow().let {
|
||||
Changelog(it.metadata.tag, it.metadata.body)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Changelog(
|
||||
val version: String,
|
||||
val body: String,
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user