|
@@ -8,6 +8,7 @@ import android.view.LayoutInflater
|
|
|
import android.view.MenuItem
|
|
import android.view.MenuItem
|
|
|
import android.view.View
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
|
|
+import android.widget.FrameLayout
|
|
|
import android.widget.ImageButton
|
|
import android.widget.ImageButton
|
|
|
import android.widget.PopupMenu
|
|
import android.widget.PopupMenu
|
|
|
import android.widget.TextView
|
|
import android.widget.TextView
|
|
@@ -26,7 +27,7 @@ import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
|
import java.lang.Exception
|
|
import java.lang.Exception
|
|
|
|
|
|
|
|
-class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesChangedListener {
|
|
|
|
|
|
|
+open class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesChangedListener {
|
|
|
companion object {
|
|
companion object {
|
|
|
const val TAG = "EuiccManagementFragment"
|
|
const val TAG = "EuiccManagementFragment"
|
|
|
|
|
|
|
@@ -38,7 +39,7 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
|
|
|
private lateinit var fab: FloatingActionButton
|
|
private lateinit var fab: FloatingActionButton
|
|
|
private lateinit var profileList: RecyclerView
|
|
private lateinit var profileList: RecyclerView
|
|
|
|
|
|
|
|
- private val adapter = EuiccProfileAdapter(listOf())
|
|
|
|
|
|
|
+ private val adapter = EuiccProfileAdapter()
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
override fun onCreateView(
|
|
|
inflater: LayoutInflater,
|
|
inflater: LayoutInflater,
|
|
@@ -76,6 +77,8 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
|
|
|
refresh()
|
|
refresh()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected open suspend fun onCreateFooterViews(parent: ViewGroup): List<View> = listOf()
|
|
|
|
|
+
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
private fun refresh() {
|
|
private fun refresh() {
|
|
|
swipeRefresh.isRefreshing = true
|
|
swipeRefresh.isRefreshing = true
|
|
@@ -88,6 +91,7 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
|
|
|
|
|
|
|
|
withContext(Dispatchers.Main) {
|
|
withContext(Dispatchers.Main) {
|
|
|
adapter.profiles = profiles.operational
|
|
adapter.profiles = profiles.operational
|
|
|
|
|
+ adapter.footerViews = onCreateFooterViews(profileList)
|
|
|
adapter.notifyDataSetChanged()
|
|
adapter.notifyDataSetChanged()
|
|
|
swipeRefresh.isRefreshing = false
|
|
swipeRefresh.isRefreshing = false
|
|
|
}
|
|
}
|
|
@@ -130,7 +134,30 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
|
|
|
channel.lpa.disableProfile(iccid)
|
|
channel.lpa.disableProfile(iccid)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inner class ViewHolder(private val root: View) : RecyclerView.ViewHolder(root) {
|
|
|
|
|
|
|
+ sealed class ViewHolder(root: View) : RecyclerView.ViewHolder(root) {
|
|
|
|
|
+ enum class Type(val value: Int) {
|
|
|
|
|
+ PROFILE(0),
|
|
|
|
|
+ FOOTER(1);
|
|
|
|
|
+
|
|
|
|
|
+ companion object {
|
|
|
|
|
+ fun fromInt(value: Int) =
|
|
|
|
|
+ Type.values().first { it.value == value }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inner class FooterViewHolder: ViewHolder(FrameLayout(requireContext())) {
|
|
|
|
|
+ fun attach(view: View) {
|
|
|
|
|
+ view.parent?.let { (it as ViewGroup).removeView(view) }
|
|
|
|
|
+ (itemView as FrameLayout).addView(view)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun detach() {
|
|
|
|
|
+ (itemView as FrameLayout).removeAllViews()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ inner class ProfileViewHolder(private val root: View) : ViewHolder(root) {
|
|
|
private val iccid: TextView = root.findViewById(R.id.iccid)
|
|
private val iccid: TextView = root.findViewById(R.id.iccid)
|
|
|
private val name: TextView = root.findViewById(R.id.name)
|
|
private val name: TextView = root.findViewById(R.id.name)
|
|
|
private val state: TextView = root.findViewById(R.id.state)
|
|
private val state: TextView = root.findViewById(R.id.state)
|
|
@@ -208,16 +235,49 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inner class EuiccProfileAdapter(var profiles: List<LocalProfileInfo>) : RecyclerView.Adapter<ViewHolder>() {
|
|
|
|
|
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
|
|
|
- val view = LayoutInflater.from(parent.context).inflate(R.layout.euicc_profile, parent, false)
|
|
|
|
|
- return ViewHolder(view)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ inner class EuiccProfileAdapter : RecyclerView.Adapter<ViewHolder>() {
|
|
|
|
|
+ var profiles: List<LocalProfileInfo> = listOf()
|
|
|
|
|
+ var footerViews: List<View> = listOf()
|
|
|
|
|
+
|
|
|
|
|
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
|
|
|
|
|
+ when (ViewHolder.Type.fromInt(viewType)) {
|
|
|
|
|
+ ViewHolder.Type.PROFILE -> {
|
|
|
|
|
+ val view = LayoutInflater.from(parent.context).inflate(R.layout.euicc_profile, parent, false)
|
|
|
|
|
+ ProfileViewHolder(view)
|
|
|
|
|
+ }
|
|
|
|
|
+ ViewHolder.Type.FOOTER -> {
|
|
|
|
|
+ FooterViewHolder()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun getItemViewType(position: Int): Int =
|
|
|
|
|
+ when {
|
|
|
|
|
+ position < profiles.size -> {
|
|
|
|
|
+ ViewHolder.Type.PROFILE.value
|
|
|
|
|
+ }
|
|
|
|
|
+ position >= profiles.size && position < profiles.size + footerViews.size -> {
|
|
|
|
|
+ ViewHolder.Type.FOOTER.value
|
|
|
|
|
+ }
|
|
|
|
|
+ else -> -1
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
|
- holder.setProfile(profiles[position])
|
|
|
|
|
|
|
+ when (holder) {
|
|
|
|
|
+ is ProfileViewHolder -> {
|
|
|
|
|
+ holder.setProfile(profiles[position])
|
|
|
|
|
+ }
|
|
|
|
|
+ is FooterViewHolder -> {
|
|
|
|
|
+ holder.attach(footerViews[position - profiles.size])
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onViewRecycled(holder: ViewHolder) {
|
|
|
|
|
+ if (holder is FooterViewHolder) {
|
|
|
|
|
+ holder.detach()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- override fun getItemCount(): Int = profiles.size
|
|
|
|
|
|
|
+ override fun getItemCount(): Int = profiles.size + footerViews.size
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|