Skip to content

Commit

Permalink
Optimized running tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
izivkov committed Aug 16, 2022
1 parent 91fef06 commit db01135
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ package org.avmedia.gShockPhoneSync.casio

import android.annotation.SuppressLint
import android.app.Notification
import android.util.Log
import org.avmedia.gShockPhoneSync.ble.Connection
import org.avmedia.gShockPhoneSync.ui.actions.ActionsModel
import org.avmedia.gShockPhoneSync.utils.ProgressEvents
import org.avmedia.gShockPhoneSync.utils.Utils
import org.avmedia.gShockPhoneSync.utils.WatchDataEvents
import org.json.JSONObject
import java.util.*
import kotlin.collections.ArrayList
import kotlin.reflect.KFunction1

/*
Expand Down Expand Up @@ -86,23 +88,24 @@ object WatchDataCollector {
private fun setBleFeatures(data: String): Unit {
bleFeaturesValue = data
ProgressEvents.onNext(ProgressEvents.Events.ButtonPressedInfoReceived)
sendRequests(filterItems(itemList))
}

private fun filterItems (_itemList:List<DataItem>): List<DataItem> {
// remove the item we have already processed
var items = _itemList.filter { it.request != "10" }

if (WatchFactory.watch.isActionButtonPressed()) {
if (!ActionsModel.hasTimeSet()) {
// We are running actions, and none of them has to set time...
// We do not need to initialise watch.
return
// We do not need to initialise watch. Return empty list.
return ArrayList<DataItem>()
}
}

// Now that we can tell which button has been pressed, we can get the rest of the watch info.
var filteredItems = itemList.filter { it.request != "10" }

if (WatchFactory.watch.isActionButtonPressed()) {
// if we are running actions, we do not need to batteryLevel.
filteredItems = filteredItems.filter { it.request != "28" }
// If we are running actions, we do not need to batteryLevel.
return items.filter { it.request != "28" }
}
sendRequests(filteredItems)
return items
}

private fun initList(): List<DataItem> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.camera.core.CameraSelector
import com.google.gson.Gson
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -111,9 +112,6 @@ object ActionsModel {
override fun run(context: Context) {
Timber.d("running ${this.javaClass.simpleName}")
createAppEventsSubscription(context)

// in order to set time, we need to get complete watch configuration.
// WatchDataCollector.requestCompleteWatchSettings()
}

private fun createAppEventsSubscription(context: Context) {
Expand Down Expand Up @@ -377,6 +375,7 @@ object ActionsModel {
runIt(it)
}
} else {
Log.i ("", "Running $it")
runIt(it)
}
}
Expand Down

0 comments on commit db01135

Please sign in to comment.