448 lines
19 KiB
Kotlin
448 lines
19 KiB
Kotlin
package com.gh.common.util
|
||
|
||
import android.content.Context
|
||
import android.content.Intent
|
||
import android.net.Uri
|
||
import android.os.Build
|
||
import android.os.Bundle
|
||
import android.text.TextUtils
|
||
import com.gh.base.BaseActivity
|
||
import com.gh.base.fragment.BaseFragment_TabLayout
|
||
import com.gh.common.AppExecutor
|
||
import com.gh.common.util.EntranceUtils.*
|
||
import com.gh.gamecenter.*
|
||
import com.gh.gamecenter.amway.AmwayActivity
|
||
import com.gh.gamecenter.category.CategoryDirectoryActivity
|
||
import com.gh.gamecenter.download.DownloadFragment.Companion.INDEX_UPDATE
|
||
import com.gh.gamecenter.entity.*
|
||
import com.gh.gamecenter.eventbus.EBReuse
|
||
import com.gh.gamecenter.eventbus.EBSkip
|
||
import com.gh.gamecenter.fragment.MainWrapperFragment
|
||
import com.gh.gamecenter.game.columncollection.detail.ColumnCollectionDetailActivity
|
||
import com.gh.gamecenter.manager.UserManager
|
||
import com.gh.gamecenter.mygame.PlayedGameActivity
|
||
import com.gh.gamecenter.personalhome.UserHomeActivity
|
||
import com.gh.gamecenter.qa.CommunityFragment
|
||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
|
||
import com.gh.gamecenter.qa.article.SimpleArticleListActivity
|
||
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
|
||
import com.gh.gamecenter.qa.column.detail.AskColumnDetailActivity
|
||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity
|
||
import com.gh.gamecenter.qa.subject.CommunitySubjectActivity
|
||
import com.gh.gamecenter.servers.GameServersActivity
|
||
import com.gh.gamecenter.subject.SubjectActivity
|
||
import com.gh.gamecenter.suggest.SuggestType
|
||
import com.gh.gamecenter.tag.TagsActivity
|
||
import com.gh.gamecenter.video.detail.VideoDetailActivity
|
||
import com.lightgame.utils.Util_System_ClipboardManager
|
||
import com.lightgame.utils.Utils
|
||
import org.greenrobot.eventbus.EventBus
|
||
|
||
/**
|
||
* 跳转用的方法
|
||
*/
|
||
object DirectUtils {
|
||
|
||
/**
|
||
* 跳转到特定页面,根据 [type] 决定跳转页面,[path] 为跳转前的页面名称
|
||
*/
|
||
@JvmStatic
|
||
fun directToSpecificPage(context: Context, type: String, link: String, text: String? = "", entrance: String? = null, path: String? = null) {
|
||
when (type) {
|
||
EntranceUtils.HOST_ARTICLE -> directToArticle(context, id = link, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_GAME -> directToGameDetail(context, id = link, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_GAME_DOWNLOAD -> directToGameDetail(context, id = link, entrance = entrance, autoDownload = true)
|
||
|
||
EntranceUtils.HOST_COLUMN -> directToSubject(context, id = link, subjectName = text, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_QUESTION -> directToQuestionDetail(context, id = link, entrance = entrance, path = path)
|
||
|
||
EntranceUtils.HOST_ANSWER -> directToAnswerDetail(context, id = link, entrance = entrance, path = path)
|
||
|
||
EntranceUtils.HOST_WEB -> directToWebView(context, url = link, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_DOWNLOAD -> directToDownloadManagerAndStartDownload(context, gameId = link, packageName = text, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_UPDATE -> directToDownloadManagerAndStartUpdate(context, gameId = link, packageName = text, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_LIBAO -> directToGiftDetail(context, giftId = link, entrance = entrance)
|
||
|
||
EntranceUtils.HOST_COMMUNITY -> directToCommunity(context, CommunityEntity(link, text!!))
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 跳转到特定页面,只支持App内部跳转
|
||
*/
|
||
@JvmStatic
|
||
fun directToLinkPage(context: Context, linkEntity: LinkEntity, entrance: String, path: String) {
|
||
when (linkEntity.type) {
|
||
"article", "news" -> {
|
||
NewsUtils.statNewsViews(context, linkEntity.link) // 统计阅读量
|
||
context.startActivity(NewsDetailActivity.getIntentById(context, linkEntity.link, BaseActivity.mergeEntranceAndPath(entrance, path)))
|
||
}
|
||
|
||
"game" -> GameDetailActivity.startGameDetailActivity(context, linkEntity.link, BaseActivity.mergeEntranceAndPath(entrance, path))
|
||
|
||
"column" -> SubjectActivity.startSubjectActivity(context, linkEntity.link, linkEntity.text, false, BaseActivity.mergeEntranceAndPath(entrance, path))
|
||
|
||
"question" -> context.startActivity(QuestionsDetailActivity.getIntent(context, linkEntity.link, entrance, path))
|
||
|
||
"answer" -> context.startActivity(AnswerDetailActivity.getIntent(context, linkEntity.link, entrance, path))
|
||
|
||
"community" -> directToCommunity(context, CommunityEntity(linkEntity.link!!, linkEntity.text!!))
|
||
|
||
"community_article" -> context.startActivity(ArticleDetailActivity.getIntent(context, linkEntity.community!!, linkEntity.link!!, entrance, path))
|
||
|
||
"community_column" -> directToCommunityColumn(context, linkEntity.community, linkEntity.link!!, entrance, path)
|
||
|
||
"community_special_column" -> context.startActivity(AskColumnDetailActivity.getIntentByColumnId(context, linkEntity.link, linkEntity.community!!, entrance, path))
|
||
|
||
"web", "inurl" -> directToWebView(context, url = linkEntity.link!!, entrance = BaseActivity.mergeEntranceAndPath(entrance, path))
|
||
|
||
"qq" -> directToQqConversation(context, linkEntity.link)
|
||
|
||
"outurl" -> directToExternalBrowser(context, linkEntity.link!!)
|
||
|
||
"qqqun" -> directToQqGroup(context, linkEntity.link!!)
|
||
|
||
"tag" -> context.startActivity(TagsActivity.getIntent(context, linkEntity.text!!, entrance, path))
|
||
|
||
"all_community_article" -> {
|
||
context.startActivity(SimpleArticleListActivity.getIntent(
|
||
context,
|
||
linkEntity.link ?: "",
|
||
entrance,
|
||
path))
|
||
}
|
||
|
||
"category" -> {
|
||
context.startActivity(CategoryDirectoryActivity.getIntent(context, linkEntity.link!!, linkEntity.text!!))
|
||
}
|
||
|
||
"block" -> {
|
||
context.startActivity(BlockActivity.getIntent(context, SubjectRecommendEntity(
|
||
link = linkEntity.link,
|
||
text = linkEntity.text,
|
||
name = linkEntity.name,
|
||
display = linkEntity.display ?: Display())))
|
||
}
|
||
|
||
"column_collection" -> directToColumnCollection(context, linkEntity.link!!, -1, entrance)
|
||
|
||
"server" -> {
|
||
context.startActivity(GameServersActivity.getIntent(context, entrance, path))
|
||
}
|
||
|
||
"top_game_comment" -> directToAmway(context, null, entrance, path)
|
||
|
||
"wechat_bind" -> context.startActivity(WebActivity.getBindWechatIntent(context))
|
||
|
||
else -> DialogUtils.showLowVersionDialog(context)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 跳转至专题合集
|
||
*/
|
||
fun directToColumnCollection(context: Context, id: String, position: Int = -1, entrance: String) {
|
||
context.startActivity(ColumnCollectionDetailActivity.getIntent(context, id, position, entrance))
|
||
}
|
||
|
||
/**
|
||
* 跳转到新闻详情
|
||
*/
|
||
@JvmStatic
|
||
fun directToArticle(context: Context, id: String, entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, NewsDetailActivity::class.java.simpleName)
|
||
bundle.putString(KEY_NEWSID, id)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
/**
|
||
* 跳转至个人主页
|
||
*/
|
||
@JvmStatic
|
||
fun directToHomeActivity(context: Context, userId: String?, entrance: String? = null, path: String? = null) {
|
||
context.startActivity(UserHomeActivity.getIntent(context, userId ?: "", entrance, path))
|
||
}
|
||
|
||
/**
|
||
* 回到首页
|
||
*/
|
||
fun directToMainActivity(context: Context) {
|
||
val intent = Intent(context, MainActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP }
|
||
context.startActivity(intent)
|
||
}
|
||
|
||
/**
|
||
* 跳转到游戏详情
|
||
*/
|
||
@JvmStatic
|
||
fun directToGameDetail(context: Context, id: String, entrance: String? = null, autoDownload: Boolean? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, GameDetailActivity::class.java.simpleName)
|
||
bundle.putString(KEY_GAMEID, id)
|
||
bundle.putBoolean(KEY_AUTO_DOWNLOAD, autoDownload ?: false)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
// 跳转至用户玩过的游戏
|
||
fun directToPlayedGame(context: Context, userId: String, entrance: String = "", path: String = "") {
|
||
context.startActivity(PlayedGameActivity.getIntent(context, userId, entrance, path))
|
||
}
|
||
|
||
// 专栏
|
||
@JvmStatic
|
||
fun directToSubject(context: Context, id: String, subjectName: String? = "", entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
val subjectData = SubjectData(subjectId = id, subjectName = subjectName, isOrder = false)
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, SubjectActivity::class.java.name)
|
||
bundle.putParcelable(EntranceUtils.KEY_SUBJECT_DATA, subjectData)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
// 反馈
|
||
@JvmStatic
|
||
fun directToFeedback(context: Context, content: String? = null, entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, SuggestionActivity::class.java.simpleName)
|
||
bundle.putString(KEY_CONTENT, content)
|
||
bundle.putString(KEY_SUGGEST_HINT_TYPE, KEY_PLUGIN)
|
||
bundle.putSerializable(EntranceUtils.KEY_SUGGESTTYPE, SuggestType.gameQuestion)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToDownloadManager(context: Context, entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, DownloadManagerActivity.TAG)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
/**
|
||
* 跳转到下载管理器并开始下载 [gameId] 和 [packageName] 用于唯一确定一个下载文件
|
||
*/
|
||
@JvmStatic
|
||
fun directToDownloadManagerAndStartDownload(context: Context, gameId: String? = "", packageName: String? = "", entrance: String? = null) {
|
||
DownloadHelper.createABrandNewDownloadTaskQuietly(gameId, packageName) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, DownloadManagerActivity.TAG)
|
||
bundle.putString(KEY_GAMEID, gameId)
|
||
bundle.putString(KEY_PACKAGENAME, packageName)
|
||
bundle.putBoolean(KEY_AUTO_DOWNLOAD, true)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToDownloadManagerAndStartUpdate(context: Context, gameId: String? = "", packageName: String? = "", entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, DownloadManagerActivity.TAG)
|
||
bundle.putString(KEY_GAMEID, gameId)
|
||
bundle.putString(KEY_PACKAGENAME, packageName)
|
||
bundle.putInt(BaseFragment_TabLayout.PAGE_INDEX, INDEX_UPDATE)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToToolbox(context: Context, gameId: String, toolboxUrl: String, entrance: String = ENTRANCE_BROWSER) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance)
|
||
bundle.putString(KEY_TO, ToolBoxActivity::class.java.simpleName)
|
||
bundle.putString(KEY_GAMEID, gameId)
|
||
bundle.putString(KEY_URL, toolboxUrl)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToAnswerDetail(context: Context, id: String, entrance: String? = null, path: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, AnswerDetailActivity::class.java.name)
|
||
bundle.putString(KEY_PATH, path)
|
||
bundle.putString(KEY_ANSWER_ID, id)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToQuestionDetail(context: Context, id: String, entrance: String? = null, path: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, QuestionsDetailActivity::class.java.name)
|
||
bundle.putString(KEY_PATH, path)
|
||
bundle.putString(KEY_QUESTIONS_ID, id)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToWebView(context: Context, url: String, entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, WebActivity::class.java.simpleName)
|
||
bundle.putString(EntranceUtils.KEY_URL, url)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
// 个人-系统消息
|
||
@JvmStatic
|
||
fun directToOfficialNotification(context: Context, entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, MessageKeFuActivity::class.java.simpleName)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToExternalBrowser(context: Context, url: String) {
|
||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||
context.startActivity(browserIntent)
|
||
}
|
||
|
||
// 跳转 QQ
|
||
@JvmStatic
|
||
fun directToQqConversation(context: Context, qqNumber: String? = null) {
|
||
var qq = qqNumber
|
||
|
||
if (TextUtils.isEmpty(qq)) {
|
||
qq = "2586716223"
|
||
}
|
||
if (ShareUtils.isQQClientAvailable(context)) {
|
||
// 安装了 QQ 直接调用QQ,打开手机QQ进行会话 默认 QQ 号:2586716223
|
||
val chatType: String
|
||
if (qq!!.startsWith("400") || qq.startsWith("800")) {
|
||
chatType = "crm"
|
||
} else {
|
||
chatType = "wpa"
|
||
}
|
||
val str = "mqqwpa://im/chat?chat_type=$chatType&uin=$qq&version=1&src_type=web"
|
||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(str)))
|
||
} else {
|
||
// 没有安装QQ 复制账号
|
||
Util_System_ClipboardManager.setText(context, qq)
|
||
Utils.toast(context, "已复制 QQ $qq")
|
||
}
|
||
}
|
||
|
||
// 跳转 QQ 群
|
||
@JvmStatic
|
||
fun directToQqGroup(context: Context, groupNumber: String? = null): Boolean {
|
||
val intent = Intent()
|
||
intent.data = Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D$groupNumber")
|
||
// 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||
try {
|
||
context.startActivity(intent)
|
||
return true
|
||
} catch (e: Exception) {
|
||
// 未安装手Q或安装的版本不支持
|
||
return false
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 跳转到 礼包详情
|
||
*/
|
||
@JvmStatic
|
||
fun directToGiftDetail(context: Context, giftId: String, entrance: String? = null) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, LibaoDetailActivity::class.java.simpleName)
|
||
bundle.putString(EntranceUtils.KEY_ID, giftId)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
/**
|
||
* 切换到社区页面
|
||
*/
|
||
@JvmStatic
|
||
fun directToCommunity(context: Context, community: CommunityEntity?) {
|
||
if (MainActivity::class.java.name != RunningUtils.getTopActivity(context)) {
|
||
val intent = Intent(context, MainActivity::class.java)
|
||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||
context.startActivity(intent)
|
||
}
|
||
UserManager.getInstance().setCommunityData(community)
|
||
|
||
// 这里换个线程操作是为了做一点延时
|
||
AppExecutor.ioExecutor.execute {
|
||
EventBus.getDefault().post(EBSkip(MainActivity.EB_SKIP_MAIN, MainWrapperFragment.INDEX_ASK))
|
||
EventBus.getDefault().post(EBReuse(CommunityFragment.EB_RETRY_PAGE))
|
||
}
|
||
}
|
||
|
||
@JvmStatic
|
||
fun directToCommunityArticle(context: Context, articleId: String?, communityId: String?, entrance: String?, path: String?) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_PATH, path)
|
||
bundle.putString(KEY_TO, ArticleDetailActivity::class.java.name)
|
||
bundle.putString(KEY_COMMUNITY_ARTICLE_ID, articleId)
|
||
bundle.putParcelable(KEY_COMMUNITY_DATA, CommunityEntity(id = communityId!!))
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
/**
|
||
* 跳转到社区专题
|
||
*/
|
||
@JvmStatic
|
||
fun directToCommunityColumn(context: Context, community: CommunityEntity?, subjectId: String, entrance: String?, path: String?) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_PATH, path)
|
||
bundle.putString(KEY_TO, CommunitySubjectActivity::class.java.name)
|
||
bundle.putString(KEY_ENTRANCE, BaseActivity.mergeEntranceAndPath(entrance, path))
|
||
bundle.putString(KEY_COLUMN_ID, subjectId)
|
||
bundle.putParcelable(KEY_COMMUNITY_DATA, community)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
/**
|
||
* @param fromLocation 可见 [VideoDetailContainerViewModel.Location]
|
||
*/
|
||
@JvmStatic
|
||
fun directToVideoDetail(context: Context, videoId: String, fromLocation: String, showComment: Boolean = false, entrance: String? = null, path: String? = "") {
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, VideoDetailActivity::class.java.name)
|
||
bundle.putString(KEY_PATH, path)
|
||
bundle.putString(KEY_ID, videoId)
|
||
bundle.putString(KEY_LOCATION, fromLocation)
|
||
bundle.putBoolean(KEY_SHOW_COMMENT, showComment)
|
||
jumpActivity(context, bundle)
|
||
} else {
|
||
DialogUtils.showLowSystemVersionDialog(context)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 跳转至安利墙
|
||
* @param fixedTopAmwayCommentId 需要置顶的安利Id
|
||
*/
|
||
@JvmStatic
|
||
fun directToAmway(context: Context, fixedTopAmwayCommentId: String? = null, entrance: String? = null, path: String? = "") {
|
||
val bundle = Bundle()
|
||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||
bundle.putString(KEY_TO, AmwayActivity::class.java.name)
|
||
bundle.putString(KEY_ID, fixedTopAmwayCommentId)
|
||
bundle.putString(KEY_PATH, path)
|
||
jumpActivity(context, bundle)
|
||
}
|
||
|
||
/**
|
||
* 跳转至徽章墙
|
||
*/
|
||
@JvmStatic
|
||
fun directToBadgeWall(context: Context, userId: String?, name: String?, icon: String?) {
|
||
context.startActivity(WebActivity.getBadgeCenterIntent(context, userId, name, icon))
|
||
}
|
||
} |