Skip to content

Commit

Permalink
Version bump. Allow to change log folder for API >= 30
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyDude1994 committed Jan 25, 2021
1 parent 692926f commit 9b348f9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 45 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 34 additions & 1 deletion app/src/main/java/crazydude/com/telemetry/ui/PrefsFragment.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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?) {
Expand All @@ -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()
}
Expand Down
89 changes: 47 additions & 42 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">

<SwitchPreference
android:title="Telemetry logging"
android:defaultValue="true"
android:key="logging_enabled"
android:summary="Save telemetry data to sdcard. They are saved to TelemetryLog at external storage (sdcard)"
android:text="Logging enabled"
android:defaultValue="true"
android:key="logging_enabled"/>
android:title="Telemetry logging" />

<Preference
android:key="log_folder"
android:title="Logs directory" />

<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="@color/colorPlane"
android:key="plane_color"
app:cpv_showAlphaSlider="false"
app:cpv_allowPresets="false"
app:cpv_allowCustom="true"
android:summary="Color of the plane icon on the map"
android:title="Plane color"/>
android:title="Plane color"
app:cpv_allowCustom="true"
app:cpv_allowPresets="false"
app:cpv_showAlphaSlider="false" />

<PreferenceCategory android:title="Heading line">

<SwitchPreference
android:title="Show heading line"
android:summary="Shows heading line on the map"
android:defaultValue="true"
android:key="show_heading_line"/>
android:key="show_heading_line"
android:summary="Shows heading line on the map"
android:title="Show heading line" />

<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="@color/colorHeadline"
android:key="headline_color"
app:cpv_showAlphaSlider="false"
app:cpv_allowPresets="false"
app:cpv_allowCustom="true"
android:summary="Color of the heading line on the map"
android:title="Heading line color"/>
android:title="Heading line color"
app:cpv_allowCustom="true"
app:cpv_allowPresets="false"
app:cpv_showAlphaSlider="false" />

</PreferenceCategory>

Expand All @@ -42,67 +46,68 @@
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="@color/colorRoute"
android:key="route_color"
app:cpv_showAlphaSlider="false"
app:cpv_allowPresets="false"
app:cpv_allowCustom="true"
android:summary="Color of the route line on the map"
android:title="Route line color"/>
android:title="Route line color"
app:cpv_allowCustom="true"
app:cpv_allowPresets="false"
app:cpv_showAlphaSlider="false" />

</PreferenceCategory>

<PreferenceCategory android:title="Sensors">

<Preference
android:title="Sensor display settings"
android:summary="Changes which data is shown and changes data format">
<intent android:targetClass="crazydude.com.telemetry.ui.SensorsActivity"
android:targetPackage="crazydude.com.telemetry"
android:action="android.intent.action.VIEW"/>
android:summary="Changes which data is shown and changes data format"
android:title="Sensor display settings">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="crazydude.com.telemetry.ui.SensorsActivity"
android:targetPackage="crazydude.com.telemetry" />
</Preference>

<ListPreference
android:title="Battery units (CLI smartport_fuel_unit)"
android:summary="%s"
android:defaultValue="mAh"
android:entries="@array/BatteryUnits"
android:entryValues="@array/BatteryUnits"
android:defaultValue="mAh"
android:key="battery_units"/>
android:key="battery_units"
android:summary="%s"
android:title="Battery units (CLI smartport_fuel_unit)" />

<SwitchPreference
android:title="Use pitot tube"
android:summary="Uses pitot tube sensor as air speed source"
android:defaultValue="false"
android:key="use_pitot_tube"/>
android:key="use_pitot_tube"
android:summary="Uses pitot tube sensor as air speed source"
android:title="Use pitot tube" />

<SwitchPreference
android:title="Show artificial horizon view"
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:defaultValue="true"
android:key="show_artificial_horizon"/>
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" />

</PreferenceCategory>

<PreferenceCategory android:title="UAV Radar">
<SwitchPreference
android:title="Send data to uavradar server"
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:defaultValue="false"
android:key="send_telemetry_data"/>
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" />

<EditTextPreference
android:title="Callsign"
android:dependency="send_telemetry_data"
android:key="callsign"/>
android:key="callsign"
android:title="Callsign" />

<EditTextPreference
android:title="Model"
android:dependency="send_telemetry_data"
android:key="model"/>
android:key="model"
android:title="Model" />

<Preference android:title="Go to UAV radar">
<intent
android:action="android.intent.action.VIEW"
android:data="https://uavradar.org"/>
android:data="https://uavradar.org" />
</Preference>

</PreferenceCategory>
Expand Down

0 comments on commit 9b348f9

Please sign in to comment.