feat: 发贴/回贴前提示风险、跳转官方 App

This commit is contained in:
HuanCheng65 2022-06-03 20:05:29 +08:00
parent 44aecb68bc
commit 6b7ff824ca
10 changed files with 139 additions and 17 deletions

View File

@ -25,6 +25,11 @@
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.miui.personalassistant.permission.FAVORITE" /> <uses-permission android:name="com.miui.personalassistant.permission.FAVORITE" />
<queries>
<package android:name="com.baidu.tieba" />
<package android:name="com.baidu.tieba_mini" />
</queries>
<supports-screens <supports-screens
android:anyDensity="true" android:anyDensity="true"
android:largeScreens="true" android:largeScreens="true"

View File

@ -4,6 +4,7 @@ package com.huanchengfly.tieba.post.activities
import android.animation.Animator import android.animation.Animator
import android.animation.AnimatorListenerAdapter import android.animation.AnimatorListenerAdapter
import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
@ -60,6 +61,7 @@ import com.huanchengfly.tieba.post.interfaces.Refreshable
import com.huanchengfly.tieba.post.interfaces.ScrollTopable import com.huanchengfly.tieba.post.interfaces.ScrollTopable
import com.huanchengfly.tieba.post.models.PhotoViewBean import com.huanchengfly.tieba.post.models.PhotoViewBean
import com.huanchengfly.tieba.post.models.database.History import com.huanchengfly.tieba.post.models.database.History
import com.huanchengfly.tieba.post.toastShort
import com.huanchengfly.tieba.post.ui.animation.addMaskAnimation import com.huanchengfly.tieba.post.ui.animation.addMaskAnimation
import com.huanchengfly.tieba.post.ui.animation.addZoomAnimation import com.huanchengfly.tieba.post.ui.animation.addZoomAnimation
import com.huanchengfly.tieba.post.ui.animation.buildPressAnimator import com.huanchengfly.tieba.post.ui.animation.buildPressAnimator
@ -427,12 +429,35 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
} }
} }
else -> { else -> {
if ("0" != mDataBean!!.anti?.ifPost) { if (appPreferences.postOrReplyWarning) {
NavigationHelper.newInstance(this).navigationByData(NavigationHelper.ACTION_THREAD_POST, forumName) showDialog {
} else { setTitle(R.string.title_thread_post_recommend)
if (!TextUtils.isEmpty(mDataBean!!.anti?.forbidInfo)) { setMessage(R.string.message_thread_post_recommend)
Toast.makeText(this, mDataBean!!.anti?.forbidInfo, Toast.LENGTH_SHORT).show() setNegativeButton(R.string.btn_cancel_post, null)
setNeutralButton(R.string.btn_continue_post) { _, _ ->
launchPost()
} }
setPositiveButton(R.string.button_official_client_post) { _, _ ->
try {
if (isOfficialClientInstalled()) {
startActivity(
Intent(Intent.ACTION_VIEW).setData(
Uri.parse(
"com.baidu.tieba://unidispatch/frs?obj_locate=frs_top_diverse&obj_source=wise&obj_name=index&obj_param2=chrome&has_token=0&qd=scheme&refer=tieba.baidu.com&wise_sample_id=3000232_2&fr=bpush&kw=$forumName"
)
)
)
} else {
toastShort(R.string.toast_official_client_not_install)
}
} catch (e: ActivityNotFoundException) {
toastShort(R.string.toast_official_client_not_install)
}
finish()
}
}
} else {
launchPost()
} }
} }
} }
@ -475,7 +500,14 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
override fun onResponse(call: Call<LikeForumResultBean>, response: Response<LikeForumResultBean>) { override fun onResponse(call: Call<LikeForumResultBean>, response: Response<LikeForumResultBean>) {
mDataBean!!.forum?.isLike = "1" mDataBean!!.forum?.isLike = "1"
Toast.makeText(this@ForumActivity, getString(R.string.toast_like_success, response.body()!!.info?.memberSum), Toast.LENGTH_SHORT).show() Toast.makeText(
this@ForumActivity,
getString(
R.string.toast_like_success,
response.body()!!.info?.memberSum
),
Toast.LENGTH_SHORT
).show()
refreshHeaderView() refreshHeaderView()
refreshForumInfo() refreshForumInfo()
} }
@ -485,6 +517,16 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
} }
} }
private fun launchPost() {
if ("0" != mDataBean!!.anti?.ifPost) {
WebViewActivity.launch(this, "https://tieba.baidu.com/mo/q/thread_post?word=$forumName")
} else {
if (!TextUtils.isEmpty(mDataBean!!.anti?.forbidInfo)) {
Toast.makeText(this, mDataBean!!.anti?.forbidInfo, Toast.LENGTH_SHORT).show()
}
}
}
private fun getNumStr(num: String): String { private fun getNumStr(num: String): String {
val long = num.toLong() val long = num.toLong()
if (long > 9999) { if (long > 9999) {

View File

@ -1,8 +1,11 @@
package com.huanchengfly.tieba.post.activities package com.huanchengfly.tieba.post.activities
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.graphics.Color import android.graphics.Color
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextUtils import android.text.TextUtils
@ -41,13 +44,13 @@ import com.huanchengfly.tieba.post.interfaces.UploadCallback
import com.huanchengfly.tieba.post.models.PhotoInfoBean import com.huanchengfly.tieba.post.models.PhotoInfoBean
import com.huanchengfly.tieba.post.models.ReplyInfoBean import com.huanchengfly.tieba.post.models.ReplyInfoBean
import com.huanchengfly.tieba.post.models.database.Draft import com.huanchengfly.tieba.post.models.database.Draft
import com.huanchengfly.tieba.post.toastShort
import com.huanchengfly.tieba.post.utils.* import com.huanchengfly.tieba.post.utils.*
import com.huanchengfly.tieba.post.widgets.edittext.widget.UndoableEditText import com.huanchengfly.tieba.post.widgets.edittext.widget.UndoableEditText
import com.huanchengfly.tieba.post.widgets.theme.TintConstraintLayout import com.huanchengfly.tieba.post.widgets.theme.TintConstraintLayout
import com.huanchengfly.tieba.post.widgets.theme.TintImageView import com.huanchengfly.tieba.post.widgets.theme.TintImageView
import com.zhihu.matisse.Matisse import com.zhihu.matisse.Matisse
import org.litepal.LitePal.where import org.litepal.LitePal.where
import java.util.*
class ReplyActivity : BaseActivity(), View.OnClickListener { class ReplyActivity : BaseActivity(), View.OnClickListener {
@BindView(R.id.activity_reply_edit_text) @BindView(R.id.activity_reply_edit_text)
@ -107,6 +110,37 @@ class ReplyActivity : BaseActivity(), View.OnClickListener {
window.setBackgroundDrawableResource(R.drawable.bg_trans) window.setBackgroundDrawableResource(R.drawable.bg_trans)
initData() initData()
initView() initView()
if (appPreferences.postOrReplyWarning) showDialog {
setTitle(R.string.title_dialog_reply_warning)
setMessage(R.string.message_dialog_reply_warning)
setNegativeButton(R.string.btn_cancel_reply) { _, _ ->
finish()
}
setNeutralButton(R.string.btn_continue_reply, null)
setPositiveButton(R.string.button_official_client_reply) { _, _ ->
try {
if (isOfficialClientInstalled()) {
startActivity(Intent(ACTION_VIEW).setData(getDispatchUri()))
} else {
toastShort(R.string.toast_official_client_not_install)
}
} catch (e: ActivityNotFoundException) {
toastShort(R.string.toast_official_client_not_install)
}
finish()
}
}
}
private fun getDispatchUri(): Uri? {
if (replyInfoBean == null) {
return null
}
return if (replyInfoBean!!.pid != 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=${replyInfoBean!!.pid}&is_anchor_to_comment=1&comment_sort_type=0&fr=bpush&tid=${replyInfoBean!!.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=${replyInfoBean!!.threadId}")
}
} }
private fun destroyWebView() { private fun destroyWebView() {

View File

@ -749,14 +749,16 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
} }
} }
fun invalidateAgreeStatus() { private fun invalidateAgreeStatus() {
val color = ThemeUtils.getColorByAttr(this, R.attr.colorAccent) val color = ThemeUtils.getColorByAttr(this, R.attr.colorAccent)
if (agreeBtn.imageTintList != null) { if (agreeBtn.imageTintList != null) {
val agreeBtnAnimator: ValueAnimator val agreeBtnAnimator: ValueAnimator
val agreeNumAnimator: ValueAnimator val agreeNumAnimator: ValueAnimator
if (agree) { if (agree) {
agreeNumAnimator = colorAnim(agreeNumTextView, ThemeUtil.getTextColor(this@ThreadActivity), color) agreeNumAnimator =
agreeBtnAnimator = colorAnim(agreeBtn, ThemeUtil.getTextColor(this@ThreadActivity), color) colorAnim(agreeNumTextView, ThemeUtil.getTextColor(this@ThreadActivity), color)
agreeBtnAnimator =
colorAnim(agreeBtn, ThemeUtil.getTextColor(this@ThreadActivity), color)
agreeNumAnimator.addListener(object : AnimatorListenerAdapter() { agreeNumAnimator.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) { override fun onAnimationEnd(animation: Animator) {
agreeNumTextView.setTextColor(color) agreeNumTextView.setTextColor(color)

View File

@ -81,6 +81,8 @@ open class AppPreferencesUtils(context: Context) {
key = "oksign_slow_mode" key = "oksign_slow_mode"
) )
var postOrReplyWarning by SharedPreferenceDelegates.boolean(defaultValue = true)
var radius by SharedPreferenceDelegates.int(defaultValue = 8) var radius by SharedPreferenceDelegates.int(defaultValue = 8)
var signDay by SharedPreferenceDelegates.int(defaultValue = -1, key = "sign_day") var signDay by SharedPreferenceDelegates.int(defaultValue = -1, key = "sign_day")

View File

@ -0,0 +1,9 @@
package com.huanchengfly.tieba.post.utils
import com.huanchengfly.tieba.post.BaseApplication
val officialClientPackages = arrayOf("com.baidu.tieba", "com.baidu.tieba_mini")
fun isOfficialClientInstalled(): Boolean {
return BaseApplication.instance.isAnyPackageInstalled(officialClientPackages)
}

View File

@ -0,0 +1,13 @@
package com.huanchengfly.tieba.post.utils
import android.content.Context
fun Context.isPackageInstalled(packageName: String): Boolean {
return packageManager.getPackageInfo(packageName, 0) != null
}
fun Context.isAnyPackageInstalled(packages: Array<String>): Boolean {
return packages.any {
isPackageInstalled(it)
}
}

View File

@ -2,8 +2,9 @@
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path <path
android:fillColor="#FF000000" android:fillColor="@android:color/white"
android:pathData="M4.47,21h15.06c1.54,0 2.5,-1.67 1.73,-3L13.73,4.99c-0.77,-1.33 -2.69,-1.33 -3.46,0L2.74,18c-0.77,1.33 0.19,3 1.73,3zM12,14c-0.55,0 -1,-0.45 -1,-1v-2c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v2c0,0.55 -0.45,1 -1,1zM13,18h-2v-2h2v2z" /> android:pathData="M4.47,21h15.06c1.54,0 2.5,-1.67 1.73,-3L13.73,4.99c-0.77,-1.33 -2.69,-1.33 -3.46,0L2.74,18c-0.77,1.33 0.19,3 1.73,3zM12,14c-0.55,0 -1,-0.45 -1,-1v-2c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v2c0,0.55 -0.45,1 -1,1zM13,18h-2v-2h2v2z" />
</vector> </vector>

View File

@ -401,12 +401,7 @@
<string name="title_oksign_fail">签到失败</string> <string name="title_oksign_fail">签到失败</string>
<string name="text_login_first">请先登录</string> <string name="text_login_first">请先登录</string>
<string name="update_tip_loading">正在检查更新</string> <string name="update_tip_loading">正在检查更新</string>
<string name="title_thread_post_recommend">建议您使用其他途径发贴</string>
<string name="message_thread_post_recommend">继续使用本软件发贴可能会出现发贴失败、发贴被隐藏甚至封号等异常情况,建议您使用官方客户端或 PC 网页版发贴</string>
<string name="button_official_client_post">使用官方客户端发贴</string>
<string name="toast_start_failed">启动失败</string> <string name="toast_start_failed">启动失败</string>
<string name="button_pc_web_post">使用 PC 网页版发贴</string>
<string name="button_lite_post">继续使用本软件发贴</string>
<string name="permission_name_clipboard_copy">写入剪贴板</string> <string name="permission_name_clipboard_copy">写入剪贴板</string>
<string name="title_history_thread_user">%1$s的贴子</string> <string name="title_history_thread_user">%1$s的贴子</string>
<string name="title_history_today">今天早些时候</string> <string name="title_history_today">今天早些时候</string>
@ -490,4 +485,17 @@
<string name="snackbar_error">出现了一点小问题(%1$d)</string> <string name="snackbar_error">出现了一点小问题(%1$d)</string>
<string name="toast_ci_version_enabled">已启用接收自动构建版本更新(需要 App Center 账号)</string> <string name="toast_ci_version_enabled">已启用接收自动构建版本更新(需要 App Center 账号)</string>
<string name="toast_ci_version_disabled">已禁用接收自动构建版本更新(需要 App Center 账号)</string> <string name="toast_ci_version_disabled">已禁用接收自动构建版本更新(需要 App Center 账号)</string>
<string name="title_thread_post_recommend">建议使用官方途径发贴</string>
<string name="message_thread_post_recommend">使用本 App 发贴可能会出现发贴失败、被吞等问题,甚至导致账户永久封禁等严重后果。\n我们建议你使用官方途径进行回贴。</string>
<string name="button_official_client_post">使用官方客户端发贴</string>
<string name="btn_cancel_post">放弃发贴</string>
<string name="btn_continue_post">无视风险,继续发帖</string>
<string name="title_dialog_reply_warning">建议使用官方途径回贴</string>
<string name="message_dialog_reply_warning">使用本 App 回贴可能会遇到回贴失败、需验证码等问题,甚至导致账户永久封禁等严重后果。\n我们建议你使用官方途径进行回贴。</string>
<string name="btn_cancel_reply">放弃回贴</string>
<string name="btn_continue_reply">无视风险,继续回贴</string>
<string name="button_official_client_reply">使用官方客户端回贴</string>
<string name="toast_official_client_not_install">未安装官方版客户端</string>
<string name="button_pc_web_post">使用 PC 网页版发贴</string>
<string name="title_post_or_reply_warning">发贴回贴风险提示</string>
</resources> </resources>

View File

@ -112,6 +112,12 @@
android:key="hideHotMessageList" android:key="hideHotMessageList"
android:title="@string/title_hide_hot_message_list" /> android:title="@string/title_hide_hot_message_list" />
<SwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_round_warning"
android:key="postOrReplyWarning"
android:title="@string/title_post_or_reply_warning" />
<ListPreference <ListPreference
android:defaultValue="post" android:defaultValue="post"
android:entries="@array/forum_fab_function_name_values" android:entries="@array/forum_fab_function_name_values"