浏览代码

ui: wizard: Lay out the download progress UI

Peter Cai 1 年之前
父节点
当前提交
39b40f9b0d

+ 3 - 0
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt

@@ -132,6 +132,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
 
 
     private fun onNextPressed() {
     private fun onNextPressed() {
         if (currentFragment?.hasNext == true) {
         if (currentFragment?.hasNext == true) {
+            currentFragment?.beforeNext()
             val nextFrag = currentFragment?.createNextFragment()
             val nextFrag = currentFragment?.createNextFragment()
             if (nextFrag == null) {
             if (nextFrag == null) {
                 finish()
                 finish()
@@ -216,5 +217,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
         protected fun refreshButtons() {
         protected fun refreshButtons() {
             (requireActivity() as DownloadWizardActivity).refreshButtons()
             (requireActivity() as DownloadWizardActivity).refreshButtons()
         }
         }
+
+        open fun beforeNext() {}
     }
     }
 }
 }

+ 8 - 2
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDetailsFragment.kt

@@ -22,10 +22,16 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
     private lateinit var confirmationCode: TextInputLayout
     private lateinit var confirmationCode: TextInputLayout
     private lateinit var imei: TextInputLayout
     private lateinit var imei: TextInputLayout
 
 
-    override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment? {
-        TODO("Not yet implemented")
+    override fun beforeNext() {
+        state.smdp = smdp.editText!!.text.toString().trim()
+        state.matchingId = matchingId.editText!!.text.toString().trim()
+        state.confirmationCode = confirmationCode.editText!!.text.toString().trim()
+        state.imei = imei.editText!!.text.toString()
     }
     }
 
 
+    override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
+        DownloadWizardProgressFragment()
+
     override fun createPrevFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
     override fun createPrevFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
         DownloadWizardMethodSelectFragment()
         DownloadWizardMethodSelectFragment()
 
 

+ 117 - 0
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardProgressFragment.kt

@@ -0,0 +1,117 @@
+package im.angry.openeuicc.ui.wizard
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.ProgressBar
+import android.widget.TextView
+import androidx.recyclerview.widget.DividerItemDecoration
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import im.angry.openeuicc.common.R
+
+class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStepFragment() {
+    private enum class ProgressState {
+        NotStarted,
+        InProgress,
+        Done,
+        Error
+    }
+
+    private data class ProgressItem(
+        val titleRes: Int,
+        val state: ProgressState
+    )
+
+    private val progressItems = arrayOf(
+        ProgressItem(R.string.download_wizard_progress_step_preparing, ProgressState.NotStarted),
+        ProgressItem(R.string.download_wizard_progress_step_connecting, ProgressState.NotStarted),
+        ProgressItem(
+            R.string.download_wizard_progress_step_authenticating,
+            ProgressState.NotStarted
+        ),
+        ProgressItem(R.string.download_wizard_progress_step_downloading, ProgressState.NotStarted),
+        ProgressItem(R.string.download_wizard_progress_step_finalizing, ProgressState.NotStarted)
+    )
+
+    private val adapter = ProgressItemAdapter()
+
+    override val hasNext: Boolean
+        get() = false
+    override val hasPrev: Boolean
+        get() = false
+
+    override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment? = null
+
+    override fun createPrevFragment(): DownloadWizardActivity.DownloadWizardStepFragment? = null
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View? {
+        val view = inflater.inflate(R.layout.fragment_download_progress, container, false)
+        val recyclerView = view.requireViewById<RecyclerView>(R.id.download_progress_list)
+        recyclerView.adapter = adapter
+        recyclerView.layoutManager =
+            LinearLayoutManager(view.context, LinearLayoutManager.VERTICAL, false)
+        recyclerView.addItemDecoration(
+            DividerItemDecoration(
+                requireContext(),
+                LinearLayoutManager.VERTICAL
+            )
+        )
+        return view
+    }
+
+    private inner class ProgressItemHolder(val root: View) : RecyclerView.ViewHolder(root) {
+        private val title = root.requireViewById<TextView>(R.id.download_progress_item_title)
+        private val progressBar =
+            root.requireViewById<ProgressBar>(R.id.download_progress_icon_progress)
+        private val icon = root.requireViewById<ImageView>(R.id.download_progress_icon)
+
+        fun bind(item: ProgressItem) {
+            title.text = getString(item.titleRes)
+
+            when (item.state) {
+                ProgressState.NotStarted -> {
+                    progressBar.visibility = View.GONE
+                    icon.visibility = View.GONE
+                }
+
+                ProgressState.InProgress -> {
+                    progressBar.visibility = View.VISIBLE
+                    icon.visibility = View.GONE
+                }
+
+                ProgressState.Done -> {
+                    progressBar.visibility = View.GONE
+                    icon.setImageResource(R.drawable.ic_checkmark_outline)
+                    icon.visibility = View.VISIBLE
+                }
+
+                ProgressState.Error -> {
+                    progressBar.visibility = View.GONE
+                    icon.setImageResource(R.drawable.ic_error_outline)
+                    icon.visibility = View.VISIBLE
+                }
+            }
+        }
+    }
+
+    private inner class ProgressItemAdapter : RecyclerView.Adapter<ProgressItemHolder>() {
+        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProgressItemHolder {
+            val root = LayoutInflater.from(parent.context)
+                .inflate(R.layout.download_progress_item, parent, false)
+            return ProgressItemHolder(root)
+        }
+
+        override fun getItemCount(): Int = progressItems.size
+
+        override fun onBindViewHolder(holder: ProgressItemHolder, position: Int) {
+            holder.bind(progressItems[position])
+        }
+    }
+}

+ 0 - 0
app-unpriv/src/main/res/drawable/ic_checkmark_outline.xml → app-common/src/main/res/drawable/ic_checkmark_outline.xml


+ 0 - 0
app-unpriv/src/main/res/drawable/ic_error_outline.xml → app-common/src/main/res/drawable/ic_error_outline.xml


+ 45 - 0
app-common/src/main/res/layout/download_progress_item.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <TextView
+        android:id="@+id/download_progress_item_title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="20dp"
+        android:textSize="14sp"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toStartOf="@id/download_progress_icon_container"
+        app:layout_constrainedWidth="true"
+        app:layout_constraintHorizontal_bias="0.0" />
+
+    <FrameLayout
+        android:id="@+id/download_progress_icon_container"
+        android:layout_margin="20dp"
+        android:layout_width="30dp"
+        android:layout_height="30dp"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent">
+
+        <ProgressBar
+            android:id="@+id/download_progress_icon_progress"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:indeterminate="true"
+            android:visibility="gone" />
+
+        <ImageView
+            android:id="@+id/download_progress_icon"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:visibility="gone"
+            app:tint="?attr/colorPrimary" />
+
+    </FrameLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 33 - 0
app-common/src/main/res/layout/fragment_download_progress.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <TextView
+        android:id="@+id/download_progress_title"
+        android:text="@string/download_wizard_progress"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:gravity="center_horizontal"
+        android:textSize="20sp"
+        android:layout_marginTop="20sp"
+        android:layout_marginBottom="20sp"
+        android:layout_marginStart="60sp"
+        android:layout_marginEnd="60sp"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constrainedWidth="true"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/download_progress_list"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        app:layout_constraintTop_toBottomOf="@id/download_progress_title"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constrainedHeight="true" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 6 - 0
app-common/src/main/res/values/strings.xml

@@ -75,6 +75,12 @@
     <string name="download_wizard_method_gallery">Load a QR code from gallery</string>
     <string name="download_wizard_method_gallery">Load a QR code from gallery</string>
     <string name="download_wizard_method_manual">Enter manually</string>
     <string name="download_wizard_method_manual">Enter manually</string>
     <string name="download_wizard_details">Input or confirm details for downloading your eSIM:</string>
     <string name="download_wizard_details">Input or confirm details for downloading your eSIM:</string>
+    <string name="download_wizard_progress">Downloading your eSIM…</string>
+    <string name="download_wizard_progress_step_preparing">Preparing</string>
+    <string name="download_wizard_progress_step_connecting">Establishing connection to server</string>
+    <string name="download_wizard_progress_step_authenticating">Authenticating your device with server</string>
+    <string name="download_wizard_progress_step_downloading">Downloading eSIM profile</string>
+    <string name="download_wizard_progress_step_finalizing">Loading eSIM profile into storage</string>
 
 
     <string name="profile_rename_new_name">New nickname</string>
     <string name="profile_rename_new_name">New nickname</string>