Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error background_locator:compileDebugKotlin #327

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -43,4 +43,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.google.android.gms:play-services-location:18.0.0"
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.material:material:1.0.0'


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import rekab.app.background_locator.pluggables.InitPluggable

class BackgroundLocatorPlugin
: MethodCallHandler, FlutterPlugin, PluginRegistry.NewIntentListener, ActivityAware {
private var context: Context? = null
public var context: Context? = null
private var activity: Activity? = null

companion object {
Expand Down Expand Up @@ -212,19 +212,23 @@ class BackgroundLocatorPlugin
override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
Keys.METHOD_PLUGIN_INITIALIZE_SERVICE -> {
val args: Map<Any, Any> = call.arguments()
val args: Map<Any, Any>? = call.arguments()

// save callback dispatcher to use it when device reboots
PreferencesManager.saveCallbackDispatcher(context!!, args)
// save callback dispatcher to use it when device reboots
PreferencesManager.saveCallbackDispatcher(context!! , args!!)




initializeService(context!!, args)
result.success(true)
}
Keys.METHOD_PLUGIN_REGISTER_LOCATION_UPDATE -> {
val args: Map<Any, Any> = call.arguments()
val args: Map<Any, Any>? = call.arguments()

// save setting to use it when device reboots
PreferencesManager.saveSettings(context!!, args)

PreferencesManager.saveSettings(context!!, args!!)

registerLocator(context!!,
args,
Expand All @@ -240,8 +244,11 @@ class BackgroundLocatorPlugin
return
}

val args: Map<Any, Any> = call.arguments()
updateNotificationText(context!!, args)
val args: Map<Any, Any>? = call.arguments()

updateNotificationText(context!!, args!!)


result.success(true)
}
else -> result.notImplemented()
Expand All @@ -263,7 +270,7 @@ class BackgroundLocatorPlugin
channel?.setMethodCallHandler(plugin)
}

override fun onNewIntent(intent: Intent?): Boolean {
override fun onNewIntent(intent: Intent): Boolean {
if (intent?.action != Keys.NOTIFICATION_ACTION) {
// this is not our notification
return false
Expand All @@ -272,7 +279,7 @@ class BackgroundLocatorPlugin
val notificationCallback = PreferencesManager.getCallbackHandle(activity!!, Keys.NOTIFICATION_CALLBACK_HANDLE_KEY)
if (notificationCallback != null && IsolateHolderService.backgroundEngine != null) {
val backgroundChannel =
MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger, Keys.BACKGROUND_CHANNEL_ID)
MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger!! , Keys.BACKGROUND_CHANNEL_ID)
activity?.mainLooper?.let {
Handler(it)
.post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal fun IsolateHolderService.startLocatorService(context: Context) {
}

backgroundChannel =
MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger,
MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger!!,
Keys.BACKGROUND_CHANNEL_ID)
backgroundChannel.setMethodCallHandler(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class IsolateHolderService : MethodChannel.MethodCallHandler, LocationUpdateList

if (backgroundEngine != null) {
val backgroundChannel =
MethodChannel(backgroundEngine?.dartExecutor?.binaryMessenger, Keys.BACKGROUND_CHANNEL_ID)
MethodChannel(backgroundEngine?.dartExecutor?.binaryMessenger!!, Keys.BACKGROUND_CHANNEL_ID)
Handler(context.mainLooper)
.post {
Log.d("plugin", "sendLocationEvent $result")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DisposePluggable : Pluggable {

override fun onServiceDispose(context: Context) {
(PreferencesManager.getCallbackHandle(context, Keys.DISPOSE_CALLBACK_HANDLE_KEY))?.let { disposeCallback ->
val backgroundChannel = MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger,
val backgroundChannel = MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger!!,
Keys.BACKGROUND_CHANNEL_ID)
Handler(context.mainLooper)
.post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class InitPluggable : Pluggable {
if (!isInitCallbackCalled) {
(PreferencesManager.getCallbackHandle(context, Keys.INIT_CALLBACK_HANDLE_KEY))?.let { initCallback ->
val initialDataMap = PreferencesManager.getDataCallback(context, Keys.INIT_DATA_CALLBACK_KEY)
val backgroundChannel = MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger,


val backgroundChannel = MethodChannel(IsolateHolderService.backgroundEngine?.dartExecutor?.binaryMessenger!!,
Keys.BACKGROUND_CHANNEL_ID)
Handler(context.mainLooper)
.post {
Expand Down
2 changes: 1 addition & 1 deletion lib/location_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LocationDto {
json[Keys.ARG_HEADING],
json[Keys.ARG_TIME],
isLocationMocked,
json[Keys.ARG_PROVIDER],
json[Keys.ARG_PROVIDER] ?? '',
);
}

Expand Down