From 206cabe070a56b1aa634e908843bfdb069150cd9 Mon Sep 17 00:00:00 2001 From: zuevval Date: Sat, 17 Oct 2020 14:06:33 +0300 Subject: [PATCH] (#284) add flip preference dialog design --- .../learnbraille/ui/Messages.kt | 22 ++++++++ .../ui/screens/menu/MenuFragment.kt | 3 ++ .../main/res/layout/fragment_flip_dialog.xml | 54 +++++++++++++++++++ app/src/main/res/values/strings.xml | 12 +++++ 4 files changed, 91 insertions(+) create mode 100644 app/src/main/res/layout/fragment_flip_dialog.xml diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt index 6e9626c9..adb80996 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt @@ -1,7 +1,12 @@ package com.github.braillesystems.learnbraille.ui import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity import com.github.braillesystems.learnbraille.R import com.github.braillesystems.learnbraille.data.entities.* import com.github.braillesystems.learnbraille.res.inputMarkerPrintRules @@ -10,6 +15,7 @@ import com.github.braillesystems.learnbraille.res.showMarkerPrintRules import com.github.braillesystems.learnbraille.res.showSymbolPrintRules import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode import com.github.braillesystems.learnbraille.utils.* +import kotlinx.android.synthetic.main.fragment_flip_dialog.view.* fun Fragment.showCorrectToast() = toast(getString(R.string.input_correct)) @@ -63,3 +69,19 @@ fun Context.showPrint(data: MaterialData): String = fun Fragment.showPrint(data: MaterialData): String = contextNotNull.showPrint(data) + +fun FragmentActivity.showFlipPreferenceDialog() { + val viewGroup: ViewGroup = findViewById(android.R.id.content) + val dialogView: View = + LayoutInflater.from(this).inflate(R.layout.fragment_flip_dialog, viewGroup, false) + val builder: AlertDialog.Builder = AlertDialog.Builder(this) + builder.setView(dialogView) + builder.setTitle(getString(R.string.fragment_flip_dialog_title)) + val alertDialog: AlertDialog = builder.create() + alertDialog.show() + dialogView.btnOK.setOnClickListener { + val flipPreferenceOn = dialogView.radioButtonFlip.isChecked + // TODO save preference & never ask again + alertDialog.hide() + } +} diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/menu/MenuFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/menu/MenuFragment.kt index 5a9e2ae9..0e99e687 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/menu/MenuFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/menu/MenuFragment.kt @@ -15,11 +15,13 @@ import com.github.braillesystems.learnbraille.data.db.LearnBrailleDatabase import com.github.braillesystems.learnbraille.databinding.FragmentMenuBinding import com.github.braillesystems.learnbraille.ui.screens.AbstractFragmentWithHelp import com.github.braillesystems.learnbraille.ui.screens.theory.toLastCourseStep +import com.github.braillesystems.learnbraille.ui.showFlipPreferenceDialog import com.github.braillesystems.learnbraille.utils.* import com.google.android.material.button.MaterialButton import org.koin.android.ext.android.inject import timber.log.Timber + class MenuFragment : AbstractFragmentWithHelp(R.string.menu_help) { private val db: LearnBrailleDatabase by inject() @@ -97,6 +99,7 @@ class MenuFragment : AbstractFragmentWithHelp(R.string.menu_help) { } colorButtons(buttons) + activity?.showFlipPreferenceDialog() // TODO ask in practice and theory }.root diff --git a/app/src/main/res/layout/fragment_flip_dialog.xml b/app/src/main/res/layout/fragment_flip_dialog.xml new file mode 100644 index 00000000..5835e6c8 --- /dev/null +++ b/app/src/main/res/layout/fragment_flip_dialog.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + +