Skip to content

Commit

Permalink
Android context fixes (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpoole authored Jun 28, 2023
1 parent 148facd commit e54c561
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SuperApp"
android:usesCleartextTraffic="true"
tools:targetApi="31">

<activity
Expand Down
12 changes: 0 additions & 12 deletions android/app/src/main/java/io/ionic/superapp/SuperApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,23 @@ class SuperApplication : Application() {
PortalManager.register("YOUR_PORTALS_KEY")

// Time Tracking Portal
val timeContext = HashMap<String, String>()
timeContext["startingRoute"] = "/time"
PortalManager.newPortal("time")
.setStartDir("time-tracking")
.setInitialContext(timeContext)
.create()

// Human Resources Portal
val hrContext = HashMap<String, String>()
hrContext["startingRoute"] = "/hr"
PortalManager.newPortal("hr")
.setStartDir("human-resources")
.setInitialContext(hrContext)
.create()

// People Perks Portal
val perksContext = HashMap<String, String>()
perksContext["startingRoute"] = "/perks"
PortalManager.newPortal("perks")
.setStartDir("perks")
.setInitialContext(perksContext)
.create()

// CRM Portal
val crmContext = HashMap<String, String>()
perksContext["startingRoute"] = "/crm"
PortalManager.newPortal("crm")
.setStartDir("crm")
.setInitialContext(crmContext)
.create()
}
}
12 changes: 7 additions & 5 deletions android/app/src/main/java/io/ionic/superapp/data/DataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.ionic.superapp.data.model.App
import io.ionic.superapp.data.model.Employee
import io.ionic.superapp.data.model.Event
import io.ionic.superapp.data.model.News
import org.json.JSONObject
import java.lang.Exception

class DataManager {
Expand Down Expand Up @@ -81,14 +82,15 @@ class DataManager {
return listOf(timeApp, hrApp, perksApp)
}

fun getSessionObject(): HashMap<String, String> {
val sessionMap = HashMap<String, String>()
fun getSessionObject(): JSONObject {
val supabaseObject = JSONObject()
session?.let {
sessionMap["refreshToken"] = it.refreshToken
sessionMap["accessToken"] = it.accessToken
supabaseObject.put("url","http://10.0.2.2:54321")
supabaseObject.put("refreshToken", it.refreshToken)
supabaseObject.put("accessToken", it.accessToken)
}

return sessionMap
return supabaseObject
}

suspend fun logout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import io.ionic.portals.PortalFragment
import io.ionic.portals.PortalManager
import io.ionic.superapp.R
import io.ionic.superapp.data.DataManager
import java.util.HashMap
import io.ionic.superapp.ui.plugins.DismissPlugin
import org.json.JSONObject

class AppActivity : AppCompatActivity() {

Expand All @@ -24,14 +25,17 @@ class AppActivity : AppCompatActivity() {
val portal: Portal = PortalManager.getPortal(portalName)
val portalFragment = PortalFragment(portal)

val initialContext = portal.initialContext as HashMap<String, String>
initialContext.putAll(DataManager.instance.getSessionObject())
portal.addPluginInstance(DismissPlugin { finish() })

val initialContext = JSONObject()
initialContext.put("supabase", DataManager.instance.getSessionObject())

if(!eventId.isNullOrEmpty()) {
initialContext["eventId"] = eventId
portalFragment.setInitialContext(initialContext)
initialContext.put("eventId", eventId)
}

portalFragment.setInitialContext(initialContext.toString())

val fragmentManager: FragmentManager = supportFragmentManager
fragmentManager.beginTransaction().replace(R.id.portalFrame, portalFragment).commit()
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.ionic.superapp.ui.plugins

import com.getcapacitor.Plugin
import com.getcapacitor.PluginCall
import com.getcapacitor.PluginMethod
import com.getcapacitor.annotation.CapacitorPlugin

@CapacitorPlugin(name = "Dismiss")
class DismissPlugin(val callback: () -> Unit) : Plugin() {

@PluginMethod
fun dismiss(call: PluginCall) {
callback()
call.resolve()
}
}

0 comments on commit e54c561

Please sign in to comment.