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