Skip to content

Commit

Permalink
Merge pull request #142 from arcao/dev
Browse files Browse the repository at this point in the history
Release app version 3.0.11
  • Loading branch information
arcao authored Apr 9, 2024
2 parents 9dc81c1 + 72f9513 commit bca5d36
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 19 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<!-- Remove AD_ID permission, we don't use ads in app -->
<uses-permission
Expand Down Expand Up @@ -68,7 +69,9 @@
android:resource="@xml/provider_paths" />
</provider>

<service android:name=".live_map.LiveMapService" />
<service
android:name=".live_map.LiveMapService"
android:foregroundServiceType="dataSync" />

<receiver
android:name=".live_map.receiver.LiveMapBroadcastReceiver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.arcao.geocaching4locus.base.util
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.ContextCompat

object PermissionUtil {
Expand Down Expand Up @@ -30,3 +31,10 @@ val Context.hasGpsLocationPermission

val Context.hasWifiLocationPermission
get() = PermissionUtil.hasPermission(this, *PermissionUtil.PERMISSION_LOCATION_WIFI)

val Context.hasPostNotificationPermission
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
PermissionUtil.hasPermission(this, Manifest.permission.POST_NOTIFICATIONS)
} else {
true
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.arcao.geocaching4locus.dashboard

sealed class DashboardAction {
object SearchNearest : DashboardAction()
object ImportGcCode : DashboardAction()
object ImportBookmarks : DashboardAction()
object DownloadLiveMapGeocaches : DashboardAction()
object UsersGuide : DashboardAction()
object Preferences : DashboardAction()
object NavigationBack : DashboardAction()
object LocusMapNotInstalled : DashboardAction()
object SignIn : DashboardAction()
object WarnPowerSaveActive : DashboardAction()
sealed interface DashboardAction {
object SearchNearest : DashboardAction
object ImportGcCode : DashboardAction
object ImportBookmarks : DashboardAction
object DownloadLiveMapGeocaches : DashboardAction
object UsersGuide : DashboardAction
object Preferences : DashboardAction
object NavigationBack : DashboardAction
object LocusMapNotInstalled : DashboardAction
object SignIn : DashboardAction
object WarnPowerSaveActive : DashboardAction
object RequestPostNotificationPermission : DashboardAction
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.arcao.geocaching4locus.dashboard

import android.Manifest
import android.os.Build
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.Toolbar
import androidx.databinding.DataBindingUtil
import com.arcao.geocaching4locus.R
Expand All @@ -14,6 +17,7 @@ import com.arcao.geocaching4locus.base.util.isCalledFromLocusMap
import com.arcao.geocaching4locus.base.util.showLocusMissingError
import com.arcao.geocaching4locus.base.util.showWebPage
import com.arcao.geocaching4locus.base.util.withObserve
import com.arcao.geocaching4locus.dashboard.fragment.NoPostNotificationPermissionErrorDialogFragment
import com.arcao.geocaching4locus.databinding.ActivityDashboardBinding
import com.arcao.geocaching4locus.download_rectangle.DownloadRectangleActivity
import com.arcao.geocaching4locus.import_bookmarks.ImportBookmarkActivity
Expand Down Expand Up @@ -49,6 +53,17 @@ class DashboardActivity : AbstractActionBarActivity(),
if (success) viewModel.onClickLiveMap()
}

private val requestPostNotificationPermission = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { result ->
if (result) {
viewModel.onClickLiveMap()
} else {
NoPostNotificationPermissionErrorDialogFragment.newInstance()
.show(supportFragmentManager)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -68,6 +83,7 @@ class DashboardActivity : AbstractActionBarActivity(),
is DashboardAction.SearchNearest -> searchNearestActivity.launch(
if (isCalledFromLocusMap()) intent else null
)

is DashboardAction.ImportGcCode -> importGeocacheCodeActivity.launch(null)
is DashboardAction.DownloadLiveMapGeocaches -> downloadRectangleActivity.launch(null)
is DashboardAction.ImportBookmarks -> importBookmarkActivity.launch(null)
Expand All @@ -77,7 +93,13 @@ class DashboardActivity : AbstractActionBarActivity(),
is DashboardAction.SignIn -> loginActivity.launch(null)
is DashboardAction.WarnPowerSaveActive -> PowerSaveWarningDialogFragment.newInstance()
.show(supportFragmentManager)

is DashboardAction.NavigationBack -> finish()
DashboardAction.RequestPostNotificationPermission -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestPostNotificationPermission.launch(
Manifest.permission.POST_NOTIFICATIONS
)
}
}
}

Expand All @@ -92,10 +114,12 @@ class DashboardActivity : AbstractActionBarActivity(),
viewModel.onClickPreferences()
true
}

