checkpoint
This commit is contained in:
parent
8f5852d157
commit
62189f9e61
11 changed files with 52 additions and 198 deletions
|
@ -61,9 +61,6 @@ import org.y20k.trackbook.helpers.*
|
||||||
*/
|
*/
|
||||||
class MapFragment : Fragment()
|
class MapFragment : Fragment()
|
||||||
{
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(MapFragment::class.java)
|
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
private var bound: Boolean = false
|
private var bound: Boolean = false
|
||||||
private val handler: Handler = Handler(Looper.getMainLooper())
|
private val handler: Handler = Handler(Looper.getMainLooper())
|
||||||
|
@ -314,7 +311,7 @@ class MapFragment : Fragment()
|
||||||
// permission was granted - re-bind service
|
// permission was granted - re-bind service
|
||||||
activity?.unbindService(connection)
|
activity?.unbindService(connection)
|
||||||
activity?.bindService(Intent(activity, TrackerService::class.java), connection, Context.BIND_AUTO_CREATE)
|
activity?.bindService(Intent(activity, TrackerService::class.java), connection, Context.BIND_AUTO_CREATE)
|
||||||
LogHelper.i(TAG, "Request result: Location permission has been granted.")
|
Log.i("VOUSSOIR", "Request result: Location permission has been granted.")
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,20 +43,11 @@ import androidx.preference.contains
|
||||||
import get_path_from_uri
|
import get_path_from_uri
|
||||||
import org.y20k.trackbook.helpers.AppThemeHelper
|
import org.y20k.trackbook.helpers.AppThemeHelper
|
||||||
import org.y20k.trackbook.helpers.LengthUnitHelper
|
import org.y20k.trackbook.helpers.LengthUnitHelper
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
|
||||||
import org.y20k.trackbook.helpers.PreferencesHelper
|
import org.y20k.trackbook.helpers.PreferencesHelper
|
||||||
import org.y20k.trackbook.helpers.random_device_id
|
import org.y20k.trackbook.helpers.random_device_id
|
||||||
|
|
||||||
const val INTENT_DATABASE_DIRECTORY_PICKER = 12121
|
class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogListener
|
||||||
|
{
|
||||||
/*
|
|
||||||
* SettingsFragment class
|
|
||||||
*/
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogListener {
|
|
||||||
|
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(SettingsFragment::class.java)
|
|
||||||
|
|
||||||
/* Overrides onViewCreated from PreferenceFragmentCompat */
|
/* Overrides onViewCreated from PreferenceFragmentCompat */
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -29,7 +30,6 @@ import android.widget.Toast
|
||||||
import androidx.activity.result.ActivityResult
|
import androidx.activity.result.ActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
|
||||||
import org.y20k.trackbook.helpers.iso8601_format
|
import org.y20k.trackbook.helpers.iso8601_format
|
||||||
import org.y20k.trackbook.ui.TrackFragmentLayoutHolder
|
import org.y20k.trackbook.ui.TrackFragmentLayoutHolder
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
@ -37,9 +37,6 @@ import java.util.*
|
||||||
|
|
||||||
class TrackFragment : Fragment(), YesNoDialog.YesNoDialogListener
|
class TrackFragment : Fragment(), YesNoDialog.YesNoDialogListener
|
||||||
{
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(TrackFragment::class.java)
|
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
private lateinit var layout: TrackFragmentLayoutHolder
|
private lateinit var layout: TrackFragmentLayoutHolder
|
||||||
|
|
||||||
|
@ -143,7 +140,7 @@ class TrackFragment : Fragment(), YesNoDialog.YesNoDialogListener
|
||||||
}
|
}
|
||||||
catch (e: Exception)
|
catch (e: Exception)
|
||||||
{
|
{
|
||||||
LogHelper.e(TAG, "Unable to save GPX.")
|
Log.e("VOUSSOIR", "Unable to save GPX.")
|
||||||
Toast.makeText(activity as Context, R.string.toast_message_install_file_helper, Toast.LENGTH_LONG).show()
|
Toast.makeText(activity as Context, R.string.toast_message_install_file_helper, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,12 @@
|
||||||
package org.y20k.trackbook
|
package org.y20k.trackbook
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.app.ActivityCompat
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
import org.y20k.trackbook.helpers.AppThemeHelper
|
import org.y20k.trackbook.helpers.AppThemeHelper
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
|
||||||
import org.y20k.trackbook.helpers.PreferencesHelper
|
import org.y20k.trackbook.helpers.PreferencesHelper
|
||||||
import org.y20k.trackbook.helpers.PreferencesHelper.initPreferences
|
import org.y20k.trackbook.helpers.PreferencesHelper.initPreferences
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -37,7 +33,8 @@ interface DatabaseChangedListener
|
||||||
fun database_changed()
|
fun database_changed()
|
||||||
}
|
}
|
||||||
|
|
||||||
class Trackbook : Application() {
|
class Trackbook : Application()
|
||||||
|
{
|
||||||
val database: Database = Database(this)
|
val database: Database = Database(this)
|
||||||
val homepoints: ArrayList<Homepoint> = ArrayList()
|
val homepoints: ArrayList<Homepoint> = ArrayList()
|
||||||
val database_changed_listeners = ArrayList<DatabaseChangedListener>()
|
val database_changed_listeners = ArrayList<DatabaseChangedListener>()
|
||||||
|
@ -53,7 +50,7 @@ class Trackbook : Application() {
|
||||||
override fun onCreate()
|
override fun onCreate()
|
||||||
{
|
{
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
LogHelper.v("VOUSSOIR", "Trackbook application started.")
|
Log.i("VOUSSOIR", "Trackbook.onCreate")
|
||||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||||
// initialize single sharedPreferences object when app is launched
|
// initialize single sharedPreferences object when app is launched
|
||||||
initPreferences()
|
initPreferences()
|
||||||
|
@ -136,7 +133,7 @@ class Trackbook : Application() {
|
||||||
override fun onTerminate()
|
override fun onTerminate()
|
||||||
{
|
{
|
||||||
super.onTerminate()
|
super.onTerminate()
|
||||||
LogHelper.v("VOUSSOIR", "Trackbook application terminated.")
|
Log.i("VOUSSOIR", "Trackbook.onTerminate")
|
||||||
database.close()
|
database.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,9 +38,6 @@ import org.y20k.trackbook.helpers.*
|
||||||
*/
|
*/
|
||||||
class TrackerService: Service()
|
class TrackerService: Service()
|
||||||
{
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(TrackerService::class.java)
|
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
var trackingState: Int = Keys.STATE_TRACKING_STOPPED
|
var trackingState: Int = Keys.STATE_TRACKING_STOPPED
|
||||||
var gpsProviderActive: Boolean = false
|
var gpsProviderActive: Boolean = false
|
||||||
|
@ -71,27 +68,27 @@ class TrackerService: Service()
|
||||||
{
|
{
|
||||||
if (! use_gps_location)
|
if (! use_gps_location)
|
||||||
{
|
{
|
||||||
LogHelper.v(TAG, "Skipping GPS listener.")
|
Log.v("VOUSSOIR", "Skipping GPS listener.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpsLocationListenerRegistered)
|
if (gpsLocationListenerRegistered)
|
||||||
{
|
{
|
||||||
LogHelper.v(TAG, "GPS location listener has already been added.")
|
Log.v("VOUSSOIR", "GPS location listener has already been added.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gpsProviderActive = isGpsEnabled(locationManager)
|
gpsProviderActive = isGpsEnabled(locationManager)
|
||||||
if (! gpsProviderActive)
|
if (! gpsProviderActive)
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Device GPS is not enabled.")
|
Log.w("VOUSSOIR", "Device GPS is not enabled.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val has_permission: Boolean = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
val has_permission: Boolean = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
if (! has_permission)
|
if (! has_permission)
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Location permission is not granted.")
|
Log.w("VOUSSOIR", "Location permission is not granted.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,34 +99,34 @@ class TrackerService: Service()
|
||||||
gpsLocationListener,
|
gpsLocationListener,
|
||||||
)
|
)
|
||||||
gpsLocationListenerRegistered = true
|
gpsLocationListenerRegistered = true
|
||||||
LogHelper.v(TAG, "Added GPS location listener.")
|
Log.v("VOUSSOIR", "Added GPS location listener.")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNetworkLocationListener()
|
private fun addNetworkLocationListener()
|
||||||
{
|
{
|
||||||
if (! use_network_location)
|
if (! use_network_location)
|
||||||
{
|
{
|
||||||
LogHelper.v(TAG, "Skipping Network listener.")
|
Log.v("VOUSSOIR", "Skipping Network listener.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (networkLocationListenerRegistered)
|
if (networkLocationListenerRegistered)
|
||||||
{
|
{
|
||||||
LogHelper.v(TAG, "Network location listener has already been added.")
|
Log.v("VOUSSOIR", "Network location listener has already been added.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
networkProviderActive = isNetworkEnabled(locationManager)
|
networkProviderActive = isNetworkEnabled(locationManager)
|
||||||
if (!networkProviderActive)
|
if (!networkProviderActive)
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Unable to add Network location listener.")
|
Log.w("VOUSSOIR", "Unable to add Network location listener.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val has_permission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
val has_permission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
if (! has_permission)
|
if (! has_permission)
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Unable to add Network location listener. Location permission is not granted.")
|
Log.w("VOUSSOIR", "Unable to add Network location listener. Location permission is not granted.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +137,7 @@ class TrackerService: Service()
|
||||||
networkLocationListener,
|
networkLocationListener,
|
||||||
)
|
)
|
||||||
networkLocationListenerRegistered = true
|
networkLocationListenerRegistered = true
|
||||||
LogHelper.v(TAG, "Added Network location listener.")
|
Log.v("VOUSSOIR", "Added Network location listener.")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createLocationListener(): LocationListener
|
private fun createLocationListener(): LocationListener
|
||||||
|
@ -186,7 +183,7 @@ class TrackerService: Service()
|
||||||
}
|
}
|
||||||
override fun onProviderEnabled(provider: String)
|
override fun onProviderEnabled(provider: String)
|
||||||
{
|
{
|
||||||
LogHelper.v(TAG, "onProviderEnabled $provider")
|
Log.v("VOUSSOIR", "onProviderEnabled $provider")
|
||||||
when (provider) {
|
when (provider) {
|
||||||
LocationManager.GPS_PROVIDER -> gpsProviderActive = isGpsEnabled(locationManager)
|
LocationManager.GPS_PROVIDER -> gpsProviderActive = isGpsEnabled(locationManager)
|
||||||
LocationManager.NETWORK_PROVIDER -> networkProviderActive = isNetworkEnabled(locationManager)
|
LocationManager.NETWORK_PROVIDER -> networkProviderActive = isNetworkEnabled(locationManager)
|
||||||
|
@ -194,7 +191,7 @@ class TrackerService: Service()
|
||||||
}
|
}
|
||||||
override fun onProviderDisabled(provider: String)
|
override fun onProviderDisabled(provider: String)
|
||||||
{
|
{
|
||||||
LogHelper.v(TAG, "onProviderDisabled $provider")
|
Log.v("VOUSSOIR", "onProviderDisabled $provider")
|
||||||
when (provider) {
|
when (provider) {
|
||||||
LocationManager.GPS_PROVIDER -> gpsProviderActive = isGpsEnabled(locationManager)
|
LocationManager.GPS_PROVIDER -> gpsProviderActive = isGpsEnabled(locationManager)
|
||||||
LocationManager.NETWORK_PROVIDER -> networkProviderActive = isNetworkEnabled(locationManager)
|
LocationManager.NETWORK_PROVIDER -> networkProviderActive = isNetworkEnabled(locationManager)
|
||||||
|
@ -253,7 +250,7 @@ class TrackerService: Service()
|
||||||
/* Overrides onDestroy from Service */
|
/* Overrides onDestroy from Service */
|
||||||
override fun onDestroy()
|
override fun onDestroy()
|
||||||
{
|
{
|
||||||
LogHelper.i("VOUSSOIR", "TrackerService.onDestroy.")
|
Log.i("VOUSSOIR", "TrackerService.onDestroy.")
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
if (trackingState == Keys.STATE_TRACKING_ACTIVE)
|
if (trackingState == Keys.STATE_TRACKING_ACTIVE)
|
||||||
{
|
{
|
||||||
|
@ -282,7 +279,7 @@ class TrackerService: Service()
|
||||||
{
|
{
|
||||||
if (trackingState == Keys.STATE_TRACKING_ACTIVE)
|
if (trackingState == Keys.STATE_TRACKING_ACTIVE)
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Trackbook has been killed by the operating system. Trying to resume recording.")
|
Log.w("VOUSSOIR", "Trackbook has been killed by the operating system. Trying to resume recording.")
|
||||||
startTracking()
|
startTracking()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,11 +317,11 @@ class TrackerService: Service()
|
||||||
{
|
{
|
||||||
locationManager.removeUpdates(gpsLocationListener)
|
locationManager.removeUpdates(gpsLocationListener)
|
||||||
gpsLocationListenerRegistered = false
|
gpsLocationListenerRegistered = false
|
||||||
LogHelper.v(TAG, "Removed GPS location listener.")
|
Log.v("VOUSSOIR", "Removed GPS location listener.")
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Unable to remove GPS location listener. Location permission is needed.")
|
Log.w("VOUSSOIR", "Unable to remove GPS location listener. Location permission is needed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,11 +331,11 @@ class TrackerService: Service()
|
||||||
{
|
{
|
||||||
locationManager.removeUpdates(networkLocationListener)
|
locationManager.removeUpdates(networkLocationListener)
|
||||||
networkLocationListenerRegistered = false
|
networkLocationListenerRegistered = false
|
||||||
LogHelper.v(TAG, "Removed Network location listener.")
|
Log.v("VOUSSOIR", "Removed Network location listener.")
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogHelper.w(TAG, "Unable to remove Network location listener. Location permission is needed.")
|
Log.w("VOUSSOIR", "Unable to remove Network location listener. Location permission is needed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
|
||||||
import org.y20k.trackbook.helpers.UiHelper
|
import org.y20k.trackbook.helpers.UiHelper
|
||||||
import org.y20k.trackbook.helpers.iso8601_format
|
import org.y20k.trackbook.helpers.iso8601_format
|
||||||
import org.y20k.trackbook.tracklist.TracklistAdapter
|
import org.y20k.trackbook.tracklist.TracklistAdapter
|
||||||
|
@ -40,25 +39,24 @@ import org.y20k.trackbook.tracklist.TracklistAdapter
|
||||||
/*
|
/*
|
||||||
* TracklistFragment class
|
* TracklistFragment class
|
||||||
*/
|
*/
|
||||||
class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener, YesNoDialog.YesNoDialogListener {
|
class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener, YesNoDialog.YesNoDialogListener
|
||||||
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(TracklistFragment::class.java)
|
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
private lateinit var tracklistAdapter: TracklistAdapter
|
private lateinit var tracklistAdapter: TracklistAdapter
|
||||||
private lateinit var trackElementList: RecyclerView
|
private lateinit var trackElementList: RecyclerView
|
||||||
private lateinit var tracklistOnboarding: ConstraintLayout
|
private lateinit var tracklistOnboarding: ConstraintLayout
|
||||||
|
|
||||||
/* Overrides onCreateView from Fragment */
|
/* Overrides onCreateView from Fragment */
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?)
|
||||||
|
{
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
// create tracklist adapter
|
// create tracklist adapter
|
||||||
tracklistAdapter = TracklistAdapter(this, (requireActivity().applicationContext as Trackbook).database)
|
tracklistAdapter = TracklistAdapter(this, (requireActivity().applicationContext as Trackbook).database)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Overrides onCreateView from Fragment */
|
/* Overrides onCreateView from Fragment */
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
|
||||||
|
{
|
||||||
// find views
|
// find views
|
||||||
val rootView = inflater.inflate(R.layout.fragment_tracklist, container, false)
|
val rootView = inflater.inflate(R.layout.fragment_tracklist, container, false)
|
||||||
trackElementList = rootView.findViewById(R.id.track_element_list)
|
trackElementList = rootView.findViewById(R.id.track_element_list)
|
||||||
|
|
|
@ -26,16 +26,12 @@ import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.y20k.trackbook.R
|
import org.y20k.trackbook.R
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ErrorDialog object
|
* ErrorDialog object
|
||||||
*/
|
*/
|
||||||
object ErrorDialog {
|
object ErrorDialog
|
||||||
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(ErrorDialog::class.java)
|
|
||||||
|
|
||||||
/* Construct and show dialog */
|
/* Construct and show dialog */
|
||||||
fun show(context: Context, errorTitle: Int, errorMessage: Int, errorDetails: String = String()) {
|
fun show(context: Context, errorTitle: Int, errorMessage: Int, errorDetails: String = String()) {
|
||||||
// prepare dialog builder
|
// prepare dialog builder
|
||||||
|
|
|
@ -18,22 +18,19 @@ import android.content.Context
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import org.y20k.trackbook.Keys
|
import org.y20k.trackbook.Keys
|
||||||
import org.y20k.trackbook.R
|
import org.y20k.trackbook.R
|
||||||
import org.y20k.trackbook.helpers.LogHelper
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* YesNoDialog class
|
* YesNoDialog class
|
||||||
*/
|
*/
|
||||||
class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener) {
|
class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener)
|
||||||
|
{
|
||||||
/* Interface used to communicate back to activity */
|
/* Interface used to communicate back to activity */
|
||||||
interface YesNoDialogListener {
|
interface YesNoDialogListener
|
||||||
|
{
|
||||||
fun onYesNoDialog(type: Int, dialogResult: Boolean, payload: Int, payloadString: String) {
|
fun onYesNoDialog(type: Int, dialogResult: Boolean, payload: Int, payloadString: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Define log tag */
|
|
||||||
private val TAG = LogHelper.makeLogTag(YesNoDialog::class.java.simpleName)
|
|
||||||
|
|
||||||
/* Construct and show dialog - variant: message from string */
|
/* Construct and show dialog - variant: message from string */
|
||||||
fun show(context: Context,
|
fun show(context: Context,
|
||||||
type: Int,
|
type: Int,
|
||||||
|
@ -42,7 +39,8 @@ class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener) {
|
||||||
yesButton: Int = R.string.dialog_yes_no_positive_button_default,
|
yesButton: Int = R.string.dialog_yes_no_positive_button_default,
|
||||||
noButton: Int = R.string.dialog_generic_button_cancel,
|
noButton: Int = R.string.dialog_generic_button_cancel,
|
||||||
payload: Int = Keys.DIALOG_EMPTY_PAYLOAD_INT,
|
payload: Int = Keys.DIALOG_EMPTY_PAYLOAD_INT,
|
||||||
payloadString: String = Keys.DIALOG_EMPTY_PAYLOAD_STRING) {
|
payloadString: String = Keys.DIALOG_EMPTY_PAYLOAD_STRING)
|
||||||
|
{
|
||||||
// extract string from message resource and feed into main show method
|
// extract string from message resource and feed into main show method
|
||||||
show(context, type, title, context.getString(message), yesButton, noButton, payload, payloadString)
|
show(context, type, title, context.getString(message), yesButton, noButton, payload, payloadString)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.y20k.trackbook.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import org.y20k.trackbook.Keys
|
import org.y20k.trackbook.Keys
|
||||||
import org.y20k.trackbook.R
|
import org.y20k.trackbook.R
|
||||||
|
@ -25,11 +26,8 @@ import org.y20k.trackbook.R
|
||||||
/*
|
/*
|
||||||
* AppThemeHelper object
|
* AppThemeHelper object
|
||||||
*/
|
*/
|
||||||
object AppThemeHelper {
|
object AppThemeHelper
|
||||||
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(AppThemeHelper::class.java)
|
|
||||||
|
|
||||||
/* Sets app theme */
|
/* Sets app theme */
|
||||||
fun setTheme(nightModeState: String) {
|
fun setTheme(nightModeState: String) {
|
||||||
when (nightModeState) {
|
when (nightModeState) {
|
||||||
|
@ -37,27 +35,27 @@ object AppThemeHelper {
|
||||||
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
|
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
|
||||||
// turn on dark mode
|
// turn on dark mode
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
LogHelper.i(TAG, "Dark Mode activated.")
|
Log.i("VOUSSOIR", "Dark Mode activated.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Keys.STATE_THEME_LIGHT_MODE -> {
|
Keys.STATE_THEME_LIGHT_MODE -> {
|
||||||
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO) {
|
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO) {
|
||||||
// turn on light mode
|
// turn on light mode
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
LogHelper.i(TAG, "Theme: Light Mode activated.")
|
Log.i("VOUSSOIR", "Theme: Light Mode activated.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Keys.STATE_THEME_FOLLOW_SYSTEM -> {
|
Keys.STATE_THEME_FOLLOW_SYSTEM -> {
|
||||||
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) {
|
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) {
|
||||||
// turn on mode "follow system"
|
// turn on mode "follow system"
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
LogHelper.i(TAG, "Theme: Follow System Mode activated.")
|
Log.i("VOUSSOIR", "Theme: Follow System Mode activated.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// turn on mode "follow system"
|
// turn on mode "follow system"
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
LogHelper.i(TAG, "Theme: Follow System Mode activated.")
|
Log.i("VOUSSOIR", "Theme: Follow System Mode activated.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
/*
|
|
||||||
* LogHelper.kt
|
|
||||||
* Implements the LogHelper object
|
|
||||||
* A LogHelper wraps the logging calls to be able to strip them out of release versions
|
|
||||||
*
|
|
||||||
* This file is part of
|
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016-22 - Y20K.org
|
|
||||||
* Licensed under the MIT-License
|
|
||||||
* http://opensource.org/licenses/MIT
|
|
||||||
*
|
|
||||||
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
|
||||||
* https://github.com/osmdroid/osmdroid
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.y20k.trackbook.helpers
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import org.y20k.trackbook.BuildConfig
|
|
||||||
|
|
||||||
/*
|
|
||||||
* LogHelper object
|
|
||||||
*/
|
|
||||||
object LogHelper {
|
|
||||||
|
|
||||||
private const val TESTING: Boolean = true // set to "false"
|
|
||||||
private const val LOG_PREFIX: String = "trackbook_"
|
|
||||||
private const val MAX_LOG_TAG_LENGTH: Int = 64
|
|
||||||
private const val LOG_PREFIX_LENGTH: Int = LOG_PREFIX.length
|
|
||||||
|
|
||||||
fun makeLogTag(str: String): String {
|
|
||||||
return if (str.length > MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH) {
|
|
||||||
LOG_PREFIX + str.substring(0, MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH - 1)
|
|
||||||
} else LOG_PREFIX + str
|
|
||||||
}
|
|
||||||
|
|
||||||
fun makeLogTag(cls: Class<*>): String {
|
|
||||||
// don't use this when obfuscating class names
|
|
||||||
return makeLogTag(cls.simpleName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun v(tag: String, vararg messages: Any) {
|
|
||||||
// Only log VERBOSE if build type is DEBUG or if TESTING is true
|
|
||||||
if (BuildConfig.DEBUG || TESTING) {
|
|
||||||
log(tag, Log.VERBOSE, null, *messages)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun d(tag: String, vararg messages: Any) {
|
|
||||||
// Only log DEBUG if build type is DEBUG or if TESTING is true
|
|
||||||
if (BuildConfig.DEBUG || TESTING) {
|
|
||||||
log(tag, Log.DEBUG, null, *messages)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun i(tag: String, vararg messages: Any) {
|
|
||||||
log(tag, Log.INFO, null, *messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun w(tag: String, vararg messages: Any) {
|
|
||||||
log(tag, Log.WARN, null, *messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun w(tag: String, t: Throwable, vararg messages: Any) {
|
|
||||||
log(tag, Log.WARN, t, *messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun e(tag: String, vararg messages: Any) {
|
|
||||||
log(tag, Log.ERROR, null, *messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun e(tag: String, t: Throwable, vararg messages: Any) {
|
|
||||||
log(tag, Log.ERROR, t, *messages)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun log(tag: String, level: Int, t: Throwable?, vararg messages: Any) {
|
|
||||||
val message: String
|
|
||||||
if (t == null && messages.size == 1) {
|
|
||||||
// handle this common case without the extra cost of creating a stringbuffer:
|
|
||||||
message = messages[0].toString()
|
|
||||||
} else {
|
|
||||||
val sb = StringBuilder()
|
|
||||||
for (m in messages) {
|
|
||||||
sb.append(m)
|
|
||||||
}
|
|
||||||
if (t != null) {
|
|
||||||
sb.append("\n").append(Log.getStackTraceString(t))
|
|
||||||
}
|
|
||||||
message = sb.toString()
|
|
||||||
}
|
|
||||||
Log.println(level, tag, message)
|
|
||||||
|
|
||||||
// if (Log.isLoggable(tag, level)) {
|
|
||||||
// val message: String
|
|
||||||
// if (t == null && messages != null && messages.size == 1) {
|
|
||||||
// // handle this common case without the extra cost of creating a stringbuffer:
|
|
||||||
// message = messages[0].toString()
|
|
||||||
// } else {
|
|
||||||
// val sb = StringBuilder()
|
|
||||||
// if (messages != null)
|
|
||||||
// for (m in messages) {
|
|
||||||
// sb.append(m)
|
|
||||||
// }
|
|
||||||
// if (t != null) {
|
|
||||||
// sb.append("\n").append(Log.getStackTraceString(t))
|
|
||||||
// }
|
|
||||||
// message = sb.toString()
|
|
||||||
// }
|
|
||||||
// Log.println(level, tag, message)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -30,17 +30,15 @@ import org.y20k.trackbook.extensions.putDouble
|
||||||
/*
|
/*
|
||||||
* PreferencesHelper object
|
* PreferencesHelper object
|
||||||
*/
|
*/
|
||||||
object PreferencesHelper {
|
object PreferencesHelper
|
||||||
|
{
|
||||||
/* Define log tag */
|
|
||||||
private val TAG: String = LogHelper.makeLogTag(PreferencesHelper::class.java)
|
|
||||||
|
|
||||||
/* The sharedPreferences object to be initialized */
|
/* The sharedPreferences object to be initialized */
|
||||||
private lateinit var sharedPreferences: SharedPreferences
|
private lateinit var sharedPreferences: SharedPreferences
|
||||||
|
|
||||||
|
|
||||||
/* Initialize a single sharedPreferences object when the app is launched */
|
/* Initialize a single sharedPreferences object when the app is launched */
|
||||||
fun Context.initPreferences() {
|
fun Context.initPreferences()
|
||||||
|
{
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue