From 5e32bb7e91e79ed54bf6dd0e5ec38f06d2d0f80e Mon Sep 17 00:00:00 2001 From: Norbel Ambanumben Date: Sat, 4 Nov 2023 11:02:10 +0100 Subject: [PATCH] Add close action to `CustomWebsiteActivity` and Fixed dark theme --- app/src/main/AndroidManifest.xml | 2 +- .../activity/CustomWebsiteActivity.kt | 25 ++++++++++++++--- .../fragment/ConfirmDialogFragment.kt | 5 ++-- .../res/layout/activity_customwebsite.xml | 8 +++--- app/src/main/res/layout/edittext_url.xml | 4 +-- app/src/main/res/menu/close.xml | 10 +++++++ app/src/main/res/values/styles.xml | 28 ++++++++++++------- 7 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 app/src/main/res/menu/close.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 15536b39d..f513b8776 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -100,7 +100,7 @@ android:exported="false" android:parentActivityName=".activity.PreferenceActivity" android:screenOrientation="userPortrait" - android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.CustomWebsite"> + android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"> diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/CustomWebsiteActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/CustomWebsiteActivity.kt index eb1ec4a5e..64c424c2f 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/CustomWebsiteActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/CustomWebsiteActivity.kt @@ -4,6 +4,8 @@ import android.content.DialogInterface import android.os.Bundle import android.os.Parcelable import android.util.Patterns +import android.view.Menu +import android.view.MenuInflater import android.view.MenuItem import android.view.View import androidx.recyclerview.widget.LinearLayoutManager @@ -47,9 +49,7 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL for (value in items) { val sanitizedUrl = value.replace("\\r\\n|\\r|\\n".toRegex(), " ") //https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer - if (Patterns.WEB_URL.matcher(sanitizedUrl) - .matches() && sanitizedUrl.length < 2084 - ) urls.add( + if (Patterns.WEB_URL.matcher(sanitizedUrl).matches() && sanitizedUrl.length < 2084) urls.add( Url.checkExistingUrl(sanitizedUrl).toString() ) } @@ -84,6 +84,23 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL return true } + override fun onCreateOptionsMenu(menu: Menu): Boolean { + val inflater: MenuInflater = menuInflater + inflater.inflate(R.menu.close, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.close_button -> { + onSupportNavigateUp() + true + } + + else -> super.onOptionsItemSelected(item) + } + } + fun add() { adapter.addAll(listOf(getString(R.string.http))) binding.bottomBar.title = getString( @@ -103,4 +120,4 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL ) { if (buttonClicked == DialogInterface.BUTTON_POSITIVE) super.onBackPressed() } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt index 115986a6c..b951c6fd4 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt @@ -7,6 +7,7 @@ import androidx.annotation.IntDef import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.openobservatory.ooniprobe.R import java.io.Serializable class ConfirmDialogFragment( @@ -51,7 +52,7 @@ class ConfirmDialogFragment( } override fun onCreateDialog(savedInstanceState: Bundle?) = - MaterialAlertDialogBuilder(requireContext()).apply { + MaterialAlertDialogBuilder(requireContext(), R.style.Theme_App_MaterialDialogAlert).apply { setTitle(requireArguments().getString(TITLE)) if (requireArguments().containsKey(MESSAGE)) setMessage( HtmlCompat.fromHtml( @@ -101,4 +102,4 @@ class ConfirmDialogFragment( DialogInterface.BUTTON_NEGATIVE, DialogInterface.BUTTON_NEUTRAL ) -internal annotation class ConfirmDialogButton \ No newline at end of file +internal annotation class ConfirmDialogButton diff --git a/app/src/main/res/layout/activity_customwebsite.xml b/app/src/main/res/layout/activity_customwebsite.xml index 5a2fde126..f80a4475c 100644 --- a/app/src/main/res/layout/activity_customwebsite.xml +++ b/app/src/main/res/layout/activity_customwebsite.xml @@ -15,7 +15,8 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - android:background="@color/color_gray0" /> + android:background="@color/color_gray0" + app:menu="@menu/close"/> + android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"> - \ No newline at end of file + diff --git a/app/src/main/res/layout/edittext_url.xml b/app/src/main/res/layout/edittext_url.xml index 637323f9e..60b01e6e5 100644 --- a/app/src/main/res/layout/edittext_url.xml +++ b/app/src/main/res/layout/edittext_url.xml @@ -16,7 +16,7 @@ android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" - android:textColor="@android:color/black" + android:textColor="@color/color_black" android:hint="@string/Settings_Websites_CustomURL_URL" android:inputType="textUri" android:paddingEnd="48dp" @@ -36,4 +36,4 @@ android:rotation="45" android:src="@drawable/add_circle_outline" app:tint="@color/color_red8" /> - \ No newline at end of file + diff --git a/app/src/main/res/menu/close.xml b/app/src/main/res/menu/close.xml new file mode 100644 index 000000000..1daa03f3c --- /dev/null +++ b/app/src/main/res/menu/close.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1fc5b1ae2..44f6bf972 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -12,20 +12,13 @@ @color/color_gray5 @color/color_gray7 @style/AlertDialogCustom + @style/AlertDialogCustom ?alertDialogTheme ?alertDialogTheme ?alertDialogTheme @style/SnackBarStyle - - - - + + + + +