|
@@ -15,11 +15,13 @@ import com.google.firebase.initialize
|
|
|
import io.newuniverse.SDK.nuSDKService
|
|
|
import io.nexilis.service.core.Data
|
|
|
import io.nexilis.service.core.Network
|
|
|
+import io.nexilis.service.core.api
|
|
|
import io.nexilis.service.core.decrypt
|
|
|
import io.nexilis.service.core.domain
|
|
|
+import io.nexilis.service.core.isLogin
|
|
|
import io.nexilis.service.core.pref
|
|
|
-import io.nexilis.service.core.optString
|
|
|
-import io.nexilis.service.core.put
|
|
|
+import io.nexilis.service.core.pin
|
|
|
+import io.nexilis.service.core.session
|
|
|
import kotlinx.coroutines.launch
|
|
|
import org.json.JSONObject
|
|
|
import java.security.SecureRandom
|
|
@@ -67,12 +69,10 @@ class Api {
|
|
|
Thread.sleep(100)
|
|
|
}
|
|
|
val preferences = activity.pref()
|
|
|
- preferences.put(key = "api", value = account)
|
|
|
+ preferences.api = account
|
|
|
val random =
|
|
|
String.format(Locale.getDefault(), "%010d", SecureRandom().nextInt(Int.MAX_VALUE))
|
|
|
- val session = preferences.optString(
|
|
|
- key = "session", default = random
|
|
|
- )
|
|
|
+ val session = preferences.session.ifEmpty { random }
|
|
|
Log.d(tag, "initConnection:$pass,$account,$activity,$session")
|
|
|
nuSDKService.getInstance(pass).initConnection(
|
|
|
pass,
|
|
@@ -90,8 +90,7 @@ class Api {
|
|
|
val signature: String = nuSDKService.getInstance(pass).sGetSignature()
|
|
|
if ("1,1,1,1,1,1,1,1,1,1,1,1" != signature) nuSDKService.getInstance(pass)
|
|
|
.UpdateSignature()
|
|
|
- val pin = preferences.optString(key = "pin", default = "")
|
|
|
- if (pin.isEmpty()) {
|
|
|
+ if (preferences.pin.isEmpty()) {
|
|
|
condition = lock.newCondition()
|
|
|
lock.withLock {
|
|
|
Log.d(tag, "wait:connection")
|
|
@@ -105,7 +104,7 @@ class Api {
|
|
|
return@Thread
|
|
|
}
|
|
|
Log.d(tag, "signup:start")
|
|
|
- preferences.put(key = "session", value = session)
|
|
|
+ preferences.session = session
|
|
|
val response = Service.sendSync(
|
|
|
Data(
|
|
|
code = "SUA01",
|
|
@@ -119,7 +118,7 @@ class Api {
|
|
|
if (r.isOk()) {
|
|
|
val p = r.bodies["A00"] ?: ""
|
|
|
Log.d(tag, "signup:put:pin:$p")
|
|
|
- preferences.put(key = "pin", value = p)
|
|
|
+ preferences.pin = p
|
|
|
Log.d(tag, "signup:retrieve")
|
|
|
Service.sendAsync(
|
|
|
Data(
|
|
@@ -132,7 +131,7 @@ class Api {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Log.d(tag, "user pin: ${preferences.optString(key = "pin", default = "")}")
|
|
|
+ Log.d(tag, "user pin: ${preferences.pin}")
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(tag, e.message, e)
|
|
|
}
|
|
@@ -140,20 +139,19 @@ class Api {
|
|
|
}
|
|
|
|
|
|
internal fun sendToken(context: Context, token: String) {
|
|
|
- if (context.pref().getBoolean("is_login", false)) {
|
|
|
- context.pref().getString("pin", null)?.let {
|
|
|
- apiScope.launch {
|
|
|
- Service.sendAsync(
|
|
|
- Data(
|
|
|
- code = "ATO",
|
|
|
- status = System.nanoTime().toString(),
|
|
|
- f_pin = it,
|
|
|
- bodies = mutableMapOf(
|
|
|
- "TKN" to token, "Bo" to Build.BRAND
|
|
|
- )
|
|
|
+ val pin = context.pref().pin
|
|
|
+ if (context.pref().isLogin && pin.isNotEmpty()) {
|
|
|
+ apiScope.launch {
|
|
|
+ Service.sendAsync(
|
|
|
+ Data(
|
|
|
+ code = "ATO",
|
|
|
+ status = System.nanoTime().toString(),
|
|
|
+ f_pin = pin,
|
|
|
+ bodies = mutableMapOf(
|
|
|
+ "TKN" to token, "Bo" to Build.BRAND
|
|
|
)
|
|
|
)
|
|
|
- }
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|