Commit d97bb8d1 authored by sheteng's avatar sheteng

2.0 开发 2

parent 7d81ef35
package com.ccwangluo.accelerator.utils
package com.ccwangluo.accelerator.manager
import android.Manifest
import android.app.DownloadManager
......@@ -12,8 +12,6 @@ import androidx.core.content.FileProvider
import androidx.fragment.app.FragmentActivity
import com.ccwangluo.accelerator.ui.dialog.DownloadDialog
import com.hjq.toast.ToastUtils
import com.xuexiang.xutil.app.AppUtils
import com.xuexiang.xutil.file.FileUtils
import com.xuexiang.xutil.system.PermissionUtils
import java.io.File
......
package com.ccwangluo.accelerator.manager
import android.Manifest
import android.app.DownloadManager
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Environment
import android.webkit.MimeTypeMap
import androidx.lifecycle.lifecycleScope
import com.ccwangluo.accelerator.model.GameInfo
import com.hjq.toast.ToastUtils
import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xutil.system.PermissionUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
object GameDownLoadManger {
private var downloadManager: DownloadManager? = null
private var gameDownloadListener: GameDownloadListener? = null
fun registerLisener(gameDownloadListener: GameDownloadListener) {
this.gameDownloadListener = gameDownloadListener
}
private val downloadMap = mutableMapOf<Long, GameInfo>()
fun download(
activity: XPageFragment,
gameInfo: GameInfo
) {
var url = gameInfo.downloadUrl
if (url.isNullOrBlank()) {
return
}
if (!PermissionUtils.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
ToastUtils.show("下载需要打开存储权限")
PermissionUtils.permission(Manifest.permission.WRITE_EXTERNAL_STORAGE.toString())
.rationale {
PermissionUtils.openAppSettings()
}.request()
return
}
var filename = url.split("/").last()
var file = File(
activity.context?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
filename
)
// if (file.exists()) {
// activity.context?.let { DownloadUtils.install(file.absolutePath, it) }
// return
// }
downloadManager =
activity.context?.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val request =
DownloadManager.Request(Uri.parse(url)) //添加下载文件的网络路径
request.setDestinationInExternalFilesDir(
activity.context,
Environment.DIRECTORY_DOWNLOADS,
filename
)
val mimeTypeMap = MimeTypeMap.getSingleton()
val mimeString =
mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url))
request.setMimeType(mimeString)
request.setTitle("下载中") //添加在通知栏里显示的标题
// request.setDescription("下载中") //添加在通知栏里显示的描述
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI) //设置下载的网络类型
request.setVisibleInDownloadsUi(false) //是否显示下载 从Android Q开始会被忽略
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) //下载中与下载完成后都会在通知中显示| 另外可以选 DownloadManager.Request.VISIBILITY_VISIBLE 仅在下载中时显示在通知中,完成后会自动隐藏
var downloadId = downloadManager!!.enqueue(request) //加入队列,会返回一个唯一下载id
downloadMap.put(downloadId, gameInfo)
gameDownloadListener?.onStart(gameInfo)
show(activity, downloadId)
}
fun show(activity: XPageFragment, downloadId: Long) {
activity.lifecycleScope.launch(Dispatchers.IO) {
var progress = 0F
while (progress < 100F) {
progress = getDownloadProgress(downloadId)
delay(2000)
}
withContext(Dispatchers.Main) {
gameDownloadListener?.onFinish(downloadMap.get(downloadId))
downloadMap.remove(downloadId)
}
}
}
fun containGame(gameInfo: GameInfo): Boolean {
downloadMap.keys.forEach {
val get = downloadMap.get(it)
if (get?.id == gameInfo.id) {
return true
}
}
return false
}
fun cancellDownload(gameInfo: GameInfo) {
try {
downloadMap.keys.forEach {
val get = downloadMap.get(it)
if (get?.id == gameInfo.id) {
downloadManager?.remove(it)
gameDownloadListener?.onFinish(gameInfo)
downloadMap.remove(it)
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
suspend fun getDownloadProgress(downloadId: Long):Float {
val query = DownloadManager.Query().setFilterById(downloadId)
downloadManager?.let {
val c: Cursor = it.query(query)
if (c != null) {
try {
if (c.moveToFirst()) {
var progress = 0F
val mDownload_so_far =
c.getLong(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))
val mDownload_all =
c.getLong(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
if (mDownload_all != 0L) {
progress = (mDownload_so_far.toFloat() / mDownload_all) * 100
}
val downloadInfo = DownloadInfo(
status,
progress,
0,
mDownload_so_far,
mDownload_all
)
withContext(Dispatchers.Main) {
gameDownloadListener?.onProgress(
downloadMap.get(downloadId),
downloadInfo
)
}
return progress
}
} catch (e : Exception){
println("progress err ${e}")
}finally {
c.close()
}
}
}
return 0F
}
interface GameDownloadListener {
fun onStart(gameInfo: GameInfo?)
fun onFinish(gameInfo: GameInfo?)
fun onProgress(gameInfo: GameInfo?, downloadInfo: DownloadInfo)
}
data class DownloadInfo(
var status: Int,
var progress: Float,
var speed: Long,
var download_so_far: Long,
var download_all: Long
)
}
\ No newline at end of file
package com.ccwangluo.accelerator.utils
package com.ccwangluo.accelerator.manager
import android.content.Context
import android.content.Intent
......@@ -7,6 +7,8 @@ import androidx.lifecycle.lifecycleScope
import com.ccwangluo.accelerator.model.LoginRes
import com.ccwangluo.accelerator.model.UserProfile
import com.ccwangluo.accelerator.ui.login.PhoneLoginActivity
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.TimeUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.ccwangluo.accelerator.utils.http.HttpGo
import com.chuanglan.shanyan_sdk.OneKeyLoginManager
......@@ -119,7 +121,10 @@ object LoginUtils {
withContext(Dispatchers.Main) {
ToastUtils.show("登录成功")
OneKeyLoginManager.getInstance().finishAuthActivity()
DataRePortUtils.report("role_entry", mutableMapOf("login" to "login_all"))
DataRePortUtils.report(
"role_entry",
mutableMapOf("login" to "login_all")
)
callBack(true)
}
} else {
......
package com.ccwangluo.accelerator.utils
package com.ccwangluo.accelerator.manager
import android.app.Application
import android.content.Context
......@@ -11,6 +11,7 @@ import android.widget.RelativeLayout
import android.widget.TextView
import com.ccwangluo.accelerator.R
import com.ccwangluo.accelerator.ui.login.PhoneLoginActivity
import com.ccwangluo.accelerator.utils.AbScreenUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.chuanglan.shanyan_sdk.OneKeyLoginManager
......
......@@ -2,21 +2,39 @@ package com.ccwangluo.accelerator.model
data class Game(
val list: List<GameInfo>?,
val total: Int?
val total: Int
)
data class GameInfo(
val announcementList: List<Announcement>,
val anotherName: String,
val boosterPackageName: String,
val boosterServer: String,
val createdDate: String,
val dnsServer: String,
val downloadUrl: String,
val gameName: String,
val greatNum: Int,
val icon: String,
val id: Int,
val boosterServer:String,
val imgs: String,
val introduction: String,
val packageName: String,
val boosterPackageName :String,
val proxyRules: String,
val dnsServer: String,
val score: String,
val size: String,
val type: Int,
val version: String
)
data class Announcement(
val addrType: Int,
val content: String,
val createName: String,
val createdDate: String,
val gameId: Int,
val id: Int,
val status: Int,
val title: String,
val url: String
)
\ No newline at end of file
......@@ -7,7 +7,7 @@ import com.ccwangluo.accelerator.databinding.FragmentBtnNavBinding
import com.ccwangluo.accelerator.ui.gameList.GameListFragment
import com.ccwangluo.accelerator.ui.home.*
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.xuexiang.xpage.annotation.Page
......
......@@ -17,7 +17,7 @@ import com.ccwangluo.accelerator.ui.dialog.PrivacyDialog
import com.ccwangluo.accelerator.ui.home.AccelertorViewModel
import com.ccwangluo.accelerator.ui.login.SplashFragment
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.PhoneUtils
import com.ccwangluo.accelerator.manager.PhoneUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.ccwangluo.cc_quickly.utils.SettingSPUtils
import com.github.shadowsocks.http.HttpConfig
......
......@@ -2,6 +2,7 @@ package com.ccwangluo.accelerator.ui.dialog
import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.ccwangluo.accelerator.R
......@@ -26,6 +27,7 @@ class CommonDialog(
fun setTitle(title: String): CommonDialog {
val tx = findViewById<TextView>(R.id.title)
tx.setText(title)
tx.visibility = View.VISIBLE
return this
}
......
......@@ -71,9 +71,6 @@ class DownloadDialog(
c.getInt(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val mDownload_all =
c.getInt(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
if (mDownload_all == 0) {
return 0f;
}
println("mDownload_so_far = $mDownload_so_far &&& mDownload_all = ${mDownload_all} &&& ${mDownload_so_far * 100 / mDownload_all} ")
return (mDownload_so_far.toFloat() / mDownload_all) * 100
}
......
package com.ccwangluo.accelerator.ui.dialog
import android.content.Context
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.ccwangluo.accelerator.R
import com.ccwangluo.accelerator.manager.GameDownLoadManger
import com.ccwangluo.accelerator.model.GameInfo
import com.ccwangluo.accelerator.utils.ByteUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.umeng.socialize.utils.DeviceConfigInternal.context
import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xui.widget.dialog.materialdialog.CustomMaterialDialog
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
class GameDownloadDialog(
val gameInfo: GameInfo,
val fragment: XPageFragment
) : CustomMaterialDialog(fragment.context) {
override fun getDialogBuilder(context: Context?): MaterialDialog.Builder {
return MaterialDialog.Builder(context!!)
.customView(R.layout.dialog_download, false);
}
override fun initViews(context: Context?) {
}
init {
val appImg = findViewById<ImageView>(R.id.app_img)
fragment.context?.let {
Glide.with(it)
.load(gameInfo.icon)
.into(appImg)
}
val appName = findViewById<TextView>(R.id.app_name)
appName.setText(gameInfo.gameName)
val appSize = findViewById<TextView>(R.id.app_size)
appSize.setText("文件大小:${gameInfo.size}")
val appVersion = findViewById<TextView>(R.id.app_version)
appVersion.setText("版本号:${gameInfo.id}")
val btnLeft = findViewById<TextView>(R.id.btn_left)
btnLeft.setOnClickListener {
dismiss<GameDownloadDialog>()
}
}
fun download() {
val btnRight = findViewById<TextView>(R.id.btn_right)
btnRight.setOnClickListener {
//流量下载提示
if (SysUtils.isMobileNet()) {
if (context != null) {
CommonDialog(context)
.setContent(
"您正在使用计量网络下载," +
"将产生${gameInfo.size}的流量,是否继续?"
)
.setBtnLeft("取消") {
}.setBtnRight("继续") {
GameDownLoadManger.download(fragment,gameInfo)
}.show<CommonDialog>()
}
} else {
dialog.dismiss()
GameDownLoadManger.download(fragment,gameInfo)
}
}
}
}
\ No newline at end of file
......@@ -3,29 +3,25 @@ package com.ccwangluo.accelerator.ui.gameList
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import com.ccwangluo.accelerator.model.Game
import com.ccwangluo.accelerator.model.GameInfo
import com.ccwangluo.accelerator.model.NewsModel
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.http.HttpGo
import com.github.shadowsocks.bg.AuthManager
import com.xuexiang.xpage.base.XPageFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class GameListModel : ViewModel() {
val gameModel = MutableLiveData<List<GameInfo>>()
val gameModel = MutableLiveData<Game>()
val clearList = MutableLiveData<Boolean>()
fun freshData(xPageFragment: XPageFragment,page: Int) {
xPageFragment.lifecycleScope.launch(Dispatchers.IO) {
val res = HttpGo.getSync<Game>("/api/new/game/list?id=1&page=${page}&size=10")
val res = HttpGo.getSync<Game>("/api/new/game/list?page=${page}&size=10&channelId=${SysUtils.getChannel()}")
res?.let {
it.data?.list?.let {
it.data?.let {
clearList.postValue(page == 1)
gameModel.postValue(it)
}
......
......@@ -17,8 +17,8 @@ import com.ccwangluo.accelerator.ui.dialog.CommonDialog
import com.ccwangluo.accelerator.ui.dialog.MemberDialog
import com.ccwangluo.accelerator.ui.web.CommonWebViewFragment
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.utils.ShareUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.AcceleratorUtils.state
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.ccwangluo.cc_quickly.utils.SettingSPUtils
......@@ -26,12 +26,15 @@ import com.github.shadowsocks.bg.AuthManager
import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.http.HttpConfig
import com.hjq.toast.ToastUtils
import com.umeng.socialize.utils.DeviceConfigInternal.context
import com.xuexiang.xpage.annotation.Page
import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xpage.core.PageOption
import com.xuexiang.xpage.utils.TitleBar
import com.xuexiang.xui.widget.progress.CircleProgressView
import com.xuexiang.xutil.app.AppUtils
@Page(name = "accelera")
class AcceleratorFragment : XPageFragment() {
private lateinit var binding: FragmentQuickBinding
private lateinit var acceleratorViewModel: AccelertorViewModel
......@@ -110,7 +113,7 @@ class AcceleratorFragment : XPageFragment() {
})
acceleratorViewModel.accState.observe(this) {
binding.accStateTx.setText(SysUtils.getAccTimeString(accTimer))
binding.accStateTx.setText("加速中 ${SysUtils.getAccTimeString(accTimer)}")
state = it
freshData(it)
if (AuthManager.isSmartAccOpen) {
......@@ -154,7 +157,7 @@ class AcceleratorFragment : XPageFragment() {
(binding.gamePicOut.background as AnimationDrawable).start()
binding.gamePicOut.startAnimation(getDefaultAnim())
}
binding.radiusTv.visibility= if (SysUtils.getChannel() == 3) View.GONE else View.VISIBLE
binding.radiusTv.visibility = if (SysUtils.getChannel() == 3) View.GONE else View.VISIBLE
}
override fun initListeners() {
......@@ -245,8 +248,7 @@ class AcceleratorFragment : XPageFragment() {
DataRePortUtils.report("st_speed_result", mapOf("result" to 0, "cause" to "3"))
return@setOnClickListener
}
AcceleratorUtils.getGameList(this) {
if (it) {
//
AcceleratorUtils.game?.let {
if (!SysUtils.isPackageInstall(requireContext(), it.packageName)) {
......@@ -259,7 +261,7 @@ class AcceleratorFragment : XPageFragment() {
"st_speed_result",
mapOf("result" to 0, "cause" to "1")
)
return@getGameList
return@setOnClickListener
}
}
//用户是否有使用时长
......@@ -275,13 +277,6 @@ class AcceleratorFragment : XPageFragment() {
MemberDialog(this@AcceleratorFragment).show<MemberDialog>()
}
}
} else {
DataRePortUtils.report("st_speed_result", mapOf("result" to 0, "cause" to "3"))
ToastUtils.show("获取游戏配置异常")
}
}
}
binding.gameStart.setOnClickListener {
......@@ -301,8 +296,13 @@ class AcceleratorFragment : XPageFragment() {
}
}
}
AcceleratorUtils.registerStateListener { state, l, net ->
net?.let {
acceleratorViewModel.netState.postValue(net)
}
accTimer = l
acceleratorViewModel.accState.postValue(state)
}
}
fun openToWebview(url: String) {
......@@ -312,11 +312,11 @@ class AcceleratorFragment : XPageFragment() {
openPage(CommonWebViewFragment::class.java, params)
} ?: let {
context?.let { it1 ->
LoginUtils.login(it1, {
if (true) {
LoginUtils.login(it1) {
if (it) {
openPage(CommonWebViewFragment::class.java, params)
}
})
}
}
}
}
......@@ -405,20 +405,16 @@ class AcceleratorFragment : XPageFragment() {
AcceleratorUtils.unRegisterVipExpireListener()
}
override fun onHiddenChanged(hidden: Boolean) {
super.onHiddenChanged(hidden)
}
override fun onStart() {
super.onStart()
AcceleratorUtils.registerStateListener { state, l, net ->
net?.let {
acceleratorViewModel.netState.postValue(net)
}
accTimer = l
acceleratorViewModel.accState.postValue(state)
}
}
override fun onStop() {
super.onStop()
AcceleratorUtils.unRegisterStateListener()
}
override fun onResume() {
......@@ -467,6 +463,7 @@ class AcceleratorFragment : XPageFragment() {
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
println("acc setUserVisibleHint")
if (isVisibleToUser) {
getUserProfile()
}
......
......@@ -8,7 +8,7 @@ import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import com.ccwangluo.accelerator.databinding.FragmentMineBinding
import com.ccwangluo.accelerator.ui.web.AndroidInterface
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.github.shadowsocks.http.HttpConfig
import com.just.agentweb.core.AgentWeb
......
......@@ -21,8 +21,7 @@ import com.ccwangluo.accelerator.model.Plugin
import com.ccwangluo.accelerator.ui.news.NewsCollectionAdapter
import com.ccwangluo.accelerator.ui.web.CommonWebViewFragment
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.DownloadUtils
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.DownloadUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.github.shadowsocks.http.HttpConfig
......@@ -176,16 +175,11 @@ class NewsFragment : XPageFragment() {
})
AcceleratorUtils.getGameList(this) {
if (it) {
AcceleratorUtils.game?.let {
newsViewModel.getNotice(it.id)
newsViewModel.getPlugin(it.id)
}
}
}
}
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
......
......@@ -8,7 +8,7 @@ import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import com.ccwangluo.accelerator.databinding.FragmentMineBinding
import com.ccwangluo.accelerator.ui.web.AndroidInterface
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.github.shadowsocks.http.HttpConfig
import com.just.agentweb.core.AgentWeb
......
......@@ -4,7 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ccwangluo.accelerator.model.LoginRes
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.ccwangluo.accelerator.utils.http.HttpGo
......
......@@ -8,7 +8,7 @@ import androidx.lifecycle.ViewModelProvider
import com.ccwangluo.accelerator.databinding.FragmentLoginPhoneBinding
import com.ccwangluo.accelerator.ui.web.BlankActivity
import com.ccwangluo.accelerator.ui.web.CommonWebViewFragment
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.github.shadowsocks.http.HttpConfig
import com.hjq.toast.ToastUtils
......
......@@ -2,7 +2,6 @@ package com.ccwangluo.accelerator.ui.news
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -26,7 +25,6 @@ import com.ccwangluo.accelerator.model.NewsModel
import com.ccwangluo.accelerator.ui.view.RatingBar
import com.ccwangluo.accelerator.ui.web.CommonWebViewFragment
import com.ccwangluo.accelerator.utils.HtmlUtil
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.github.shadowsocks.http.HttpConfig
import com.hjq.toast.ToastUtils
......
......@@ -4,7 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ccwangluo.accelerator.model.NewsModel
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.http.HttpGo
import com.xuexiang.xpage.base.XPageFragment
......
package com.ccwangluo.accelerator.ui.web
import android.webkit.JavascriptInterface
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.github.shadowsocks.http.HttpConfig
import com.ccwangluo.cc_quickly.utils.XToastUtils
import com.just.agentweb.core.AgentWeb
......
......@@ -12,6 +12,8 @@ import android.content.Intent
import android.net.Uri
import android.os.Handler
import android.provider.Settings
import com.ccwangluo.accelerator.manager.DownloadUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.*
import com.ccwangluo.accelerator.utils.datareport.DataRePortUtils
import com.github.shadowsocks.bg.AuthManager
......
......@@ -14,7 +14,7 @@ import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import com.ccwangluo.accelerator.databinding.FragmentWebviewBinding
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.github.shadowsocks.http.HttpConfig
import com.just.agentweb.core.AgentWeb
......
......@@ -8,6 +8,7 @@ import android.os.RemoteException
import androidx.activity.result.ActivityResultLauncher
import androidx.lifecycle.lifecycleScope
import com.ccnet.acc.NetworkAdapter
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.model.Game
import com.ccwangluo.accelerator.model.GameInfo
import com.ccwangluo.accelerator.model.NetState
......@@ -72,24 +73,9 @@ object AcceleratorUtils : TencentLocationListener {
var netState = NetState(-1, -1, "100")
fun getGameList(xPageFragment: XPageFragment, callback: (Boolean) -> Unit) {
game?.let {
callback(true)
} ?: let {
xPageFragment.lifecycleScope.launch(Dispatchers.IO) {
val res = HttpGo.getSync<Game>("/api/new/game/list?id=1&page=1&size=1")
res?.let {
game = it.data?.list?.get(0)
withContext(Dispatchers.Main) {
callback(true)
}
game?.let { gameInfo ->
fun setGameInfo(gameInfo: GameInfo) {
AuthManager.gameId = gameInfo.id.toString()
}
}
}
}
this.game = gameInfo
}
fun initContext(context: XPageActivity, connect: ActivityResultLauncher<Void?>) {
......@@ -163,7 +149,7 @@ object AcceleratorUtils : TencentLocationListener {
fun openLocation(context: Context) {
PermissionUtils.permission(
Manifest.permission.ACCESS_FINE_LOCATION
Manifest.permission.ACCESS_FINE_LOCATION.toString()
).rationale({
}).callback(object : PermissionUtils.FullCallback {
override fun onGranted(permissionsGranted: MutableList<String>?) {
......
package com.ccwangluo.accelerator.utils
object ByteUtils {
fun bytesToDisplay(bytes: Long) = when {
bytes == Long.MIN_VALUE || bytes < 0 -> "0"
bytes < 1024L -> "$bytes B"
bytes <= 0xfffccccccccccccL shr 40 -> "%.1f KB".format(bytes.toDouble() / (0x1 shl 10))
bytes <= 0xfffccccccccccccL shr 30 -> "%.1f MB".format(bytes.toDouble() / (0x1 shl 20))
bytes <= 0xfffccccccccccccL shr 20 -> "%.1f GB".format(bytes.toDouble() / (0x1 shl 30))
bytes <= 0xfffccccccccccccL shr 10 -> "%.1f TB".format(bytes.toDouble() / (0x1 shl 40))
bytes <= 0xfffccccccccccccL -> "%.1f PiB".format((bytes shr 10).toDouble() / (0x1 shl 40))
else -> "%.1f EiB".format((bytes shr 20).toDouble() / (0x1 shl 40))
}
}
\ No newline at end of file
package com.ccwangluo.accelerator.utils
import android.Manifest
import android.app.DownloadManager
import android.content.Context
import android.content.Context.DOWNLOAD_SERVICE
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.text.TextUtils
import android.util.DisplayMetrics
import androidx.core.content.FileProvider
import androidx.fragment.app.FragmentActivity
import com.ccwangluo.accelerator.ui.dialog.DownloadDialog
import com.ccwangluo.cc_quickly.utils.SettingSPUtils
import com.hjq.toast.ToastUtils
import com.mcxiaoke.packer.helper.PackerNg
import com.tencent.mmkv.MMKV
import com.xuexiang.xpage.base.XPageActivity
import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xutil.app.AppUtils
import com.xuexiang.xutil.net.NetworkUtils
import com.xuexiang.xutil.system.DeviceUtils
import com.xuexiang.xutil.system.PermissionUtils
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
......@@ -49,6 +39,10 @@ object SysUtils {
}
}
fun isMobileNet(): Boolean {
return NetworkUtils.isMobile()
}
/*
* 判断设备 是否使用代理上网
......@@ -86,7 +80,7 @@ object SysUtils {
}
fun getAccTimeString(time: Long): String {
return "加速中 ${tranlateTime(time)} "
return "${tranlateTime(time)} "
}
fun tranlateTime(long: Long): String {
......
package com.ccwangluo.accelerator.utils.datareport
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.google.gson.JsonObject
import java.time.LocalDateTime
......
package com.ccwangluo.accelerator.utils.http
import com.ccwangluo.accelerator.model.BaseModel
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.manager.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.datareport.BaseData
import com.github.shadowsocks.http.HttpConfig
......
......@@ -12,6 +12,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginTop="22dp"
android:textColor="#FF000000"
android:visibility="gone"
android:textSize="16sp" />
<TextView
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/white"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="22dp"
android:textColor="#FF000000"
android:text="来自第三方下载"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="19dp"
android:layout_marginLeft="30.5dp"
android:layout_marginRight="30.5dp"
android:layout_marginBottom="21dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/app_img"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:background="#FFD8D8D8"
/>
<LinearLayout
android:layout_marginLeft="15dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="xxxx"
android:textColor="#FF000000"
android:textSize="15sp"
/>
<TextView
android:id="@+id/app_size"
android:layout_marginTop="1.5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文件大小:"
android:textColor="#FF4A4A4A"
android:textSize="12sp"
/>
<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="版本号:"
android:textColor="#FF4A4A4A"
android:textSize="12sp"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_marginLeft="30.5dp"
android:layout_marginRight="30.5dp"
android:layout_marginBottom="21dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="下载资源来自第三方提供。若该资源侵犯了您的合法权益或违反相关法规,请通过意见反馈投诉,我们会尽快与您联系并处理该问题。"
android:textColor="#FF4A4A4A"
android:textSize="15sp"
/>
<View
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_height="0.5dp"
android:background="#FFF0F0F0" />
<LinearLayout
android:layout_marginTop="4.5dp"
android:layout_width="match_parent"
android:layout_height="53dp"
android:orientation="horizontal">
<TextView
android:id="@+id/btn_left"
android:gravity="center"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="取消"
android:textColor="#FFA8A8A8"
android:textSize="15sp" />
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="#FFF0F0F0" />
<TextView
android:text="下载"
android:id="@+id/btn_right"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:textColor="#FF3CA4FD"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:orientation="vertical"
android:layout_height="match_parent">
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#31354B"
>
android:orientation="horizontal">
<TextView
android:layout_weight="1"
android:layout_marginTop="32.5dp"
android:layout_marginLeft="15.5dp"
android:layout_width="36dp"
android:layout_height="25dp"
android:layout_marginLeft="15.5dp"
android:layout_marginTop="32.5dp"
android:layout_weight="1"
android:text="加速"
android:textColor="#FFFFFFFF"
android:textSize="18sp"
/>
android:textSize="18sp" />
<View
android:id="@+id/acc_share"
android:layout_marginTop="37.5dp"
android:layout_marginRight="16.5dp"
android:layout_width="18dp"
android:layout_height="18dp"
android:background="@mipmap/share"
/>
android:layout_marginTop="37.5dp"
android:layout_marginRight="16.5dp"
android:background="@mipmap/share" />
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_game"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/game_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
\ No newline at end of file
This diff is collapsed.
......@@ -4,14 +4,14 @@ object HttpConfig {
//app后端
//val baseUrl = "http://10.16.1.98:9002"
// val baseUrl = "https://test-cc-tt-api.orangenet.org.cn" //测试
val baseUrl = "https://cc-tt-front.srccwl.com" //生产
val baseUrl = "https://test-cc-tt-api-v2.orangenet.org.cn" //测试
// val baseUrl = "https://cc-tt-front.srccwl.com" //生产
/**
* 主页h5
*/
// val UI_MAIN_URL = "http://10.3.64.200:8080/#"
// val UI_MAIN_URL = "https://test-cc-tt-front.orangenet.org.cn/#" //测试
val UI_MAIN_URL = "https://cc-tt-front.srccwl.com/#" //生产
val UI_MAIN_URL = "https://test-cc-tt-front.orangenet.org.cn/#" //测试
// val UI_MAIN_URL = "https://cc-tt-front.srccwl.com/#" //生产
//隐私协议地址
val HTML_HOST_PRIVACY="https://sdk-static.srccwl.com/tt_html/"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment