Skip to content

Commit

Permalink
Add close action to CustomWebsiteActivity and Fixed dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Nov 4, 2023
1 parent 1412af1 commit 5e32bb7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<intent-filter>
<action android:name="${applicationId}.activity.CustomWebsiteActivity" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
}
Expand Down Expand Up @@ -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(
Expand All @@ -103,4 +120,4 @@ class CustomWebsiteActivity : AbstractActivity(), ConfirmDialogFragment.OnClickL
) {
if (buttonClicked == DialogInterface.BUTTON_POSITIVE) super.onBackPressed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -101,4 +102,4 @@ class ConfirmDialogFragment(
DialogInterface.BUTTON_NEGATIVE,
DialogInterface.BUTTON_NEUTRAL
)
internal annotation class ConfirmDialogButton
internal annotation class ConfirmDialogButton
8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_customwebsite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</com.google.android.material.appbar.AppBarLayout>

<ScrollView
Expand Down Expand Up @@ -52,16 +53,15 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.CustomWebsite">
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">

<androidx.appcompat.widget.Toolbar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_gray0"
app:titleTextColor="@color/color_black"
app:menu="@menu/run"
app:title="@string/OONIRun_URLs"
app:titleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title.App" />
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
</LinearLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/edittext_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,4 +36,4 @@
android:rotation="45"
android:src="@drawable/add_circle_outline"
app:tint="@color/color_red8" />
</FrameLayout>
</FrameLayout>
10 changes: 10 additions & 0 deletions app/src/main/res/menu/close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/close_button"
android:title="@string/OONIRun_Close"
android:icon="@drawable/close"
app:iconTint="@color/color_black"
app:showAsAction="ifRoom|withText" />
</menu>
28 changes: 18 additions & 10 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@
<item name="colorOnSurface">@color/color_gray5</item>
<item name="android:colorForeground">@color/color_gray7</item>
<item name="alertDialogTheme">@style/AlertDialogCustom</item>
<item name="materialAlertDialogBodyTextStyle">@style/AlertDialogCustom</item>
<item name="android:alertDialogTheme">?alertDialogTheme</item>
<item name="dialogTheme">?alertDialogTheme</item>
<item name="android:dialogTheme">?alertDialogTheme</item>
<item name="snackbarStyle">@style/SnackBarStyle</item>
</style>

<style name="Theme.MaterialComponents.Light.NoActionBar.CustomWebsite">
<item name="colorPrimary">@color/color_base</item>
<item name="colorPrimaryDark">@color/color_blue6</item>
<item name="colorAccent">@color/color_blue4</item>
<item name="fontFamily">@font/firasans</item>
<item name="android:colorBackground">@color/color_white</item>
</style>

<style name="Theme.MaterialComponents.NoActionBar.App">
<item name="colorPrimary">@color/color_base</item>
<item name="colorPrimaryDark">@color/color_blue6</item>
Expand Down Expand Up @@ -73,8 +66,23 @@
<item name="android:background">@color/color_white</item>
<item name="colorAccent">@color/color_blue4</item>
</style>

<style name="SnackBarStyle" parent="Widget.MaterialComponents.Snackbar">
<style name="Theme.App.MaterialDialogAlert" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:background">@color/color_white</item>
<item name="materialAlertDialogTitleTextStyle">@style/AppMaterialAlertDialog</item>
<item name="materialAlertDialogBodyTextStyle">@style/AppBodyTextAppearance.MaterialComponents.Body2</item>
</style>
<style name="AppMaterialAlertDialog" parent="@style/MaterialAlertDialog.MaterialComponents.Title.Text">
<item name="android:textColor">@color/color_black</item>
<item name="android:textAppearance">@style/AppTextAppearance.MaterialComponents.Subtitle1</item>
</style>
<style name="AppTextAppearance.MaterialComponents.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">
<item name="android:textColor">@color/color_black</item>
</style>
<style name="AppBodyTextAppearance.MaterialComponents.Body2" parent="@style/MaterialAlertDialog.MaterialComponents.Body.Text">
<item name="android:textColor">@color/color_gray6</item>
</style>

<style name="SnackBarStyle" parent="Widget.MaterialComponents.Snackbar">
<item name="android:background">@color/color_gray8</item>
</style>

Expand Down

0 comments on commit 5e32bb7

Please sign in to comment.