From 9b348f9dee100d301ce07ddfb107f23b1ed82189 Mon Sep 17 00:00:00 2001 From: CrazyDude1994 Date: Mon, 25 Jan 2021 16:56:00 +0200 Subject: [PATCH] Version bump. Allow to change log folder for API >= 30 --- app/build.gradle | 4 +- .../com/telemetry/ui/PrefsFragment.kt | 35 +++++++- app/src/main/res/xml/preferences.xml | 89 ++++++++++--------- 3 files changed, 83 insertions(+), 45 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 314f65e2..c674a5ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,8 +22,8 @@ android { applicationId "crazydude.com.telemetry" minSdkVersion 17 targetSdkVersion 30 - versionCode 28 - versionName "1.8" + versionCode 29 + versionName "1.8.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/crazydude/com/telemetry/ui/PrefsFragment.kt b/app/src/main/java/crazydude/com/telemetry/ui/PrefsFragment.kt index 405be5ba..2b8a4d26 100644 --- a/app/src/main/java/crazydude/com/telemetry/ui/PrefsFragment.kt +++ b/app/src/main/java/crazydude/com/telemetry/ui/PrefsFragment.kt @@ -1,5 +1,7 @@ package crazydude.com.telemetry.ui +import android.app.Activity.RESULT_OK +import android.content.Intent import android.content.SharedPreferences import android.os.Bundle import androidx.preference.PreferenceFragmentCompat @@ -9,10 +11,17 @@ import crazydude.com.telemetry.manager.PreferenceManager class PrefsFragment : PreferenceFragmentCompat() { + companion object { + private const val REQUEST_FILE_TREE = 0 + } + private lateinit var prefManager: PreferenceManager private val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ -> updateSummary() - FirebaseAnalytics.getInstance(context!!).setUserProperty("telemetry_sharing_enable", prefManager.isSendDataEnabled().toString().toLowerCase()) + FirebaseAnalytics.getInstance(context!!).setUserProperty( + "telemetry_sharing_enable", + prefManager.isSendDataEnabled().toString().toLowerCase() + ) } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -22,15 +31,39 @@ class PrefsFragment : PreferenceFragmentCompat() { prefManager = PreferenceManager(context!!) preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(listener) + findPreference("log_folder").apply { + isVisible = shouldUseStorageAPI() + }.setOnPreferenceClickListener { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { + flags = + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + } + startActivityForResult(intent, REQUEST_FILE_TREE) + return@setOnPreferenceClickListener true + } updateSummary() } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == REQUEST_FILE_TREE && resultCode == RESULT_OK) { + prefManager.setLogsStorageFolder(data?.dataString) + context?.contentResolver?.takePersistableUriPermission( + data?.data!!, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + updateSummary() + } + } + override fun onDestroy() { super.onDestroy() preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener) } private fun updateSummary() { + preferenceScreen.findPreference("log_folder").summary = + prefManager.getLogsStorageFolder() ?: "No directory has been set yet" preferenceScreen.findPreference("callsign").summary = prefManager.getCallsign() preferenceScreen.findPreference("model").summary = prefManager.getModel() } diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 6ea04e3b..7b394ddf 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -1,39 +1,43 @@ + xmlns:app="http://schemas.android.com/apk/res-auto"> + android:title="Telemetry logging" /> + + + android:title="Plane color" + app:cpv_allowCustom="true" + app:cpv_allowPresets="false" + app:cpv_showAlphaSlider="false" /> + android:key="show_heading_line" + android:summary="Shows heading line on the map" + android:title="Show heading line" /> + android:title="Heading line color" + app:cpv_allowCustom="true" + app:cpv_allowPresets="false" + app:cpv_showAlphaSlider="false" /> @@ -42,67 +46,68 @@ + android:title="Route line color" + app:cpv_allowCustom="true" + app:cpv_allowPresets="false" + app:cpv_showAlphaSlider="false" /> - + android:summary="Changes which data is shown and changes data format" + android:title="Sensor display settings"> + + android:key="battery_units" + android:summary="%s" + android:title="Battery units (CLI smartport_fuel_unit)" /> + android:key="use_pitot_tube" + android:summary="Uses pitot tube sensor as air speed source" + android:title="Use pitot tube" /> + android:key="show_artificial_horizon" + android:summary="Shows attitude. Works only on Inav 2.0.+ You need to set frsky_pitch_roll = ON CLI in order it to work" + android:title="Show artificial horizon view" /> + android:key="send_telemetry_data" + android:summary="Sends telemetry data to uavradar server. It allows other users to see your aircraft at the https://uavradar.org/ Data is sent when acquired valid GPS fix and aircraft is armed" + android:title="Send data to uavradar server" /> + android:key="callsign" + android:title="Callsign" /> + android:key="model" + android:title="Model" /> + android:data="https://uavradar.org" />