chore: improve readability #95
6 changed files with 41 additions and 36 deletions
|
@ -66,8 +66,9 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
|||
|
||||
private val usbReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (intent?.action == UsbManager.ACTION_USB_DEVICE_ATTACHED || intent?.action == UsbManager.ACTION_USB_DEVICE_DETACHED) {
|
||||
refresh(true)
|
||||
when (intent?.action) {
|
||||
UsbManager.ACTION_USB_DEVICE_ATTACHED -> refresh(fromUsbEvent = true)
|
||||
UsbManager.ACTION_USB_DEVICE_DETACHED -> refresh(fromUsbEvent = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,10 +127,10 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
|||
}
|
||||
|
||||
private fun ensureNotificationPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
requestPermissions(
|
||||
arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),
|
||||
PERMISSION_REQUEST_CODE
|
||||
PERMISSION_REQUEST_CODE,
|
||||
android.Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -160,15 +161,9 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
|||
// but it could change in the future
|
||||
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
||||
|
||||
newPages.add(
|
||||
Page(
|
||||
channel.logicalSlotId,
|
||||
getString(R.string.channel_name_format, channel.logicalSlotId)
|
||||
) {
|
||||
appContainer.uiComponentFactory.createEuiccManagementFragment(
|
||||
slotId,
|
||||
portId
|
||||
)
|
||||
val channelName = getString(R.string.channel_name_format, channel.logicalSlotId)
|
||||
newPages.add(Page(channel.logicalSlotId, channelName) {
|
||||
appContainer.uiComponentFactory.createEuiccManagementFragment(slotId, portId)
|
||||
})
|
||||
}
|
||||
}.collect()
|
||||
|
@ -176,22 +171,19 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
|||
// If USB readers exist, add them at the very last
|
||||
// We use a wrapper fragment to handle logic specific to USB readers
|
||||
usbDevice?.let {
|
||||
newPages.add(
|
||||
Page(
|
||||
EuiccChannelManager.USB_CHANNEL_ID,
|
||||
it.productName ?: getString(R.string.usb)
|
||||
) { UsbCcidReaderFragment() })
|
||||
val productName = it.productName ?: getString(R.string.usb)
|
||||
newPages.add(Page(EuiccChannelManager.USB_CHANNEL_ID, productName) {
|
||||
UsbCcidReaderFragment()
|
||||
})
|
||||
}
|
||||
viewPager.visibility = View.VISIBLE
|
||||
|
||||
if (newPages.size > 1) {
|
||||
tabs.visibility = View.VISIBLE
|
||||
} else if (newPages.isEmpty()) {
|
||||
newPages.add(
|
||||
Page(
|
||||
-1,
|
||||
""
|
||||
) { appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment() })
|
||||
newPages.add(Page(-1, "") {
|
||||
appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment()
|
||||
})
|
||||
}
|
||||
|
||||
newPages.sortBy { it.logicalSlotId }
|
||||
|
|
|
@ -39,12 +39,13 @@ class ProfileDeleteFragment : DialogFragment(), EuiccChannelFragmentMarker {
|
|||
private var deleting = false
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return AlertDialog.Builder(requireContext(), R.style.AlertDialogTheme).apply {
|
||||
AlertDialog.Builder(requireContext(), R.style.AlertDialogTheme).apply {
|
||||
setMessage(getString(R.string.profile_delete_confirm, requireArguments().getString("name")))
|
||||
setView(editText)
|
||||
setPositiveButton(android.R.string.ok, null) // Set listener to null to prevent auto closing
|
||||
setNegativeButton(android.R.string.cancel, null)
|
||||
}.create()
|
||||
return create()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
|
@ -120,7 +120,7 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
|||
try {
|
||||
requireContext().unregisterReceiver(usbPermissionReceiver)
|
||||
} catch (_: Exception) {
|
||||
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
|||
try {
|
||||
requireContext().unregisterReceiver(usbPermissionReceiver)
|
||||
} catch (_: Exception) {
|
||||
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,8 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
|||
replace(
|
||||
R.id.child_container,
|
||||
appContainer.uiComponentFactory.createEuiccManagementFragment(
|
||||
EuiccChannelManager.USB_CHANNEL_ID,
|
||||
0
|
||||
slotId = EuiccChannelManager.USB_CHANNEL_ID,
|
||||
portId = 0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package im.angry.openeuicc.util
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.pm.PackageManager
|
||||
|
||||
fun Activity.requestPermissions(requestCode: Int, vararg permissions: String) {
|
||||
val deniedPermissions = permissions.filter { name ->
|
||||
checkSelfPermission(name) == PackageManager.PERMISSION_DENIED
|
||||
}
|
||||
if (deniedPermissions.isNotEmpty()) {
|
||||
requestPermissions(deniedPermissions.toTypedArray(), requestCode)
|
||||
}
|
||||
}
|
|
@ -110,7 +110,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
|||
telephonyManager.simSlotMapping = mappings
|
||||
return
|
||||
} catch (_: Exception) {
|
||||
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Sometimes hardware supports one ordering but not the reverse
|
||||
|
|
|
@ -16,10 +16,9 @@ class PrivilegedMainActivity : MainActivity() {
|
|||
menu.findItem(R.id.slot_mapping).isVisible = false
|
||||
}
|
||||
|
||||
if (tm.supportsDSDS) {
|
||||
val dsds = menu.findItem(R.id.dsds)
|
||||
dsds.isVisible = true
|
||||
dsds.isChecked = tm.dsdsEnabled
|
||||
menu.findItem(R.id.dsds).apply {
|
||||
isVisible = tm.supportsDSDS
|
||||
isChecked = tm.dsdsEnabled
|
||||
}
|
||||
|
||||
return true
|
||||
|
|
Loading…
Add table
Reference in a new issue