Skip to content

Commit

Permalink
Merge branch 'compose-dev' into feat/installer-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminHalko committed Aug 15, 2024
2 parents 87261b7 + 747017a commit d709990
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 74 deletions.
16 changes: 3 additions & 13 deletions app/schemas/app.revanced.manager.data.room.AppDatabase/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "c0c780e55e10c9b095c004733c846b67",
"identityHash": "1dd9d5c0201fdf3cfef3ae669fd65e46",
"entities": [
{
"tableName": "patch_bundles",
Expand Down Expand Up @@ -51,17 +51,7 @@
"uid"
]
},
"indices": [
{
"name": "index_patch_bundles_name",
"unique": true,
"columnNames": [
"name"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_patch_bundles_name` ON `${TABLE_NAME}` (`name`)"
}
],
"indices": [],
"foreignKeys": []
},
{
Expand Down Expand Up @@ -407,7 +397,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c0c780e55e10c9b095c004733c846b67')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1dd9d5c0201fdf3cfef3ae669fd65e46')"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package app.revanced.manager.data.platform

import android.Manifest
import android.app.Application
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Environment
import android.Manifest
import android.content.pm.PackageManager
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import app.revanced.manager.util.RequestManageStorageContract
Expand All @@ -16,7 +17,7 @@ class Filesystem(private val app: Application) {
* A directory that gets cleared when the app restarts.
* Do not store paths to this directory in a parcel.
*/
val tempDir = app.cacheDir.resolve("ephemeral").apply {
val tempDir = app.getDir("ephemeral", Context.MODE_PRIVATE).apply {
deleteRecursively()
mkdirs()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sealed class Source {
}

companion object {
fun from(value: String) = when(value) {
fun from(value: String) = when (value) {
Local.SENTINEL -> Local
API.SENTINEL -> API
else -> Remote(Url(value))
Expand All @@ -34,7 +34,7 @@ data class VersionInfo(
@ColumnInfo(name = "integrations_version") val integrations: String? = null,
)

@Entity(tableName = "patch_bundles", indices = [Index(value = ["name"], unique = true)])
@Entity(tableName = "patch_bundles")
data class PatchBundleEntity(
@PrimaryKey val uid: Int,
@ColumnInfo(name = "name") val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class PatcherWorker(
Result.failure()
} finally {
patchedApk.delete()
if (args.input is SelectedApp.Local && args.input.temporary) {
args.input.file.delete()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun SettingsScreen(
) to SettingsDestination.Advanced,
Triple(
R.string.about,
R.string.about_description,
R.string.app_name,
Icons.Outlined.Info
) to SettingsDestination.About,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package app.revanced.manager.ui.screen.settings

import android.app.ActivityManager
import android.content.ClipData
import android.content.ClipboardManager
import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Api
Expand All @@ -13,7 +17,9 @@ import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand All @@ -28,9 +34,10 @@ import app.revanced.manager.ui.component.settings.BooleanItem
import app.revanced.manager.ui.component.settings.IntegerItem
import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.viewmodel.AdvancedSettingsViewModel
import app.revanced.manager.util.toast
import org.koin.androidx.compose.koinViewModel

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun AdvancedSettingsScreen(
onBackClick: () -> Unit,
Expand All @@ -45,6 +52,7 @@ fun AdvancedSettingsScreen(
activityManager.largeMemoryClass
)
}
val haptics = LocalHapticFeedback.current

Scaffold(
topBar = {
Expand Down Expand Up @@ -82,15 +90,6 @@ fun AdvancedSettingsScreen(
}
)

val exportDebugLogsLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) {
it?.let(vm::exportDebugLogs)
}
SettingsListItem(
headlineContent = stringResource(R.string.debug_logs_export),
modifier = Modifier.clickable { exportDebugLogsLauncher.launch(vm.debugLogFileName) }
)

GroupHeader(stringResource(R.string.patcher))
BooleanItem(
preference = vm.prefs.useProcessRuntime,
Expand Down Expand Up @@ -138,16 +137,38 @@ fun AdvancedSettingsScreen(
)

GroupHeader(stringResource(R.string.debugging))
val exportDebugLogsLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) {
it?.let(vm::exportDebugLogs)
}
SettingsListItem(
headlineContent = stringResource(R.string.about_device),
supportingContent = """
**Version**: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})
**Build type**: ${BuildConfig.BUILD_TYPE}
**Model**: ${Build.MODEL}
**Android version**: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})
**Supported Archs**: ${Build.SUPPORTED_ABIS.joinToString(", ")}
**Memory limit**: $memoryLimit
headlineContent = stringResource(R.string.debug_logs_export),
modifier = Modifier.clickable { exportDebugLogsLauncher.launch(vm.debugLogFileName) }
)
val clipboard = remember { context.getSystemService<ClipboardManager>()!! }
val deviceContent = """
Version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})
Build type: ${BuildConfig.BUILD_TYPE}
Model: ${Build.MODEL}
Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})
Supported Archs: ${Build.SUPPORTED_ABIS.joinToString(", ")}
Memory limit: $memoryLimit
""".trimIndent()
SettingsListItem(
modifier = Modifier.combinedClickable(
onClick = { },
onLongClickLabel = stringResource(R.string.copy_to_clipboard),
onLongClick = {
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
clipboard.setPrimaryClip(
ClipData.newPlainText("Device Information", deviceContent)
)

context.toast(context.getString(R.string.toast_copied_to_clipboard))
}
),
headlineContent = stringResource(R.string.about_device),
supportingContent = deviceContent
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ package app.revanced.manager.ui.screen.settings

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun DeveloperOptionsScreen(
Column(modifier = Modifier.padding(paddingValues)) {
GroupHeader(stringResource(R.string.patch_bundles_section))
SettingsListItem(
headlineContent = stringResource(R.string.patch_bundles_redownload),
headlineContent = stringResource(R.string.patch_bundles_force_download),
modifier = Modifier.clickable(onClick = vm::redownloadBundles)
)
SettingsListItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ package app.revanced.manager.ui.screen.settings

import android.os.Build
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
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.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.RadioButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -96,7 +106,7 @@ private fun ThemePicker(
title = { Text(stringResource(R.string.theme)) },
text = {
Column {
Theme.values().forEach {
Theme.entries.forEach {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,17 @@ private fun PackageSelector(packages: Set<String>, onFinish: (String?) -> Unit)
}

@Composable
private fun GroupItem(onClick: () -> Unit, @StringRes headline: Int, @StringRes description: Int) =
private fun GroupItem(
onClick: () -> Unit,
@StringRes headline: Int,
@StringRes description: Int? = null
) {
SettingsListItem(
modifier = Modifier.clickable { onClick() },
headlineContent = stringResource(headline),
supportingContent = stringResource(description)
supportingContent = description?.let { stringResource(it) }
)
}

@Composable
fun KeystoreCredentialsDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package app.revanced.manager.ui.screen.settings

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.*
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AppSelectorViewModel(
private val pm: PM,
private val patchBundleRepository: PatchBundleRepository
) : ViewModel() {
private val inputFile = File(app.cacheDir, "input.apk").also {
private val inputFile = File(app.filesDir, "input.apk").also {
it.delete()
}
val appList = pm.appList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,26 +230,14 @@ class PatcherViewModel(
app.unregisterReceiver(installerBroadcastReceiver)
workManager.cancelWorkById(patcherWorkerId)

when (val selectedApp = input.selectedApp) {
is SelectedApp.Local -> {
if (selectedApp.temporary) selectedApp.file.delete()
}

is SelectedApp.Installed -> {
GlobalScope.launch(Dispatchers.Main) {
uiSafe(app, R.string.failed_to_mount, "Failed to mount") {
installedApp?.let {
if (it.installType == InstallType.ROOT) {
withTimeout(Duration.ofMinutes(1L)) {
rootInstaller.mount(packageName)
}
}
}
if (input.selectedApp is SelectedApp.Installed && installedApp?.installType == InstallType.ROOT) {
GlobalScope.launch(Dispatchers.Main) {
uiSafe(app, R.string.failed_to_mount, "Failed to mount") {
withTimeout(Duration.ofMinutes(1L)) {
rootInstaller.mount(packageName)
}
}
}

else -> Unit
}

tempDir.deleteRecursively()
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<string name="cli">CLI</string>
<string name="manager">Manager</string>

<string name="toast_copied_to_clipboard">Copied!</string>
<string name="copy_to_clipboard">Copy to clipboard</string>

<string name="dashboard">Dashboard</string>
<string name="settings">Settings</string>
<string name="select_app">Select an app</string>
Expand Down Expand Up @@ -49,19 +52,18 @@
<string name="auto_updates_dialog_note">These settings can be changed later.</string>

<string name="general">General</string>
<string name="general_description">General settings</string>
<string name="advanced">Advanced</string>
<string name="advanced_description">Advanced settings</string>
<string name="general_description">Theme, dynamic color</string>
<string name="updates">Updates</string>
<string name="updates_description">Updates for ReVanced Manager</string>
<string name="opensource_licenses">Open source licenses</string>
<string name="opensource_licenses_description">View all the libraries used to make this application</string>
<string name="updates_description">Check for updates and view changelogs</string>
<string name="downloads">Downloads</string>
<string name="downloads_description">Manage downloaded content</string>
<string name="downloads_description">Downloader plugins and downloaded apps</string>
<string name="import_export">Import &amp; export</string>
<string name="import_export_description">Import and export settings</string>
<string name="import_export_description">Keystore, patch options and selection</string>
<string name="advanced">Advanced</string>
<string name="advanced_description">API URL, memory limit, debugging</string>
<string name="about">About</string>
<string name="about_description">About ReVanced</string>
<string name="opensource_licenses">Open source licenses</string>
<string name="opensource_licenses_description">View all the libraries used to make this application</string>

<string name="contributors">Contributors</string>
<string name="contributors_description">View the contributors of ReVanced</string>
Expand Down Expand Up @@ -169,7 +171,7 @@
<string name="device_memory_limit">Memory limits</string>
<string name="device_memory_limit_format">%1$dMB (Normal) - %2$dMB (Large)</string>
<string name="patch_bundles_section">Patch bundles</string>
<string name="patch_bundles_redownload">Redownload all patch bundles</string>
<string name="patch_bundles_force_download">Force download all patch bundles</string>
<string name="patch_bundles_reset">Reset patch bundles</string>
<string name="patching">Patching</string>
<string name="signing">Signing</string>
Expand Down

0 comments on commit d709990

Please sign in to comment.