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()
|
||||
{
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(MapFragment::class.java)
|
||||
|
||||
/* Main class variables */
|
||||
private var bound: Boolean = false
|
||||
private val handler: Handler = Handler(Looper.getMainLooper())
|
||||
|
@ -314,7 +311,7 @@ class MapFragment : Fragment()
|
|||
// permission was granted - re-bind service
|
||||
activity?.unbindService(connection)
|
||||
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
|
||||
{
|
||||
|
|
|
@ -43,20 +43,11 @@ import androidx.preference.contains
|
|||
import get_path_from_uri
|
||||
import org.y20k.trackbook.helpers.AppThemeHelper
|
||||
import org.y20k.trackbook.helpers.LengthUnitHelper
|
||||
import org.y20k.trackbook.helpers.LogHelper
|
||||
import org.y20k.trackbook.helpers.PreferencesHelper
|
||||
import org.y20k.trackbook.helpers.random_device_id
|
||||
|
||||
const val INTENT_DATABASE_DIRECTORY_PICKER = 12121
|
||||
|
||||
/*
|
||||
* SettingsFragment class
|
||||
*/
|
||||
class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogListener {
|
||||
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(SettingsFragment::class.java)
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogListener
|
||||
{
|
||||
/* Overrides onViewCreated from PreferenceFragmentCompat */
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -29,7 +30,6 @@ import android.widget.Toast
|
|||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.y20k.trackbook.helpers.LogHelper
|
||||
import org.y20k.trackbook.helpers.iso8601_format
|
||||
import org.y20k.trackbook.ui.TrackFragmentLayoutHolder
|
||||
import java.text.SimpleDateFormat
|
||||
|
@ -37,9 +37,6 @@ import java.util.*
|
|||
|
||||
class TrackFragment : Fragment(), YesNoDialog.YesNoDialogListener
|
||||
{
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(TrackFragment::class.java)
|
||||
|
||||
/* Main class variables */
|
||||
private lateinit var layout: TrackFragmentLayoutHolder
|
||||
|
||||
|
@ -143,7 +140,7 @@ class TrackFragment : Fragment(), YesNoDialog.YesNoDialogListener
|
|||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,16 +17,12 @@
|
|||
package org.y20k.trackbook
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.pm.PackageManager
|
||||
import android.database.Cursor
|
||||
import android.util.Log
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import org.y20k.trackbook.helpers.AppThemeHelper
|
||||
import org.y20k.trackbook.helpers.LogHelper
|
||||
import org.y20k.trackbook.helpers.PreferencesHelper
|
||||
import org.y20k.trackbook.helpers.PreferencesHelper.initPreferences
|
||||
import java.io.File
|
||||
|
@ -37,7 +33,8 @@ interface DatabaseChangedListener
|
|||
fun database_changed()
|
||||
}
|
||||
|
||||
class Trackbook : Application() {
|
||||
class Trackbook : Application()
|
||||
{
|
||||
val database: Database = Database(this)
|
||||
val homepoints: ArrayList<Homepoint> = ArrayList()
|
||||
val database_changed_listeners = ArrayList<DatabaseChangedListener>()
|
||||
|
@ -53,7 +50,7 @@ class Trackbook : Application() {
|
|||
override fun onCreate()
|
||||
{
|
||||
super.onCreate()
|
||||
LogHelper.v("VOUSSOIR", "Trackbook application started.")
|
||||
Log.i("VOUSSOIR", "Trackbook.onCreate")
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
// initialize single sharedPreferences object when app is launched
|
||||
initPreferences()
|
||||
|
@ -136,7 +133,7 @@ class Trackbook : Application() {
|
|||
override fun onTerminate()
|
||||
{
|
||||
super.onTerminate()
|
||||
LogHelper.v("VOUSSOIR", "Trackbook application terminated.")
|
||||
Log.i("VOUSSOIR", "Trackbook.onTerminate")
|
||||
database.close()
|
||||
}
|
||||
}
|
|
@ -38,9 +38,6 @@ import org.y20k.trackbook.helpers.*
|
|||
*/
|
||||
class TrackerService: Service()
|
||||
{
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(TrackerService::class.java)
|
||||
|
||||
/* Main class variables */
|
||||
var trackingState: Int = Keys.STATE_TRACKING_STOPPED
|
||||
var gpsProviderActive: Boolean = false
|
||||
|
@ -71,27 +68,27 @@ class TrackerService: Service()
|
|||
{
|
||||
if (! use_gps_location)
|
||||
{
|
||||
LogHelper.v(TAG, "Skipping GPS listener.")
|
||||
Log.v("VOUSSOIR", "Skipping GPS listener.")
|
||||
return
|
||||
}
|
||||
|
||||
if (gpsLocationListenerRegistered)
|
||||
{
|
||||
LogHelper.v(TAG, "GPS location listener has already been added.")
|
||||
Log.v("VOUSSOIR", "GPS location listener has already been added.")
|
||||
return
|
||||
}
|
||||
|
||||
gpsProviderActive = isGpsEnabled(locationManager)
|
||||
if (! gpsProviderActive)
|
||||
{
|
||||
LogHelper.w(TAG, "Device GPS is not enabled.")
|
||||
Log.w("VOUSSOIR", "Device GPS is not enabled.")
|
||||
return
|
||||
}
|
||||
|
||||
val has_permission: Boolean = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||
if (! has_permission)
|
||||
{
|
||||
LogHelper.w(TAG, "Location permission is not granted.")
|
||||
Log.w("VOUSSOIR", "Location permission is not granted.")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -102,34 +99,34 @@ class TrackerService: Service()
|
|||
gpsLocationListener,
|
||||
)
|
||||
gpsLocationListenerRegistered = true
|
||||
LogHelper.v(TAG, "Added GPS location listener.")
|
||||
Log.v("VOUSSOIR", "Added GPS location listener.")
|
||||
}
|
||||
|
||||
private fun addNetworkLocationListener()
|
||||
{
|
||||
if (! use_network_location)
|
||||
{
|
||||
LogHelper.v(TAG, "Skipping Network listener.")
|
||||
Log.v("VOUSSOIR", "Skipping Network listener.")
|
||||
return
|
||||
}
|
||||
|
||||
if (networkLocationListenerRegistered)
|
||||
{
|
||||
LogHelper.v(TAG, "Network location listener has already been added.")
|
||||
Log.v("VOUSSOIR", "Network location listener has already been added.")
|
||||
return
|
||||
}
|
||||
|
||||
networkProviderActive = isNetworkEnabled(locationManager)
|
||||
if (!networkProviderActive)
|
||||
{
|
||||
LogHelper.w(TAG, "Unable to add Network location listener.")
|
||||
Log.w("VOUSSOIR", "Unable to add Network location listener.")
|
||||
return
|
||||
}
|
||||
|
||||
val has_permission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -140,7 +137,7 @@ class TrackerService: Service()
|
|||
networkLocationListener,
|
||||
)
|
||||
networkLocationListenerRegistered = true
|
||||
LogHelper.v(TAG, "Added Network location listener.")
|
||||
Log.v("VOUSSOIR", "Added Network location listener.")
|
||||
}
|
||||
|
||||
private fun createLocationListener(): LocationListener
|
||||
|
@ -186,7 +183,7 @@ class TrackerService: Service()
|
|||
}
|
||||
override fun onProviderEnabled(provider: String)
|
||||
{
|
||||
LogHelper.v(TAG, "onProviderEnabled $provider")
|
||||
Log.v("VOUSSOIR", "onProviderEnabled $provider")
|
||||
when (provider) {
|
||||
LocationManager.GPS_PROVIDER -> gpsProviderActive = isGpsEnabled(locationManager)
|
||||
LocationManager.NETWORK_PROVIDER -> networkProviderActive = isNetworkEnabled(locationManager)
|
||||
|
@ -194,7 +191,7 @@ class TrackerService: Service()
|
|||
}
|
||||
override fun onProviderDisabled(provider: String)
|
||||
{
|
||||
LogHelper.v(TAG, "onProviderDisabled $provider")
|
||||
Log.v("VOUSSOIR", "onProviderDisabled $provider")
|
||||
when (provider) {
|
||||
LocationManager.GPS_PROVIDER -> gpsProviderActive = isGpsEnabled(locationManager)
|
||||
LocationManager.NETWORK_PROVIDER -> networkProviderActive = isNetworkEnabled(locationManager)
|
||||
|
@ -253,7 +250,7 @@ class TrackerService: Service()
|
|||
/* Overrides onDestroy from Service */
|
||||
override fun onDestroy()
|
||||
{
|
||||
LogHelper.i("VOUSSOIR", "TrackerService.onDestroy.")
|
||||
Log.i("VOUSSOIR", "TrackerService.onDestroy.")
|
||||
super.onDestroy()
|
||||
if (trackingState == Keys.STATE_TRACKING_ACTIVE)
|
||||
{
|
||||
|
@ -282,7 +279,7 @@ class TrackerService: Service()
|
|||
{
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -320,11 +317,11 @@ class TrackerService: Service()
|
|||
{
|
||||
locationManager.removeUpdates(gpsLocationListener)
|
||||
gpsLocationListenerRegistered = false
|
||||
LogHelper.v(TAG, "Removed GPS location listener.")
|
||||
Log.v("VOUSSOIR", "Removed GPS location listener.")
|
||||
}
|
||||
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)
|
||||
networkLocationListenerRegistered = false
|
||||
LogHelper.v(TAG, "Removed Network location listener.")
|
||||
Log.v("VOUSSOIR", "Removed Network location listener.")
|
||||
}
|
||||
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 kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import org.y20k.trackbook.helpers.LogHelper
|
||||
import org.y20k.trackbook.helpers.UiHelper
|
||||
import org.y20k.trackbook.helpers.iso8601_format
|
||||
import org.y20k.trackbook.tracklist.TracklistAdapter
|
||||
|
@ -40,25 +39,24 @@ import org.y20k.trackbook.tracklist.TracklistAdapter
|
|||
/*
|
||||
* TracklistFragment class
|
||||
*/
|
||||
class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener, YesNoDialog.YesNoDialogListener {
|
||||
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(TracklistFragment::class.java)
|
||||
|
||||
class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener, YesNoDialog.YesNoDialogListener
|
||||
{
|
||||
/* Main class variables */
|
||||
private lateinit var tracklistAdapter: TracklistAdapter
|
||||
private lateinit var trackElementList: RecyclerView
|
||||
private lateinit var tracklistOnboarding: ConstraintLayout
|
||||
|
||||
/* Overrides onCreateView from Fragment */
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
// create tracklist adapter
|
||||
tracklistAdapter = TracklistAdapter(this, (requireActivity().applicationContext as Trackbook).database)
|
||||
}
|
||||
|
||||
/* 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
|
||||
val rootView = inflater.inflate(R.layout.fragment_tracklist, container, false)
|
||||
trackElementList = rootView.findViewById(R.id.track_element_list)
|
||||
|
|
|
@ -26,16 +26,12 @@ import androidx.core.view.isGone
|
|||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.y20k.trackbook.R
|
||||
import org.y20k.trackbook.helpers.LogHelper
|
||||
|
||||
/*
|
||||
* ErrorDialog object
|
||||
*/
|
||||
object ErrorDialog {
|
||||
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(ErrorDialog::class.java)
|
||||
|
||||
object ErrorDialog
|
||||
{
|
||||
/* Construct and show dialog */
|
||||
fun show(context: Context, errorTitle: Int, errorMessage: Int, errorDetails: String = String()) {
|
||||
// prepare dialog builder
|
||||
|
|
|
@ -18,22 +18,19 @@ import android.content.Context
|
|||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.y20k.trackbook.Keys
|
||||
import org.y20k.trackbook.R
|
||||
import org.y20k.trackbook.helpers.LogHelper
|
||||
|
||||
/*
|
||||
* YesNoDialog class
|
||||
*/
|
||||
class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener) {
|
||||
|
||||
class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener)
|
||||
{
|
||||
/* Interface used to communicate back to activity */
|
||||
interface YesNoDialogListener {
|
||||
interface YesNoDialogListener
|
||||
{
|
||||
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 */
|
||||
fun show(context: Context,
|
||||
type: Int,
|
||||
|
@ -42,7 +39,8 @@ class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener) {
|
|||
yesButton: Int = R.string.dialog_yes_no_positive_button_default,
|
||||
noButton: Int = R.string.dialog_generic_button_cancel,
|
||||
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
|
||||
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.res.Configuration
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import org.y20k.trackbook.Keys
|
||||
import org.y20k.trackbook.R
|
||||
|
@ -25,11 +26,8 @@ import org.y20k.trackbook.R
|
|||
/*
|
||||
* AppThemeHelper object
|
||||
*/
|
||||
object AppThemeHelper {
|
||||
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(AppThemeHelper::class.java)
|
||||
|
||||
object AppThemeHelper
|
||||
{
|
||||
/* Sets app theme */
|
||||
fun setTheme(nightModeState: String) {
|
||||
when (nightModeState) {
|
||||
|
@ -37,27 +35,27 @@ object AppThemeHelper {
|
|||
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
|
||||
// turn on dark mode
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
LogHelper.i(TAG, "Dark Mode activated.")
|
||||
Log.i("VOUSSOIR", "Dark Mode activated.")
|
||||
}
|
||||
}
|
||||
Keys.STATE_THEME_LIGHT_MODE -> {
|
||||
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_NO) {
|
||||
// turn on light mode
|
||||
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 -> {
|
||||
if (AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) {
|
||||
// turn on mode "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 -> {
|
||||
// turn on mode "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
|
||||
*/
|
||||
object PreferencesHelper {
|
||||
|
||||
/* Define log tag */
|
||||
private val TAG: String = LogHelper.makeLogTag(PreferencesHelper::class.java)
|
||||
|
||||
object PreferencesHelper
|
||||
{
|
||||
/* The sharedPreferences object to be initialized */
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
|
||||
|
||||
/* Initialize a single sharedPreferences object when the app is launched */
|
||||
fun Context.initPreferences() {
|
||||
fun Context.initPreferences()
|
||||
{
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue