Various linting.
This commit is contained in:
parent
7788352286
commit
89035e0323
19 changed files with 37 additions and 202 deletions
|
@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase.openOrCreateDatabase
|
|||
import android.util.Log
|
||||
import java.io.File
|
||||
|
||||
class Database(val trackbook: net.voussoir.trkpt.Trackbook)
|
||||
class Database(val trackbook: Trackbook)
|
||||
{
|
||||
var ready: Boolean = false
|
||||
lateinit var file: File
|
||||
|
@ -68,7 +68,7 @@ class Database(val trackbook: net.voussoir.trkpt.Trackbook)
|
|||
this.commit()
|
||||
}
|
||||
|
||||
fun insert_trkpt(trkpt: net.voussoir.trkpt.Trkpt)
|
||||
fun insert_trkpt(trkpt: Trkpt)
|
||||
{
|
||||
Log.i("VOUSSOIR", "Database.insert_trkpt")
|
||||
val values = ContentValues().apply {
|
||||
|
@ -183,7 +183,7 @@ class Database(val trackbook: net.voussoir.trkpt.Trackbook)
|
|||
cursor = this.connection.rawQuery("PRAGMA journal_mode = DELETE", null)
|
||||
cursor.moveToNext()
|
||||
cursor.close()
|
||||
cursor = this.connection.rawQuery("PRAGMA user_version = ${net.voussoir.trkpt.Keys.DATABASE_VERSION}", null)
|
||||
cursor = this.connection.rawQuery("PRAGMA user_version = ${Keys.DATABASE_VERSION}", null)
|
||||
cursor.moveToNext()
|
||||
cursor.close()
|
||||
// Not using this.commit because this.ready is not true yet.
|
||||
|
|
|
@ -8,12 +8,12 @@ class Homepoint(val id: Long, val latitude: Double, val longitude: Double, val r
|
|||
|
||||
private fun to_location(): Location
|
||||
{
|
||||
val location: Location = Location("homepoint")
|
||||
val location = Location("homepoint")
|
||||
location.latitude = latitude
|
||||
location.longitude = longitude
|
||||
location.altitude = 0.0
|
||||
location.accuracy = radius.toFloat()
|
||||
location.time = GregorianCalendar.getInstance().time.time
|
||||
location.time = System.currentTimeMillis()
|
||||
return location
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
||||
* https://github.com/osmdroid/osmdroid
|
||||
*/
|
||||
/*
|
||||
* Modified by voussoir for trkpt, forked from Trackbook.
|
||||
*/
|
||||
|
||||
package net.voussoir.trkpt
|
||||
|
||||
|
@ -22,10 +25,6 @@ import java.util.*
|
|||
* Keys object
|
||||
*/
|
||||
object Keys {
|
||||
|
||||
// application name
|
||||
const val APPLICATION_NAME: String = "trkpt"
|
||||
|
||||
// axioms
|
||||
const val ONE_SECOND_IN_MILLISECONDS: Long = 1000
|
||||
const val ONE_MINUTE_IN_MILLISECONDS: Long = 60 * ONE_SECOND_IN_MILLISECONDS
|
||||
|
@ -77,7 +76,6 @@ object Keys {
|
|||
|
||||
// dialog types
|
||||
const val DIALOG_DELETE_TRACK: Int = 1
|
||||
const val DIALOG_DELETE_NON_STARRED: Int = 2
|
||||
|
||||
// dialog results
|
||||
const val DIALOG_EMPTY_PAYLOAD_STRING: String = ""
|
||||
|
@ -94,11 +92,8 @@ object Keys {
|
|||
// default values
|
||||
val DEFAULT_DATE: Date = Date(0L)
|
||||
const val EMPTY_STRING_RESOURCE: Int = 0
|
||||
const val REQUEST_CURRENT_LOCATION_INTERVAL: Long = 1 * ONE_SECOND_IN_MILLISECONDS
|
||||
const val SAVE_TEMP_TRACK_INTERVAL: Long = 30 * ONE_SECOND_IN_MILLISECONDS
|
||||
const val SIGNIFICANT_TIME_DIFFERENCE: Long = 1 * ONE_MINUTE_IN_MILLISECONDS
|
||||
const val STOP_OVER_THRESHOLD: Long = 5 * ONE_MINUTE_IN_MILLISECONDS
|
||||
const val IMPLAUSIBLE_TRACK_START_SPEED: Double = 250.0 // 250 km/h
|
||||
const val DEFAULT_LATITUDE: Double = 71.172500 // latitude Nordkapp, Norway
|
||||
const val DEFAULT_LONGITUDE: Double = 25.784444 // longitude Nordkapp, Norway
|
||||
const val DEFAULT_ACCURACY: Float = 300f // in meters
|
||||
|
@ -111,7 +106,6 @@ object Keys {
|
|||
const val DEFAULT_ZOOM_LEVEL: Double = 16.0
|
||||
const val DEFAULT_OMIT_RESTS: Boolean = true
|
||||
const val DEFAULT_ALLOW_SLEEP: Boolean = true
|
||||
const val ALTITUDE_MEASUREMENT_ERROR_THRESHOLD = 10 // altitude changes of 10 meter or more (per 15 seconds) are being discarded
|
||||
|
||||
// notification
|
||||
const val TRACKER_SERVICE_NOTIFICATION_ID: Int = 1
|
||||
|
|
|
@ -51,7 +51,7 @@ class MainActivity: AppCompatActivity()
|
|||
super.onCreate(savedInstanceState)
|
||||
request_permissions(this)
|
||||
// todo: remove after testing finished
|
||||
if (net.voussoir.trkpt.BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
{
|
||||
StrictMode.setVmPolicy(
|
||||
VmPolicy.Builder()
|
||||
|
@ -62,14 +62,14 @@ class MainActivity: AppCompatActivity()
|
|||
}
|
||||
|
||||
// set user agent to prevent getting banned from the osm servers
|
||||
Configuration.getInstance().userAgentValue = net.voussoir.trkpt.BuildConfig.APPLICATION_ID
|
||||
Configuration.getInstance().userAgentValue = BuildConfig.APPLICATION_ID
|
||||
// set the path for osmdroid's files (e.g. tile cache)
|
||||
Configuration.getInstance().osmdroidBasePath = this.getExternalFilesDir(null)
|
||||
|
||||
// set up views
|
||||
setContentView(R.layout.activity_main)
|
||||
navHostFragment = supportFragmentManager.findFragmentById(R.id.main_container) as NavHostFragment
|
||||
bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation_view)
|
||||
bottomNavigationView = findViewById(R.id.bottom_navigation_view)
|
||||
// Prevents the UI from flickering when clicking the tab that you are already on.
|
||||
// Problem: clicking the Tracks nav while looking at a track should bring you back to the
|
||||
// list of tracks.
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
||||
* https://github.com/osmdroid/osmdroid
|
||||
*/
|
||||
/*
|
||||
* Modified by voussoir for trkpt, forked from Trackbook.
|
||||
*/
|
||||
|
||||
package net.voussoir.trkpt
|
||||
|
||||
|
@ -20,7 +23,6 @@ import android.Manifest
|
|||
import android.app.Dialog
|
||||
import android.content.*
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.location.Location
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
package net.voussoir.trkpt
|
||||
|
||||
import YesNoDialog
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -46,7 +45,7 @@ import net.voussoir.trkpt.helpers.LengthUnitHelper
|
|||
import net.voussoir.trkpt.helpers.PreferencesHelper
|
||||
import net.voussoir.trkpt.helpers.random_device_id
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogListener
|
||||
class SettingsFragment : PreferenceFragmentCompat()
|
||||
{
|
||||
/* Overrides onViewCreated from PreferenceFragmentCompat */
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -222,7 +221,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
|||
source_code.summary = "Available on github, gitlab, and codeberg."
|
||||
source_code.setOnPreferenceClickListener {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setData(Uri.parse("https://github.com/voussoir/trkpt"))
|
||||
intent.data = Uri.parse("https://github.com/voussoir/trkpt")
|
||||
startActivity(intent)
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
|
@ -235,7 +234,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
|||
fork_notice.summary = "Thank you y20k."
|
||||
fork_notice.setOnPreferenceClickListener {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setData(Uri.parse("https://codeberg.org/y20k/trackbook"))
|
||||
intent.data = Uri.parse("https://codeberg.org/y20k/trackbook")
|
||||
startActivity(intent)
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
|
@ -248,7 +247,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
|||
copyright_notice.setIcon(R.drawable.ic_map_24dp)
|
||||
copyright_notice.setOnPreferenceClickListener {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setData(Uri.parse("https://www.openstreetmap.org"))
|
||||
intent.data = Uri.parse("https://www.openstreetmap.org")
|
||||
startActivity(intent)
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
|
@ -264,16 +263,5 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
|||
|
||||
preferenceScreen = screen
|
||||
}
|
||||
|
||||
/* Overrides onYesNoDialog from YesNoDialogListener */
|
||||
override fun onYesNoDialog(type: Int, dialogResult: Boolean, payload: Int, payloadString: String) {
|
||||
when (type) {
|
||||
Keys.DIALOG_DELETE_NON_STARRED -> {
|
||||
}
|
||||
else -> {
|
||||
super.onYesNoDialog(type, dialogResult, payload, payloadString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.text.SimpleDateFormat
|
|||
import java.util.*
|
||||
|
||||
data class Track (
|
||||
val database: net.voussoir.trkpt.Database,
|
||||
val database: Database,
|
||||
val device_id: String,
|
||||
var name: String = "",
|
||||
var _start_time: Long = 0L,
|
||||
|
|
|
@ -438,11 +438,12 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
|||
style.style = Paint.Style.FILL
|
||||
style.color = requireContext().getColor(R.color.fuchsia)
|
||||
style.flags = Paint.ANTI_ALIAS_FLAG
|
||||
val density_scaling_factor = requireContext().resources.displayMetrics.density
|
||||
val overlayOptions: SimpleFastPointOverlayOptions = SimpleFastPointOverlayOptions.getDefaultStyle()
|
||||
.setAlgorithm(SimpleFastPointOverlayOptions.RenderingAlgorithm.MEDIUM_OPTIMIZATION)
|
||||
.setSymbol(SimpleFastPointOverlayOptions.Shape.CIRCLE)
|
||||
.setPointStyle(style)
|
||||
.setRadius(((Keys.POLYLINE_THICKNESS + 1 ) / 2) * UiHelper.getDensityScalingFactor(requireContext()))
|
||||
.setRadius(((Keys.POLYLINE_THICKNESS + 1 ) / 2) * density_scaling_factor)
|
||||
.setIsClickable(true)
|
||||
.setCellSize(12)
|
||||
track_points_overlay = SimpleFastPointOverlay(pointTheme, overlayOptions)
|
||||
|
@ -549,7 +550,7 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
|||
|
||||
private fun setupStatisticsViews()
|
||||
{
|
||||
val stats: TrackStatistics = TrackStatistics(track.trkpts)
|
||||
val stats = TrackStatistics(track.trkpts)
|
||||
trackNameView.text = track.name
|
||||
distanceView.text = LengthUnitHelper.convertDistanceToString(stats.distance, useImperialUnits)
|
||||
waypointsView.text = track.trkpts.size.toString()
|
||||
|
|
|
@ -39,7 +39,7 @@ interface DatabaseChangedListener
|
|||
|
||||
class Trackbook : Application()
|
||||
{
|
||||
val database: net.voussoir.trkpt.Database = net.voussoir.trkpt.Database(this)
|
||||
val database = Database(this)
|
||||
val homepoints: ArrayDeque<Homepoint> = ArrayDeque()
|
||||
val database_changed_listeners = ArrayList<DatabaseChangedListener>()
|
||||
|
||||
|
|
|
@ -40,10 +40,8 @@ import android.media.ToneGenerator
|
|||
import android.os.*
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import net.voussoir.trkpt.helpers.*
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import java.lang.ref.WeakReference
|
||||
|
|
|
@ -115,17 +115,6 @@ class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener,
|
|||
override fun onLayoutCompleted(state: RecyclerView.State?)
|
||||
{
|
||||
super.onLayoutCompleted(state)
|
||||
// handle delete request from TrackFragment - after layout calculations are complete
|
||||
val deleteTrackId: Long = arguments?.getLong(Keys.ARG_TRACK_ID, -1L) ?: -1L
|
||||
arguments?.putLong(Keys.ARG_TRACK_ID, -1L)
|
||||
if (deleteTrackId == -1L)
|
||||
{
|
||||
return
|
||||
}
|
||||
CoroutineScope(Main). launch {
|
||||
tracklistAdapter.delete_track_by_id(this@TracklistFragment.activity as Context, deleteTrackId)
|
||||
toggleOnboardingLayout()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ object ErrorDialog
|
|||
/* Construct and show dialog */
|
||||
fun show(context: Context, errorTitle: Int, errorMessage: Int, errorDetails: String = String()) {
|
||||
// prepare dialog builder
|
||||
val builder: MaterialAlertDialogBuilder = MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
||||
val builder = MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
||||
|
||||
// set title
|
||||
builder.setTitle(context.getString(errorTitle))
|
||||
|
|
|
@ -56,7 +56,7 @@ class YesNoDialog (private var yesNoDialogListener: YesNoDialogListener)
|
|||
payloadString: String = Keys.DIALOG_EMPTY_PAYLOAD_STRING) {
|
||||
|
||||
// prepare dialog builder
|
||||
val builder: MaterialAlertDialogBuilder = MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
||||
val builder = MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
||||
|
||||
// set title and message
|
||||
builder.setMessage(messageString)
|
||||
|
|
|
@ -28,12 +28,12 @@ fun iso8601_local_noms(timestamp: Long): String
|
|||
|
||||
fun random_int(): Int
|
||||
{
|
||||
return abs(RNG.nextInt())
|
||||
return kotlin.math.abs(RNG.nextInt())
|
||||
}
|
||||
|
||||
fun random_long(): Long
|
||||
{
|
||||
return abs(RNG.nextLong())
|
||||
return kotlin.math.abs(RNG.nextLong())
|
||||
}
|
||||
|
||||
fun random_device_id(): String
|
||||
|
|
|
@ -79,14 +79,14 @@ object LengthUnitHelper
|
|||
/* Determines which unit system the device is using (metric or imperial) */
|
||||
fun useImperialUnits(): Boolean {
|
||||
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||
val imperialSystemCountries = Arrays.asList("US", "LR", "MM")
|
||||
val imperialSystemCountries = listOf("US", "LR", "MM")
|
||||
val countryCode = Locale.getDefault().country
|
||||
return imperialSystemCountries.contains(countryCode)
|
||||
}
|
||||
|
||||
/* Converts for the given unit System distance and duration values to a readable velocity string */
|
||||
fun convertToVelocityString(velocity: Double, useImperialUnits: Boolean = false) : String {
|
||||
var speed: String = "0"
|
||||
var speed = "0"
|
||||
|
||||
if (velocity > 0.0) {
|
||||
// speed in km/h / mph
|
||||
|
|
|
@ -26,11 +26,9 @@ import org.osmdroid.views.overlay.ItemizedIconOverlay
|
|||
import org.osmdroid.views.overlay.OverlayItem
|
||||
import net.voussoir.trkpt.R
|
||||
import net.voussoir.trkpt.Trkpt
|
||||
import java.text.DecimalFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
fun create_start_end_markers(context: Context, map_view: MapView, startpoint: Trkpt, endpoint: Trkpt): ItemizedIconOverlay<OverlayItem>?
|
||||
fun create_start_end_markers(context: Context, map_view: MapView, startpoint: Trkpt, endpoint: Trkpt): ItemizedIconOverlay<OverlayItem>
|
||||
{
|
||||
Log.i("VOUSSOIR", "MapOverlayHelper.create_start_end_markers")
|
||||
val overlayItems: ArrayList<OverlayItem> = ArrayList<OverlayItem>()
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* UiHelper.kt
|
||||
* Implements the UiHelper object
|
||||
* A UiHelper provides helper methods for User Interface related tasks
|
||||
*
|
||||
* 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 net.voussoir.trkpt.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffXfermode
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import net.voussoir.trkpt.R
|
||||
|
||||
/*
|
||||
* UiHelper object
|
||||
*/
|
||||
object UiHelper {
|
||||
/* Get scaling factor from display density */
|
||||
fun getDensityScalingFactor(context: Context): Float {
|
||||
return context.resources.displayMetrics.density
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Inner class: Callback that detects a left swipe
|
||||
* Credit: https://github.com/kitek/android-rv-swipe-delete/blob/master/app/src/main/java/pl/kitek/rvswipetodelete/SwipeToDeleteCallback.kt
|
||||
*/
|
||||
abstract class SwipeToDeleteCallback(context: Context): ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
|
||||
|
||||
private val deleteIcon = ContextCompat.getDrawable(context, R.drawable.ic_remove_circle_24dp)
|
||||
private val intrinsicWidth: Int = deleteIcon?.intrinsicWidth ?: 0
|
||||
private val intrinsicHeight: Int = deleteIcon?.intrinsicHeight ?: 0
|
||||
private val background: ColorDrawable = ColorDrawable()
|
||||
private val backgroundColor = context.resources.getColor(R.color.list_card_delete_background, null)
|
||||
private val clearPaint: Paint = Paint().apply { xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR) }
|
||||
|
||||
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
|
||||
// do nothing
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) {
|
||||
val itemView = viewHolder.itemView
|
||||
val itemHeight = itemView.bottom - itemView.top
|
||||
val isCanceled = dX == 0f && !isCurrentlyActive
|
||||
|
||||
if (isCanceled) {
|
||||
clearCanvas(c, itemView.right + dX, itemView.top.toFloat(), itemView.right.toFloat(), itemView.bottom.toFloat())
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
|
||||
return
|
||||
}
|
||||
|
||||
// draw red delete background
|
||||
background.color = backgroundColor
|
||||
background.setBounds(
|
||||
itemView.right + dX.toInt(),
|
||||
itemView.top,
|
||||
itemView.right,
|
||||
itemView.bottom
|
||||
)
|
||||
background.draw(c)
|
||||
|
||||
// calculate position of delete icon
|
||||
val deleteIconTop = itemView.top + (itemHeight - intrinsicHeight) / 2
|
||||
val deleteIconMargin = (itemHeight - intrinsicHeight) / 2
|
||||
val deleteIconLeft = itemView.right - deleteIconMargin - intrinsicWidth
|
||||
val deleteIconRight = itemView.right - deleteIconMargin
|
||||
val deleteIconBottom = deleteIconTop + intrinsicHeight
|
||||
|
||||
// draw delete icon
|
||||
deleteIcon?.setBounds(deleteIconLeft, deleteIconTop, deleteIconRight, deleteIconBottom)
|
||||
deleteIcon?.draw(c)
|
||||
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
|
||||
}
|
||||
|
||||
private fun clearCanvas(c: Canvas?, left: Float, top: Float, right: Float, bottom: Float) {
|
||||
c?.drawRect(left, top, right, bottom, clearPaint)
|
||||
}
|
||||
}
|
||||
/*
|
||||
* End of inner class
|
||||
*/
|
||||
|
||||
}
|
|
@ -34,7 +34,7 @@ import java.text.DateFormat
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class TracklistAdapter(val fragment: Fragment, val database: net.voussoir.trkpt.Database) : RecyclerView.Adapter<RecyclerView.ViewHolder>()
|
||||
class TracklistAdapter(val fragment: Fragment, val database: Database) : RecyclerView.Adapter<RecyclerView.ViewHolder>()
|
||||
{
|
||||
private lateinit var tracklistListener: TracklistAdapterListener
|
||||
val tracks: ArrayList<Track> = ArrayList<Track>()
|
||||
|
@ -64,15 +64,12 @@ class TracklistAdapter(val fragment: Fragment, val database: net.voussoir.trkpt.
|
|||
{
|
||||
val trackdate = cursor.getString(0)
|
||||
val device_id = cursor.getString(1)
|
||||
val start_time: Long? = df.parse(trackdate + "T00:00:00.000").time
|
||||
val stop_time: Long? = df.parse(trackdate + "T23:59:59.999").time
|
||||
val start_time: Long = df.parse(trackdate + "T00:00:00.000").time
|
||||
val stop_time: Long = df.parse(trackdate + "T23:59:59.999").time
|
||||
Log.i("VOUSSOIR", "TracklistAdapter prep track ${trackdate}")
|
||||
if (start_time != null && stop_time != null)
|
||||
{
|
||||
val track = Track(database=database, device_id=device_id, _start_time=start_time, _end_time=stop_time)
|
||||
track.name = "$trackdate $device_id"
|
||||
tracks.add(track)
|
||||
}
|
||||
val track = Track(database=database, device_id=device_id, _start_time=start_time, _end_time=stop_time)
|
||||
track.name = "$trackdate $device_id"
|
||||
tracks.add(track)
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -118,27 +115,6 @@ class TracklistAdapter(val fragment: Fragment, val database: net.voussoir.trkpt.
|
|||
return SimpleDateFormat("yyyy-MM-dd", Locale.US).format(tracks[positionInRecyclerView]._start_time)
|
||||
}
|
||||
|
||||
fun delete_track_at_position(context: Context, index: Int)
|
||||
{
|
||||
// val track = tracklist.tracks[index]
|
||||
// track.delete()
|
||||
// tracklist.tracks.remove(track)
|
||||
// notifyItemRemoved(index)
|
||||
// notifyItemRangeChanged(index, this.itemCount);
|
||||
}
|
||||
|
||||
fun delete_track_by_id(context: Context, trackId: Long)
|
||||
{
|
||||
// val index: Int = tracklist.tracks.indexOfFirst {it.id == trackId}
|
||||
// if (index == -1) {
|
||||
// return
|
||||
// }
|
||||
// tracklist.tracks[index].delete()
|
||||
// tracklist.tracks.removeAt(index)
|
||||
// notifyItemRemoved(index)
|
||||
// notifyItemRangeChanged(index, this.itemCount);
|
||||
}
|
||||
|
||||
fun isEmpty(): Boolean
|
||||
{
|
||||
return tracks.size == 0
|
||||
|
@ -149,17 +125,6 @@ class TracklistAdapter(val fragment: Fragment, val database: net.voussoir.trkpt.
|
|||
{
|
||||
val track: Track = tracks[position]
|
||||
return "device: " + track.device_id
|
||||
// val track_duration_string = DateTimeHelper.convertToReadableTime(context, track.duration)
|
||||
// val trackDataString: String
|
||||
// if (track.name == track.dateString)
|
||||
// {
|
||||
// trackDataString = "${LengthUnitHelper.convertDistanceToString(track.distance, useImperial)} • ${track_duration_string}"
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// trackDataString = "${track.dateString} • ${LengthUnitHelper.convertDistanceToString(track.distance, useImperial)} • ${track_duration_string}"
|
||||
// }
|
||||
// return trackDataString
|
||||
}
|
||||
|
||||
inner class ElementTrackViewHolder (elementTrackLayout: View): RecyclerView.ViewHolder(elementTrackLayout) {
|
||||
|
|
|
@ -92,6 +92,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
app:fontFamily="monospace"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
|
Loading…
Reference in a new issue