Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material 3 Redesign and Material You Theming #4

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".PrivateDNSApp"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ru.karasevm.privatednstoggle
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import ru.karasevm.privatednstoggle.databinding.DialogAddBinding


Expand Down Expand Up @@ -45,7 +45,7 @@ class AddServerDialogFragment : DialogFragment() {
savedInstanceState: Bundle?
): Dialog {
return activity?.let {
val builder = AlertDialog.Builder(it)
val builder = MaterialAlertDialogBuilder(it)
// Get the layout inflater
val inflater = requireActivity().layoutInflater
_binding = DialogAddBinding.inflate(inflater)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ru.karasevm.privatednstoggle
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder


class DeleteServerDialogFragment(private val position: Int): DialogFragment() {
Expand Down Expand Up @@ -33,9 +33,10 @@ class DeleteServerDialogFragment(private val position: Int): DialogFragment() {
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
val builder = AlertDialog.Builder(it)
val builder = MaterialAlertDialogBuilder(it)

builder.setMessage(R.string.delete_question)
builder.setTitle(R.string.delete_question)
.setMessage(R.string.delete_message)
.setPositiveButton(R.string.delete
) { _, _ ->
listener.onDialogPositiveClick(this, position)
Expand Down
56 changes: 24 additions & 32 deletions app/src/main/java/ru/karasevm/privatednstoggle/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,31 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi
val newFragment = DeleteServerDialogFragment(position)
newFragment.show(supportFragmentManager, "delete_server")
}
binding.floatingActionButton.setOnClickListener {
val newFragment = AddServerDialogFragment()
newFragment.show(supportFragmentManager, "add_server")
}
binding.recyclerView.adapter = adapter

binding.topAppBar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.privacy_policy -> {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://karasevm.github.io/PrivateDNSAndroid/privacy_policy"))
startActivity(browserIntent)
true
}

R.id.enable_auto -> {
if (!item.isChecked){
Toast.makeText(this, R.string.auto_mode_clarification, Toast.LENGTH_LONG).show()
}
sharedPrefs.edit().putBoolean("auto_enabled", !item.isChecked).apply()
item.setChecked(!item.isChecked)
true
}
else -> true
}
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand Down Expand Up @@ -116,35 +140,6 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi
Shizuku.removeRequestPermissionResultListener(this::onRequestPermissionResult)
}

override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
R.id.add_server -> {
val newFragment = AddServerDialogFragment()
newFragment.show(supportFragmentManager, "add_server")
true
}
R.id.privacy_policy -> {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://karasevm.github.io/PrivateDNSAndroid/privacy_policy"))
startActivity(browserIntent)
true
}

R.id.enable_auto -> {
if (!item.isChecked){
Toast.makeText(this, R.string.auto_mode_clarification, Toast.LENGTH_LONG).show()
}
sharedPrefs.edit().putBoolean("auto_enabled", !item.isChecked).apply()
item.setChecked(!item.isChecked)

true
}

else -> {
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
super.onOptionsItemSelected(item)
}
}

override fun onDialogPositiveClick(dialog: DialogFragment, server: String) {
if (server.isEmpty()) {
Toast.makeText(this, R.string.server_length_error, Toast.LENGTH_SHORT).show()
Expand All @@ -163,7 +158,6 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi
adapter.notifyItemRemoved(position)
sharedPrefs.edit()
.putString("dns_servers", items.joinToString(separator = ",") { it }).apply()

}

/**
Expand Down Expand Up @@ -217,7 +211,5 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi
startActivity(browserIntent)
finish()
}

}

}
11 changes: 11 additions & 0 deletions app/src/main/java/ru/karasevm/privatednstoggle/PrivateDNSApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.karasevm.privatednstoggle

import android.app.Application
import com.google.android.material.color.DynamicColors

class PrivateDNSApp : Application() {
override fun onCreate() {
super.onCreate()
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/drawable/ic_baseline_add_24.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
<vector android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
Expand Down
34 changes: 31 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/topAppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:title="@string/app_name"
app:menu="@menu/menu_main" />

</com.google.android.material.appbar.AppBarLayout>
Comment on lines +9 to +25
Copy link
Contributor Author

@InfiniteCoder06 InfiniteCoder06 Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be done to maintain consistency of Theming otherwise it would use default colors in the app bar


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/topAppBarLayout" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:contentDescription="@string/add_server"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_baseline_add_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
31 changes: 20 additions & 11 deletions app/src/main/res/layout/dialog_add.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/editTextServerAddr"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_margin="24dp"
android:ems="10"
android:maxLines="1"
android:inputType="textNoSuggestions"
android:importantForAutofill="no"
android:hint="@string/add_edittext_hint"
<com.google.android.material.textfield.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
android:hint="@string/add_edittext_hint">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextServerAddr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:ems="10"
android:importantForAutofill="no"
/>

</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 1 addition & 5 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/add_server"
android:icon="@drawable/ic_baseline_add_24"
android:title="@string/menu_add"
app:showAsAction="ifRoom" />
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/enable_auto"
android:checkable="true"
Expand Down
22 changes: 9 additions & 13 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<resources>
<!-- Base application theme. -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<style name="Theme.MyApplication" parent="Theme.Material3.Dark.NoActionBar">
<item name="colorPrimary">@color/md_theme_dark_primary</item>
<item name="colorSecondary">@color/md_theme_dark_secondary</item>
<item name="colorTertiary">@color/md_theme_dark_tertiary</item>
<item name="android:colorBackground">@color/md_theme_dark_background</item>

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
</resources>
23 changes: 14 additions & 9 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
<color name="ic_launcher_background">#498EE8</color>

<color name="seed">#6750A4</color>
<color name="md_theme_light_primary">#6750A4</color>
<color name="md_theme_light_secondary">#625B71</color>
<color name="md_theme_light_tertiary">#7D5260</color>
<color name="md_theme_light_background">#FFFBFE</color>

<color name="md_theme_dark_primary">#D0BCFF</color>
<color name="md_theme_dark_secondary">#CCC2DC</color>
<color name="md_theme_dark_tertiary">#EFB8C8</color>
<color name="md_theme_dark_background">#1C1B1F</color>
</resources>
4 changes: 0 additions & 4 deletions app/src/main/res/values/ic_launcher_background.xml

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<string name="menu_auto_enabled">Enable auto</string>
<string name="auto_mode_clarification">Automatic (opportunistic) DNS mode will now be available in the tile</string>
<string name="cancel">Cancel</string>
<string name="delete_question">Delete server?</string>
<string name="delete_question">Delete</string>
<string name="delete_message">Are you sure you want to delete server?</string>
<string name="delete">Delete</string>
<string name="server_length_error">Server address cannot be empty</string>
<string name="add_edittext_hint">DNS server address</string>
Expand Down
23 changes: 10 additions & 13 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<resources>
<!-- Base application theme. -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<style name="Theme.MyApplication" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/md_theme_light_primary</item>
<item name="colorSecondary">@color/md_theme_light_secondary</item>
<item name="colorTertiary">@color/md_theme_light_tertiary</item>

<item name="android:colorBackground">@color/md_theme_light_background</item>

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
</resources>