feat: 新版回贴风险警告

This commit is contained in:
HuanCheng65 2023-07-21 16:04:21 +08:00
parent 5156684276
commit b0bffd2533
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
1 changed files with 61 additions and 0 deletions

View File

@ -1,5 +1,8 @@
package com.huanchengfly.tieba.post.ui.page.reply
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.util.Log
import android.view.View
@ -94,7 +97,11 @@ import com.huanchengfly.tieba.post.ui.page.reply.ReplyPanelType.EMOJI
import com.huanchengfly.tieba.post.ui.page.reply.ReplyPanelType.IMAGE
import com.huanchengfly.tieba.post.ui.page.reply.ReplyPanelType.NONE
import com.huanchengfly.tieba.post.ui.utils.imeNestedScroll
import com.huanchengfly.tieba.post.ui.widgets.compose.Dialog
import com.huanchengfly.tieba.post.ui.widgets.compose.DialogNegativeButton
import com.huanchengfly.tieba.post.ui.widgets.compose.DialogPositiveButton
import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalDivider
import com.huanchengfly.tieba.post.ui.widgets.compose.rememberDialogState
import com.huanchengfly.tieba.post.ui.widgets.edittext.widget.UndoableEditText
import com.huanchengfly.tieba.post.utils.AccountUtil
import com.huanchengfly.tieba.post.utils.Emoticon
@ -610,6 +617,60 @@ fun ReplyPage(
}
}
}
fun getDispatchUri(): Uri {
return if (postId != null) {
Uri.parse("com.baidu.tieba://unidispatch/pb?obj_locate=comment_lzl_cut_guide&obj_source=wise&obj_name=index&obj_param2=chrome&has_token=0&qd=scheme&refer=tieba.baidu.com&wise_sample_id=3000232_2&hightlight_anchor_pid=${postId}&is_anchor_to_comment=1&comment_sort_type=0&fr=bpush&tid=${threadId}")
} else {
Uri.parse("com.baidu.tieba://unidispatch/pb?obj_locate=pb_reply&obj_source=wise&obj_name=index&obj_param2=chrome&has_token=0&qd=scheme&refer=tieba.baidu.com&wise_sample_id=3000232_2-99999_9&fr=bpush&tid=${threadId}")
}
}
fun launchOfficialApp() {
val intent = Intent(Intent.ACTION_VIEW).setData(getDispatchUri())
val resolveInfos =
context.packageManager.queryIntentActivities(
intent,
PackageManager.MATCH_DEFAULT_ONLY
).filter { it.activityInfo.packageName != context.packageName }
try {
if (resolveInfos.isNotEmpty()) {
context.startActivity(intent)
} else {
context.toastShort(R.string.toast_official_client_not_install)
}
} catch (e: ActivityNotFoundException) {
context.toastShort(R.string.toast_official_client_not_install)
}
}
val warningDialogState = rememberDialogState()
Dialog(
dialogState = warningDialogState,
buttons = {
DialogPositiveButton(
text = stringResource(id = R.string.button_official_client_reply),
onClick = { launchOfficialApp() }
)
DialogNegativeButton(text = stringResource(id = R.string.btn_continue_reply))
DialogNegativeButton(
text = stringResource(id = R.string.btn_cancel_reply),
onClick = { navigator.navigateUp() }
)
},
title = { Text(text = stringResource(id = R.string.title_dialog_reply_warning)) },
) {
Text(
text = stringResource(id = R.string.message_dialog_reply_warning),
modifier = Modifier.padding(horizontal = 24.dp)
)
}
LaunchedEffect(Unit) {
if (context.appPreferences.postOrReplyWarning) {
warningDialogState.show()
}
}
}
@Composable