修改服务器地址,提升程序稳定性。

This commit is contained in:
Cold-Mint 2023-05-18 22:37:49 +08:00
parent dd8b2117f3
commit c6cc1bc212
5 changed files with 138 additions and 104 deletions

View File

@ -124,11 +124,15 @@ class ApplicationListAdapter(
apkFolder.mkdirs() apkFolder.mkdirs()
} }
handler.post { handler.post {
try {
materialDialog.show { materialDialog.show {
title(R.string.export_apk_title).message( title(R.string.export_apk_title).message(
R.string.export_apk_load R.string.export_apk_load
).positiveButton(R.string.dialog_close).cancelable(false) ).positiveButton(R.string.dialog_close).cancelable(false)
} }
} catch (e: Exception) {
e.printStackTrace()
}
} }
val path = folder + "/" + appName + "_" + data.versionName + ".apk" val path = folder + "/" + appName + "_" + data.versionName + ".apk"
val result = val result =
@ -146,12 +150,16 @@ class ApplicationListAdapter(
} }
} else { } else {
handler.post { handler.post {
try {
materialDialog.dismiss() materialDialog.dismiss()
Snackbar.make( Snackbar.make(
viewBinding.root, viewBinding.root,
context.getString(R.string.export_apk_failure), context.getString(R.string.export_apk_failure),
Snackbar.LENGTH_SHORT Snackbar.LENGTH_SHORT
).show() ).show()
} catch (e: Exception) {
e.printStackTrace()
}
} }
} }
}.start() }.start()

View File

