424 lines
20 KiB
Kotlin
424 lines
20 KiB
Kotlin
package com.gh.common
|
||
|
||
import android.content.Context
|
||
import android.content.Intent
|
||
import android.net.Uri
|
||
import android.text.TextUtils
|
||
import android.util.Base64
|
||
import com.gh.common.util.*
|
||
import com.gh.common.util.DirectUtils.directToFeedback
|
||
import com.gh.common.util.DirectUtils.directToGameDetailVideoStreaming
|
||
import com.gh.common.util.DirectUtils.directToGameServerCalendar
|
||
import com.gh.common.util.DirectUtils.directToGameVideo
|
||
import com.gh.common.util.DirectUtils.directToLinkPage
|
||
import com.gh.common.util.DirectUtils.directToQa
|
||
import com.gh.common.util.DirectUtils.directToVideoDetail
|
||
import com.gh.common.util.GsonUtils.gson
|
||
import com.gh.gamecenter.LibaoDetailActivity
|
||
import com.gh.gamecenter.MainActivity
|
||
import com.gh.gamecenter.NewsDetailActivity
|
||
import com.gh.gamecenter.WebActivity
|
||
import com.gh.gamecenter.entity.*
|
||
import com.gh.gamecenter.subject.SubjectActivity
|
||
import com.gh.gamecenter.video.detail.VideoDetailContainerViewModel
|
||
import com.lightgame.utils.Utils
|
||
import java.nio.charset.Charset
|
||
|
||
object DefaultUrlHandler {
|
||
|
||
@JvmStatic
|
||
fun interceptUrl(context: Context, url: String, entrance: String): Boolean {
|
||
val uri = Uri.parse(url)
|
||
if ("ghzhushou" == uri.scheme) {
|
||
Utils.log("url = $url")
|
||
Utils.log("url = " + uri.scheme!!)
|
||
val host = uri.host
|
||
val path = uri.path
|
||
var id = ""
|
||
if (!TextUtils.isEmpty(path)) {
|
||
id = path!!.substring(1)
|
||
}
|
||
val intent: Intent
|
||
when (host) {
|
||
"article" -> context.startActivity(NewsDetailActivity.getIntentById(context, id, entrance))
|
||
|
||
"game" -> DirectUtils.directToGameDetail(context, id = id, tab = uri.getQueryParameter("to"), autoDownload = uri.getQueryParameter("auto_download") == "true", entrance = entrance)
|
||
|
||
"column" -> SubjectActivity.startSubjectActivity(context, id, uri.getQueryParameter("name"), false, entrance)
|
||
|
||
"libao" -> context.startActivity(LibaoDetailActivity.getIntentById(context, id, entrance))
|
||
|
||
"qq" -> try {
|
||
DirectUtils.directToQqConversation(context, id)
|
||
} catch (e: Throwable) {
|
||
Utils.toast(context, "请检查是否已经安装手机QQ")
|
||
e.printStackTrace()
|
||
}
|
||
|
||
EntranceUtils.HOST_QQ_QUN -> {
|
||
val key = uri.getQueryParameter("key")
|
||
if (!DirectUtils.directToQqGroup(context, key)) {
|
||
Utils.toast(context, "请检查是否已经安装手机QQ")
|
||
}
|
||
}
|
||
|
||
"inurl" -> {
|
||
intent = Intent(context, WebActivity::class.java)
|
||
intent.putExtra(EntranceUtils.KEY_URL, uri.getQueryParameter("url"))
|
||
context.startActivity(intent)
|
||
}
|
||
|
||
"outurl" -> {
|
||
intent = Intent()
|
||
intent.action = Intent.ACTION_VIEW
|
||
intent.data = Uri.parse(uri.getQueryParameter("url"))
|
||
try {
|
||
context.startActivity(intent)
|
||
} catch (e: Exception) {
|
||
Utils.toast(context, "请检查是否已经安装手机浏览器")
|
||
e.printStackTrace()
|
||
}
|
||
|
||
}
|
||
"question" -> DirectUtils.directToQuestionDetail(context, id, entrance, "文章链接")
|
||
|
||
"community" -> {
|
||
val community = CommunityEntity()
|
||
community.id = id
|
||
community.name = uri.getQueryParameter("name") ?: ""
|
||
DirectUtils.directToCommunity(context, community)
|
||
}
|
||
|
||
"community_column" -> {
|
||
val community = CommunityEntity()
|
||
community.id = uri.getQueryParameter("community_id") ?: ""
|
||
community.name = uri.getQueryParameter("community_name") ?: ""
|
||
val columnId = uri.getQueryParameter("column_id") ?: ""
|
||
DirectUtils.directToCommunityColumn(context, community, columnId, entrance, "文章链接")
|
||
}
|
||
|
||
"answer" -> DirectUtils.directToAnswerDetail(context, id, entrance, "文章链接")
|
||
|
||
"communities" -> {
|
||
// ghzhushou://communities/5a32405b2397ab000f688de3/articles/5c99d262c140b321564f04e3
|
||
var communityId = ""
|
||
var type = ""
|
||
var typeId = ""
|
||
val split = id.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||
for (text in split) {
|
||
if (TextUtils.isEmpty(communityId)) {
|
||
communityId = text
|
||
continue
|
||
}
|
||
if (TextUtils.isEmpty(type)) {
|
||
type = text
|
||
continue
|
||
}
|
||
if (TextUtils.isEmpty(typeId)) {
|
||
typeId = text
|
||
}
|
||
}
|
||
if ("articles" == type) {
|
||
DirectUtils.directToCommunityArticle(
|
||
context, typeId, communityId,
|
||
entrance, "文章链接")
|
||
}
|
||
}
|
||
EntranceUtils.HOST_UPLOAD_VIDEO -> {
|
||
val titleParameter = uri.getQueryParameter("title")
|
||
val title = if (titleParameter.isNullOrEmpty()) "" else "#$titleParameter#"
|
||
val categoryId = uri.getQueryParameter("category_id") ?: ""
|
||
val link = uri.getQueryParameter("link") ?: ""
|
||
val gameId = uri.getQueryParameter("gameId") ?: ""
|
||
val gameName = uri.getQueryParameter("gameName") ?: ""
|
||
val tagActivityId = uri.getQueryParameter("tagActivityId") ?: ""
|
||
val tagActivityName = uri.getQueryParameter("tagActivityName") ?: ""
|
||
val linkEntity = VideoLinkEntity(title, categoryId, link, tagActivityId, tagActivityName)
|
||
val simpleGameEntity = SimpleGameEntity(gameId, gameName)
|
||
CheckLoginUtils.checkLogin(context, null, true, EntranceUtils.ENTRANCE_BROWSER) {
|
||
DirectUtils.directToVideoManager(context, linkEntity, simpleGameEntity, EntranceUtils.ENTRANCE_BROWSER, "")
|
||
}
|
||
}
|
||
EntranceUtils.HOST_USERHOME -> {
|
||
val position = uri.getQueryParameter("position")
|
||
DirectUtils.directToHomeActivity(context, id, if (position.isNullOrEmpty()) -1 else position.toInt(), entrance, "")
|
||
}
|
||
EntranceUtils.HOST_VIDEO_MORE -> {
|
||
val referer = uri.getQueryParameter("referer") ?: ""
|
||
val type = uri.getQueryParameter("type") ?: ""
|
||
val act = uri.getQueryParameter("act") ?: ""
|
||
val gameId = uri.getQueryParameter("gameId") ?: ""
|
||
val fieldId = uri.getQueryParameter("fieldId") ?: ""
|
||
val sectionName = uri.getQueryParameter("sectionName") ?: ""
|
||
val paginationType = uri.getQueryParameter("paginationType")
|
||
?: "page"//活动分页方式 page filter
|
||
val location = if (!TextUtils.isEmpty(act)) {
|
||
VideoDetailContainerViewModel.Location.VIDEO_ACTIVITY.value
|
||
} else if (!TextUtils.isEmpty(fieldId)) {
|
||
VideoDetailContainerViewModel.Location.GAME_ZONE.value
|
||
} else {
|
||
id
|
||
}
|
||
directToVideoDetail(context, id, location, false, gameId, entrance, "", referer, type, act, paginationType, fieldId, sectionName)
|
||
}
|
||
EntranceUtils.HOST_VIDEO_SINGLE -> {
|
||
val referer = uri.getQueryParameter("referer") ?: ""
|
||
directToVideoDetail(context, id, VideoDetailContainerViewModel.Location.SINGLE_VIDEO.value,
|
||
false, "", entrance, "", if (TextUtils.isEmpty(referer)) "" else referer)
|
||
}
|
||
EntranceUtils.HOST_VIDEO_STREAMING_HOME -> {
|
||
intent = Intent(context, MainActivity::class.java)
|
||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||
intent.putExtra(MainActivity.SWITCH_TO_VIDEO, true)
|
||
context.startActivity(intent)
|
||
}
|
||
EntranceUtils.HOST_VIDEO_STREAMING_DESC -> {
|
||
directToGameDetailVideoStreaming(context, id, entrance)
|
||
}
|
||
EntranceUtils.HOST_VIDEO_COLLECTION -> {
|
||
directToGameVideo(context, id, entrance, "")
|
||
}
|
||
|
||
EntranceUtils.HOST_CATEGORY -> {
|
||
val title = uri.getQueryParameter("title")
|
||
DirectUtils.directCategoryDirectory(context, id, title ?: "", entrance, "")
|
||
}
|
||
EntranceUtils.HOST_COLUMN_COLLECTION -> {
|
||
val name = uri.getQueryParameter("name")
|
||
DirectUtils.directToColumnCollection(context, id, -1, entrance, name ?: "")
|
||
}
|
||
EntranceUtils.HOST_COLUMN -> {
|
||
DirectUtils.directToSubject(context, id, uri.getQueryParameter(EntranceUtils.KEY_NAME), entrance)
|
||
}
|
||
EntranceUtils.HOST_COMMUNITY_QUESTION_LABEL_DETAIL -> {
|
||
val community = CommunityEntity()
|
||
community.id = uri.getQueryParameter("community_id") ?: ""
|
||
community.name = uri.getQueryParameter("community_name") ?: ""
|
||
val tag = uri.getQueryParameter("tag") ?: ""
|
||
DirectUtils.directAskColumnLabelDetail(context, tag, community, entrance, "")
|
||
}
|
||
EntranceUtils.HOST_COMMUNITY_COLUMN_DETAIL -> {
|
||
val community = CommunityEntity()
|
||
community.id = uri.getQueryParameter("community_id") ?: ""
|
||
community.name = uri.getQueryParameter("community_name") ?: ""
|
||
val columnId = uri.getQueryParameter("column_id") ?: ""
|
||
DirectUtils.directAskColumnDetail(context, columnId, community, entrance, "")
|
||
}
|
||
|
||
EntranceUtils.HOST_BLOCK -> {
|
||
val name = uri.getQueryParameter("name")
|
||
?: ""
|
||
val entity = SubjectRecommendEntity(link = id, name = name, text = name)
|
||
DirectUtils.directToBlock(context, entity, entrance)
|
||
}
|
||
|
||
EntranceUtils.HOST_SERVER_BLOCK -> {
|
||
DirectUtils.directToGameServers(context, entrance = entrance, path = "")
|
||
}
|
||
|
||
EntranceUtils.HOST_AMWAY_BLOCK -> {
|
||
DirectUtils.directToAmway(context, entrance = entrance, path = "")
|
||
}
|
||
|
||
EntranceUtils.HOST_HELP -> {
|
||
val name = uri.getQueryParameter("name")
|
||
?: ""
|
||
DirectUtils.directToQa(context, name, id)
|
||
}
|
||
|
||
EntranceUtils.HOST_HELP_COLLECTION -> {
|
||
val name = uri.getQueryParameter("name")
|
||
?: ""
|
||
DirectUtils.directToQaCollection(context, name, id)
|
||
}
|
||
|
||
EntranceUtils.HOST_GAME_UPLOAD -> {
|
||
DirectUtils.directGameUpload(context, entrance = entrance, path = "")
|
||
}
|
||
EntranceUtils.HOST_GAME_ZONE -> {
|
||
val zoneUrl = uri.getQueryParameter("url") ?: ""
|
||
DirectUtils.directGameZone(context, id, zoneUrl, entrance)
|
||
}
|
||
|
||
EntranceUtils.HOST_LINK -> {
|
||
try {
|
||
val dataString = uri.getQueryParameter("data")
|
||
if (!TextUtils.isEmpty(dataString)) {
|
||
val linkData = Base64.decode(dataString, Base64.DEFAULT)
|
||
val linkDataString = String(linkData, Charset.defaultCharset())
|
||
val le = gson.fromJson(linkDataString, LinkEntity::class.java)
|
||
directToLinkPage(context, le, entrance, "")
|
||
}
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
}
|
||
}
|
||
|
||
EntranceUtils.HOST_GAME_NEWS -> {
|
||
DirectUtils.directToGameNews(
|
||
context,
|
||
uri.getQueryParameter(EntranceUtils.KEY_GAME_ID),
|
||
uri.getQueryParameter(EntranceUtils.KEY_GAME_NAME),
|
||
entrance);
|
||
}
|
||
|
||
EntranceUtils.HOST_GAME_CALENDAR -> {
|
||
directToGameServerCalendar(context, uri.getQueryParameter(EntranceUtils.KEY_GAME_ID))
|
||
}
|
||
|
||
EntranceUtils.HOST_HISTORY_APK -> {
|
||
DirectUtils.directToHistoryApk(context, uri.getQueryParameter(EntranceUtils.KEY_GAME_ID))
|
||
}
|
||
|
||
EntranceUtils.HOST_FORUM_DETAIL -> {
|
||
DirectUtils.directForumDetail(context, id, entrance)
|
||
}
|
||
|
||
EntranceUtils.HOST_GAME_RATING_DETAIL -> {
|
||
DirectUtils.directToGameRatingDetail(context, uri.getQueryParameter(EntranceUtils.KEY_GAME_ID), uri.getQueryParameter(EntranceUtils.KEY_COMMENT_ID), EntranceUtils.ENTRANCE_BROWSER)
|
||
}
|
||
|
||
EntranceUtils.HOST_FORUM -> {
|
||
DirectUtils.directToForum(context)
|
||
}
|
||
|
||
EntranceUtils.HOST_SUGGESTION -> {
|
||
val platform = uri.getQueryParameter(EntranceUtils.KEY_PLATFORM)
|
||
val platformName = PlatformUtils.getInstance(context).getPlatformName(platform)
|
||
val gameId = uri.getQueryParameter(EntranceUtils.KEY_GAMEID)
|
||
val packageMd5 = uri.getQueryParameter(EntranceUtils.KEY_PACKAGE_MD5)
|
||
val content = if (TextUtils.isEmpty(gameId) || TextUtils.isEmpty(packageMd5)) String.format("%s-%s-V%s,",
|
||
uri.getQueryParameter(EntranceUtils.KEY_GAME_NAME),
|
||
if (TextUtils.isEmpty(platformName)) platform else platformName,
|
||
uri.getQueryParameter(EntranceUtils.KEY_VERSION)) else String.format("%s-%s-V%s\n游戏ID:%s\n游戏包MD5:%s\n",
|
||
uri.getQueryParameter(EntranceUtils.KEY_GAME_NAME),
|
||
if (TextUtils.isEmpty(platformName)) platform else platformName,
|
||
uri.getQueryParameter(EntranceUtils.KEY_VERSION), gameId, packageMd5)
|
||
val qaId = uri.getQueryParameter("qa_id") ?: ""
|
||
val qaTitle = uri.getQueryParameter(EntranceUtils.KEY_QA_TITLE)
|
||
if (!TextUtils.isEmpty(qaId)) {
|
||
directToQa(context, qaTitle, qaId)
|
||
} else {
|
||
directToFeedback(context, content, EntranceUtils.ENTRANCE_BROWSER)
|
||
}
|
||
}
|
||
|
||
EntranceUtils.HOST_HELP_AND_FEEDBACK -> {
|
||
val position = uri.getQueryParameter("position") ?: ""
|
||
DirectUtils.directToHelpAndFeedback(context, position.toInt())
|
||
}
|
||
else -> DialogUtils.showLowVersionDialog(context)
|
||
}
|
||
return true
|
||
} else if ("zhiqu" == uri.scheme) {
|
||
if (PackageUtils.isInstalled(context, "com.beieryouxi.zqyxh")) {
|
||
val intent = Intent()
|
||
intent.data = Uri.parse(url)
|
||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||
context.startActivity(intent)
|
||
} else {
|
||
Utils.toast(context, "请安装指趣游戏盒")
|
||
}
|
||
}
|
||
|
||
if (url.startsWith("alipays:") || url.startsWith("alipay")) {
|
||
try {
|
||
context.startActivity(Intent("android.intent.action.VIEW", Uri.parse(url)))
|
||
} catch (e: Exception) {
|
||
ToastUtils.showToast("请安装支付宝客户端")
|
||
}
|
||
return true
|
||
} else if (url.startsWith("weixin")) {
|
||
try {
|
||
context.startActivity(Intent("android.intent.action.VIEW", Uri.parse(url)))
|
||
} catch (e: Exception) {
|
||
ToastUtils.showToast("请安装微信客户端")
|
||
}
|
||
return true
|
||
} else if (url.startsWith("mqqwpa")) {
|
||
try {
|
||
context.startActivity(Intent("android.intent.action.VIEW", Uri.parse(url)))
|
||
} catch (e: Exception) {
|
||
ToastUtils.showToast("请安装QQ客户端")
|
||
}
|
||
return true
|
||
}
|
||
|
||
// 处理内部页面逻辑
|
||
if (transformNormalScheme(context, url, entrance)) {
|
||
return true
|
||
}
|
||
|
||
if ("http" != uri.scheme && "https" != uri.scheme) return true
|
||
return false
|
||
}
|
||
|
||
@JvmStatic
|
||
fun transformNormalScheme(context: Context, url: String, entrance: String): Boolean {
|
||
val uri = Uri.parse(url)
|
||
if (uri.host == "www.ghzs666.com"
|
||
|| uri.host == "www.ghzs.com"
|
||
|| uri.host == "ask.ghzs.com"
|
||
|| uri.host == "m.ghzs.com"
|
||
|| uri.host == "m.ghzs666.com") {
|
||
Utils.log(uri.path)
|
||
uri.path?.apply {
|
||
when {
|
||
contains("game") -> {
|
||
val gameId = uri.getQueryParameter("gameId") ?: uri.pathSegments.last() ?: ""
|
||
DirectUtils.directToGameDetail(context, gameId, entrance, autoDownload = false, traceEvent = null)
|
||
}
|
||
contains("question") -> {
|
||
val questionId = split("/")[2]
|
||
val answerId = uri.getQueryParameter("answer")
|
||
if (answerId.isNullOrEmpty()) {
|
||
DirectUtils.directToQuestionDetail(context, questionId, entrance, "")
|
||
} else {
|
||
DirectUtils.directToAnswerDetail(context, answerId, entrance, "")
|
||
}
|
||
}
|
||
contains("communities") && contains("article") -> {
|
||
var communityId = ""
|
||
var type = ""
|
||
var typeId = ""
|
||
val split = replace("/communities", "").replace(".html", "").split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||
for (text in split) {
|
||
if (TextUtils.isEmpty(communityId)) {
|
||
communityId = text
|
||
continue
|
||
}
|
||
if (TextUtils.isEmpty(type)) {
|
||
type = text
|
||
continue
|
||
}
|
||
if (TextUtils.isEmpty(typeId)) {
|
||
typeId = text
|
||
}
|
||
}
|
||
if ("articles" == type) {
|
||
DirectUtils.directToCommunityArticle(
|
||
context, typeId, communityId,
|
||
entrance, "文章链接")
|
||
}
|
||
}
|
||
contains("article") -> {
|
||
val articleId = split("/")[2].replace(".html", "")
|
||
DirectUtils.directToArticle(context, articleId, entrance)
|
||
}
|
||
contains("columns") -> {
|
||
val columnsId = split("/")[3]
|
||
val id = uri.getQueryParameter("communityId") ?: ""
|
||
val name = uri.getQueryParameter("communityName") ?: ""
|
||
DirectUtils.directToCommunityColumn(context, CommunityEntity(id, name), columnsId, entrance, "")
|
||
}
|
||
contains("zone") -> {
|
||
val gameId = split("/")[2]
|
||
DirectUtils.directGameZone(context, gameId, url, entrance)
|
||
}
|
||
}
|
||
}
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
} |