Skip to content

Commit

Permalink
feat: use of OpenCage reverse geocoder shows the privacy policy and u…
Browse files Browse the repository at this point in the history
…ses TLS for connection
  • Loading branch information
growse committed Jun 3, 2024
1 parent 05d78b2 commit dce7d2d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal constructor(private val apiKey: String, private val httpClient: OkHttpC
}
val url =
HttpUrl.Builder()
.scheme("http")
.scheme("https")
.host(OPENCAGE_HOST)
.addPathSegment("geocode")
.addPathSegment("v1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import android.content.Context
import android.os.Build
import android.os.Bundle
import androidx.core.content.PermissionChecker
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.owntracks.android.R
Expand Down Expand Up @@ -58,12 +59,33 @@ class AdvancedFragment @Inject constructor() :
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
PermissionChecker.checkSelfPermission(requireActivity(), ACCESS_BACKGROUND_LOCATION) ==
PermissionChecker.PERMISSION_DENIED

findPreference<ListPreference>(Preferences::reverseGeocodeProvider.name)
?.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { preference, newValue ->
if (newValue == ReverseGeocodeProvider.OPENCAGE.value) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.preferencesAdvancedOpencagePrivacyDialogTitle)
.setMessage(R.string.preferencesAdvancedOpencagePrivacyDialogMessage)
.setPositiveButton(R.string.preferencesAdvancedOpencagePrivacyDialogAccept) { _, _
->
(preference as ListPreference).value = newValue.toString()
}
.setNegativeButton(R.string.preferencesAdvancedOpencagePrivacyDialogCancel, null)
.show()
false
} else {
true
}
}
setOpenCageAPIKeyPreferenceVisibility()
}

private fun setOpenCageAPIKeyPreferenceVisibility() {
findPreference<EditTextPreference>(Preferences::opencageApiKey.name)?.isVisible =
preferences.reverseGeocodeProvider == ReverseGeocodeProvider.OPENCAGE
setOf(Preferences::opencageApiKey.name, "opencagePrivacy").forEach {
findPreference<Preference>(it)?.isVisible =
preferences.reverseGeocodeProvider == ReverseGeocodeProvider.OPENCAGE
}
}

override fun onPreferenceChanged(properties: Set<String>) {
Expand Down
5 changes: 5 additions & 0 deletions project/app/src/main/res/drawable/baseline_privacy_tip_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12c5.16,-1.26 9,-6.45 9,-12V5L12,1L12,1zM11,7h2v2h-2V7zM11,11h2v6h-2V11z"/>

</vector>
5 changes: 5 additions & 0 deletions project/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ To allow this, please enable Location in the device settings."</string>
<string name="play_services_update_required">"Google Play Services update is required"</string>
<string name="preferencesAdvanced">"Advanced"</string>
<string name="preferencesAdvancedAutostartWarning">"This version of Android restricts OwnTracks from receiving locations when automatically started on device boot until the app is opened."</string>
<string name="preferencesAdvancedOpencagePrivacy"><a href="https://opencagedata.com/api#privacy">OpenCage Privacy Policy</a></string>
<string name="preferencesAdvancedOpencagePrivacyDialogMessage">To use the OpenCage geocoder, OwnTracks will send every location it processes to OpenCage over a TLS-encrypted connection.\n\nThe OpenCage privacy policy can be found <a href="https://opencagedata.com/api#privacy">on their website</a>.</string>
<string name="preferencesAdvancedOpencagePrivacyDialogTitle">OpenCage Privacy Policy</string>
<string name="preferencesAdvancedOpencagePrivacyDialogAccept">Accept</string>
<string name="preferencesAdvancedOpencagePrivacyDialogCancel">Cancel</string>
<string name="preferencesAutostart">"Autostart"</string>
<string name="preferencesAutostartSummary">"Automatically start on device boot"</string>
<string name="preferencesBrokerPassword">"Password"</string>
Expand Down
5 changes: 5 additions & 0 deletions project/app/src/main/res/xml/preferences_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
app:key="reverseGeocodeProvider"
app:title="@string/preferencesReverseGeocodeProvider"
app:useSimpleSummaryProvider="true" />
<Preference
android:icon="@drawable/baseline_privacy_tip_24"
app:iconSpaceReserved="true"
app:key="opencagePrivacy"
app:summary="@string/preferencesAdvancedOpencagePrivacy" />
<androidx.preference.EditTextPreference
app:dialogMessage="@string/preferencesOpencageGeocoderApiKeyDialog"
app:iconSpaceReserved="false"
Expand Down
6 changes: 6 additions & 0 deletions project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ plugins {
alias(libs.plugins.triplet).apply(false)
alias(libs.plugins.ktfmt).apply(false)
alias(libs.plugins.ksp).apply(false)
id( "com.xcporter.metaview").version( "0.0.5")
}
generateUml {
classTree {
target = file("app/src/main")
}
}

extensions.findByName("buildScan")
Expand Down

0 comments on commit dce7d2d

Please sign in to comment.