feat(section/social): click add dialog
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import me.rhunk.snapenhance.bridge.BridgeService
|
||||
import me.rhunk.snapenhance.bridge.wrapper.LocaleWrapper
|
||||
import me.rhunk.snapenhance.bridge.wrapper.MappingsWrapper
|
||||
import me.rhunk.snapenhance.core.config.ModConfig
|
||||
@@ -22,6 +23,7 @@ class RemoteSideContext(
|
||||
val androidContext: Context
|
||||
) {
|
||||
private var _activity: WeakReference<Activity>? = null
|
||||
lateinit var bridgeService: BridgeService
|
||||
|
||||
var activity: Activity?
|
||||
get() = _activity?.get()
|
||||
|
||||
@@ -21,16 +21,29 @@ import kotlin.system.measureTimeMillis
|
||||
class BridgeService : Service() {
|
||||
private lateinit var messageLoggerWrapper: MessageLoggerWrapper
|
||||
private lateinit var remoteSideContext: RemoteSideContext
|
||||
private lateinit var syncCallback: SyncCallback
|
||||
lateinit var syncCallback: SyncCallback
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
remoteSideContext = SharedContextHolder.remote(this).apply {
|
||||
checkForRequirements()
|
||||
}
|
||||
remoteSideContext.bridgeService = this
|
||||
messageLoggerWrapper = MessageLoggerWrapper(getDatabasePath(BridgeFileType.MESSAGE_LOGGER_DATABASE.fileName)).also { it.init() }
|
||||
return BridgeBinder()
|
||||
}
|
||||
|
||||
fun triggerFriendSync(friendId: String) {
|
||||
SerializableDataObject.fromJson<FriendInfo>(syncCallback.syncFriend(friendId)).let {
|
||||
remoteSideContext.modDatabase.syncFriend(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun triggerGroupSync(groupId: String) {
|
||||
SerializableDataObject.fromJson<MessagingGroupInfo>(syncCallback.syncGroup(groupId)).let {
|
||||
remoteSideContext.modDatabase.syncGroupInfo(it)
|
||||
}
|
||||
}
|
||||
|
||||
inner class BridgeBinder : BridgeInterface.Stub() {
|
||||
override fun fileOperation(action: Int, fileType: Int, content: ByteArray?): ByteArray {
|
||||
val resolvedFile by lazy {
|
||||
@@ -111,18 +124,14 @@ class BridgeService : Service() {
|
||||
measureTimeMillis {
|
||||
remoteSideContext.modDatabase.getFriendsIds().forEach { friendId ->
|
||||
runCatching {
|
||||
SerializableDataObject.fromJson<FriendInfo>(callback.syncFriend(friendId)).let {
|
||||
remoteSideContext.modDatabase.syncFriend(it)
|
||||
}
|
||||
triggerFriendSync(friendId)
|
||||
}.onFailure {
|
||||
Logger.error("Failed to sync friend $friendId", it)
|
||||
}
|
||||
}
|
||||
remoteSideContext.modDatabase.getGroupsIds().forEach { groupId ->
|
||||
runCatching {
|
||||
SerializableDataObject.fromJson<MessagingGroupInfo>(callback.syncGroup(groupId)).let {
|
||||
remoteSideContext.modDatabase.syncGroupInfo(it)
|
||||
}
|
||||
triggerGroupSync(groupId)
|
||||
}.onFailure {
|
||||
Logger.error("Failed to sync group $groupId", it)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ class ModDatabase(
|
||||
|
||||
var receiveMessagingDataCallback: (friends: List<MessagingFriendInfo>, groups: List<MessagingGroupInfo>) -> Unit = { _, _ -> }
|
||||
|
||||
fun executeAsync(block: () -> Unit) {
|
||||
executor.execute(block)
|
||||
}
|
||||
|
||||
fun init() {
|
||||
database = context.androidContext.openOrCreateDatabase("main.db", 0, null)
|
||||
@@ -126,7 +129,7 @@ class ModDatabase(
|
||||
|
||||
|
||||
fun syncGroupInfo(conversationInfo: MessagingGroupInfo) {
|
||||
executor.execute {
|
||||
executeAsync {
|
||||
try {
|
||||
database.execSQL("INSERT OR REPLACE INTO groups VALUES (?, ?, ?)", arrayOf(
|
||||
conversationInfo.conversationId,
|
||||
@@ -140,12 +143,12 @@ class ModDatabase(
|
||||
}
|
||||
|
||||
fun syncFriend(friend: FriendInfo) {
|
||||
executor.execute {
|
||||
executeAsync {
|
||||
try {
|
||||
database.execSQL("INSERT OR REPLACE INTO friends VALUES (?, ?, ?, ?, ?)", arrayOf(
|
||||
friend.userId,
|
||||
friend.displayName,
|
||||
friend.usernameForSorting!!.split("|")[1],
|
||||
friend.usernameForSorting!!,
|
||||
friend.bitmojiAvatarId,
|
||||
friend.bitmojiSelfieId
|
||||
))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.rhunk.snapenhance.ui.manager.sections.social
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -39,9 +40,9 @@ class AddFriendDialog(
|
||||
|
||||
|
||||
@Composable
|
||||
private fun ListCardEntry(name: String) {
|
||||
private fun ListCardEntry(name: String, modifier: Modifier = Modifier) {
|
||||
Card(
|
||||
modifier = Modifier.padding(5.dp),
|
||||
modifier = Modifier.padding(5.dp).then(modifier),
|
||||
) {
|
||||
Text(text = name, modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
@@ -108,14 +109,24 @@ class AddFriendDialog(
|
||||
Spacer(modifier = Modifier.padding(5.dp))
|
||||
}
|
||||
items(cachedGroups!!.size) {
|
||||
ListCardEntry(name = cachedGroups!![it].name)
|
||||
ListCardEntry(name = cachedGroups!![it].name, modifier = Modifier.clickable {
|
||||
context.bridgeService.triggerGroupSync(cachedGroups!![it].conversationId)
|
||||
context.modDatabase.executeAsync {
|
||||
section.onResumed()
|
||||
}
|
||||
})
|
||||
}
|
||||
item {
|
||||
Text(text = "Friends", fontSize = 20.sp)
|
||||
Spacer(modifier = Modifier.padding(5.dp))
|
||||
}
|
||||
items(cachedFriends!!.size) {
|
||||
ListCardEntry(name = cachedFriends!![it].displayName ?: cachedFriends!![it].mutableUsername)
|
||||
ListCardEntry(name = cachedFriends!![it].displayName ?: cachedFriends!![it].mutableUsername, modifier = Modifier.clickable {
|
||||
context.bridgeService.triggerFriendSync(cachedFriends!![it].userId)
|
||||
context.modDatabase.executeAsync {
|
||||
section.onResumed()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user