mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-04 06:00:11 +00:00
优化:FrpcLib下载流程(增加确认对话框)
This commit is contained in:
parent
6f034b0cfc
commit
0579a5815b
@ -32,6 +32,9 @@ import com.idormy.sms.forwarder.widget.GuideTipsDialog.Companion.showTips
|
||||
import com.idormy.sms.forwarder.widget.GuideTipsDialog.Companion.showTipsForce
|
||||
import com.jeremyliao.liveeventbus.LiveEventBus
|
||||
import com.xuexiang.xaop.annotation.SingleClick
|
||||
import com.xuexiang.xhttp2.XHttp
|
||||
import com.xuexiang.xhttp2.callback.DownloadProgressCallBack
|
||||
import com.xuexiang.xhttp2.exception.ApiException
|
||||
import com.xuexiang.xpage.base.XPageFragment
|
||||
import com.xuexiang.xpage.core.PageOption
|
||||
import com.xuexiang.xpage.model.PageInfo
|
||||
@ -43,8 +46,6 @@ import com.xuexiang.xui.utils.WidgetUtils
|
||||
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction
|
||||
import com.xuexiang.xui.widget.dialog.materialdialog.GravityEnum
|
||||
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
|
||||
import com.xuexiang.xupdate.XUpdate
|
||||
import com.xuexiang.xupdate.service.OnFileDownloadListener
|
||||
import com.xuexiang.xutil.common.CollectionUtils
|
||||
import com.xuexiang.xutil.file.FileUtils
|
||||
import frpclib.Frpclib
|
||||
@ -53,7 +54,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.io.File
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
@Suppress("DEPRECATION", "PrivatePropertyName")
|
||||
@ -144,15 +144,31 @@ class MainActivity : BaseActivity<ActivityMainBinding?>(),
|
||||
R.id.nav_server -> openNewPage(ServerFragment::class.java)
|
||||
R.id.nav_client -> openNewPage(ClientFragment::class.java)
|
||||
R.id.nav_frpc -> {
|
||||
if (FileUtils.isFileExists(filesDir.absolutePath + "/libs/libgojni.so")) {
|
||||
if (FRPC_LIB_VERSION == Frpclib.getVersion()) {
|
||||
openNewPage(FrpcFragment::class.java)
|
||||
} else {
|
||||
XToastUtils.error(getString(R.string.frpclib_version_mismatch))
|
||||
downloadFrpcLib()
|
||||
}
|
||||
if (!FileUtils.isFileExists(filesDir.absolutePath + "/libs/libgojni.so")) {
|
||||
MaterialDialog.Builder(this)
|
||||
.title(String.format(getString(R.string.frpclib_download_title), FRPC_LIB_VERSION))
|
||||
.content(R.string.download_frpc_tips)
|
||||
.positiveText(R.string.lab_yes)
|
||||
.negativeText(R.string.lab_no)
|
||||
.onPositive { _: MaterialDialog?, _: DialogAction? ->
|
||||
downloadFrpcLib()
|
||||
}
|
||||
.show()
|
||||
return@setNavigationItemSelectedListener false
|
||||
}
|
||||
|
||||
if (FRPC_LIB_VERSION == Frpclib.getVersion()) {
|
||||
openNewPage(FrpcFragment::class.java)
|
||||
} else {
|
||||
downloadFrpcLib()
|
||||
MaterialDialog.Builder(this)
|
||||
.title(R.string.frpclib_version_mismatch)
|
||||
.content(R.string.download_frpc_tips)
|
||||
.positiveText(R.string.lab_yes)
|
||||
.negativeText(R.string.lab_no)
|
||||
.onPositive { _: MaterialDialog?, _: DialogAction? ->
|
||||
downloadFrpcLib()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
R.id.nav_app_list -> openNewPage(AppListFragment::class.java)
|
||||
@ -361,27 +377,30 @@ class MainActivity : BaseActivity<ActivityMainBinding?>(),
|
||||
.progress(false, 0, true)
|
||||
.progressNumberFormat("%2dMB/%1dMB")
|
||||
.build()
|
||||
XUpdate.newBuild(mContext)
|
||||
.apkCacheDir(cacheDir.absolutePath) //设置下载缓存的根目录
|
||||
.build()
|
||||
.download(downloadUrl, object : OnFileDownloadListener {
|
||||
|
||||
XHttp.downLoad(downloadUrl)
|
||||
.savePath(cacheDir.absolutePath)
|
||||
.execute(object : DownloadProgressCallBack<String?>() {
|
||||
override fun onStart() {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onProgress(progress: Float, total: Long) {
|
||||
Log.d(TAG, "onProgress: progress=$progress, total=$total")
|
||||
|
||||
val max = (total / 1024F / 1024F).roundToInt()
|
||||
dialog.maxProgress = max
|
||||
dialog.setProgress((progress * max).roundToInt())
|
||||
override fun onError(e: ApiException) {
|
||||
dialog.dismiss()
|
||||
XToastUtils.error(e.message.toString())
|
||||
}
|
||||
|
||||
override fun onCompleted(srcFile: File): Boolean {
|
||||
dialog.dismiss()
|
||||
Log.d(TAG, srcFile.path)
|
||||
override fun update(bytesRead: Long, contentLength: Long, done: Boolean) {
|
||||
Log.d(TAG, "onProgress: bytesRead=$bytesRead, contentLength=$contentLength")
|
||||
dialog.maxProgress = (contentLength / 1048576L).toInt()
|
||||
dialog.setProgress((bytesRead / 1048576L).toInt())
|
||||
}
|
||||
|
||||
override fun onComplete(srcPath: String) {
|
||||
dialog.dismiss()
|
||||
Log.d(TAG, "srcPath = $srcPath")
|
||||
|
||||
val srcFile = File(srcPath)
|
||||
val destFile = File("$libPath/libgojni.so")
|
||||
FileUtils.moveFile(srcFile, destFile, null)
|
||||
|
||||
@ -389,15 +408,9 @@ class MainActivity : BaseActivity<ActivityMainBinding?>(),
|
||||
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
startActivity(intent)
|
||||
android.os.Process.killProcess(android.os.Process.myPid()) //杀掉以前进程
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onError(throwable: Throwable) {
|
||||
dialog.dismiss()
|
||||
XToastUtils.error(throwable.message!!)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ import com.idormy.sms.forwarder.activity.MainActivity
|
||||
import com.idormy.sms.forwarder.database.AppDatabase
|
||||
import com.idormy.sms.forwarder.utils.*
|
||||
import com.jeremyliao.liveeventbus.LiveEventBus
|
||||
import com.xuexiang.xutil.file.FileUtils
|
||||
import frpclib.Frpclib
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.SingleObserver
|
||||
@ -85,21 +86,23 @@ class ForegroundService : Service() {
|
||||
CommonUtils.toggleNotificationListenerService(this)
|
||||
}
|
||||
|
||||
//监听Frpc启动指令
|
||||
LiveEventBus.get(INTENT_FRPC_APPLY_FILE, String::class.java).observeStickyForever(frpcObserver)
|
||||
//自启动的Frpc
|
||||
GlobalScope.async(Dispatchers.IO) {
|
||||
val frpcList = AppDatabase.getInstance(App.context).frpcDao().getAutorun()
|
||||
if (FileUtils.isFileExists(filesDir.absolutePath + "/libs/libgojni.so")) {
|
||||
//监听Frpc启动指令
|
||||
LiveEventBus.get(INTENT_FRPC_APPLY_FILE, String::class.java).observeStickyForever(frpcObserver)
|
||||
//自启动的Frpc
|
||||
GlobalScope.async(Dispatchers.IO) {
|
||||
val frpcList = AppDatabase.getInstance(App.context).frpcDao().getAutorun()
|
||||
|
||||
if (frpcList.isEmpty()) {
|
||||
Log.d(TAG, "没有自启动的Frpc")
|
||||
return@async
|
||||
}
|
||||
if (frpcList.isEmpty()) {
|
||||
Log.d(TAG, "没有自启动的Frpc")
|
||||
return@async
|
||||
}
|
||||
|
||||
for (frpc in frpcList) {
|
||||
val error = Frpclib.runContent(frpc.uid, frpc.config)
|
||||
if (!TextUtils.isEmpty(error)) {
|
||||
Log.e(TAG, error)
|
||||
for (frpc in frpcList) {
|
||||
val error = Frpclib.runContent(frpc.uid, frpc.config)
|
||||
if (!TextUtils.isEmpty(error)) {
|
||||
Log.e(TAG, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -713,7 +713,7 @@
|
||||
<string name="no_sms_sending_permission">No SMS sending permission</string>
|
||||
<string name="frpclib_download_title">Missing FrpcLib v%s</string>
|
||||
<string name="frpclib_download_content">Downloading, please wait…</string>
|
||||
<string name="frpclib_version_mismatch">FrpcLib version mismatch, download again</string>
|
||||
<string name="frpclib_version_mismatch">FrpcLib version mismatch</string>
|
||||
<string name="page_not_found">Page not found!</string>
|
||||
<string name="data_error">Data error!</string>
|
||||
<string name="cannot_open_with_browser">Can\'t open with browser</string>
|
||||
@ -872,4 +872,5 @@
|
||||
<string name="select_time_period">Select Time Period</string>
|
||||
<string name="silent_time_period">Silent (disable forwarding) time period</string>
|
||||
<string name="silent_time_period_tips">If the end time is less than the start time, it will span days; if it is equal, it will be disabled</string>
|
||||
<string name="download_frpc_tips">Do you want to download and restart to load!</string>
|
||||
</resources>
|
||||
|
@ -714,7 +714,7 @@
|
||||
<string name="no_sms_sending_permission">没有短信发送权限</string>
|
||||
<string name="frpclib_download_title">缺少 FrpcLib v%s 动态库</string>
|
||||
<string name="frpclib_download_content">正在下载中,请稍后……</string>
|
||||
<string name="frpclib_version_mismatch">FrpcLib 版本不匹配,重新下载</string>
|
||||
<string name="frpclib_version_mismatch">FrpcLib 版本不匹配</string>
|
||||
<string name="page_not_found">页面未找到!</string>
|
||||
<string name="data_error">数据出错!</string>
|
||||
<string name="cannot_open_with_browser">Can\'t open with browser</string>
|
||||
@ -873,4 +873,5 @@
|
||||
<string name="select_time_period">时间段选择</string>
|
||||
<string name="silent_time_period">免打扰(禁用转发)时间段</string>
|
||||
<string name="silent_time_period_tips">结束时间小于开始时间则跨天;相等则禁用</string>
|
||||
<string name="download_frpc_tips">是否立即下载,并重启加载?</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user