forked from PeterCxy/OpenEUICC
ui: Add footer view when no profiles are found
This commit is contained in:
parent
f84baa02f0
commit
829f019aa2
|
@ -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)
|
||||
|
|
21
app-common/src/main/res/layout/footer_no_profile.xml
Normal file
21
app-common/src/main/res/layout/footer_no_profile.xml
Normal 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>
|
|
@ -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>
|
||||
|
|
|
@ -16,7 +16,11 @@ class PrivilegedEuiccManagementFragment: EuiccManagementFragment() {
|
|||
newInstanceEuicc(PrivilegedEuiccManagementFragment::class.java, slotId, portId)
|
||||
}
|
||||
|
||||
override suspend fun onCreateFooterViews(parent: ViewGroup): List<View> =
|
||||
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 }) {
|
||||
|
@ -24,9 +28,10 @@ class PrivilegedEuiccManagementFragment: EuiccManagementFragment() {
|
|||
view.requireViewById<Button>(R.id.footer_mep_slot_mapping).setOnClickListener {
|
||||
(requireActivity() as PrivilegedMainActivity).showSlotMappingFragment()
|
||||
}
|
||||
listOf(view)
|
||||
footers + view
|
||||
} else {
|
||||
listOf()
|
||||
footers
|
||||
}
|
||||
}
|
||||
|
||||
override fun populatePopupWithProfileActions(popup: PopupMenu, profile: LocalProfileInfo) {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue