forked from ReVanced/revanced-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updater changelogs (ReVanced#48)
--------- Co-authored-by: Aunali321 <[email protected]>
- Loading branch information
Showing
21 changed files
with
528 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
app/src/main/java/app/revanced/manager/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/app/revanced/manager/domain/repository/GithubRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.revanced.manager.domain.repository | ||
|
||
import app.revanced.manager.network.service.GithubService | ||
|
||
class GithubRepository(private val service: GithubService) { | ||
suspend fun getChangelog(repo: String) = service.getChangelog(repo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/src/main/java/app/revanced/manager/network/dto/GithubChangelog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package app.revanced.manager.network.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GithubChangelog( | ||
@SerialName("tag_name") val version: String, | ||
@SerialName("body") val body: String, | ||
@SerialName("assets") val assets: List<GithubAsset> | ||
) | ||
|
||
@Serializable | ||
data class GithubAsset( | ||
@SerialName("download_count") val downloadCount: Int, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/app/revanced/manager/network/service/GithubService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app/src/main/java/app/revanced/manager/ui/component/Markdown.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package app.revanced.manager.ui.component | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.MotionEvent | ||
import android.view.ViewGroup | ||
import android.webkit.WebResourceRequest | ||
import android.webkit.WebView | ||
import androidx.compose.foundation.background | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import app.revanced.manager.util.hexCode | ||
import app.revanced.manager.util.openUrl | ||
import com.google.accompanist.web.AccompanistWebViewClient | ||
import com.google.accompanist.web.WebView | ||
import com.google.accompanist.web.rememberWebViewStateWithHTMLData | ||
|
||
@Composable | ||
@SuppressLint("ClickableViewAccessibility") | ||
fun Markdown( | ||
text: String, | ||
modifier: Modifier = Modifier | ||
) { | ||
val ctx = LocalContext.current | ||
val state = rememberWebViewStateWithHTMLData(data = generateMdHtml(source = text)) | ||
val client = remember { | ||
object : AccompanistWebViewClient() { | ||
override fun shouldOverrideUrlLoading( | ||
view: WebView?, | ||
request: WebResourceRequest? | ||
): Boolean { | ||
if (request != null) ctx.openUrl(request.url.toString()) | ||
return true | ||
} | ||
} | ||
} | ||
|
||
WebView( | ||
state, | ||
modifier = Modifier | ||
.background(Color.Transparent) | ||
.then(modifier), | ||
client = client, | ||
onCreated = { | ||
it.setBackgroundColor(android.graphics.Color.TRANSPARENT) | ||
it.isVerticalScrollBarEnabled = false | ||
it.isHorizontalScrollBarEnabled = false | ||
it.setOnTouchListener { _, event -> event.action == MotionEvent.ACTION_MOVE } | ||
it.layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT | ||
) | ||
} | ||
) | ||
} | ||
|
||
@Composable | ||
fun generateMdHtml( | ||
source: String, | ||
wrap: Boolean = false, | ||
headingColor: Color = MaterialTheme.colorScheme.onSurface, | ||
textColor: Color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
linkColor: Color = MaterialTheme.colorScheme.primary | ||
) = remember(source, wrap, headingColor, textColor, linkColor) { | ||
"""<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Markdown</title> | ||
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> | ||
<style> | ||
body { | ||
color: #${textColor.hexCode}; | ||
} | ||
a { | ||
color: #${linkColor.hexCode}!important; | ||
} | ||
a.anchor { | ||
display: none; | ||
} | ||
.highlight pre, pre { | ||
word-wrap: ${if (wrap) "break-word" else "normal"}; | ||
white-space: ${if (wrap) "pre-wrap" else "pre"}; | ||
} | ||
h2 { | ||
color: #${headingColor.hexCode}; | ||
font-size: 18px; | ||
font-weight: 500; | ||
line-height: 24px; | ||
letter-spacing: 0.15px; | ||
} | ||
ul { | ||
margin-left: 0px; | ||
padding-left: 18px; | ||
} | ||
li { | ||
margin-left: 2px; | ||
} | ||
::marker { | ||
font-size: 16px; | ||
margin-right: 8px; | ||
color: #${textColor.hexCode}; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
$source | ||
</body> | ||
</html>""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.