From 31fee9928289be9812e35cbeda39a2dbb95c7359 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 24 Sep 2022 10:47:17 +0200 Subject: [PATCH] use material library inbuilts --- .../ui/adapters/BackupOptionsAdapter.kt | 38 ------------------- .../libretube/ui/dialogs/BackupDialog.kt | 20 +++------- app/src/main/res/layout/backup_row.xml | 22 ----------- app/src/main/res/layout/dialog_backup.xml | 11 ------ 4 files changed, 6 insertions(+), 85 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/ui/adapters/BackupOptionsAdapter.kt delete mode 100644 app/src/main/res/layout/backup_row.xml delete mode 100644 app/src/main/res/layout/dialog_backup.xml diff --git a/app/src/main/java/com/github/libretube/ui/adapters/BackupOptionsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/BackupOptionsAdapter.kt deleted file mode 100644 index df171b4af..000000000 --- a/app/src/main/java/com/github/libretube/ui/adapters/BackupOptionsAdapter.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.libretube.ui.adapters - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import com.github.libretube.databinding.BackupRowBinding - -class BackupOptionsAdapter( - private val options: List, - private val onChange: (position: Int, isChecked: Boolean) -> Unit -) : RecyclerView.Adapter() { - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BackupOptionsViewHolder { - val binding = BackupRowBinding.inflate( - LayoutInflater.from(parent.context), - parent, - false - ) - return BackupOptionsViewHolder(binding) - } - - override fun getItemCount(): Int { - return options.size - } - - override fun onBindViewHolder(holder: BackupOptionsViewHolder, position: Int) { - holder.binding.apply { - title.text = root.context?.getString(options[position]) - switchWidget.setOnCheckedChangeListener { _, isChecked -> - onChange.invoke(position, isChecked) - } - } - } -} - -class BackupOptionsViewHolder( - val binding: BackupRowBinding -) : RecyclerView.ViewHolder(binding.root) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt index 494eb63c7..4723ce7ef 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt @@ -3,25 +3,20 @@ package com.github.libretube.ui.dialogs import android.app.Dialog import android.os.Bundle import androidx.fragment.app.DialogFragment -import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R -import com.github.libretube.databinding.DialogBackupBinding import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.obj.BackupFile import com.github.libretube.obj.PreferenceItem -import com.github.libretube.ui.adapters.BackupOptionsAdapter import com.github.libretube.util.PreferenceHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder class BackupDialog( private val createBackupFile: (BackupFile) -> Unit ) : DialogFragment() { - private lateinit var binding: DialogBackupBinding - private val backupFile = BackupFile() override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val backupOptions = listOf( + val backupOptionNames = listOf( R.string.watch_history, R.string.watch_positions, R.string.search_history, @@ -30,18 +25,15 @@ class BackupDialog( R.string.preferences ) - val selected = MutableList(backupOptions.size) { false } + val backupItems = backupOptionNames.map { context?.getString(it)!! }.toTypedArray() - binding = DialogBackupBinding.inflate(layoutInflater) - binding.backupOptionsRecycler.layoutManager = LinearLayoutManager(context) - binding.backupOptionsRecycler.adapter = - BackupOptionsAdapter(backupOptions) { position, isChecked -> - selected[position] = isChecked - } + val selected = BooleanArray(backupOptionNames.size) { false } return MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.backup) - .setView(binding.root) + .setMultiChoiceItems(backupItems, selected) { _, index, newValue -> + selected[index] = newValue + } .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.backup) { _, _ -> val thread = Thread { diff --git a/app/src/main/res/layout/backup_row.xml b/app/src/main/res/layout/backup_row.xml deleted file mode 100644 index 340927967..000000000 --- a/app/src/main/res/layout/backup_row.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_backup.xml b/app/src/main/res/layout/dialog_backup.xml deleted file mode 100644 index 5b4fe20df..000000000 --- a/app/src/main/res/layout/dialog_backup.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file