Skip to content

Commit

Permalink
Added What's New
Browse files Browse the repository at this point in the history
F-Droid source will check apk signature
  • Loading branch information
rumboalla committed Aug 15, 2023
1 parent 9516f2a commit ac10474
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ data class AppExistsResponseApk(
val signaturesSha256: List<String>? = emptyList()
)

fun AppExistsResponseApk.toAppUpdate(app: AppInstalled, version: String) = AppUpdate(
fun AppExistsResponseApk.toAppUpdate(app: AppInstalled, release: AppExistsResponseRelease) = AppUpdate(
app.name,
app.packageName,
version,
release.version,
app.version,
versionCode,
app.versionCode,
ApkMirrorSource,
app.iconUri,
"https://www.apkmirror.com$link"
"https://www.apkmirror.com$link",
release.whatsNew.orEmpty()
)
4 changes: 3 additions & 1 deletion app/src/main/java/com/apkupdater/data/fdroid/FdroidApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ data class FdroidApp(
val suggestedVersionCode: String = "",
val suggestedVersionName: String = "",
val added: Long = 0L,
val lastUpdated: Long = 0L
val lastUpdated: Long = 0L,
val allowedAPKSigningKeys: List<String> = emptyList(),
val localized: Map<String, FdroidLocalized> = emptyMap()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.apkupdater.data.fdroid


data class FdroidLocalized(
val summary: String = "",
val whatsNew: String = ""
)
3 changes: 2 additions & 1 deletion app/src/main/java/com/apkupdater/data/fdroid/FdroidUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ fun FdroidUpdate.toAppUpdate(current: AppInstalled?, source: Source) = AppUpdate
"https://f-droid.org/assets/ic_repo_app_default.png".toUri()
else
"https://f-droid.org/repo/icons-640/${app.icon}".toUri(),
"https://f-droid.org/repo/${apk.apkName}"
"https://f-droid.org/repo/${apk.apkName}",
if (current != null) app.localized["en-US"]?.whatsNew.orEmpty() else app.localized["en-US"]?.summary.orEmpty()
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ data class GitHubRelease(
val name: String,
val prerelease: Boolean,
val assets: List<GitHubReleaseAsset>,
val tag_name: String
val tag_name: String,
val body: String = ""
)

3 changes: 2 additions & 1 deletion app/src/main/java/com/apkupdater/data/ui/AppUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ data class AppUpdate(
val source: Source,
val iconUri: Uri = Uri.EMPTY,
val link: String = "",
val whatsNew: String = "",
val isInstalling: Boolean = false,
val id: Int = "${source.name}.$packageName.$versionCode".hashCode()
val id: Int = "${source.name}.$packageName.$versionCode.$version".hashCode()
)

fun List<AppUpdate>.indexOf(id: Int) = indexOfFirst { it.id == id }
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ApkMirrorRepository(
.filter { filterAndroidTv(it) }
.filter { filterWearOS(it) }
.maxByOrNull { it.versionCode }
?.toAppUpdate(apps.getApp(data.pname)!!, data.release.version)
?.toAppUpdate(apps.getApp(data.pname)!!, data.release)
}

private fun filterSignature(apk: AppExistsResponseApk, signature: String?) = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.apkupdater.repository

import android.os.Build
import android.util.Log
import com.apkupdater.data.fdroid.FdroidApp
import com.apkupdater.data.fdroid.FdroidData
import com.apkupdater.data.fdroid.FdroidUpdate
import com.apkupdater.data.fdroid.toAppUpdate
Expand Down Expand Up @@ -34,6 +35,7 @@ class FdroidRepository(
val updates = data.apps
.asSequence()
.filter { appNames.contains(it.packageName) }
.filter { filterSignature(apps.getApp(it.packageName)!!, it) }
.map { FdroidUpdate(data.packages[it.packageName]!![0], it) }
.filter { it.apk.versionCode > apps.getVersionCode(it.app.packageName) }
.parseUpdates(apps)
Expand Down Expand Up @@ -65,6 +67,12 @@ class FdroidRepository(
.map { it.toAppUpdate(apps?.getApp(it.app.packageName), source) }
.toList()

private fun filterSignature(installed: AppInstalled, update: FdroidApp) = when {
update.allowedAPKSigningKeys.isEmpty() -> true
update.allowedAPKSigningKeys.contains(installed.signature) -> true
else -> false
}

private fun filterAlpha(update: FdroidUpdate) = when {
prefs.ignoreAlpha.get() && update.apk.versionName.contains("alpha") -> false
else -> true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class GitHubRepository(
versionCode = versions.second,
oldVersionCode = BuildConfig.VERSION_CODE.toLong(),
source = GitHubSource,
link = releases[0].assets[0].browser_download_url
link = releases[0].assets[0].browser_download_url,
whatsNew = releases[0].body
)))
} else {
// We need to emit empty so it can be combined later
Expand Down Expand Up @@ -80,7 +81,8 @@ class GitHubRepository(
versionCode = 0L,
oldVersionCode = app?.versionCode ?: 0L,
source = GitHubSource,
link = release.assets[0].browser_download_url
link = release.assets[0].browser_download_url,
whatsNew = release.body
)))
} else {
emit(emptyList())
Expand Down
27 changes: 26 additions & 1 deletion app/src/main/java/com/apkupdater/ui/component/Text.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.apkupdater.ui.component

import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
Expand All @@ -19,10 +21,13 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -46,7 +51,8 @@ fun TextBubble(text: String, modifier: Modifier = Modifier) = Text(
.background(
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.7f),
shape = RoundedCornerShape(16.dp)
).then(modifier),
)
.then(modifier),
text = " $text "
)

