|
@@ -1,8 +1,9 @@
|
|
package io.nexilis.service
|
|
package io.nexilis.service
|
|
|
|
|
|
-import android.app.Activity
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.os.Build
|
|
import android.os.Build
|
|
|
|
+import android.os.Handler
|
|
|
|
+import android.os.Looper
|
|
import android.util.Base64
|
|
import android.util.Base64
|
|
import android.util.Log
|
|
import android.util.Log
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
@@ -40,7 +41,7 @@ class Api {
|
|
|
|
|
|
internal var condition: Condition? = null
|
|
internal var condition: Condition? = null
|
|
|
|
|
|
- fun connect(appName: String, account: String, activity: Activity) {
|
|
|
|
|
|
+ fun connect(context: Context, appName: String, account: String) {
|
|
Log.d(tag, "connect:$appName:$account")
|
|
Log.d(tag, "connect:$appName:$account")
|
|
Thread {
|
|
Thread {
|
|
try {
|
|
try {
|
|
@@ -55,8 +56,8 @@ class Api {
|
|
val address = arrayAddress.getJSONObject(0)
|
|
val address = arrayAddress.getJSONObject(0)
|
|
val ip = address.getString("ip")
|
|
val ip = address.getString("ip")
|
|
val port = address.getString("portD").toInt()
|
|
val port = address.getString("portD").toInt()
|
|
- activity.pref().domain = domain
|
|
|
|
- Log.d(tag, "domain:${activity.pref().domain}")
|
|
|
|
|
|
+ context.pref().domain = domain
|
|
|
|
+ Log.d(tag, "domain:${context.pref().domain}")
|
|
val options = FirebaseOptions.Builder()
|
|
val options = FirebaseOptions.Builder()
|
|
.setProjectId("push-kit-de2e3")
|
|
.setProjectId("push-kit-de2e3")
|
|
.setApplicationId("1:36827599888:android:29e65c0ec8a560c5916695")
|
|
.setApplicationId("1:36827599888:android:29e65c0ec8a560c5916695")
|
|
@@ -64,15 +65,15 @@ class Api {
|
|
.build()
|
|
.build()
|
|
try {
|
|
try {
|
|
Firebase.app(FirebaseApp.DEFAULT_APP_NAME)
|
|
Firebase.app(FirebaseApp.DEFAULT_APP_NAME)
|
|
- Firebase.initialize(activity.applicationContext, options, "nexilis")
|
|
|
|
|
|
+ Firebase.initialize(context.applicationContext, options, "nexilis")
|
|
} catch (_: Exception) {
|
|
} catch (_: Exception) {
|
|
Firebase.initialize(
|
|
Firebase.initialize(
|
|
- activity.applicationContext,
|
|
|
|
|
|
+ context.applicationContext,
|
|
options,
|
|
options,
|
|
FirebaseApp.DEFAULT_APP_NAME
|
|
FirebaseApp.DEFAULT_APP_NAME
|
|
)
|
|
)
|
|
}
|
|
}
|
|
- val preferences = activity.pref()
|
|
|
|
|
|
+ val preferences = context.pref()
|
|
preferences.appName = appName
|
|
preferences.appName = appName
|
|
preferences.api = account
|
|
preferences.api = account
|
|
val random =
|
|
val random =
|
|
@@ -86,8 +87,8 @@ class Api {
|
|
nuSDKService.initConnection(
|
|
nuSDKService.initConnection(
|
|
pass,
|
|
pass,
|
|
account,
|
|
account,
|
|
- activity,
|
|
|
|
- SdkCallback(activity),
|
|
|
|
|
|
+ context,
|
|
|
|
+ SdkCallback(context),
|
|
ip,
|
|
ip,
|
|
port,
|
|
port,
|
|
session,
|
|
session,
|
|
@@ -106,9 +107,9 @@ class Api {
|
|
val await = it.await(15, TimeUnit.SECONDS)
|
|
val await = it.await(15, TimeUnit.SECONDS)
|
|
Log.d(tag, "wait:result:$await")
|
|
Log.d(tag, "wait:result:$await")
|
|
if (!await) {
|
|
if (!await) {
|
|
- activity.runOnUiThread {
|
|
|
|
|
|
+ Handler(Looper.getMainLooper()).post {
|
|
Toast.makeText(
|
|
Toast.makeText(
|
|
- activity,
|
|
|
|
|
|
+ context,
|
|
"Please check your internet connection",
|
|
"Please check your internet connection",
|
|
Toast.LENGTH_LONG
|
|
Toast.LENGTH_LONG
|
|
).show()
|
|
).show()
|
|
@@ -132,7 +133,7 @@ class Api {
|
|
Log.d(tag, "signup:put:pin:$p")
|
|
Log.d(tag, "signup:put:pin:$p")
|
|
preferences.pin = p
|
|
preferences.pin = p
|
|
apiScope.launch {
|
|
apiScope.launch {
|
|
- ApiRoomDatabase.getDatabase(activity).buddyDao().insert(
|
|
|
|
|
|
+ ApiRoomDatabase.getDatabase(context).buddyDao().insert(
|
|
Buddy(
|
|
Buddy(
|
|
f_pin = p,
|
|
f_pin = p,
|
|
first_name = "USR_12345",
|
|
first_name = "USR_12345",
|