From b0bffd25330519b7b538bffcd9da92a5ae193b8f Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:04:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E7=89=88=E5=9B=9E=E8=B4=B4?= =?UTF-8?q?=E9=A3=8E=E9=99=A9=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/ui/page/reply/ReplyPage.kt | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt index 902705af..afd09686 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt @@ -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