Compare commits

..

No commits in common. "fe4903605c1ccc8ed6b46af8b4bf0f75984201fd" and "c82cace7faaf89ed7708e14171227a06b7d8d302" have entirely different histories.

2 changed files with 24 additions and 27 deletions

View file

@ -88,12 +88,15 @@ class ProfileDeleteFragment : DialogFragment(), EuiccChannelFragmentMarker {
requireParentFragment().lifecycleScope.launch {
ensureEuiccChannelManager()
euiccChannelManagerService.waitForForegroundTask()
euiccChannelManagerService.launchProfileDeleteTask(slotId, portId, iccid)
.onStart {
parentFragment?.notifyEuiccProfilesChanged()
runCatching(::dismiss)
euiccChannelManagerService.launchProfileDeleteTask(slotId, portId, iccid).onStart {
parentFragment?.notifyEuiccProfilesChanged()
try {
dismiss()
} catch (e: IllegalStateException) {
// Ignored
}
.waitDone()
}.waitDone()
}
}
}

View file

@ -7,7 +7,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.lifecycleScope
import com.google.android.material.textfield.TextInputLayout
@ -19,15 +18,12 @@ import net.typeblog.lpac_jni.LocalProfileAssistant
class ProfileRenameFragment : BaseMaterialDialogFragment(), EuiccChannelFragmentMarker {
companion object {
private const val FIELD_ICCID = "iccid"
private const val FIELD_CURRENT_NAME = "currentName"
const val TAG = "ProfileRenameFragment"
fun newInstance(slotId: Int, portId: Int, iccid: String, currentName: String) =
newInstanceEuicc(ProfileRenameFragment::class.java, slotId, portId) {
putString(FIELD_ICCID, iccid)
putString(FIELD_CURRENT_NAME, currentName)
putString("iccid", iccid)
putString("currentName", currentName)
}
}
@ -37,14 +33,6 @@ class ProfileRenameFragment : BaseMaterialDialogFragment(), EuiccChannelFragment
private var renaming = false
private val iccid: String by lazy {
requireArguments().getString(FIELD_ICCID)!!
}
private val currentName: String by lazy {
requireArguments().getString(FIELD_CURRENT_NAME)!!
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@ -63,7 +51,7 @@ class ProfileRenameFragment : BaseMaterialDialogFragment(), EuiccChannelFragment
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
profileRenameNewName.editText!!.setText(currentName)
profileRenameNewName.editText!!.setText(requireArguments().getString("currentName"))
toolbar.apply {
setTitle(R.string.rename)
setNavigationOnClickListener {
@ -87,8 +75,12 @@ class ProfileRenameFragment : BaseMaterialDialogFragment(), EuiccChannelFragment
}
}
private fun showErrorAndCancel(@StringRes resId: Int) {
Toast.makeText(requireContext(), resId, Toast.LENGTH_LONG).show()
private fun showErrorAndCancel(errorStrRes: Int) {
Toast.makeText(
requireContext(),
errorStrRes,
Toast.LENGTH_LONG
).show()
renaming = false
progress.visibility = View.GONE
@ -99,15 +91,17 @@ class ProfileRenameFragment : BaseMaterialDialogFragment(), EuiccChannelFragment
progress.isIndeterminate = true
progress.visibility = View.VISIBLE
val newName = profileRenameNewName.editText!!.text.toString().trim()
lifecycleScope.launch {
ensureEuiccChannelManager()
euiccChannelManagerService.waitForForegroundTask()
val response = euiccChannelManagerService
.launchProfileRenameTask(slotId, portId, iccid, newName).waitDone()
val res = euiccChannelManagerService.launchProfileRenameTask(
slotId,
portId,
requireArguments().getString("iccid")!!,
profileRenameNewName.editText!!.text.toString().trim()
).waitDone()
when (response) {
when (res) {
is LocalProfileAssistant.ProfileNameTooLongException -> {
showErrorAndCancel(R.string.profile_rename_too_long)
}