From 586011456fefb3d96497720b9e8423ee557451be Mon Sep 17 00:00:00 2001 From: Niko Diamadis Date: Tue, 6 Dec 2022 01:25:10 +0100 Subject: [PATCH] Replace library bottom sheet with native M3 one --- .../com/cyb3rko/logviewerforopenhab/Utils.kt | 16 ++++------ .../modals/PolicyBottomSheet.kt | 31 +++++++++++++++++++ .../main/res/layout/bottom_sheet_policy.xml | 17 ++++++++++ app/src/main/res/values/styles.xml | 1 - 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/cyb3rko/logviewerforopenhab/modals/PolicyBottomSheet.kt create mode 100644 app/src/main/res/layout/bottom_sheet_policy.xml diff --git a/app/src/main/java/com/cyb3rko/logviewerforopenhab/Utils.kt b/app/src/main/java/com/cyb3rko/logviewerforopenhab/Utils.kt index 97db937..12c6b01 100644 --- a/app/src/main/java/com/cyb3rko/logviewerforopenhab/Utils.kt +++ b/app/src/main/java/com/cyb3rko/logviewerforopenhab/Utils.kt @@ -3,17 +3,15 @@ package com.cyb3rko.logviewerforopenhab import android.app.Activity import android.content.* import android.net.Uri -import android.text.Html -import android.text.method.LinkMovementMethod import android.view.View import android.view.inputmethod.InputMethodManager import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.drawerlayout.widget.DrawerLayout import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity import androidx.navigation.findNavController -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.bottomsheets.BottomSheet +import com.cyb3rko.logviewerforopenhab.modals.PolicyBottomSheet import com.google.android.material.navigation.NavigationView internal const val PRIVACY_POLICY = "privacy_policy" @@ -148,12 +146,10 @@ internal fun hideConnections(activity: Activity?) { } internal fun showLicenseDialog(context: Context?, type: String) { - MaterialDialog(context!!, BottomSheet()).show { - @Suppress("DEPRECATION") - message(0, Html.fromHtml(context.assets.open("$type.html").bufferedReader().use { it.readText() })) { - messageTextView.movementMethod = LinkMovementMethod.getInstance() - } - } + PolicyBottomSheet(type).show( + (context as FragmentActivity).supportFragmentManager, + PolicyBottomSheet.TAG + ) } fun setToolbarVisibility(activity: Activity?, visibility: Int) { diff --git a/app/src/main/java/com/cyb3rko/logviewerforopenhab/modals/PolicyBottomSheet.kt b/app/src/main/java/com/cyb3rko/logviewerforopenhab/modals/PolicyBottomSheet.kt new file mode 100644 index 0000000..d539b2f --- /dev/null +++ b/app/src/main/java/com/cyb3rko/logviewerforopenhab/modals/PolicyBottomSheet.kt @@ -0,0 +1,31 @@ +package com.cyb3rko.logviewerforopenhab.modals + +import android.os.Bundle +import android.text.Html +import android.text.method.LinkMovementMethod +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.cyb3rko.logviewerforopenhab.R +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.google.android.material.textview.MaterialTextView + +class PolicyBottomSheet(private val policyType: String) : BottomSheetDialogFragment() { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val view = inflater.inflate(R.layout.bottom_sheet_policy, container, false) + val messageView = view.findViewById(R.id.message_view) + messageView.text = Html.fromHtml( + requireContext().assets.open("$policyType.html").bufferedReader().use { it.readText() } + ) + messageView.movementMethod = LinkMovementMethod.getInstance() + return view + } + + companion object { + const val TAG = "Policy Bottom Sheet" + } +} diff --git a/app/src/main/res/layout/bottom_sheet_policy.xml b/app/src/main/res/layout/bottom_sheet_policy.xml new file mode 100644 index 0000000..4e2e65d --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet_policy.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9c13c33..f5f234e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -37,7 +37,6 @@ @color/cardColor - 10dp @style/Preference.SwitchPreferenceCompat