Skip to content

Commit

Permalink
feat: add icons to main screen
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Mar 26, 2023
1 parent 4150cd4 commit 55cc80a
Show file tree
Hide file tree
Showing 31 changed files with 252 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang

override fun onCreate() {
Timber.plant(DebugTree())
Timber.plant(PlutoTimberTree())

if(BuildConfig.DEBUG) {
Timber.plant(PlutoTimberTree())
enableDebugTools()
}
if(!BuildConfig.FOSS_ONLY)
Timber.plant(CrashReportingTree())

Expand All @@ -124,54 +127,6 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang
dumpFile.delete()
}

if(BuildConfig.DEBUG) {
// Hide LeakCanary icons
LeakCanary.showLeakDisplayActivityLauncherIcon(false)

// Setup strict mode with death penalty
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.apply {
detectCustomSlowCalls()
detectNetwork()
detectResourceMismatches()
penaltyLog()
penaltyDeath()
}
.build()
)

StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.apply {
detectLeakedRegistrationObjects()
detectCleartextNetwork()
detectActivityLeaks()
detectLeakedClosableObjects()
detectLeakedSqlLiteObjects()
detectContentUriWithoutPermission()
penaltyLog()
penaltyDeath()
}
.build()
)

Pluto.Installer(this)
.addPlugin(PlutoNetworkPlugin("network"))
.addPlugin(PlutoExceptionsPlugin("exceptions"))
.addPlugin(PlutoLoggerPlugin("logger"))
.addPlugin(PlutoSharePreferencesPlugin("sharedPref"))
.addPlugin(PlutoRoomsDatabasePlugin("rooms-db"))
.install()
Pluto.showNotch(true)

PlutoExceptions.setANRHandler { thread, exception ->
Timber.e("unhandled ANR handled on thread: " + thread.name, exception)
}

PlutoRoomsDBWatcher.watch("blocked_apps.db", AppBlocklistDatabase::class.java)
}

Notifications.createChannels(this)

val appModule = module {
Expand All @@ -197,8 +152,7 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang
prefs.set(R.string.key_share_crash_reports, false)
}

val crashlytics = prefs.get(R.string.key_share_crash_reports) &&
(!BuildConfig.DEBUG || BuildConfig.PREVIEW)
val crashlytics = prefs.get<Boolean>(R.string.key_share_crash_reports)
Timber.d("Crashlytics enabled? $crashlytics")
CrashlyticsImpl.setCollectionEnabled(crashlytics)

Expand Down Expand Up @@ -259,6 +213,54 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang
}
}

private fun enableDebugTools() {
// Hide LeakCanary icons
LeakCanary.showLeakDisplayActivityLauncherIcon(false)

// Setup strict mode with death penalty
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.apply {
detectCustomSlowCalls()
detectNetwork()
detectResourceMismatches()
penaltyLog()
penaltyDeath()
}
.build()
)

StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.apply {
detectLeakedRegistrationObjects()
detectCleartextNetwork()
detectActivityLeaks()
detectLeakedClosableObjects()
detectLeakedSqlLiteObjects()
detectContentUriWithoutPermission()
penaltyLog()
penaltyDeath()
}
.build()
)

Pluto.Installer(this)
.addPlugin(PlutoNetworkPlugin("network"))
.addPlugin(PlutoExceptionsPlugin("exceptions"))
.addPlugin(PlutoLoggerPlugin("logger"))
.addPlugin(PlutoSharePreferencesPlugin("sharedPref"))
.addPlugin(PlutoRoomsDatabasePlugin("rooms-db"))
.install()
Pluto.showNotch(true)

PlutoExceptions.setANRHandler { thread, exception ->
Timber.e("unhandled ANR handled on thread: " + thread.name, exception)
}

PlutoRoomsDBWatcher.watch("blocked_apps.db", AppBlocklistDatabase::class.java)
}