Expand Down Expand Up @@ -146,3 +152,22 @@ fun BadgeText(number: String) {
}
}
}

@Composable
fun ExpandingAnnotatedText(
text: AnnotatedString,
modifier: Modifier = Modifier,
minLines: Int = 2,
style: TextStyle = MaterialTheme.typography.bodySmall,
) {
var isExpanded by remember { mutableStateOf(false) }
Text(
text = if (text.text.last() == '\n') text.subSequence(0, text.length - 1) else text,
maxLines = if (isExpanded) Int.MAX_VALUE else minLines,
style = style,
overflow = TextOverflow.Ellipsis,
modifier = modifier
.clickable(true) { isExpanded = !isExpanded }
.animateContentSize(),
)
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/apkupdater/ui/component/TvComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -22,10 +23,12 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.text.HtmlCompat
import com.apkupdater.R
import com.apkupdater.data.ui.AppInstalled
import com.apkupdater.data.ui.AppUpdate
import com.apkupdater.util.getAppName
import com.apkupdater.util.toAnnotatedString


@Composable
Expand Down Expand Up @@ -110,6 +113,7 @@ fun TvInstalledItem(app: AppInstalled, onIgnore: (String) -> Unit = {}) = Card(
fun TvUpdateItem(app: AppUpdate, onInstall: (String) -> Unit = {}) = Card {
Column {
TvCommonItem(app.packageName, app.name, app.version, app.oldVersion, app.versionCode, app.oldVersionCode)
WhatsNew(app.whatsNew)
Box {
TvSourceIcon(app)
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.End) {
Expand All @@ -123,6 +127,7 @@ fun TvUpdateItem(app: AppUpdate, onInstall: (String) -> Unit = {}) = Card {
fun TvSearchItem(app: AppUpdate, onInstall: (String) -> Unit = {}) = Card {
Column {
TvCommonItem(app.packageName, app.name, app.version, app.oldVersion, app.versionCode, app.oldVersionCode, app.iconUri, true)
WhatsNew(app.whatsNew)
Box {
TvSourceIcon(app)
Row(modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.End) {
Expand All @@ -131,3 +136,14 @@ fun TvSearchItem(app: AppUpdate, onInstall: (String) -> Unit = {}) = Card {
}
}
}

@Composable
fun WhatsNew(whatsNew: String) {
if (whatsNew.isNotEmpty()) {
val spanned = HtmlCompat.fromHtml(whatsNew.trim(), HtmlCompat.FROM_HTML_MODE_COMPACT)
ExpandingAnnotatedText(
spanned.toAnnotatedString(),
Modifier.padding(8.dp).fillMaxWidth()
)
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/apkupdater/ui/component/UiComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun UpdateImage(app: AppUpdate, onInstall: (String) -> Unit = {}) = Box {
Modifier
.align(Alignment.TopStart)
.padding(4.dp)
.size(32.dp)
.size(28.dp)
)
}

Expand All @@ -56,7 +56,7 @@ fun SearchImage(app: AppUpdate, onInstall: (String) -> Unit = {}) = Box {
Modifier
.align(Alignment.TopStart)
.padding(4.dp)
.size(32.dp)
.size(28.dp)
)
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/apkupdater/ui/screen/AppsScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.apkupdater.ui.screen

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
Expand All @@ -11,8 +13,12 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.grid.items
import com.apkupdater.R
Expand Down Expand Up @@ -92,7 +98,7 @@ fun AppsTopBar(
}
},
navigationIcon = {
IconButton(onClick = {}) {
Box(Modifier.minimumInteractiveComponentSize().size(40.dp), Alignment.Center) {
Icon(Icons.Filled.Home, "Tab Icon")
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/apkupdater/ui/screen/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
Expand Down Expand Up @@ -99,7 +101,7 @@ fun SearchTopBar(viewModel: SearchViewModel) = TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.statusBarColor()),
actions = {},
navigationIcon = {
IconButton(onClick = {}) {
Box(Modifier.minimumInteractiveComponentSize().size(40.dp), Alignment.Center) {
Icon(Icons.Filled.Search, "Tab Icon")
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/apkupdater/ui/screen/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
Expand Down Expand Up @@ -213,7 +214,7 @@ fun SettingsTopBar(viewModel: SettingsViewModel) = TopAppBar(
}
},
navigationIcon = {
IconButton(onClick = {}) {
Box(Modifier.minimumInteractiveComponentSize().size(40.dp), Alignment.Center) {
Icon(Icons.Filled.Settings, "Tab Icon")
}
}
Expand All @@ -230,7 +231,7 @@ fun AboutTopBar(viewModel: SettingsViewModel) = TopAppBar(
}
},
navigationIcon = {
IconButton(onClick = {}) {
Box(Modifier.minimumInteractiveComponentSize().size(40.dp), Alignment.Center) {
Icon(Icons.Filled.Info, "Tab Icon")
}
}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/apkupdater/ui/screen/UpdatesScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.apkupdater.ui.screen

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ThumbUp
Expand All @@ -11,10 +13,14 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.grid.items
import com.apkupdater.R
Expand Down Expand Up @@ -57,7 +63,7 @@ fun UpdatesTopBar(viewModel: UpdatesViewModel) = TopAppBar(
}
},
navigationIcon = {
IconButton(onClick = {}) {
Box(Modifier.minimumInteractiveComponentSize().size(40.dp), Alignment.Center) {
Icon(Icons.Filled.ThumbUp, "Tab Icon")
}
}
Expand Down
Loading

0 comments on commit ac10474

Please sign in to comment.