Skip to content

Commit

Permalink
feat: handle dual SIM (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyujin-cho authored Feb 8, 2023
1 parent 95e9426 commit e9347c6
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 129 deletions.
22 changes: 15 additions & 7 deletions app/src/main/java/dev/bluehouse/enablevolte/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.bluehouse.enablevolte

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.*
import androidx.compose.runtime.*
Expand Down Expand Up @@ -41,7 +42,7 @@ fun HeaderText(text: String) {
}

@Composable
fun BooleanPropertyView(label: String, toggled: Boolean, enabled: Boolean = true, onClick: ((Boolean) -> Unit)? = null) {
fun BooleanPropertyView(label: String, toggled: Boolean, enabled: Boolean = true, trueLabel: String = "Yes", falseLabel: String = "No", onClick: ((Boolean) -> Unit)? = null) {
if (onClick != null) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
Text(text = label, modifier = Modifier.weight(1F), fontSize = 18.sp)
Expand All @@ -50,7 +51,7 @@ fun BooleanPropertyView(label: String, toggled: Boolean, enabled: Boolean = true
} else {
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
Text(text = label, fontSize = 18.sp, modifier = Modifier.padding(bottom = Dp(4f)))
Text(text = if (toggled) { "Yes" } else { "No" }, fontSize = 14.sp, color = MaterialTheme.colorScheme.outline)
Text(text = if (toggled) { trueLabel } else { falseLabel }, fontSize = 14.sp, color = MaterialTheme.colorScheme.outline)
}
}
}
Expand Down Expand Up @@ -95,10 +96,18 @@ fun StringPropertyView(label: String, value: String, onUpdate: ((String) -> Unit
}
)
}
Surface(onClick = {
typedText = value
openTextEditDialog = true
}) {
}
ClickablePropertyView(label = label, value = value) {
typedText = value
openTextEditDialog = true
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ClickablePropertyView(label: String, value: String, onClick: (() -> Unit)? = null) {
if (onClick != null) {
Surface(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.padding(top = Dp(12f), bottom = Dp(12f))) {
Text(text = label, modifier = Modifier.padding(bottom = Dp(4f)), fontSize = 18.sp)
Text(text = value, color = MaterialTheme.colorScheme.outline, fontSize = 14f.sp)
Expand All @@ -110,5 +119,4 @@ fun StringPropertyView(label: String, value: String, onUpdate: ((String) -> Unit
Text(text = value, color = MaterialTheme.colorScheme.outline, fontSize = 14f.sp)
}
}

}
93 changes: 71 additions & 22 deletions app/src/main/java/dev/bluehouse/enablevolte/HomeActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.bluehouse.enablevolte

import android.annotation.StringRes
import android.content.pm.PackageManager
import android.os.Bundle
import android.telephony.SubscriptionInfo
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
Expand All @@ -10,11 +12,17 @@ import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.Lifecycle
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavGraphBuilder
import androidx.navigation.Navigator
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
Expand All @@ -23,8 +31,11 @@ import dev.bluehouse.enablevolte.pages.Config
import dev.bluehouse.enablevolte.pages.Home
import dev.bluehouse.enablevolte.ui.theme.EnableVoLTETheme
import org.lsposed.hiddenapibypass.HiddenApiBypass
import rikka.shizuku.Shizuku
import java.lang.IllegalStateException

private val TAG = "HomeActivity"
private const val TAG = "HomeActivity"
data class Screen(val route: String, val title: String, val icon: ImageVector)

class HomeActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -50,7 +61,51 @@ class HomeActivity : ComponentActivity() {
@Composable
fun PixelIMSApp() {
val navController = rememberNavController()
val carrierModer = CarrierModer(LocalContext.current)

var subscriptions by rememberSaveable { mutableStateOf(listOf<SubscriptionInfo>()) }
var navBuilder by remember {
mutableStateOf<NavGraphBuilder.() -> Unit>({
composable("home") {
Home(navController)
}
})
}

fun generateNavBuilder(): (NavGraphBuilder.() -> Unit) {
return {
composable("home") {
Home(navController)
}
for (subscription in subscriptions) {
composable("config${subscription.subscriptionId}") {
Config(navController, subscription.subscriptionId)
}
}
}
}

OnLifecycleEvent { _, event ->
if (event == Lifecycle.Event.ON_CREATE) {
try {
if (checkShizukuPermission(0)) {
Log.d(dev.bluehouse.enablevolte.pages.TAG, "Shizuku granted")
subscriptions = carrierModer.subscriptions
navBuilder = generateNavBuilder()
} else {
Shizuku.addRequestPermissionResultListener { _, grantResult ->
if (grantResult == PackageManager.PERMISSION_GRANTED) {
Log.d(dev.bluehouse.enablevolte.pages.TAG, "Shizuku granted")
subscriptions = carrierModer.subscriptions
navBuilder = generateNavBuilder()
}
}
}
} catch (_: IllegalStateException) {

}
}
}
Scaffold(
topBar = {
TopAppBar(
Expand All @@ -64,10 +119,21 @@ fun PixelIMSApp() {
NavigationBar {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val items = arrayListOf(
Screen("home", stringResource(R.string.home), Icons.Filled.Home)
)
for (subscription in subscriptions) {
items.add(
Screen("config${subscription.subscriptionId}", subscription.uniqueName, Icons.Filled.Settings)
)
}

items.forEach { screen ->
NavigationBarItem(
icon = { Icon(screen.icon, contentDescription = null) },
label = { Text(stringResource(screen.resourceId)) },
label = {
Text(screen.title)
},
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
onClick = {
navController.navigate(screen.route) {
Expand All @@ -89,23 +155,6 @@ fun PixelIMSApp() {
}
}
) { innerPadding ->
NavHost(navController, startDestination = Screen.Home.route, Modifier.padding(innerPadding)) {
composable(Screen.Home.route) {
Home(navController)
}
composable(Screen.Config.route) {
Config(navController)
}
}
NavHost(navController, startDestination = "home", Modifier.padding(innerPadding), builder = navBuilder)
}
}

sealed class Screen(val route: String, @StringRes val resourceId: Int, val icon: ImageVector) {
object Home : Screen("home", R.string.home, Icons.Filled.Home)
object Config : Screen("config", R.string.config, Icons.Filled.Settings)
}

val items = listOf(
Screen.Home,
Screen.Config,
)
}
Loading

0 comments on commit e9347c6

Please sign in to comment.