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 { requireParentFragment().lifecycleScope.launch {
ensureEuiccChannelManager() ensureEuiccChannelManager()
euiccChannelManagerService.waitForForegroundTask() euiccChannelManagerService.waitForForegroundTask()
euiccChannelManagerService.launchProfileDeleteTask(slotId, portId, iccid) euiccChannelManagerService.launchProfileDeleteTask(slotId, portId, iccid).onStart {
.onStart { parentFragment?.notifyEuiccProfilesChanged()
parentFragment?.notifyEuiccProfilesChanged()
runCatching(::dismiss) try {
dismiss()
} catch (e: IllegalStateException) {
// Ignored
} }
.waitDone() }.waitDone()
} }
} }
} }

View file

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