浏览代码

ui: Lay out the method select fragment for wizard

Peter Cai 1 年之前
父节点
当前提交
92b7b46598

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

@@ -0,0 +1,93 @@
+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.TextView
+import androidx.recyclerview.widget.DividerItemDecoration
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import androidx.recyclerview.widget.RecyclerView.ViewHolder
+import im.angry.openeuicc.common.R
+
+class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizardStepFragment() {
+    data class DownloadMethod(
+        val iconRes: Int,
+        val titleRes: Int,
+        val onClick: () -> Unit
+    )
+
+    val downloadMethods = arrayOf(
+        DownloadMethod(R.drawable.ic_scan_black, R.string.download_wizard_method_qr_code) {
+
+        },
+        DownloadMethod(R.drawable.ic_gallery_black, R.string.download_wizard_method_gallery) {
+
+        },
+        DownloadMethod(R.drawable.ic_edit, R.string.download_wizard_method_manual) {
+
+        }
+    )
+
+    override val hasNext: Boolean
+        get() = false
+    override val hasPrev: Boolean
+        get() = true
+
+    override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment? {
+        TODO("Not yet implemented")
+    }
+
+    override fun createPrevFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
+        DownloadWizardSlotSelectFragment()
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View? {
+        val view = inflater.inflate(R.layout.fragment_download_method_select, container, false)
+        val recyclerView = view.requireViewById<RecyclerView>(R.id.download_method_list)
+        recyclerView.adapter = DownloadMethodAdapter()
+        recyclerView.layoutManager =
+            LinearLayoutManager(view.context, LinearLayoutManager.VERTICAL, false)
+        recyclerView.addItemDecoration(
+            DividerItemDecoration(
+                requireContext(),
+                LinearLayoutManager.VERTICAL
+            )
+        )
+        return view
+    }
+
+    private class DownloadMethodViewHolder(private val root: View) : ViewHolder(root) {
+        private val icon = root.requireViewById<ImageView>(R.id.download_method_icon)
+        private val title = root.requireViewById<TextView>(R.id.download_method_title)
+
+        fun bind(item: DownloadMethod) {
+            icon.setImageResource(item.iconRes)
+            title.setText(item.titleRes)
+            root.setOnClickListener { item.onClick() }
+        }
+    }
+
+    private inner class DownloadMethodAdapter : RecyclerView.Adapter<DownloadMethodViewHolder>() {
+        override fun onCreateViewHolder(
+            parent: ViewGroup,
+            viewType: Int
+        ): DownloadMethodViewHolder {
+            val view = LayoutInflater.from(parent.context)
+                .inflate(R.layout.download_method_item, parent, false)
+            return DownloadMethodViewHolder(view)
+        }
+
+        override fun getItemCount(): Int = downloadMethods.size
+
+        override fun onBindViewHolder(holder: DownloadMethodViewHolder, position: Int) {
+            holder.bind(downloadMethods[position])
+        }
+
+    }
+}

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

@@ -39,9 +39,8 @@ class DownloadWizardSlotSelectFragment : DownloadWizardActivity.DownloadWizardSt
     override val hasPrev: Boolean
     override val hasPrev: Boolean
         get() = true
         get() = true
 
 
-    override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment? {
-        TODO("Not yet implemented")
-    }
+    override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
+        DownloadWizardMethodSelectFragment()
 
 
     override fun createPrevFragment(): DownloadWizardActivity.DownloadWizardStepFragment? = null
     override fun createPrevFragment(): DownloadWizardActivity.DownloadWizardStepFragment? = null
 
 

+ 5 - 0
app-common/src/main/res/drawable/ic_edit.xml

@@ -0,0 +1,5 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
+      
+    <path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
+    
+</vector>

+ 44 - 0
app-common/src/main/res/layout/download_method_item.xml

@@ -0,0 +1,44 @@
+<?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"
+    android:padding="20dp"
+    android:background="?attr/selectableItemBackground">
+
+    <ImageView
+        android:id="@+id/download_method_icon"
+        android:layout_width="30dp"
+        android:layout_height="30dp"
+        app:tint="?attr/colorAccent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toStartOf="parent" />
+
+    <TextView
+        android:id="@+id/download_method_title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="20dp"
+        android:layout_marginEnd="20dp"
+        android:textSize="15sp"
+        android:maxLines="1"
+        android:ellipsize="marquee"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintStart_toEndOf="@id/download_method_icon"
+        app:layout_constraintEnd_toStartOf="@id/download_method_chevron"
+        app:layout_constraintHorizontal_bias="0.0"
+        app:layout_constrainedWidth="true" />
+
+    <ImageView
+        android:id="@+id/download_method_chevron"
+        android:src="@drawable/ic_chevron_right"
+        android:layout_width="30dp"
+        android:layout_height="30dp"
+        app:tint="?attr/colorAccent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 33 - 0
app-common/src/main/res/layout/fragment_download_method_select.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_method_select_title"
+        android:text="@string/download_wizard_method_select"
+        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_method_list"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        app:layout_constraintTop_toBottomOf="@id/download_method_select_title"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constrainedHeight="true" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

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

@@ -70,6 +70,10 @@
     <string name="download_wizard_slot_eid">eID:</string>
     <string name="download_wizard_slot_eid">eID:</string>
     <string name="download_wizard_slot_active_profile">Active Profile:</string>
     <string name="download_wizard_slot_active_profile">Active Profile:</string>
     <string name="download_wizard_slot_free_space">Free Space:</string>
     <string name="download_wizard_slot_free_space">Free Space:</string>
+    <string name="download_wizard_method_select">How would you like to download the eSIM profile?</string>
+    <string name="download_wizard_method_qr_code">Scan a QR code with camera</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="profile_rename_new_name">New nickname</string>
     <string name="profile_rename_new_name">New nickname</string>