ui: Add footer view when no profiles are found
All checks were successful
/ build-debug (push) Successful in 5m11s

This commit is contained in:
Peter Cai 2024-07-07 20:59:55 -04:00
parent f84baa02f0
commit 829f019aa2
5 changed files with 59 additions and 14 deletions

View file

@ -110,10 +110,20 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
}
true
}
else -> super.onOptionsItemSelected(item)
}
protected open suspend fun onCreateFooterViews(parent: ViewGroup): List<View> = listOf()
protected open suspend fun onCreateFooterViews(
parent: ViewGroup,
profiles: List<LocalProfileInfo>
): List<View> =
if (profiles.isEmpty()) {
val view = layoutInflater.inflate(R.layout.footer_no_profile, parent, false)
listOf(view)
} else {
listOf()
}
@SuppressLint("NotifyDataSetChanged")
private fun refresh() {
@ -128,12 +138,12 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
val profiles = withContext(Dispatchers.IO) {
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
channel.lpa.profiles
channel.lpa.profiles.operational
}
withContext(Dispatchers.Main) {
adapter.profiles = profiles.operational
adapter.footerViews = onCreateFooterViews(profileList)
adapter.profiles = profiles
adapter.footerViews = onCreateFooterViews(profileList, profiles)
adapter.notifyDataSetChanged()
swipeRefresh.isRefreshing = false
}
@ -250,6 +260,13 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
}
inner class FooterViewHolder: ViewHolder(FrameLayout(requireContext())) {
init {
itemView.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
}
fun attach(view: View) {
view.parent?.let { (it as ViewGroup).removeView(view) }
(itemView as FrameLayout).addView(view)

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="@string/no_profile"
android:textStyle="italic"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="no_euicc">No removable eUICC card accessible by this app is detected on this device.</string>
<string name="no_profile">No profiles (yet) on this eSIM.</string>
<string name="unknown">Unknown</string>
<string name="help">Help</string>
<string name="reload">Reload Slots</string>

View file

@ -16,17 +16,22 @@ class PrivilegedEuiccManagementFragment: EuiccManagementFragment() {
newInstanceEuicc(PrivilegedEuiccManagementFragment::class.java, slotId, portId)
}
override suspend fun onCreateFooterViews(parent: ViewGroup): List<View> =
// isMEP can map to a slow operation (UiccCardInfo.isMultipleEnabledProfilesSupported())
// so let's do it in the IO context
if (withContext(Dispatchers.IO) { channel.isMEP }) {
val view = layoutInflater.inflate(R.layout.footer_mep, parent, false)
view.requireViewById<Button>(R.id.footer_mep_slot_mapping).setOnClickListener {
(requireActivity() as PrivilegedMainActivity).showSlotMappingFragment()
override suspend fun onCreateFooterViews(
parent: ViewGroup,
profiles: List<LocalProfileInfo>
): List<View> =
super.onCreateFooterViews(parent, profiles).let { footers ->
// isMEP can map to a slow operation (UiccCardInfo.isMultipleEnabledProfilesSupported())
// so let's do it in the IO context
if (withContext(Dispatchers.IO) { channel.isMEP }) {
val view = layoutInflater.inflate(R.layout.footer_mep, parent, false)
view.requireViewById<Button>(R.id.footer_mep_slot_mapping).setOnClickListener {
(requireActivity() as PrivilegedMainActivity).showSlotMappingFragment()
}
footers + view
} else {
footers
}
listOf(view)
} else {
listOf()
}
override fun populatePopupWithProfileActions(popup: PopupMenu, profile: LocalProfileInfo) {

View file

@ -10,6 +10,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="@string/footer_mep"
android:textStyle="italic"