Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pro.growfood.android.receiver
- import android.content.BroadcastReceiver
- import android.content.Context
- import android.content.Intent
- import android.net.Uri
- import android.os.Bundle
- import androidx.annotation.IdRes
- import androidx.annotation.NavigationRes
- import androidx.core.content.ContextCompat.startActivity
- import androidx.navigation.NavDeepLinkBuilder
- import com.exponea.sdk.models.NotificationAction
- import com.exponea.sdk.services.ExponeaPushReceiver
- import org.koin.core.KoinComponent
- import org.koin.core.inject
- import pro.growfood.android.R
- import pro.growfood.android.base.BaseActivity
- import pro.growfood.android.extentions.openAppInGooglePlay
- import pro.growfood.android.extentions.orFalse
- import pro.growfood.android.model.interactors.PropertyInteractor
- import pro.growfood.android.view.profile.PageRouter
- import pro.growfood.android.view.profile.ProfileViewModel
- import timber.log.Timber
- class ExponeaReceiver : BroadcastReceiver(), KoinComponent {
- private val viewModel: ProfileViewModel by inject()
- private val propertyInteractor: PropertyInteractor by inject()
- override fun onReceive(context: Context, intent: Intent) {
- val action = intent.getSerializableExtra(ExponeaPushReceiver.EXTRA_ACTION_INFO) as? NotificationAction?
- val buttonClickedIntent = Intent(Intent.ACTION_VIEW)
- buttonClickedIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- val url = action?.url
- Timber.tag("testLog").d("message ")
- if (url != null && url.isNotEmpty())
- buttonClickedIntent.data = Uri.parse(url)
- if (url?.contains("flutter").orFalse()) {
- val sessionId = url?.split("=")?.get(1).orEmpty()
- viewModel.getProfileValue { profile ->
- PageRouter.openPageByUrl(context, "gf://flutter/nps",
- hashMapOf(
- "profile" to profile,
- "sessionId" to sessionId,
- "client_token" to propertyInteractor.getToken(),
- "baseUrl" to "https://admin.growfood.pro/api/mobile-apps/v2_10/"
- )
- )
- }
- return
- }
- when(intent.action) {
- ExponeaPushReceiver.ACTION_CLICKED -> {
- val launchIntent = Intent(context, BaseActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK }
- startActivity(context, launchIntent, null)
- }
- ExponeaPushReceiver.ACTION_DEEPLINK_CLICKED -> {
- if (url != null && url.isNotEmpty()) {
- deeplinkHandler(context, url)
- }
- else {
- deepLinkNavigate(context, Bundle(), R.navigation.active_orders, R.id.supertFtragment)
- }
- }
- }
- }
- private fun deeplinkHandler(context: Context, url: String) {
- val args = Bundle()
- val uri = Uri.parse(url)
- val server = uri.authority
- // uri.pathSegments
- when(server){
- SERVER_ORDERS -> {}
- SERVER_RATE -> {}
- // SERVER_PROFILE -> {deepLinkNavigate(context, args, R.navigation.profile, R.id.profile)}
- SERVER_NEW_ORDER -> {}
- SERVER_RATE_APP -> context.openAppInGooglePlay()
- else -> deepLinkNavigate(context, args, R.navigation.active_orders, R.id.supertFtragment)
- }
- }
- private fun deepLinkNavigate(context: Context, args: Bundle, @NavigationRes navGraphId: Int, @IdRes destId: Int) {
- NavDeepLinkBuilder(context)
- .setGraph(navGraphId)
- .setDestination(destId)
- .setArguments(args)
- .createPendingIntent()
- .send()
- }
- companion object{
- const val SERVER_ORDERS = "orders"
- const val SECOND_SEGMENT_MENU = "menu"
- const val SECOND_SEGMENT_LONGATE = "longate"
- const val SERVER_RATE = "rate"
- const val SECOND_SEGMENT_DELIVERY = "delivery"
- const val SECOND_SEGMENT_DISH = "dish"
- const val SERVER_PROFILE = "profile"
- const val SERVER_CHAT = "chat"
- const val SERVER_NEW_ORDER = "neworder"
- const val SERVER_RATE_APP = "rateApp"
- }
- // override fun onReceive(p0: Context?, p1: Intent?) {
- //
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement