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

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,10 +124,14 @@ class ApplicationListAdapter(
apkFolder.mkdirs() apkFolder.mkdirs()
} }
handler.post { handler.post {
materialDialog.show { try {
title(R.string.export_apk_title).message( materialDialog.show {
R.string.export_apk_load title(R.string.export_apk_title).message(
).positiveButton(R.string.dialog_close).cancelable(false) R.string.export_apk_load
).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"
@ -146,12 +150,16 @@ class ApplicationListAdapter(
} }
} else { } else {
handler.post { handler.post {
materialDialog.dismiss() try {
Snackbar.make( materialDialog.dismiss()
viewBinding.root, Snackbar.make(
context.getString(R.string.export_apk_failure), viewBinding.root,
Snackbar.LENGTH_SHORT context.getString(R.string.export_apk_failure),
).show() Snackbar.LENGTH_SHORT
).show()
} catch (e: Exception) {
e.printStackTrace()
}
} }
} }
}.start() }.start()

View File

@ -659,14 +659,20 @@ class ModActionAdapter(
} }
} }
handler.post { handler.post {
materialDialog.dismiss() try {
val modClass = ModClass(unzip_path) materialDialog.dismiss()
if (!modClass.hasInfo()) { val modClass = ModClass(unzip_path)
val repairThread = RepairThread() if (!modClass.hasInfo()) {
repairThread.setModpath(unzip_path.absolutePath) val repairThread = RepairThread()
repairThread.start() repairThread.setModpath(unzip_path.absolutePath)
repairThread.start()
}
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()
} }
mModFragment.loadModList()
} }
} else { } else {
handler.post { handler.post {

View File

@ -128,7 +128,9 @@ class AllUnitsFragment(
historyDao.update(newHistoryRecord) historyDao.update(newHistoryRecord)
} }
useHandler.post { useHandler.post {
whenAddComplete.invoke() if (isAdded) {
whenAddComplete.invoke()
}
} }
} }
if (useThread) { if (useThread) {
@ -146,15 +148,18 @@ 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 {
viewBinding.swipeRefreshLayout.isVisible = false if (isAdded) {
viewBinding.progressBar.isVisible = true viewBinding.swipeRefreshLayout.isVisible = false
viewBinding.unitError.isVisible = false viewBinding.progressBar.isVisible = true
viewBinding.unitError.isVisible = false
}
} }
dataList.clear() dataList.clear()
val fileFinder2 = FileFinder2(file) val fileFinder2 = FileFinder2(file)
@ -193,25 +198,27 @@ class AllUnitsFragment(
notFindUnits(handler) notFindUnits(handler)
} else { } else {
handler.post { handler.post {
viewBinding.swipeRefreshLayout.isVisible = true if (isAdded) {
viewBinding.progressBar.isVisible = false viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.unitError.isVisible = false viewBinding.progressBar.isVisible = false
val adapter = UnitAdapter(requireContext(), dataList, "") viewBinding.unitError.isVisible = false
adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass -> val adapter = UnitAdapter(requireContext(), dataList, "")
unitItemBinding.root.setOnClickListener { adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass ->
openEditActivity(sourceFileClass) unitItemBinding.root.setOnClickListener {
openEditActivity(sourceFileClass)
}
} }
} adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 ->
adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 -> whenNumberChanged?.invoke(i2)
whenNumberChanged?.invoke(i2) if (i2 == 0) {
if (i2 == 0) { loadFiles()
loadFiles() }
} }
FastScrollerBuilder(viewBinding.unitList).useMd2Style()
.setPopupTextProvider(adapter).build()
viewBinding.unitList.adapter = adapter
whenNumberChanged?.invoke(dataList.size)
} }
FastScrollerBuilder(viewBinding.unitList).useMd2Style()
.setPopupTextProvider(adapter).build()
viewBinding.unitList.adapter = adapter
whenNumberChanged?.invoke(dataList.size)
} }
} }
} }
@ -225,32 +232,34 @@ 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 {
viewBinding.swipeRefreshLayout.isVisible = false if (isAdded) {
viewBinding.progressBar.isVisible = false viewBinding.swipeRefreshLayout.isVisible = false
viewBinding.unitError.isVisible = true viewBinding.progressBar.isVisible = false
if (key != null) { viewBinding.unitError.isVisible = true
val source = if (key != null) {
String.format(getString(R.string.not_find_units_name), key) val source =
val spannableString = SpannableString(source) String.format(getString(R.string.not_find_units_name), key)
val action = getString(R.string.not_find_units_action) val spannableString = SpannableString(source)
spannableString.setSpan(object : ClickableSpan() { val action = getString(R.string.not_find_units_action)
override fun onClick(widget: View) { spannableString.setSpan(object : ClickableSpan() {
loadFiles() override fun onClick(widget: View) {
} loadFiles()
}, source.indexOf(action), source.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) }
viewBinding.unitError.movementMethod = LinkMovementMethod.getInstance() }, source.indexOf(action), source.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
viewBinding.unitError.text = spannableString viewBinding.unitError.movementMethod = LinkMovementMethod.getInstance()
} else { viewBinding.unitError.text = spannableString
if (searchMode) {
viewBinding.unitError.text = getString(R.string.search_tip)
viewBinding.unitError.setOnClickListener {
loadFiles()
}
} else { } else {
viewBinding.unitError.setText(R.string.not_find_units) if (searchMode) {
viewBinding.unitError.text = getString(R.string.search_tip)
viewBinding.unitError.setOnClickListener {
loadFiles()
}
} else {
viewBinding.unitError.setText(R.string.not_find_units)
}
} }
whenNumberChanged?.invoke(0)
} }
whenNumberChanged?.invoke(0)
} }
} }
@ -262,9 +271,11 @@ class AllUnitsFragment(
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
executorService.submit { executorService.submit {
handler.post { handler.post {
viewBinding.swipeRefreshLayout.isVisible = false if (isAdded) {
viewBinding.progressBar.isVisible = true viewBinding.swipeRefreshLayout.isVisible = false
viewBinding.unitError.isVisible = false viewBinding.progressBar.isVisible = true
viewBinding.unitError.isVisible = false
}
} }
dataList.clear() dataList.clear()
val data = modClass!!.modConfigurationManager?.readData() val data = modClass!!.modConfigurationManager?.readData()
@ -324,27 +335,30 @@ class AllUnitsFragment(
notFindUnits(handler, searchMode = true) notFindUnits(handler, searchMode = true)
} else { } else {
handler.post { handler.post {
viewBinding.swipeRefreshLayout.isVisible = true if (isAdded) {
viewBinding.progressBar.isVisible = false viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.unitError.isVisible = true viewBinding.progressBar.isVisible = false
viewBinding.unitError.text = getString(R.string.search_tip) viewBinding.unitError.isVisible = true
viewBinding.unitError.setOnClickListener { viewBinding.unitError.text = getString(R.string.search_tip)
loadFiles() viewBinding.unitError.setOnClickListener {
}
val adapter = UnitAdapter(requireContext(), dataList, configuration.unitName)
adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass ->
unitItemBinding.root.setOnClickListener {
openEditActivity(sourceFileClass)
}
}
adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 ->
whenNumberChanged?.invoke(i2)
if (i2 == 0) {
loadFiles() loadFiles()
} }
val adapter =
UnitAdapter(requireContext(), dataList, configuration.unitName)
adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass ->
unitItemBinding.root.setOnClickListener {
openEditActivity(sourceFileClass)
}
}
adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 ->
whenNumberChanged?.invoke(i2)
if (i2 == 0) {
loadFiles()
}
}
viewBinding.unitList.adapter = adapter
whenNumberChanged?.invoke(dataList.size)
} }
viewBinding.unitList.adapter = adapter
whenNumberChanged?.invoke(dataList.size)
} }
} }
} }
@ -372,27 +386,29 @@ class AllUnitsFragment(
notFindUnits(handler, key) notFindUnits(handler, key)
} else { } else {
handler.post { handler.post {
viewBinding.swipeRefreshLayout.isVisible = true if (isAdded) {
viewBinding.progressBar.isVisible = false viewBinding.swipeRefreshLayout.isVisible = true
viewBinding.unitError.isVisible = true viewBinding.progressBar.isVisible = false
viewBinding.unitError.text = getString(R.string.not_find_units_action) viewBinding.unitError.isVisible = true
viewBinding.unitError.setOnClickListener { viewBinding.unitError.text = getString(R.string.not_find_units_action)
loadFiles() viewBinding.unitError.setOnClickListener {
}
val adapter = UnitAdapter(requireContext(), newList, key)
adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass ->
unitItemBinding.root.setOnClickListener {
openEditActivity(sourceFileClass)
}
}
adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 ->
whenNumberChanged?.invoke(i2)
if (i2 == 0) {
loadFiles() loadFiles()
} }
val adapter = UnitAdapter(requireContext(), newList, key)
adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass ->
unitItemBinding.root.setOnClickListener {
openEditActivity(sourceFileClass)
}
}
adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 ->
whenNumberChanged?.invoke(i2)
if (i2 == 0) {
loadFiles()
}
}
viewBinding.unitList.adapter = adapter
whenNumberChanged?.invoke(newList.size)
} }
viewBinding.unitList.adapter = adapter
whenNumberChanged?.invoke(newList.size)
} }
} }
} }

View File

@ -41,10 +41,14 @@ 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)
handler.post { if (finalBannerItemDataBean == null) {
apiCallBack.onResponse(finalBannerItemDataBean) handler.post { apiCallBack.onFailure(IOException()) }
} else {
handler.post {
apiCallBack.onResponse(finalBannerItemDataBean)
}
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()

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