2020-07-12 23:56:06 +02:00
|
|
|
package fr.astrolabe.astronote_app
|
|
|
|
|
2020-07-23 20:15:44 +02:00
|
|
|
import android.content.BroadcastReceiver
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import androidx.annotation.NonNull
|
2020-07-12 23:56:06 +02:00
|
|
|
import io.flutter.embedding.android.FlutterActivity
|
2020-07-23 20:15:44 +02:00
|
|
|
import io.flutter.embedding.engine.FlutterEngine
|
|
|
|
import io.flutter.plugin.common.EventChannel
|
|
|
|
import io.flutter.plugin.common.EventChannel.EventSink
|
|
|
|
import io.flutter.plugin.common.MethodChannel
|
|
|
|
import io.flutter.plugins.GeneratedPluginRegistrant
|
2020-07-12 23:56:06 +02:00
|
|
|
|
2020-07-23 20:15:44 +02:00
|
|
|
class MainActivity : FlutterActivity() {
|
|
|
|
|
|
|
|
private val CHANNEL = "https://demo.endi.coop"
|
|
|
|
private val EVENTS = "https://demo.endi.coop/login?nextpage=%2F"
|
|
|
|
private var startString: String? = null
|
|
|
|
private var linksReceiver: BroadcastReceiver? = null
|
|
|
|
|
|
|
|
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
|
|
|
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
|
|
|
|
|
|
|
MethodChannel(flutterEngine.dartExecutor, CHANNEL).setMethodCallHandler { call, result ->
|
|
|
|
if (call.method == "initialLink") {
|
|
|
|
if (startString != null) {
|
|
|
|
result.success(startString)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EventChannel(flutterEngine.dartExecutor, EVENTS).setStreamHandler(
|
|
|
|
object : EventChannel.StreamHandler {
|
|
|
|
override fun onListen(args: Any?, events: EventSink) {
|
|
|
|
linksReceiver = createChangeReceiver(events)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCancel(args: Any?) {
|
|
|
|
linksReceiver = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
val intent = getIntent()
|
|
|
|
startString = intent.data?.toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onNewIntent(intent: Intent) {
|
|
|
|
super.onNewIntent(intent)
|
|
|
|
if (intent.action === Intent.ACTION_VIEW) {
|
|
|
|
linksReceiver?.onReceive(this.applicationContext, intent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun createChangeReceiver(events: EventSink): BroadcastReceiver? {
|
|
|
|
return object : BroadcastReceiver() {
|
|
|
|
override fun onReceive(context: Context, intent: Intent) { // assuming intent.getAction() is Intent.ACTION_VIEW
|
|
|
|
val dataString = intent.dataString
|
|
|
|
?: events.error("UNAVAILABLE", "Link unavailable", null)
|
|
|
|
events.success(dataString)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-12 23:56:06 +02:00
|
|
|
}
|