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: selected app info page (ReVanced#1395)
- Loading branch information
Showing
16 changed files
with
768 additions
and
298 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
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/app/revanced/manager/ui/component/AppInfo.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,39 @@ | ||
package app.revanced.manager.ui.component | ||
|
||
import android.content.pm.PackageInfo | ||
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.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun AppInfo(appInfo: PackageInfo?, placeholderLabel: String? = null, extraContent: @Composable () -> Unit = {}) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 24.dp, vertical = 16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
AppIcon( | ||
appInfo, | ||
contentDescription = null, | ||
modifier = Modifier | ||
.size(100.dp) | ||
.padding(bottom = 5.dp) | ||
) | ||
|
||
AppLabel( | ||
appInfo, | ||
modifier = Modifier.padding(top = 16.dp), | ||
style = MaterialTheme.typography.titleLarge, | ||
defaultText = placeholderLabel | ||
) | ||
|
||
extraContent() | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
app/src/main/java/app/revanced/manager/ui/destination/SelectedAppInfoDestination.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,19 @@ | ||
package app.revanced.manager.ui.destination | ||
|
||
import android.os.Parcelable | ||
import app.revanced.manager.ui.model.SelectedApp | ||
import app.revanced.manager.util.Options | ||
import app.revanced.manager.util.PatchesSelection | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.parcelize.RawValue | ||
|
||
sealed interface SelectedAppInfoDestination : Parcelable { | ||
@Parcelize | ||
data object Main : SelectedAppInfoDestination | ||
|
||
@Parcelize | ||
data class PatchesSelector(val app: SelectedApp, val currentSelection: PatchesSelection?, val options: @RawValue Options) : SelectedAppInfoDestination | ||
|
||
@Parcelize | ||
data object VersionSelector: SelectedAppInfoDestination | ||
} |
82 changes: 82 additions & 0 deletions
82
app/src/main/java/app/revanced/manager/ui/model/BundleInfo.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,82 @@ | ||
package app.revanced.manager.ui.model | ||
|
||
import app.revanced.manager.domain.repository.PatchBundleRepository | ||
import app.revanced.manager.patcher.patch.PatchInfo | ||
import app.revanced.manager.util.PatchesSelection | ||
import app.revanced.manager.util.flatMapLatestAndCombine | ||
import kotlinx.coroutines.flow.map | ||
|
||
/** | ||
* A data class that contains patch bundle metadata for use by UI code. | ||
*/ | ||
data class BundleInfo( | ||
val name: String, | ||
val uid: Int, | ||
val supported: List<PatchInfo>, | ||
val unsupported: List<PatchInfo>, | ||
val universal: List<PatchInfo> | ||
) { | ||
val all = sequence { | ||
yieldAll(supported) | ||
yieldAll(unsupported) | ||
yieldAll(universal) | ||
} | ||
|
||
val patchCount get() = supported.size + unsupported.size + universal.size | ||
|
||
fun patchSequence(allowUnsupported: Boolean) = if (allowUnsupported) { | ||
all | ||
} else { | ||
sequence { | ||
yieldAll(supported) | ||
yieldAll(universal) | ||
} | ||
} | ||
|
||
companion object Extensions { | ||
inline fun Iterable<BundleInfo>.toPatchSelection(allowUnsupported: Boolean, condition: (Int, PatchInfo) -> Boolean): PatchesSelection = this.associate { bundle -> | ||
val patches = | ||
bundle.patchSequence(allowUnsupported) | ||
.mapNotNullTo(mutableSetOf()) { patch -> | ||
patch.name.takeIf { | ||
condition( | ||
bundle.uid, | ||
patch | ||
) | ||
} | ||
} | ||
|
||
bundle.uid to patches | ||
} | ||
|
||
fun PatchBundleRepository.bundleInfoFlow(packageName: String, version: String) = | ||
sources.flatMapLatestAndCombine( | ||
combiner = { it.filterNotNull() } | ||
) { source -> | ||
// Regenerate bundle information whenever this source updates. | ||
source.state.map { state -> | ||
val bundle = state.patchBundleOrNull() ?: return@map null | ||
|
||
val supported = mutableListOf<PatchInfo>() | ||
val unsupported = mutableListOf<PatchInfo>() | ||
val universal = mutableListOf<PatchInfo>() | ||
|
||
bundle.patches.filter { it.compatibleWith(packageName) }.forEach { | ||
val targetList = when { | ||
it.compatiblePackages == null -> universal | ||
it.supportsVersion( | ||
packageName, | ||
version | ||
) -> supported | ||
|
||
else -> unsupported | ||
} | ||
|
||
targetList.add(it) | ||
} | ||
|
||
BundleInfo(source.name, source.uid, supported, unsupported, universal) | ||
} | ||
} | ||
} | ||
} |
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.