Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
bailuk committed Oct 14, 2024
1 parent 3266a0a commit 1879136
Show file tree
Hide file tree
Showing 40 changed files with 189 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class SolidExportedDocument(storage: StorageInterface) : SolidString(storage, KE
const val LIMIT_MILLIS = 30 * 1000 // 1/2 minute
}

override fun setValue(string: String) {
override fun setValue(v: String) {
time.setValue(System.currentTimeMillis())
super.setValue(string)
super.setValue(v)
}

fun setDocument(file: Foc) {
Expand Down
12 changes: 6 additions & 6 deletions aat-android/src/main/kotlin/ch/bailu/aat/services/AbsService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import ch.bailu.aat.util.AndroidTimer
import ch.bailu.aat_lib.logger.AppLog
import java.util.Date

abstract class AbsService : Service() {
abstract class AbsService : Service(), ServiceContext {
private var creations = 0
private var startTime: Long = 0
private var up = false
private var lock = 0

@Synchronized
fun lock(): Boolean {
override fun lock(): Boolean {
if (up) {
lock++
try {
Expand All @@ -30,7 +30,7 @@ abstract class AbsService : Service() {
}

@Synchronized
fun free() {
override fun free() {
if (up) {
lock--
if (lock == 0) {
Expand All @@ -55,14 +55,14 @@ abstract class AbsService : Service() {
}

@Synchronized
fun lock(resource: String) {
override fun lock(resource: String) {
if (locks.add(resource)) {
lock()
}
}

@Synchronized
fun free(resource: String) {
override fun free(resource: String) {
if (locks.remove(resource)) free()
}

Expand Down Expand Up @@ -101,7 +101,7 @@ abstract class AbsService : Service() {
return START_STICKY
}

open fun appendStatusText(builder: StringBuilder) {
override fun appendStatusText(builder: StringBuilder) {
builder.append("<h1>")
builder.append(javaClass.simpleName)
builder.append("</h1>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import ch.bailu.aat_lib.service.tracker.TrackerService
import ch.bailu.aat_lib.service.tracker.TrackerServiceInterface
import ch.bailu.aat_lib.util.WithStatusText

class OneService : AbsService(), ServiceContext {
class OneService : AbsService() {
private var location: LocationService? = null
private var tracker: TrackerService? = null
private var background: BackgroundServiceInterface? = null
Expand Down
15 changes: 6 additions & 9 deletions aat-android/src/main/kotlin/ch/bailu/aat/services/ServiceLink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ abstract class ServiceLink(private val context: Context) : ServiceContext, Servi

private fun grabService(binder: IBinder) {
if (binder is CommonBinder) {

val service = binder.service
if (service is ServiceContext) {
this.service = service
service.lock(ServiceLink::class.java.simpleName)
}
this.service = service
service.lock(ServiceLink::class.java.simpleName)
}
}

Expand Down Expand Up @@ -135,13 +132,13 @@ abstract class ServiceLink(private val context: Context) : ServiceContext, Servi
}

@Synchronized
override fun lock(simpleName: String) {
if (isUp) getService()?.lock(simpleName)
override fun lock(resource: String) {
if (isUp) getService()?.lock(resource)
}

@Synchronized
override fun free(simpleName: String) {
if (isUp) getService()?.free(simpleName)
override fun free(resource: String) {
if (isUp) getService()?.free(resource)
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class GtkServices (appContext: AppContext) : ServicesInterface {
return lazyLocationService
}

override fun lock(simpleName: String) {}
override fun free(simpleName: String) {}
override fun lock(resource: String) {}
override fun free(resource: String) {}
override fun lock(): Boolean {
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package ch.bailu.aat_gtk.service.location

import ch.bailu.aat_lib.gpx.GpxPointNode
import ch.bailu.aat_lib.gpx.information.StateID
import ch.bailu.aat_lib.gpx.attributes.AutoPause
import ch.bailu.aat_lib.gpx.information.StateID
import ch.bailu.aat_lib.gpx.linked_list.Node
import ch.bailu.aat_lib.logger.AppLog
import ch.bailu.aat_lib.preferences.StorageInterface
import ch.bailu.aat_lib.preferences.location.SolidMockLocationFile
import ch.bailu.aat_lib.service.location.*
import ch.bailu.aat_lib.service.location.LocationInformation
import ch.bailu.aat_lib.service.location.LocationServiceInterface
import ch.bailu.aat_lib.service.location.LocationStackChainedItem
import ch.bailu.aat_lib.service.location.LocationStackItem
import ch.bailu.aat_lib.service.location.MockLocationInformation
import ch.bailu.aat_lib.xml.parser.gpx.GpxListReader
import ch.bailu.foc.Foc
import ch.bailu.foc.FocFactory
Expand Down Expand Up @@ -115,11 +119,11 @@ class ThreadedMockLocation(
synchronized(lock) { super.passLocation(location) }
}

override fun passState(s: Int) {
override fun passState(state: Int) {
synchronized(lock) {
if (serviceState != s) {
serviceState = s
super.passState(s)
if (serviceState != state) {
serviceState = state
super.passState(state)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class InfoBar(app: Application,
nodeInfo.hide()
}

override fun onNodeSelected(IID: Int, info: GpxInformation, node: GpxPointNode, index: Int) {
override fun onNodeSelected(iid: Int, info: GpxInformation, node: GpxPointNode, index: Int) {
nodeInfo.displayNode(info, node, index)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SolidDirectoryDropDownView(appContext: AppContext)
indexFromSolid()

dropDown.onNotify {
AppLog.d(SolidDirectoryQuery@this, it.name.toString())
AppLog.d(this, it.name.toString())

if ("selected" == it.name.toString()) { // Property "selected" has changed
solidDirectoryQuery.setValue(directories[dropDown.selected].file.path)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ch.bailu.aat_lib.description

import ch.bailu.aat_lib.gpx.information.GpxInformation
import ch.bailu.aat_lib.gpx.information.InfoID
import ch.bailu.aat_lib.gpx.attributes.CadenceSpeedAttributes
import ch.bailu.aat_lib.gpx.attributes.GpxAttributes
import ch.bailu.aat_lib.gpx.information.GpxInformation
import ch.bailu.aat_lib.gpx.information.InfoID
import ch.bailu.aat_lib.gpx.interfaces.GpxDeltaInterface
import ch.bailu.aat_lib.preferences.StorageInterface
import ch.bailu.aat_lib.resources.Res
Expand Down Expand Up @@ -68,13 +68,11 @@ class CurrentSpeedDescription(storage: StorageInterface) : SpeedDescription(stor

private fun setSpeedFromLastPoint(info: GpxInformation): Boolean {
val track = info.getGpxList()
if (track != null) {
if (track.pointList.size() > 0) {
val delta = info.getGpxList().pointList.last
if (delta is GpxDeltaInterface) {
setCache(delta.getSpeed())
return true
}
if (track.pointList.size() > 0) {
val delta = info.getGpxList().pointList.last
if (delta is GpxDeltaInterface) {
setCache(delta.getSpeed())
return true
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TrackSizeDescription : ContentDescription() {
private var size = -1
override fun onContentUpdated(iid: Int, info: GpxInformation) {
val track = info.getGpxList()
if (track != null && size != track.pointList.size()) {
if (size != track.pointList.size()) {
size = track.pointList.size()
value = "P: " + track.pointList.size() +
", M: " + track.markerList.size() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbsFilterList<T> {
}
}

abstract fun showElement(t: T, keyList: KeyList): Boolean
abstract fun showElement(filterList: T, keyList: KeyList): Boolean

fun add(t: T) {
all.add(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package ch.bailu.aat_lib.lib.filter_list

class FilterList : AbsFilterList<AbsListItem>() {

override fun showElement(listEntry: AbsListItem, keyList: KeyList): Boolean {
override fun showElement(filterList: AbsListItem, keyList: KeyList): Boolean {
return if (keyList.isEmpty) {
listEntry.isSelected() || listEntry.isSummary()
filterList.isSelected() || filterList.isSummary()
} else {
listEntry.isSelected() || listEntry.getKeys().fits(keyList)
filterList.isSelected() || filterList.getKeys().fits(keyList)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ch.bailu.aat_lib.map.layer.gpx

import ch.bailu.aat_lib.dispatcher.TargetInterface
import ch.bailu.aat_lib.gpx.information.GpxInformation
import ch.bailu.aat_lib.gpx.GpxList
import ch.bailu.aat_lib.gpx.information.GpxInformation
import ch.bailu.aat_lib.map.MapColor.getColorFromIID
import ch.bailu.aat_lib.map.MapContext
import ch.bailu.aat_lib.map.layer.MapLayerInterface
Expand All @@ -18,7 +18,7 @@ abstract class GpxLayer : MapLayerInterface, TargetInterface {

override fun drawForeground(mcontext: MapContext) {}
override fun onContentUpdated(iid: Int, info: GpxInformation) {
gpxList = info.getGpxList() ?: GpxList.NULL_ROUTE
gpxList = info.getGpxList()
colorFromIID = getColorFromIID(iid)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ch.bailu.aat_lib.gpx.GpxPointNode

interface OnNodeSelectedInterface {
fun onNodeSelected(
IID: Int,
iid: Int,
info: GpxInformation,
node: GpxPointNode,
index: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ interface ServicesInterface {
fun getRenderService(): RenderServiceInterface
fun getTileRemoverService(): TileRemoverService

fun lock(simpleName: String)
fun free(simpleName: String)
fun lock(resource: String)
fun free(resource: String)

fun lock(): Boolean
fun free()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class HandleStack(private val limit: Int = DEFAULT_LIMIT) {
insert(handle)
}

fun close(i: Int) {
var i = i
fun close(size: Int) {
var i = size
while (remove() != null);
while (i > 0) {
queue.offerFirst(BackgroundTask.NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import org.mapsforge.core.graphics.Bitmap

class ObjBitmap(private val imageFile: Foc, private val syncBitmap: MapTileInterface) : ObjImageAbstract(imageFile.path) {

override fun onInsert(sc: AppContext) {
load(sc.services)
sc.services.getCacheService().addToBroadcaster(this)
override fun onInsert(appContext: AppContext) {
load(appContext.services)
appContext.services.getCacheService().addToBroadcaster(this)
}

override fun onRemove(sc: AppContext) {
super.onRemove(sc)
override fun onRemove(appContext: AppContext) {
super.onRemove(appContext)
syncBitmap.free()
}

Expand All @@ -43,13 +43,13 @@ class ObjBitmap(private val imageFile: Foc, private val syncBitmap: MapTileInter
}
}

override fun onDownloaded(id: String, url: String, sc: AppContext) {
override fun onDownloaded(id: String, url: String, appContext: AppContext) {
if (id == toString()) {
load(sc.services)
load(appContext.services)
}
}

override fun onChanged(id: String, sc: AppContext) {}
override fun onChanged(id: String, appContext: AppContext) {}
private class BitmapLoader(f: Foc) : FileTask(f) {

override fun bgOnProcess(appContext: AppContext): Long {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ object ObjNull : Obj(ObjNull::class.java.simpleName) {
return MIN_SIZE.toLong()
}

override fun onDownloaded(id: String, url: String, sc: AppContext) {}
override fun onChanged(id: String, sc: AppContext) {}
override fun onDownloaded(id: String, url: String, appContext: AppContext) {}
override fun onChanged(id: String, appContext: AppContext) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ abstract class ObjTile(id: String) : Obj(id) {
return MIN_SIZE.toLong()
}

override fun onDownloaded(id: String, url: String, sc: AppContext) {}
override fun onChanged(id: String, sc: AppContext) {}
override fun onDownloaded(id: String, url: String, appContext: AppContext) {}
override fun onChanged(id: String, appContext: AppContext) {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ open class ObjTileCacheOnly(id: String, sc: AppContext, private val tile: Tile,
}

override fun reDownload(sc: AppContext) {}
override fun onInsert(sc: AppContext) {
if (isLoadable) load(sc.services)
override fun onInsert(appContext: AppContext) {
if (isLoadable) load(appContext.services)
}

override fun onRemove(sc: AppContext) {
super.onRemove(sc)
override fun onRemove(appContext: AppContext) {
super.onRemove(appContext)
bitmap.free()
}

Expand All @@ -51,9 +51,9 @@ open class ObjTileCacheOnly(id: String, sc: AppContext, private val tile: Tile,
return file.isFile && file.canRead()
}

override fun onDownloaded(id: String, u: String, sc: AppContext) {
override fun onDownloaded(id: String, url: String, appContext: AppContext) {
if (Objects.equals(id, getID()) && isLoadable) {
load(sc.services)
load(appContext.services)
}
}

Expand All @@ -72,7 +72,7 @@ open class ObjTileCacheOnly(id: String, sc: AppContext, private val tile: Tile,
return loaded || notLoadable
}

override fun onChanged(id: String, sc: AppContext) {}
override fun onChanged(id: String, appContext: AppContext) {}
override fun getSize(): Long {
return bitmap.getSize()
}
Expand Down Expand Up @@ -110,8 +110,8 @@ open class ObjTileCacheOnly(id: String, sc: AppContext, private val tile: Tile,
}

class Factory(private val tile: Tile, private val source: Source) : Obj.Factory() {
override fun factory(id: String, cs: AppContext): Obj {
return ObjTileCacheOnly(id, cs, tile, source)
override fun factory(id: String, appContext: AppContext): Obj {
return ObjTileCacheOnly(id, appContext, tile, source)
}
}
}
Loading

0 comments on commit 1879136

Please sign in to comment.