/** A tree which logs important information for crash reporting. */
private class CrashReportingTree : DebugTree() {
private fun priorityAsString(priority: Int): String {
Expand All @@ -274,12 +276,8 @@ class MainApplication : Application(), SharedPreferences.OnSharedPreferenceChang
}

override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
val safeTag = tag ?: "Unknown"
CrashlyticsImpl.log("[${priorityAsString(priority)}] $safeTag: $message")

if (t != null && (priority == Log.ERROR || priority == Log.WARN || priority == Log.ASSERT)) {
CrashlyticsImpl.recordException(t)
}
CrashlyticsImpl.log("[${priorityAsString(priority)}] ${tag ?: "???"}: $message")
t?.takeIf { priority >= Log.WARN }?.let(CrashlyticsImpl::recordException)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ import me.timschneeberger.rootlessjamesdsp.liveprog.EelParser
import me.timschneeberger.rootlessjamesdsp.preference.EqualizerPreference
import me.timschneeberger.rootlessjamesdsp.preference.FileLibraryPreference
import me.timschneeberger.rootlessjamesdsp.preference.MaterialSeekbarPreference
import me.timschneeberger.rootlessjamesdsp.preference.SwitchPreferenceGroup
import me.timschneeberger.rootlessjamesdsp.utils.Constants
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.registerLocalReceiver
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.sendLocalBroadcast
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.unregisterLocalReceiver
import me.timschneeberger.rootlessjamesdsp.utils.preferences.Preferences
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import timber.log.Timber


class PreferenceGroupFragment : PreferenceFragmentCompat() {
class PreferenceGroupFragment : PreferenceFragmentCompat(), KoinComponent {
private val prefsApp: Preferences.App by inject()
private val eelParser = EelParser()
private var recyclerView: RecyclerView? = null

Expand All @@ -33,6 +38,13 @@ class PreferenceGroupFragment : PreferenceFragmentCompat() {
requireContext().sendLocalBroadcast(Intent(Constants.ACTION_PREFERENCES_UPDATED))
}

private val listenerApp =
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
when(key) {
getString(R.string.key_appearance_show_icons) -> updateIconState()
}
}

private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if(intent?.action == Constants.ACTION_PRESET_LOADED) {
Expand All @@ -43,6 +55,13 @@ class PreferenceGroupFragment : PreferenceFragmentCompat() {
}
}

private fun updateIconState() {
if(preferenceScreen.preferenceCount > 0) {
(preferenceScreen.getPreference(0) as? SwitchPreferenceGroup?)
?.setIsIconVisible(prefsApp.get<Boolean>(R.string.key_appearance_show_icons))
}
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
val args = requireArguments()
preferenceManager.sharedPreferencesName = args.getString(BUNDLE_PREF_NAME)
Expand Down Expand Up @@ -146,7 +165,10 @@ class PreferenceGroupFragment : PreferenceFragmentCompat() {
}
}

updateIconState()

preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(listener)
prefsApp.registerOnSharedPreferenceChangeListener(listenerApp)
}

override fun onCreateRecyclerView(
Expand All @@ -169,6 +191,7 @@ class PreferenceGroupFragment : PreferenceFragmentCompat() {
override fun onDestroy() {
super.onDestroy()
requireContext().unregisterLocalReceiver(receiver)
prefsApp.unregisterOnSharedPreferenceChangeListener(listener)
preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(listener)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.preference.Preference
import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceViewHolder
Expand All @@ -25,6 +26,7 @@ class SwitchPreferenceGroup(context: Context, attrs: AttributeSet) : PreferenceG
private var switch: MaterialSwitch? = null
private var itemView: View? = null
private var bgAnimation: ValueAnimator? = null
private var isIconVisible: Boolean = false
private var state = false

init {
Expand Down Expand Up @@ -54,10 +56,12 @@ class SwitchPreferenceGroup(context: Context, attrs: AttributeSet) : PreferenceG

setChildrenVisibility(state)
animateHeaderState(state)
setIsIconVisible(isIconVisible)

switch = (holder.findViewById(R.id.switchWidget) as MaterialSwitch).apply {
// Apply initial state
isChecked = state
isVisible = isSelectable

setOnCheckedChangeListener { _, isChecked ->
setValueInternal(isChecked, false)
Expand All @@ -76,6 +80,11 @@ class SwitchPreferenceGroup(context: Context, attrs: AttributeSet) : PreferenceG
return super.onPrepareAddPreference(preference)
}

fun setIsIconVisible(value: Boolean) {
isIconVisible = value
itemView?.findViewById<View>(R.id.icon_frame)?.isVisible = value
}

fun setValue(value: Boolean) {
setValueInternal(value, true)
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_arrow_collapse_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/arrow_collapse.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M19.5,3.09L15,7.59V4H13V11H20V9H16.41L20.91,4.5L19.5,3.09M4,13V15H7.59L3.09,19.5L4.5,20.91L9,16.41V20H11V13H4Z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/chart_timeline_variant.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M3,14L3.5,14.07L8.07,9.5C7.89,8.85 8.06,8.11 8.59,7.59C9.37,6.8 10.63,6.8 11.41,7.59C11.94,8.11 12.11,8.85 11.93,9.5L14.5,12.07L15,12C15.18,12 15.35,12 15.5,12.07L19.07,8.5C19,8.35 19,8.18 19,8A2,2 0 0,1 21,6A2,2 0 0,1 23,8A2,2 0 0,1 21,10C20.82,10 20.65,10 20.5,9.93L16.93,13.5C17,13.65 17,13.82 17,14A2,2 0 0,1 15,16A2,2 0 0,1 13,14L13.07,13.5L10.5,10.93C10.18,11 9.82,11 9.5,10.93L4.93,15.5L5,16A2,2 0 0,1 3,18A2,2 0 0,1 1,16A2,2 0 0,1 3,14Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_code_tags_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/code_tags.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M14.6,16.6L19.2,12L14.6,7.4L16,6L22,12L16,18L14.6,16.6M9.4,16.6L4.8,12L9.4,7.4L8,6L2,12L8,18L9.4,16.6Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_cone_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/cone.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M21.62 16.68H21.62L12.85 2.5C12.66 2.16 12.33 2 12 2C11.67 2 11.34 2.16 11.15 2.47L2.38 16.65H2.4C2.15 17.04 2 17.5 2 18C2 19.5 3.3 22 12 22C15.74 22 22 21.5 22 18C22 17.61 21.91 17.15 21.62 16.68M12 4.9L18 14.58C16.53 14.23 14.6 14 12 14C10.25 14 7.96 14.12 6 14.6L12 4.9M12 20C7.58 20 4 19.11 4 18C4 16.9 7.58 16 12 16S20 16.9 20 18C20 19.11 16.42 20 12 20Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_cube_outline_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/cube_outline.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M21,16.5C21,16.88 20.79,17.21 20.47,17.38L12.57,21.82C12.41,21.94 12.21,22 12,22C11.79,22 11.59,21.94 11.43,21.82L3.53,17.38C3.21,17.21 3,16.88 3,16.5V7.5C3,7.12 3.21,6.79 3.53,6.62L11.43,2.18C11.59,2.06 11.79,2 12,2C12.21,2 12.41,2.06 12.57,2.18L20.47,6.62C20.79,6.79 21,7.12 21,7.5V16.5M12,4.15L6.04,7.5L12,10.85L17.96,7.5L12,4.15M5,15.91L11,19.29V12.58L5,9.21V15.91M19,15.91V9.21L13,12.58V19.29L19,15.91Z" />
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_equalizer_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<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="M10,20h4L14,4h-4v16zM4,20h4v-8L4,12v8zM16,9v11h4L20,9h-4z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/image_filter_tilt_shift.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M5.68,19.74C7.16,20.95 9,21.75 11,21.95V19.93C9.54,19.75 8.21,19.17 7.1,18.31M13,19.93V21.95C15,21.75 16.84,20.95 18.32,19.74L16.89,18.31C15.79,19.17 14.46,19.75 13,19.93M18.31,16.9L19.74,18.33C20.95,16.85 21.75,15 21.95,13H19.93C19.75,14.46 19.17,15.79 18.31,16.9M15,12A3,3 0 0,0 12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12M4.07,13H2.05C2.25,15 3.05,16.84 4.26,18.32L5.69,16.89C4.83,15.79 4.25,14.46 4.07,13M5.69,7.1L4.26,5.68C3.05,7.16 2.25,9 2.05,11H4.07C4.25,9.54 4.83,8.21 5.69,7.1M19.93,11H21.95C21.75,9 20.95,7.16 19.74,5.68L18.31,7.1C19.17,8.21 19.75,9.54 19.93,11M18.32,4.26C16.84,3.05 15,2.25 13,2.05V4.07C14.46,4.25 15.79,4.83 16.9,5.69M11,4.07V2.05C9,2.25 7.16,3.05 5.68,4.26L7.1,5.69C8.21,4.83 9.54,4.25 11,4.07Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_led_outline_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/led_outline.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="m12 2.083a4.667 4.667 0 0 0-4.667 4.667v7h-2.333v2.333h3.5v5.833h2.333v-5.833h2.333v5.833h2.333v-5.833h3.5v-2.333h-2.333v-7a4.667 4.667 0 0 0-4.667-4.667m0 2.333a2.333 2.333 0 0 1 2.333 2.333v5.833h-4.667v-5.833a2.333 2.333 0 0 1 2.333-2.333z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_sine_wave_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/sine_wave.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#000000"
android:pathData="M16.5,21C13.5,21 12.31,16.76 11.05,12.28C10.14,9.04 9,5 7.5,5C4.11,5 4,11.93 4,12H2C2,11.63 2.06,3 7.5,3C10.5,3 11.71,7.25 12.97,11.74C13.83,14.8 15,19 16.5,19C19.94,19 20.03,12.07 20.03,12H22.03C22.03,12.37 21.97,21 16.5,21Z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_baseline_waveform_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- drawable/waveform.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M22 12L20 13L19 14L18 13L17 16L16 13L15 21L14 13L13 15L12 13L11 17L10 13L9 22L8 13L7 19L6 13L5 14L4 13L2 12L4 11L5 10L6 11L7 5L8 11L9 2L10 11L11 7L12 11L13 9L14 11L15 3L16 11L17 8L18 11L19 10L20 11L22 12Z" />
</vector>
8 changes: 0 additions & 8 deletions app/src/main/res/drawable/ic_twotone_speaker_phone_24dp.xml

This file was deleted.

Loading

0 comments on commit 55cc80a

Please sign in to comment.