Configure log fields and timezone
This commit is contained in:
@@ -97,6 +97,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||||||
R.id.content_frame,
|
R.id.content_frame,
|
||||||
when {
|
when {
|
||||||
page == Page.VIEW_LOGS -> ViewLogsFragment()
|
page == Page.VIEW_LOGS -> ViewLogsFragment()
|
||||||
|
page == Page.SETTINGS -> SettingsFragment()
|
||||||
page.loggingType != null -> EventSettingsFragment.newInstance(page.titleRes, page.loggingType)
|
page.loggingType != null -> EventSettingsFragment.newInstance(page.titleRes, page.loggingType)
|
||||||
else -> PageFragment.newInstance(page.titleRes)
|
else -> PageFragment.newInstance(page.titleRes)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package se.ajpanton.notificationlog
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
import se.ajpanton.notificationlog.databinding.FragmentSettingsBinding
|
||||||
|
import se.ajpanton.notificationlog.settings.LogField
|
||||||
|
import se.ajpanton.notificationlog.settings.LogViewSettingsStore
|
||||||
|
import se.ajpanton.notificationlog.settings.TimestampZone
|
||||||
|
|
||||||
|
class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||||
|
private var binding: FragmentSettingsBinding? = null
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
binding = FragmentSettingsBinding.bind(view)
|
||||||
|
val store = LogViewSettingsStore(requireContext())
|
||||||
|
var settings = store.load()
|
||||||
|
LogField.entries.forEach { field ->
|
||||||
|
binding!!.fieldToggles.addView(SwitchMaterial(requireContext()).apply {
|
||||||
|
text = when (field) {
|
||||||
|
LogField.TIMESTAMP -> "Timestamp"; LogField.APP_NAME -> "App name"
|
||||||
|
LogField.PACKAGE_NAME -> "Package name"; LogField.ACTION -> "What the app did"
|
||||||
|
LogField.CONTENTS -> "Contents of the notification"
|
||||||
|
}
|
||||||
|
isChecked = field in settings.visibleFields
|
||||||
|
setOnCheckedChangeListener { _, checked ->
|
||||||
|
settings = settings.copy(visibleFields = settings.visibleFields.toMutableSet().apply {
|
||||||
|
if (checked) add(field) else remove(field)
|
||||||
|
})
|
||||||
|
store.save(settings)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
val labels = listOf("Current local timezone", "UTC", "Local timezone when event happened")
|
||||||
|
binding!!.timezone.adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, labels)
|
||||||
|
binding!!.timezone.setSelection(TimestampZone.entries.indexOf(settings.timestampZone))
|
||||||
|
binding!!.timezone.onItemSelectedListener = object : android.widget.AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onNothingSelected(parent: android.widget.AdapterView<*>?) = Unit
|
||||||
|
override fun onItemSelected(parent: android.widget.AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||||
|
settings = settings.copy(timestampZone = TimestampZone.entries[position]); store.save(settings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun onDestroyView() { binding = null; super.onDestroyView() }
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"><LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="@dimen/page_padding"><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Settings" android:textAppearance="?attr/textAppearanceHeadline5"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Show on each log line"/><LinearLayout android:id="@+id/field_toggles" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:text="Timestamp timezone"/><Spinner android:id="@+id/timezone" android:layout_width="match_parent" android:layout_height="wrap_content"/></LinearLayout></ScrollView>
|
||||||
Reference in New Issue
Block a user