-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remember selected sim card (closes #320)
- Loading branch information
Showing
6 changed files
with
67 additions
and
54 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
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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/bnyro/contacts/presentation/screens/sms/components/SimCardSelector.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,51 @@ | ||
package com.bnyro.contacts.presentation.screens.sms.components | ||
|
||
import android.telephony.SubscriptionInfo | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.OutlinedButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import com.bnyro.contacts.util.Preferences | ||
import com.bnyro.contacts.util.rememberPreference | ||
|
||
@Composable | ||
fun SimCardSelector( | ||
subscriptions: List<SubscriptionInfo>, | ||
onSubscriptionIndexChange: (SubscriptionInfo) -> Unit | ||
) { | ||
var selectedSubscriptionId by rememberPreference(Preferences.selectedSimSubscriptionIdKey, -1) | ||
|
||
if (subscriptions.size >= 2) { | ||
var currentSubscriptionIndex by remember { | ||
mutableIntStateOf(0) | ||
} | ||
LaunchedEffect(Unit) { | ||
currentSubscriptionIndex = | ||
subscriptions.indexOfFirst { it.subscriptionId == selectedSubscriptionId } | ||
.takeIf { it != -1 } ?: 0 | ||
onSubscriptionIndexChange(subscriptions[currentSubscriptionIndex]) | ||
} | ||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { | ||
OutlinedButton( | ||
onClick = { | ||
currentSubscriptionIndex = | ||
(currentSubscriptionIndex + 1) % subscriptions.size | ||
onSubscriptionIndexChange(subscriptions[currentSubscriptionIndex]) | ||
selectedSubscriptionId = subscriptions[currentSubscriptionIndex].subscriptionId | ||
} | ||
) { | ||
Text( | ||
text = "SIM ${subscriptions[currentSubscriptionIndex].simSlotIndex + 1} - ${subscriptions[currentSubscriptionIndex].displayName}" | ||
) | ||
} | ||
} | ||
} | ||
} |
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