diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt index 2d0b67d..d6ffa32 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt @@ -29,6 +29,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import net.typeblog.lpac_jni.LocalProfileNotification import java.lang.Exception open class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesChangedListener { @@ -158,14 +159,6 @@ open class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfi preferenceRepository.notificationDisableFlow.first() } - protected open fun populatePopupWithProfileActions(popup: PopupMenu, profile: LocalProfileInfo) { - popup.inflate(R.menu.profile_options) - if (profile.isEnabled) { - popup.menu.findItem(R.id.enable).isVisible = false - popup.menu.findItem(R.id.delete).isVisible = false - } - } - sealed class ViewHolder(root: View) : RecyclerView.ViewHolder(root) { enum class Type(val value: Int) { PROFILE(0), @@ -215,7 +208,7 @@ open class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfi name.text = profile.displayName state.setText( - if (profile.isEnabled) { + if (isEnabled()) { R.string.enabled } else { R.string.disabled @@ -226,10 +219,19 @@ open class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfi iccid.transformationMethod = PasswordTransformationMethod.getInstance() } + private fun isEnabled(): Boolean = + profile.state == LocalProfileInfo.State.Enabled + private fun showOptionsMenu() { PopupMenu(root.context, profileMenu).apply { setOnMenuItemClickListener(::onMenuItemClicked) - populatePopupWithProfileActions(this, profile) + inflate(R.menu.profile_options) + if (isEnabled()) { + menu.findItem(R.id.enable).isVisible = false + menu.findItem(R.id.delete).isVisible = false + } else { + menu.findItem(R.id.disable).isVisible = false + } show() } } diff --git a/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt b/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt index 6e6f162..e5a7d2e 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/Utils.kt @@ -2,7 +2,6 @@ package im.angry.openeuicc.util import android.content.Context import android.content.pm.PackageManager -import net.typeblog.lpac_jni.LocalProfileInfo import java.lang.RuntimeException val Context.selfAppVersion: String @@ -12,7 +11,4 @@ val Context.selfAppVersion: String pInfo.versionName } catch (e: PackageManager.NameNotFoundException) { throw RuntimeException(e) - } - -val LocalProfileInfo.isEnabled: Boolean - get() = state == LocalProfileInfo.State.Enabled \ No newline at end of file + } \ No newline at end of file diff --git a/app-common/src/main/res/menu/profile_options.xml b/app-common/src/main/res/menu/profile_options.xml index 6add53d..4c9bede 100644 --- a/app-common/src/main/res/menu/profile_options.xml +++ b/app-common/src/main/res/menu/profile_options.xml @@ -6,7 +6,6 @@ euiccManager.findEuiccChannelByPortBlocking(mapping.physicalSlotIndex, mapping.portIndex)?.let { channel -> - if (!channel.removable) { - return@mapNotNull channel.lpa.disableActiveProfileWithUndo() - } else { - // Do not do anything for external eUICCs -- we can't really trust them to work properly - // with no profile enabled. - return@mapNotNull null - } + return@mapNotNull channel.lpa.disableActiveProfileWithUndo() } }