Skip to content

Commit

Permalink
Improve Settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
rumboalla committed Aug 2, 2023
1 parent c7efcc2 commit 920e11d
Show file tree
Hide file tree
Showing 26 changed files with 246 additions and 71 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The 3.x branch is a full rewrite using modern technologies like **Jetpack Compos
* **Material Design 3** with **Dark**, **Light** and **Dynamic** theme support.
* **Direct install** of updates for sources that support it.
* **Root install** of updates. TODO
* **Languages**: English. TODO
* **Languages**: English, Spanish.

# Download
* [Alpha Preview release (3.0.0-alpha-12)](https://github.com/rumboalla/apkupdater/releases/download/3.0.0-alpha-12/app-debug.apk)
Expand All @@ -29,7 +29,6 @@ If you want to help with translations, open a [Pull Request](https://github.com/
| ![5](https://github.com/rumboalla/apkupdater/assets/21153554/b6ef8b65-6483-482c-a363-220d70dd1f13) | ![6](https://github.com/rumboalla/apkupdater/assets/21153554/e02fb243-12db-47df-8927-fca6e247eca0) |
|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|


# Other Projects
* [CoolRs](https://github.com/rumboalla/coolrs): A collection of Android RenderScript effects.
* [KryptoPrefs](https://github.com/rumboalla/KryptoPrefs): Kotlin library for handling encrypted SharedPreferences.
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/com/apkupdater/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ val mainModule = module {
}
}

single { OkHttpClient
.Builder()
.cache(get())
.addNetworkInterceptor { chain ->
chain.proceed(
single {
OkHttpClient
.Builder()
.cache(get())
.addNetworkInterceptor { chain ->
chain.proceed(
chain.request()
.newBuilder()
.header("User-Agent", "APKUpdater-v" + BuildConfig.VERSION_NAME)
Expand Down Expand Up @@ -90,8 +91,12 @@ val mainModule = module {
}

single(named("aptoide")) {
val client = OkHttpClient.Builder().cache(get()).addNetworkInterceptor {
it.proceed(it.request().newBuilder().header("User-Agent", AptoideRepository.UserAgent).build())
}.build()

Retrofit.Builder()
.client(get())
.client(client)
.baseUrl("https://ws75.aptoide.com/api/7/")
.addConverterFactory(GsonConverterFactory.create(get()))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ class ApkMirrorRepository(
else -> false
}

// Filter out standalone AndroidTV apps if we are not an AndroidTV device
private fun filterAndroidTv(apk: AppExistsResponseApk): Boolean {
if (!isAndroidTV) {
// Filter out standalone AndroidTV apps if we are not an AndroidTV device
if(apk.capabilities?.contains("leanback_standalone").orFalse()) {
return false
}
} else {
// Filter out apps that don't have leanback if we are an AndroidTV device
return (apk.capabilities?.contains("leanback_standalone").orFalse()
|| apk.capabilities?.contains("leanback").orFalse())
}
return true
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/apkupdater/repository/AptoideRepository.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.apkupdater.repository

import android.os.Build
import android.util.Log
import com.apkupdater.data.aptoide.App
import com.apkupdater.data.aptoide.ListAppsUpdatesRequest
Expand All @@ -9,6 +10,7 @@ import com.apkupdater.data.ui.AppInstalled
import com.apkupdater.data.ui.toApksData
import com.apkupdater.prefs.Prefs
import com.apkupdater.service.AptoideService
import com.apkupdater.util.randomUUID
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow

Expand All @@ -17,6 +19,14 @@ class AptoideRepository(
private val service: AptoideService,
private val prefs: Prefs
) {
companion object {
val UserAgent = "aptoide-9.20.6.1;" + getTerminal() + ";0x0;id:" + randomUUID() + ";;"
private fun getTerminal() = "${getModel()}(${getProduct()});v${getRelease()};${getArch()}"
private fun getProduct() = Build.PRODUCT.replace(";", " ")
private fun getModel() = Build.MODEL.replace(";", " ")
private fun getRelease() = Build.VERSION.RELEASE.replace(";", " ")
private fun getArch() = System.getProperty("os.arch")
}

suspend fun updates(apps: List<AppInstalled>) = flow {
val data = apps.map(AppInstalled::toApksData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class GitHubRepository(
val releases = service.getReleases()
val versions = getVersions(releases[0].name)

if (versions.second > BuildConfig.VERSION_CODE) {
if (versions.second != BuildConfig.VERSION_CODE.toLong()) {
emit(listOf(AppUpdate(
name = "ApkUpdater",
name = "APKUpdater",
packageName = BuildConfig.APPLICATION_ID,
version = versions.first,
versionCode = versions.second,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class UpdatesRepository(
fun updates() = flow {
appsRepository.getApps().collect { result ->
result.onSuccess { apps ->
val filtered = apps.filter { !it.ignored }
val sources = mutableListOf<Flow<List<AppUpdate>>>()
if (prefs.useApkMirror.get()) sources.add(apkMirrorRepository.updates(apps))
if (prefs.useGitHub.get()) sources.add(gitHubRepository.updates(apps))
if (prefs.useFdroid.get()) sources.add(fdroidRepository.updates(apps))
if (prefs.useAptoide.get()) sources.add(aptoideRepository.updates(apps))
if (prefs.useApkMirror.get()) sources.add(apkMirrorRepository.updates(filtered))
if (prefs.useGitHub.get()) sources.add(gitHubRepository.updates(filtered))
if (prefs.useFdroid.get()) sources.add(fdroidRepository.updates(filtered))
if (prefs.useAptoide.get()) sources.add(aptoideRepository.updates(filtered))
sources
.combine { updates -> emit(updates.flatMap { it }) }
.collect()
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/apkupdater/ui/component/Image.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
Expand Down Expand Up @@ -51,7 +50,7 @@ fun LoadingImage(
fun LoadingImageApp(
packageName: String,
modifier: Modifier = Modifier.height(120.dp).fillMaxSize(),
crossfade: Boolean = true,
crossfade: Boolean = false,
color: Color = Color.Transparent
) = BaseLoadingImage(
ImageRequest.Builder(LocalContext.current).data(LocalContext.current.getAppIcon(packageName)).crossfade(crossfade).build(),
Expand Down
107 changes: 82 additions & 25 deletions app/src/main/java/com/apkupdater/ui/component/Settings.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
package com.apkupdater.ui.component

import androidx.annotation.DrawableRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Slider
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterEnd
import androidx.compose.ui.Alignment.Companion.CenterStart
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalTextInputService
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.apkupdater.R


@Composable
Expand All @@ -30,13 +41,30 @@ fun SliderSetting(
setValue: (Float) -> Unit,
text: String,
valueRange: ClosedFloatingPointRange<Float>,
steps: Int
) = Box(
Modifier.fillMaxWidth().height(60.dp).padding(horizontal = 16.dp)) {
var position by remember { mutableStateOf(getValue()) }
Text(text, Modifier.align(Alignment.CenterStart))
Row(Modifier.align(Alignment.CenterEnd)) {
Text("${getValue().toInt()}", Modifier.align(Alignment.CenterVertically).padding(8.dp))
steps: Int,
@DrawableRes icon: Int
) = Row(
Modifier
.fillMaxWidth()
.height(70.dp)
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp)
) {
var position by remember { mutableFloatStateOf(getValue()) }
Icon(painterResource(id = icon), text, Modifier.align(CenterVertically))
Column(
Modifier
.padding(start = 16.dp)
.fillMaxWidth()) {
Box(Modifier.fillMaxWidth()) {
Text(text,
Modifier
.align(CenterStart)
.padding(start = 8.dp))
Text("${getValue().toInt()}",
Modifier
.align(CenterEnd)
.padding(end = 8.dp))
}
Slider(
value = position,
valueRange = valueRange,
Expand All @@ -45,7 +73,9 @@ fun SliderSetting(
position = it
setValue(it)
},
modifier = Modifier.width(150.dp)
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp)
)
}
}
Expand All @@ -54,18 +84,30 @@ fun SliderSetting(
fun SwitchSetting(
getValue: () -> Boolean,
setValue: (Boolean) -> Unit,
text: String
text: String,
@DrawableRes icon: Int = R.drawable.ic_system
) = Box (
Modifier.fillMaxWidth().height(60.dp).padding(horizontal = 16.dp)) {
Modifier
.fillMaxWidth()
.height(60.dp)
.padding(horizontal = 16.dp)
) {
var value by remember { mutableStateOf(getValue()) }
Text(text, Modifier.align(Alignment.CenterStart))
Row(Modifier.align(CenterStart)) {
Icon(
painterResource(id = icon),
text,
Modifier.align(CenterVertically).padding(end = 16.dp).size(24.dp)
)
Text(text, Modifier.align(CenterVertically))
}
Switch(
checked = value,
onCheckedChange = {
value = it
setValue(it)
},
modifier = Modifier.align(Alignment.CenterEnd)
modifier = Modifier.align(CenterEnd)
)
}

Expand All @@ -75,25 +117,40 @@ fun DropDownSetting(
text: String,
options: List<String>,
getValue: () -> Int,
setValue: (Int) -> Unit
) = Box(Modifier.padding(16.dp).fillMaxWidth()) {
setValue: (Int) -> Unit,
@DrawableRes icon: Int
) = Box(
Modifier
.padding(16.dp)
.fillMaxWidth()) {
var expanded by remember { mutableStateOf(false) }
var selectedOptionText by remember { mutableStateOf(options[getValue()]) }

Text(text, modifier = Modifier.align(Alignment.CenterStart))
Row(Modifier.align(CenterStart)) {
Icon(
painterResource(id = icon),
text,
Modifier.align(CenterVertically).padding(end = 16.dp).size(24.dp)
)
Text(text, Modifier.align(CenterVertically))
}
ExposedDropdownMenuBox(
expanded = expanded,
onExpandedChange = { expanded = !expanded },
modifier = Modifier.align(Alignment.CenterEnd).width(150.dp)
modifier = Modifier
.align(CenterEnd)
.width(150.dp)
) {
OutlinedTextField(
readOnly = true,
value = selectedOptionText,
onValueChange = { setValue(options.indexOf(it)) },
modifier = Modifier.menuAnchor(),
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
colors = ExposedDropdownMenuDefaults.textFieldColors()
)
CompositionLocalProvider(LocalTextInputService provides null) { // Disable Keyboard
OutlinedTextField(
readOnly = true,
value = selectedOptionText,
onValueChange = { setValue(options.indexOf(it)) },
modifier = Modifier.menuAnchor(),
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
colors = ExposedDropdownMenuDefaults.textFieldColors()
)
}
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
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 com.apkupdater.R
import com.apkupdater.data.ui.AppInstalled
import com.apkupdater.data.ui.AppUpdate
import com.apkupdater.util.getAppName

@Composable
fun TvCommonItem(
Expand Down Expand Up @@ -53,7 +55,7 @@ fun TvCommonItem(
.align(Alignment.CenterVertically)
.padding(horizontal = 8.dp)
) {
LargeTitle(name)
LargeTitle(name.ifEmpty { LocalContext.current.getAppName(packageName) })
MediumText(version)
MediumText(versionCode.toString())
}
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/apkupdater/ui/screen/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.core.util.Consumer
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
Expand Down Expand Up @@ -148,7 +149,13 @@ fun RowScope.BottomBarItem(
Icon(if (selected) screen.iconSelected else screen.icon, contentDescription = null)
}
},
label = { Text(stringResource(screen.resourceId)) },
label = {
Text(
stringResource(screen.resourceId),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
},
selected = selected,
onClick = { mainViewModel.navigateTo(navController, screen.route) }
)
Expand Down
8 changes: 6 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 @@ -18,10 +18,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.tv.foundation.lazy.grid.items
import com.apkupdater.R
import com.apkupdater.data.ui.SearchUiState
import com.apkupdater.prefs.Prefs
import com.apkupdater.ui.component.DefaultErrorScreen
Expand Down Expand Up @@ -84,8 +86,10 @@ fun SearchTopBar(viewModel: SearchViewModel) = Box {
OutlinedTextField(
value = value,
onValueChange = { value = it },
modifier = Modifier.fillMaxWidth().padding(8.dp),
label = { Text("Search") },
modifier = Modifier
.fillMaxWidth()
.padding(8.dp),
label = { Text(stringResource(R.string.tab_search)) },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions = KeyboardActions(onSearch = { keyboardController?.hide() })
)
Expand Down
Loading

0 comments on commit 920e11d

Please sign in to comment.