android service and notifications #167

Merged
sarah merged 12 commits from androidservice into trunk 2021-06-11 22:25:55 +00:00
3 changed files with 18 additions and 14 deletions
Showing only changes of commit 6972028ecf - Show all commits

View File

@ -111,4 +111,9 @@ dependencies {
// optional - Multiprocess support // optional - Multiprocess support
implementation "androidx.work:work-multiprocess:2.5.0" implementation "androidx.work:work-multiprocess:2.5.0"
// end of workmanager deps
// ipc
implementation "io.reactivex:rxkotlin:1.x.y"
} }

View File

@ -7,25 +7,17 @@ import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.work.CoroutineWorker import androidx.work.*
import androidx.work.Data import cwtch.Cwtch
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import androidx.work.WorkManager
import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.json.JSONObject import org.json.JSONObject
import cwtch.Cwtch
class FlwtchWorker(context: Context, parameters: WorkerParameters) : class FlwtchWorker(context: Context, parameters: WorkerParameters) :
Review

lol maybe now is a good time to rename test.flutter.dev/eventBut here and in gomobile.dart

lol maybe now is a good time to rename test.flutter.dev/eventBut here and in gomobile.dart
CoroutineWorker(context, parameters) { CoroutineWorker(context, parameters) {
@ -67,7 +59,11 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
Log.i("FlwtchWorker.kt", "COROUTINEWORKER DOT ISSTOPPED TRUE OH MY") Log.i("FlwtchWorker.kt", "COROUTINEWORKER DOT ISSTOPPED TRUE OH MY")
} }
//todo: this elides evt.EventID which may be needed at some point? //todo: this elides evt.EventID which may be needed at some point?
val data = Data.Builder().putString("EventType", evt.EventType).putString("Data", evt.Data).build() val data = Data.Builder()
.putString("EventType", evt.EventType)
.putString("Data", evt.Data)
.putString("EventID", evt.EventID)
Review

delete?

delete?
.build()
setProgress(data) setProgress(data)
Thread.sleep(200) Thread.sleep(200)
} }

View File

@ -77,7 +77,7 @@ class MainActivity: FlutterActivity() {
WorkManager.getInstance(applicationContext) WorkManager.getInstance(applicationContext)
// requestId is the WorkRequest id // requestId is the WorkRequest id
.getWorkInfosByTagLiveData("cwtchEventBus") .getWorkInfosByTagLiveData("cwtchEventBus")
.observeForever(Observer<List<WorkInfo>> { listOfWorkInfo -> .observe(this, Observer<List<WorkInfo>> { listOfWorkInfo ->
if (listOfWorkInfo.isNullOrEmpty()) { if (listOfWorkInfo.isNullOrEmpty()) {
return@Observer return@Observer
} }
@ -87,9 +87,12 @@ class MainActivity: FlutterActivity() {
val progress = workInfo.progress val progress = workInfo.progress
val eventType = progress.getString("EventType") ?: "" val eventType = progress.getString("EventType") ?: ""
val eventData = progress.getString("Data") val eventData = progress.getString("Data")
Log.i("MainActivity.kt", "got event $progress $eventType $eventData") val output = progress.keyValueMap.toString()
try { try {
eventbus_chan.invokeMethod(eventType, eventData) if (eventType != "") {
Log.i("MainActivity.kt", "got event $output $eventType $eventData")
eventbus_chan.invokeMethod(eventType, eventData)
}
} catch (e: Exception) { } catch (e: Exception) {
Log.i("MainActivity.kt", "event bus exception") Log.i("MainActivity.kt", "event bus exception")
} }