ソースを参照

ui: Add footer view when no profiles are found

Peter Cai 1 年間 前
コミット
829f019aa2

+ 21 - 4
app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt

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

+ 21 - 0
app-common/src/main/res/layout/footer_no_profile.xml

@@ -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 - 0
app-common/src/main/res/values/strings.xml

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

+ 15 - 10
app/src/main/java/im/angry/openeuicc/ui/PrivilegedEuiccManagementFragment.kt

@@ -16,17 +16,22 @@ class PrivilegedEuiccManagementFragment: EuiccManagementFragment() {
             newInstanceEuicc(PrivilegedEuiccManagementFragment::class.java, slotId, portId)
             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) {
     override fun populatePopupWithProfileActions(popup: PopupMenu, profile: LocalProfileInfo) {

+ 1 - 0
app/src/main/res/layout/footer_mep.xml

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