133 lines
5.5 KiB
Kotlin
133 lines
5.5 KiB
Kotlin
package com.gh.common
|
|
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import android.net.Uri
|
|
import android.text.TextUtils
|
|
import com.gh.common.util.CheckLoginUtils
|
|
import com.gh.common.util.DialogUtils
|
|
import com.gh.common.util.DirectUtils
|
|
import com.gh.common.util.EntranceUtils
|
|
import com.gh.gamecenter.GameDetailActivity
|
|
import com.gh.gamecenter.LibaoDetailActivity
|
|
import com.gh.gamecenter.NewsDetailActivity
|
|
import com.gh.gamecenter.WebActivity
|
|
import com.gh.gamecenter.entity.CommunityEntity
|
|
import com.gh.gamecenter.entity.VideoLinkEntity
|
|
import com.gh.gamecenter.subject.SubjectActivity
|
|
import com.halo.assistant.HaloApp
|
|
import com.lightgame.utils.Utils
|
|
|
|
object DefaultWebViewUrlHandler {
|
|
|
|
@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" -> GameDetailActivity.startGameDetailActivity(context, id, 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: Exception) {
|
|
Utils.toast(context, "请检查是否已经安装手机QQ")
|
|
e.printStackTrace()
|
|
}
|
|
|
|
"qqqun" -> {
|
|
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)
|
|
}
|
|
|
|
"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 linkEntity = VideoLinkEntity(title, categoryId, link)
|
|
if (!CheckLoginUtils.isLogin()) {
|
|
HaloApp.put(EntranceUtils.HOST_UPLOAD_VIDEO, linkEntity)
|
|
}
|
|
CheckLoginUtils.checkLogin(context, EntranceUtils.ENTRANCE_BROWSER) {
|
|
DirectUtils.directToVideoManager(context, linkEntity, EntranceUtils.ENTRANCE_BROWSER, "")
|
|
}
|
|
}
|
|
else -> DialogUtils.showLowVersionDialog(context)
|
|
}
|
|
return true
|
|
}
|
|
if ("http" != uri.scheme && "https" != uri.scheme) return true
|
|
return false
|
|
}
|
|
} |