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() {
|
private val usbReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
if (intent?.action == UsbManager.ACTION_USB_DEVICE_ATTACHED || intent?.action == UsbManager.ACTION_USB_DEVICE_DETACHED) {
|
when (intent?.action) {
|
||||||
refresh(true)
|
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() {
|
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(
|
requestPermissions(
|
||||||
arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),
|
PERMISSION_REQUEST_CODE,
|
||||||
PERMISSION_REQUEST_CODE
|
android.Manifest.permission.POST_NOTIFICATIONS
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,38 +161,29 @@ open class MainActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
|
||||||
// but it could change in the future
|
// but it could change in the future
|
||||||
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
||||||
|
|
||||||
newPages.add(
|
val channelName = getString(R.string.channel_name_format, channel.logicalSlotId)
|
||||||
Page(
|
newPages.add(Page(channel.logicalSlotId, channelName) {
|
||||||
channel.logicalSlotId,
|
appContainer.uiComponentFactory.createEuiccManagementFragment(slotId, portId)
|
||||||
getString(R.string.channel_name_format, channel.logicalSlotId)
|
})
|
||||||
) {
|
|
||||||
appContainer.uiComponentFactory.createEuiccManagementFragment(
|
|
||||||
slotId,
|
|
||||||
portId
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}.collect()
|
}.collect()
|
||||||
|
|
||||||
// If USB readers exist, add them at the very last
|
// If USB readers exist, add them at the very last
|
||||||
// We use a wrapper fragment to handle logic specific to USB readers
|
// We use a wrapper fragment to handle logic specific to USB readers
|
||||||
usbDevice?.let {
|
usbDevice?.let {
|
||||||
newPages.add(
|
val productName = it.productName ?: getString(R.string.usb)
|
||||||
Page(
|
newPages.add(Page(EuiccChannelManager.USB_CHANNEL_ID, productName) {
|
||||||
EuiccChannelManager.USB_CHANNEL_ID,
|
UsbCcidReaderFragment()
|
||||||
it.productName ?: getString(R.string.usb)
|
})
|
||||||
) { UsbCcidReaderFragment() })
|
|
||||||
}
|
}
|
||||||
viewPager.visibility = View.VISIBLE
|
viewPager.visibility = View.VISIBLE
|
||||||
|
|
||||||
if (newPages.size > 1) {
|
if (newPages.size > 1) {
|
||||||
tabs.visibility = View.VISIBLE
|
tabs.visibility = View.VISIBLE
|
||||||
} else if (newPages.isEmpty()) {
|
} else if (newPages.isEmpty()) {
|
||||||
newPages.add(
|
newPages.add(Page(-1, "") {
|
||||||
Page(
|
appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment()
|
||||||
-1,
|
})
|
||||||
""
|
|
||||||
) { appContainer.uiComponentFactory.createNoEuiccPlaceholderFragment() })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newPages.sortBy { it.logicalSlotId }
|
newPages.sortBy { it.logicalSlotId }
|
||||||
|
|
|
@ -39,12 +39,13 @@ class ProfileDeleteFragment : DialogFragment(), EuiccChannelFragmentMarker {
|
||||||
private var deleting = false
|
private var deleting = false
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
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")))
|
setMessage(getString(R.string.profile_delete_confirm, requireArguments().getString("name")))
|
||||||
setView(editText)
|
setView(editText)
|
||||||
setPositiveButton(android.R.string.ok, null) // Set listener to null to prevent auto closing
|
setPositiveButton(android.R.string.ok, null) // Set listener to null to prevent auto closing
|
||||||
setNegativeButton(android.R.string.cancel, null)
|
setNegativeButton(android.R.string.cancel, null)
|
||||||
}.create()
|
return create()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
|
@ -120,7 +120,7 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
try {
|
try {
|
||||||
requireContext().unregisterReceiver(usbPermissionReceiver)
|
requireContext().unregisterReceiver(usbPermissionReceiver)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
try {
|
try {
|
||||||
requireContext().unregisterReceiver(usbPermissionReceiver)
|
requireContext().unregisterReceiver(usbPermissionReceiver)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ class UsbCcidReaderFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
replace(
|
replace(
|
||||||
R.id.child_container,
|
R.id.child_container,
|
||||||
appContainer.uiComponentFactory.createEuiccManagementFragment(
|
appContainer.uiComponentFactory.createEuiccManagementFragment(
|
||||||
EuiccChannelManager.USB_CHANNEL_ID,
|
slotId = EuiccChannelManager.USB_CHANNEL_ID,
|
||||||
0
|
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
|
telephonyManager.simSlotMapping = mappings
|
||||||
return
|
return
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes hardware supports one ordering but not the reverse
|
// Sometimes hardware supports one ordering but not the reverse
|
||||||
|
|
|
@ -16,10 +16,9 @@ class PrivilegedMainActivity : MainActivity() {
|
||||||
menu.findItem(R.id.slot_mapping).isVisible = false
|
menu.findItem(R.id.slot_mapping).isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tm.supportsDSDS) {
|
menu.findItem(R.id.dsds).apply {
|
||||||
val dsds = menu.findItem(R.id.dsds)
|
isVisible = tm.supportsDSDS
|
||||||
dsds.isVisible = true
|
isChecked = tm.dsdsEnabled
|
||||||
dsds.isChecked = tm.dsdsEnabled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Add table
Reference in a new issue