|
@@ -1,23 +1,19 @@
|
|
|
package io.nexilis.service.data.repositories
|
|
|
|
|
|
-import android.content.Context
|
|
|
import android.util.Log
|
|
|
import androidx.lifecycle.LiveData
|
|
|
import io.nexilis.service.Service
|
|
|
import io.nexilis.service.core.Data
|
|
|
-import io.nexilis.service.core.optString
|
|
|
-import io.nexilis.service.core.put
|
|
|
import io.nexilis.service.core.toMD5
|
|
|
import io.nexilis.service.data.daos.BuddyDao
|
|
|
import io.nexilis.service.data.entities.Buddy
|
|
|
import io.nexilis.service.data.entities.MainEntity
|
|
|
-import io.nexilis.service.namePreference
|
|
|
import io.nexilis.service.tag
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.withContext
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
-class BuddyRepository @Inject constructor(private val context: Context, private val dao: BuddyDao) : Repository {
|
|
|
+class BuddyRepository @Inject constructor(private val dao: BuddyDao) : Repository {
|
|
|
|
|
|
val all: LiveData<List<Buddy>> = dao.getAll()
|
|
|
|
|
@@ -31,18 +27,17 @@ class BuddyRepository @Inject constructor(private val context: Context, private
|
|
|
dao.insert(entity as Buddy)
|
|
|
}
|
|
|
|
|
|
- suspend fun signUp(username: String, password: String, completion: (Boolean) -> Unit) {
|
|
|
- val preferences = context.getSharedPreferences(
|
|
|
- namePreference,
|
|
|
- Context.MODE_PRIVATE
|
|
|
- )
|
|
|
- val pin = preferences.optString(key = "pin", default = "")
|
|
|
- if (pin.isEmpty()) return
|
|
|
+ suspend fun signUp(
|
|
|
+ me: String,
|
|
|
+ username: String,
|
|
|
+ password: String,
|
|
|
+ completion: (Boolean) -> Unit
|
|
|
+ ) {
|
|
|
Service.sendAsync(
|
|
|
Data(
|
|
|
code = "A003",
|
|
|
status = System.nanoTime().toString(),
|
|
|
- f_pin = pin,
|
|
|
+ f_pin = me,
|
|
|
bodies = mutableMapOf(
|
|
|
"A02" to username,
|
|
|
"A03" to "",
|
|
@@ -53,8 +48,7 @@ class BuddyRepository @Inject constructor(private val context: Context, private
|
|
|
) { data ->
|
|
|
Log.d(tag, "insert >>>> $data")
|
|
|
if (data.isOk()) {
|
|
|
- dao.insert(Buddy(f_pin = pin, first_name = username, image_id = "", type = "1"))
|
|
|
- preferences.put("pin", pin)
|
|
|
+ dao.insert(Buddy(f_pin = me, first_name = username, image_id = "", type = "1"))
|
|
|
}
|
|
|
withContext(Dispatchers.Main) {
|
|
|
completion(data.isOk())
|
|
@@ -62,18 +56,17 @@ class BuddyRepository @Inject constructor(private val context: Context, private
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- suspend fun signIn(username: String, password: String, completion: (Boolean) -> Unit) {
|
|
|
- val preferences = context.getSharedPreferences(
|
|
|
- namePreference,
|
|
|
- Context.MODE_PRIVATE
|
|
|
- )
|
|
|
- val pin = preferences.optString(key = "pin", default = "")
|
|
|
- if (pin.isEmpty()) return
|
|
|
+ suspend fun signIn(
|
|
|
+ me: String,
|
|
|
+ username: String,
|
|
|
+ password: String,
|
|
|
+ completion: (Boolean) -> Unit
|
|
|
+ ) {
|
|
|
Service.sendSync(
|
|
|
Data(
|
|
|
code = "SSI01",
|
|
|
status = System.nanoTime().toString(),
|
|
|
- f_pin = pin,
|
|
|
+ f_pin = me,
|
|
|
bodies = mutableMapOf(
|
|
|
"A92" to username,
|
|
|
"Bm" to password.toMD5()
|
|
@@ -82,8 +75,7 @@ class BuddyRepository @Inject constructor(private val context: Context, private
|
|
|
)?.let { data ->
|
|
|
Log.d(tag, "insert >>>> $data")
|
|
|
if (data.isOk()) {
|
|
|
- dao.insert(Buddy(f_pin = pin, first_name = username, image_id = "", type = "1"))
|
|
|
- preferences.put("pin", pin)
|
|
|
+ dao.insert(Buddy(f_pin = me, first_name = username, image_id = "", type = "1"))
|
|
|
}
|
|
|
withContext(Dispatchers.Main) {
|
|
|
completion(data.isOk())
|
|
@@ -91,13 +83,7 @@ class BuddyRepository @Inject constructor(private val context: Context, private
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun addFriend(pin: String) {
|
|
|
- val preferences = context.getSharedPreferences(
|
|
|
- namePreference,
|
|
|
- Context.MODE_PRIVATE
|
|
|
- )
|
|
|
- val me = preferences.optString(key = "pin", default = "")
|
|
|
- if (pin.isEmpty() || me.isEmpty()) return
|
|
|
+ fun addFriend(me: String, pin: String) {
|
|
|
Service.sendAsync(
|
|
|
Data(
|
|
|
code = "A100",
|