diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index f312bb66..1824a223 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -7,10 +7,7 @@ import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothDevice import android.bluetooth.BluetoothManager import android.companion.CompanionDeviceManager -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter +import android.content.* import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.hardware.usb.UsbDevice @@ -28,7 +25,9 @@ import android.view.View import android.widget.TextView import android.widget.Toast import androidx.activity.viewModels +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.widget.Toolbar import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat @@ -379,6 +378,9 @@ class MainActivity : AppCompatActivity(), Logging, val prefs = UIViewModel.getPreferences(this) model.ownerName.value = prefs.getString("owner", "")!! + /// Set theme + setUITheme(prefs) + /// Set initial bluetooth state updateBluetoothEnabled() @@ -1068,6 +1070,10 @@ class MainActivity : AppCompatActivity(), Logging, startActivityForResult(intent, CREATE_CSV_FILE) return true } + R.id.theme -> { + chooseThemeDialog() + return true + } else -> super.onOptionsItemSelected(item) } } @@ -1114,5 +1120,80 @@ class MainActivity : AppCompatActivity(), Logging, } } } + + + /// Theme functions + + private fun chooseThemeDialog() { + + /// Prepare dialog and its items + val builder = AlertDialog.Builder(this) + builder.setTitle(getString(R.string.choose_theme_title)) + + val styles = arrayOf( + getString(R.string.theme_light), + getString(R.string.theme_dark), + getString(R.string.theme_system)) + + /// Load preferences and its value + val prefs = UIViewModel.getPreferences(this) + val editor: SharedPreferences.Editor = prefs.edit() + val checkedItem = prefs.getInt("theme", 2) + + builder.setSingleChoiceItems(styles, checkedItem) { dialog, which -> + + when (which) { + 0 -> { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) + editor.putInt("theme", 0) + editor.apply() + + delegate.applyDayNight() + dialog.dismiss() + } + 1 -> { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + editor.putInt("theme", 1) + editor.apply() + + delegate.applyDayNight() + dialog.dismiss() + } + 2 -> { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + editor.putInt("theme", 2) + editor.apply() + + delegate.applyDayNight() + dialog.dismiss() + } + + } + } + + val dialog = builder.create() + dialog.show() + } + + private fun setUITheme(prefs: SharedPreferences) { + /// Read theme settings from preferences and set it + /// If nothing is found set FOLLOW SYSTEM option + + when (prefs.getInt("theme", 2)) { + 0 -> { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) + delegate.applyDayNight() + } + 1 -> { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + delegate.applyDayNight() + } + 2 -> { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) + delegate.applyDayNight() + } + } + } + } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index cf7de3c0..7608ff3c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -23,6 +23,7 @@ + app:srcCompat="@drawable/cloud_download_outline_24" + android:contentDescription="TODO" + app:tint="@color/colorIconTint" /> diff --git a/app/src/main/res/layout/advanced_settings.xml b/app/src/main/res/layout/advanced_settings.xml index 79f9fb0a..690a745c 100644 --- a/app/src/main/res/layout/advanced_settings.xml +++ b/app/src/main/res/layout/advanced_settings.xml @@ -3,8 +3,8 @@ 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="match_parent" android:background="#FFFFFF" - > + android:layout_height="match_parent" + android:background="@color/colorAdvancedBackground"> \ No newline at end of file + android:textAppearance="?attr/textAppearanceSubtitle1" + /> \ No newline at end of file diff --git a/app/src/main/res/layout/settings_fragment.xml b/app/src/main/res/layout/settings_fragment.xml index 352fab9a..07650f07 100644 --- a/app/src/main/res/layout/settings_fragment.xml +++ b/app/src/main/res/layout/settings_fragment.xml @@ -132,7 +132,7 @@ android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" - android:background="@color/cardview_light_background" + android:background="@android:color/transparent" android:checked="true" android:text="@string/analytics_okay" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 45f8e5cf..03211deb 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -24,6 +24,10 @@ android:id="@+id/save_messages_csv" app:showAsAction="withText" android:title="@string/save_messages" /> + + + #3700B3 + #3700B3 + #212121 + #212121 + #141414 + #141414 + #FFFFFF + #FFFFFF + #000000 + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 545dd613..d8da3c61 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,4 +4,9 @@ #3700B3 #F2F2F2 #EDEAF4 + #FFFFFF + #FFFFFF + #000000 + #000000 + #FFFFFF diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e930b4a..85adfc27 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -103,4 +103,9 @@ Reset to defaults Apply No application found to send URLs + Theme + Light + Dark + System default + Choose theme diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index e36ac68c..eeaff985 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,14 +1,14 @@ - - @@ -31,7 +31,7 @@ + + // Toolbar style +