@ -659,6 +659,7 @@ class ModActionAdapter(
} }
} }
handler.post { handler.post {
try {
materialDialog.dismiss() materialDialog.dismiss()
val modClass = ModClass(unzip_path) val modClass = ModClass(unzip_path)
if (!modClass.hasInfo()) { if (!modClass.hasInfo()) {
@ -667,6 +668,11 @@ class ModActionAdapter(
repairThread.start() repairThread.start()
} }
mModFragment.loadModList() mModFragment.loadModList()
}catch (e: Exception) {
//此处try-catch用于处理某些情况下materialDialog.dismiss()无法获取上下文环境的问题。
// https://console.firebase.google.com/project/rust-assistant-58ca5/crashlytics/app/android:com.coldmint.rust.pro/issues/6daf3a4848ba02f1fb7eee1b8498f9e6?hl=zh-cn&time=last-seven-days&sessionEventKey=645E56A60377000134A21E1A97CE75C2_1810764589804755675
e.printStackTrace()
}
} }
} else { } else {
handler.post { handler.post {

View File

@ -128,9 +128,11 @@ class AllUnitsFragment(
historyDao.update(newHistoryRecord) historyDao.update(newHistoryRecord)
} }
useHandler.post { useHandler.post {
if (isAdded) {
whenAddComplete.invoke() whenAddComplete.invoke()
} }
} }
}
if (useThread) { if (useThread) {
executorService.submit { executorService.submit {
funData.invoke() funData.invoke()
@ -146,16 +148,19 @@ class AllUnitsFragment(
*/ */
fun loadFiles(file: File? = modClass?.modFile) { fun loadFiles(file: File? = modClass?.modFile) {
if (file == null) { if (file == null) {
Snackbar.make(viewBinding.unitList,R.string.file_not_exist,Snackbar.LENGTH_SHORT).show() Snackbar.make(viewBinding.unitList, R.string.file_not_exist, Snackbar.LENGTH_SHORT)
.show()
return return
} }
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
executorService.submit { executorService.submit {
handler.post { handler.post {
if (isAdded) {
viewBinding.swipeRefreshLayout.isVisible = false viewBinding.swipeRefreshLayout.isVisible = false
viewBinding.progressBar.isVisible = true viewBinding.progressBar.isVisible = true
viewBinding.unitError.isVisible = false viewBinding.unitError.isVisible = false
} }
}
dataList.clear() dataList.clear()
val fileFinder2 = FileFinder2(file) val fileFinder2 = FileFinder2(file)
val data = modClass!!.modConfigurationManager?.readData() val data = modClass!!.modConfigurationManager?.readData()
@ -193,6 +198,7 @@ class AllUnitsFragment(
notFindUnits(handler) notFindUnits(handler)
} else { } else {
handler.post { handler.post {
if (isAdded) {
viewBinding.swipeRefreshLayout.isVisible = true viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.progressBar.isVisible = false viewBinding.progressBar.isVisible = false
viewBinding.unitError.isVisible = false viewBinding.unitError.isVisible = false
@ -216,6 +222,7 @@ class AllUnitsFragment(
} }
} }
} }
}
/** /**
@ -225,6 +232,7 @@ class AllUnitsFragment(
fun notFindUnits(handler: Handler? = null, key: String? = null, searchMode: Boolean = false) { fun notFindUnits(handler: Handler? = null, key: String? = null, searchMode: Boolean = false) {
val temHandler = handler ?: Handler(Looper.getMainLooper()) val temHandler = handler ?: Handler(Looper.getMainLooper())
temHandler.post { temHandler.post {
if (isAdded) {
viewBinding.swipeRefreshLayout.isVisible = false viewBinding.swipeRefreshLayout.isVisible = false
viewBinding.progressBar.isVisible = false viewBinding.progressBar.isVisible = false
viewBinding.unitError.isVisible = true viewBinding.unitError.isVisible = true
@ -253,6 +261,7 @@ class AllUnitsFragment(
whenNumberChanged?.invoke(0) whenNumberChanged?.invoke(0)
} }
} }
}
/** /**
@ -262,10 +271,12 @@ class AllUnitsFragment(
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
executorService.submit { executorService.submit {
handler.post { handler.post {
if (isAdded) {
viewBinding.swipeRefreshLayout.isVisible = false viewBinding.swipeRefreshLayout.isVisible = false
viewBinding.progressBar.isVisible = true viewBinding.progressBar.isVisible = true
viewBinding.unitError.isVisible = false viewBinding.unitError.isVisible = false
} }
}
dataList.clear() dataList.clear()
val data = modClass!!.modConfigurationManager?.readData() val data = modClass!!.modConfigurationManager?.readData()
val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template" val sourceFileFilteringRule = data?.sourceFileFilteringRule ?: ".+\\.ini|.+\\.template"
@ -324,6 +335,7 @@ class AllUnitsFragment(
notFindUnits(handler, searchMode = true) notFindUnits(handler, searchMode = true)
} else { } else {
handler.post { handler.post {
if (isAdded) {
viewBinding.swipeRefreshLayout.isVisible = true viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.progressBar.isVisible = false viewBinding.progressBar.isVisible = false
viewBinding.unitError.isVisible = true viewBinding.unitError.isVisible = true
@ -331,7 +343,8 @@ class AllUnitsFragment(
viewBinding.unitError.setOnClickListener { viewBinding.unitError.setOnClickListener {
loadFiles() loadFiles()
} }
val adapter = UnitAdapter(requireContext(), dataList, configuration.unitName) val adapter =
UnitAdapter(requireContext(), dataList, configuration.unitName)
adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass -> adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass ->
unitItemBinding.root.setOnClickListener { unitItemBinding.root.setOnClickListener {
openEditActivity(sourceFileClass) openEditActivity(sourceFileClass)
@ -349,6 +362,7 @@ class AllUnitsFragment(
} }
} }
} }
}
/** /**
* 过滤数据 * 过滤数据
@ -372,6 +386,7 @@ class AllUnitsFragment(
notFindUnits(handler, key) notFindUnits(handler, key)
} else { } else {
handler.post { handler.post {
if (isAdded) {
viewBinding.swipeRefreshLayout.isVisible = true viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.progressBar.isVisible = false viewBinding.progressBar.isVisible = false
viewBinding.unitError.isVisible = true viewBinding.unitError.isVisible = true
@ -398,6 +413,7 @@ class AllUnitsFragment(
} }
} }
} }
}
override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentAllUnitsBinding { override fun getViewBindingObject(layoutInflater: LayoutInflater): FragmentAllUnitsBinding {
return FragmentAllUnitsBinding.inflate(layoutInflater) return FragmentAllUnitsBinding.inflate(layoutInflater)

View File

@ -41,11 +41,15 @@ class BannerManager private constructor() {
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
try { try {
val data = response.body!!.string() val data = response.body!!.string()
val finalBannerItemDataBean = val finalBannerItemDataBean: BannerItemDataBean? =
gson.fromJson(data, BannerItemDataBean::class.java) gson.fromJson(data, BannerItemDataBean::class.java)
if (finalBannerItemDataBean == null) {
handler.post { apiCallBack.onFailure(IOException()) }
} else {
handler.post { handler.post {
apiCallBack.onResponse(finalBannerItemDataBean) apiCallBack.onResponse(finalBannerItemDataBean)
} }
}
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
handler.post { handler.post {

View File

@ -26,7 +26,7 @@ object ServerConfiguration {
//电脑查 ip [ipconfig] //电脑查 ip [ipconfig]
private const val testIp = "http://10.0.2.2/" private const val testIp = "http://10.0.2.2/"
const val defaultIp = "http://39.105.229.249/" const val defaultIp = "https://rust.coldmint.top/"
var website = defaultIp var website = defaultIp
const val Success_Code = 0 const val Success_Code = 0
const val Error_Code = 1 const val Error_Code = 1