android.R.id.home -> {
viewModel.onClickNavigationBack()
true
}

else -> super.onOptionsItemSelected(item)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.arcao.geocaching4locus.base.BaseViewModel
import com.arcao.geocaching4locus.base.coroutine.CoroutinesDispatcherProvider
import com.arcao.geocaching4locus.base.util.AnalyticsManager
import com.arcao.geocaching4locus.base.util.Command
import com.arcao.geocaching4locus.base.util.hasPostNotificationPermission
import com.arcao.geocaching4locus.base.util.hidePowerManagementWarning
import com.arcao.geocaching4locus.base.util.invoke
import com.arcao.geocaching4locus.data.account.AccountManager
Expand Down Expand Up @@ -60,6 +61,11 @@ class DashboardViewModel(
return@mainLaunch
}

if (!context.hasPostNotificationPermission) {
action(DashboardAction.RequestPostNotificationPermission)
return@mainLaunch
}

if (!context.hidePowerManagementWarning) {
action(DashboardAction.WarnPowerSaveActive)
return@mainLaunch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.arcao.geocaching4locus.dashboard.fragment

import com.arcao.geocaching4locus.R
import com.arcao.geocaching4locus.base.fragment.AbstractErrorDialogFragment

class NoPostNotificationPermissionErrorDialogFragment : AbstractErrorDialogFragment() {
companion object {
fun newInstance() = NoPostNotificationPermissionErrorDialogFragment().apply {
prepareDialog(
message = R.string.error_no_post_notification_permission
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.arcao.geocaching4locus.live_map
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.lifecycle.LifecycleService
import com.arcao.geocaching4locus.base.ProgressState
import com.arcao.geocaching4locus.base.constants.AppConstants
Expand All @@ -11,6 +13,7 @@ import com.arcao.geocaching4locus.base.util.exhaustive
import com.arcao.geocaching4locus.base.util.withObserve
import com.arcao.geocaching4locus.live_map.util.LiveMapNotificationManager
import org.koin.android.ext.android.inject
import timber.log.Timber

class LiveMapService : LifecycleService() {
private val notificationManager by inject<LiveMapNotificationManager>()
Expand All @@ -27,10 +30,23 @@ class LiveMapService : LifecycleService() {

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// in case the service is already running, this must be called after each startForegroundService
startForeground(
AppConstants.NOTIFICATION_ID_LIVEMAP,
notificationManager.createNotification().build()
)
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
AppConstants.NOTIFICATION_ID_LIVEMAP,
notificationManager.createNotification().build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
} else {
startForeground(
AppConstants.NOTIFICATION_ID_LIVEMAP,
notificationManager.createNotification().build()
)
}
} catch (e: Exception) {
// if service is restarted after app kill, startForeground may crash on Android 14
Timber.e(e)
}

if (intent != null) {
if (ACTION_START == intent.action) {
Expand Down Expand Up @@ -60,6 +76,7 @@ class LiveMapService : LifecycleService() {
is ProgressState.ShowProgress -> {
notificationManager.setDownloadingProgress(state.progress, state.maxProgress)
}

is ProgressState.HideProgress -> {
notificationManager.setDownloadingProgress(Int.MAX_VALUE, Int.MAX_VALUE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.arcao.geocaching4locus.base.constants.PrefConstants
import com.arcao.geocaching4locus.base.coroutine.CoroutinesDispatcherProvider
import com.arcao.geocaching4locus.base.usecase.RemoveLocusMapPointsUseCase
import com.arcao.geocaching4locus.base.util.getText
import com.arcao.geocaching4locus.base.util.hasPostNotificationPermission
import com.arcao.geocaching4locus.error.ErrorActivity
import com.arcao.geocaching4locus.live_map.LiveMapService
import com.arcao.geocaching4locus.live_map.model.LastLiveMapCoordinates
Expand Down Expand Up @@ -71,6 +72,11 @@ class LiveMapNotificationManager(
showError(R.string.error_live_map_periodic_updates)
}

willBeEnabled && !context.hasPostNotificationPermission -> {
willBeEnabled = false
showError(R.string.error_no_post_notification_permission)
}

willBeEnabled -> showLiveMapToast(R.string.toast_live_map_enabled)

else -> {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-ach-rUG/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<string name="notify_live_map" comment="Live map notification title. This title is used only for Android 6 and lower.">crwdns492:0crwdne492:0</string>
<string name="notify_live_map_message_enabled" comment="Live map notification message when Live map is enabled.">crwdns494:0crwdne494:0</string>
<string name="notify_live_map_message_disabled" comment="Live map notification message when Live map is disabled.">crwdns496:0crwdne496:0</string>
<string name="notify_live_map_message_downloading" comment="Live map notification message when geocaches are being downloaded. The '%1$d' is replaced with current downloaded geocaches, '%2$d' with expected count of geocaches to download and '%3$d' with percent state. Note: The '%%' is escape sequence for percent char.">crwdns498:0%1$dcrwdnd498:0%2$dcrwdnd498:0%3$dcrwdnd498:0%%crwdne498:0</string>
<string name="notify_live_map_message_downloading" comment="Live map notification message when geocaches are being downloaded. The '%1$d' is replaced with current downloaded geocaches, '%2$d' with expected count of geocaches to download and '%3$d' with percent state. Note: The '%%' is escape sequence for percent char.">crwdns498:0%1$dcrwdnd498:0%2$dcrwdnd498:0%3$dcrwdne498:0</string>
<string name="notify_live_map_action_enable" comment="Enable action in Live map notification. This enable Live map.">crwdns500:0crwdne500:0</string>
<string name="notify_live_map_action_disable" comment="Disable action in Live map notification. This disable Live map.">crwdns502:0crwdne502:0</string>
<string name="notify_live_map_action_settings" comment="Settings action in Live map notification. This open the Live map section in add-on settings.">crwdns504:0crwdne504:0</string>
Expand Down Expand Up @@ -171,4 +171,5 @@
<string name="pref_account_powered_by" comment="Title of preference in Account section.">crwdns626:0crwdne626:0</string>
<string name="pref_account_powered_by_summary" comment="Sumarry of preference in Account section. The text is from API Agreement, Exhibit C: https://apidevelopers.geocaching.com/apiagreement">crwdns628:0crwdne628:0</string>
<string name="button_continue" comment="Dialog button for Continue action.">crwdns634:0crwdne634:0</string>
<string name="error_no_post_notification_permission" comment="Error dialog message when app doesn't have permission to create notifications.">crwdns636:0crwdne636:0</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@
<string name="pref_account_powered_by" comment="Title of preference in Account section.">Běží na Geocaching API</string>
<string name="pref_account_powered_by_summary" comment="Sumarry of preference in Account section. The text is from API Agreement, Exhibit C: https://apidevelopers.geocaching.com/apiagreement">API program, který je umožněn díky podpoře prémiového členství Geocaching, dává vývojářům třetích stran příležitost spolupracovat s Geocaching HQ na celé řadě sjednocených produktů a služeb pro komunitu. Aplikace vývojářů používající API jsou navrženy tak, aby pracovali se základními službami geocaching.com a poskytovali další funkce geocaching komunitě.</string>
<string name="button_continue" comment="Dialog button for Continue action.">Pokračovat</string>
<string name="error_no_post_notification_permission" comment="Error dialog message when app doesn't have permission to create notifications.">Aplikace nemá oprávnění vytvářet oznámení.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@
<string name="pref_account_powered_by" comment="Title of preference in Account section.">Drevet af Geocaching API</string>
<string name="pref_account_powered_by_summary" comment="Sumarry of preference in Account section. The text is from API Agreement, Exhibit C: https://apidevelopers.geocaching.com/apiagreement">API-programmet, der er gjort muligt med støtte fra Geocaching Premium-medlemskaber, giver tredjepartsudviklere mulighed for at arbejde med Geocaching HQ på en komplet pakke af integrerede produkter og tjenester til samfundet. API-udviklerapplikationer er designet til at arbejde med kernetjenesterne i geocaching.com og giver yderligere funktioner til geocaching-samfundet.</string>
<string name="button_continue" comment="Dialog button for Continue action.">Forsæt</string>
<string name="error_no_post_notification_permission" comment="Error dialog message when app doesn't have permission to create notifications.">Programmet har ikke tilladelse til at oprette notifikationer.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@
<string name="pref_account_powered_by" comment="Title of preference in Account section.">Bereitgestellt vom Geocaching API</string>
<string name="pref_account_powered_by_summary" comment="Sumarry of preference in Account section. The text is from API Agreement, Exhibit C: https://apidevelopers.geocaching.com/apiagreement">Das API-Programm wurde durch die Unterstützung von Geocaching Premium-Mitgliedschaften ermöglicht und bietet Drittentwicklern die Möglichkeit, mit Geocaching HQ an einer vollständigen Suite integrierter Produkte und Dienstleistungen für die Community zu arbeiten. API-Entwickleranwendungen arbeiten mit den Kerndiensten von geocaching.com zusammen und bieten der Geocaching-Community zusätzliche Funktionen.</string>
<string name="button_continue" comment="Dialog button for Continue action.">Weiter</string>
<string name="error_no_post_notification_permission" comment="Error dialog message when app doesn't have permission to create notifications.">Die App hat keine Berechtigung um Benachrichtigungen zu erstellen.</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
<string name="pref_disable_dnf_nm_na_geocaches_logs_count" comment="Title of slider preference in Downloading settings. There can be selected how many Did Not Fond, Needs Maintenance or Need Archived logs (1 to 5) cause to mark geocache as not available.">Cuántos últimos logs comprobar</string>
<string name="launcher_watch_geocache" comment="Share button item title in geocache detail in Locus Map, which add geocache to watch list.">Ver geocaché</string>
<string name="launcher_bookmark_geocache" comment="Share button item title in geocache detail in Locus Map, which add geocache to bookmark list.">Geocaché de favoritos</string>
<string name="launcher_download_rectangle" comment="Locus map function button title to import visible Live map geocaches to Locus map.">Importar cachés de mapa en vivo</string>
<string name="error_live_map_geocaches_not_visible" comment="Error message when user wants to import Live map geocaches, but Live map is disabled or Live map geocaches are not visible in Locus map.">Por favor, asegúrese de que el mapa en vivo está habilitado y Locus Map muestra los cachés de mapas en vivo.</string>
<string name="checkbox_do_not_show_again" comment="Checkbox message in dialog which prevent to show dialog again when checkbox is checked">No mostrar este mensaje de nuevo</string>
<string name="title_warning" comment="Warning dialog title">Atención</string>
<string name="warning_power_management" comment="Warning dialog message which is shown, when user wants to turn on the Live Map and app detects that the Live Map feature can be affected by a manufacturer battery saver functionality.">Su dispositivo Android contiene una aplicación personalizada de ahorro de batería del fabricante del dispositivo que impide que Live Map funcione correctamente. Agregue una excepción a la aplicación de ahorro de batería para Geocaching4Locus.</string>
Expand All @@ -170,4 +172,5 @@
<string name="pref_account_powered_by" comment="Title of preference in Account section.">Desarrollado por Geocaching API</string>
<string name="pref_account_powered_by_summary" comment="Sumarry of preference in Account section. The text is from API Agreement, Exhibit C: https://apidevelopers.geocaching.com/apiagreement">Hecho posible a través del soporte de las Membresías Premium de Geocaching, el programa API brinda a los desarrolladores externos la oportunidad de trabajar con Geocaching HQ en un conjunto completo de productos y servicios integrados para la comunidad. Las aplicaciones de desarrollador de API están diseñadas para trabajar con los servicios principales de geocaching.com y proporcionar funciones adicionales a la comunidad de geocaching.</string>
<string name="button_continue" comment="Dialog button for Continue action.">Continuar</string>
<string name="error_no_post_notification_permission" comment="Error dialog message when app doesn't have permission to create notifications.">La aplicación no tiene permiso para crear notificaciones.</string>
</resources>
Loading

0 comments on commit bca5d36

Please sign in to comment.