diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt index 9af847f..687a230 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt @@ -124,10 +124,14 @@ class ApplicationListAdapter( apkFolder.mkdirs() } handler.post { - materialDialog.show { - title(R.string.export_apk_title).message( - R.string.export_apk_load - ).positiveButton(R.string.dialog_close).cancelable(false) + try { + materialDialog.show { + title(R.string.export_apk_title).message( + R.string.export_apk_load + ).positiveButton(R.string.dialog_close).cancelable(false) + } + } catch (e: Exception) { + e.printStackTrace() } } val path = folder + "/" + appName + "_" + data.versionName + ".apk" @@ -146,12 +150,16 @@ class ApplicationListAdapter( } } else { handler.post { - materialDialog.dismiss() - Snackbar.make( - viewBinding.root, - context.getString(R.string.export_apk_failure), - Snackbar.LENGTH_SHORT - ).show() + try { + materialDialog.dismiss() + Snackbar.make( + viewBinding.root, + context.getString(R.string.export_apk_failure), + Snackbar.LENGTH_SHORT + ).show() + } catch (e: Exception) { + e.printStackTrace() + } } } }.start() diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt index 736d13e..f47cd7e 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt @@ -659,14 +659,20 @@ class ModActionAdapter( } } handler.post { - materialDialog.dismiss() - val modClass = ModClass(unzip_path) - if (!modClass.hasInfo()) { - val repairThread = RepairThread() - repairThread.setModpath(unzip_path.absolutePath) - repairThread.start() + try { + materialDialog.dismiss() + val modClass = ModClass(unzip_path) + if (!modClass.hasInfo()) { + val repairThread = RepairThread() + 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 { handler.post { diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt index 29feca0..823e299 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/AllUnitsFragment.kt @@ -128,7 +128,9 @@ class AllUnitsFragment( historyDao.update(newHistoryRecord) } useHandler.post { - whenAddComplete.invoke() + if (isAdded) { + whenAddComplete.invoke() + } } } if (useThread) { @@ -146,15 +148,18 @@ class AllUnitsFragment( */ fun loadFiles(file: File? = modClass?.modFile) { 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 } val handler = Handler(Looper.getMainLooper()) executorService.submit { handler.post { - viewBinding.swipeRefreshLayout.isVisible = false - viewBinding.progressBar.isVisible = true - viewBinding.unitError.isVisible = false + if (isAdded) { + viewBinding.swipeRefreshLayout.isVisible = false + viewBinding.progressBar.isVisible = true + viewBinding.unitError.isVisible = false + } } dataList.clear() val fileFinder2 = FileFinder2(file) @@ -193,25 +198,27 @@ class AllUnitsFragment( notFindUnits(handler) } else { handler.post { - viewBinding.swipeRefreshLayout.isVisible = true - viewBinding.progressBar.isVisible = false - viewBinding.unitError.isVisible = false - val adapter = UnitAdapter(requireContext(), dataList, "") - adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass -> - unitItemBinding.root.setOnClickListener { - openEditActivity(sourceFileClass) + if (isAdded) { + viewBinding.swipeRefreshLayout.isVisible = true + viewBinding.progressBar.isVisible = false + viewBinding.unitError.isVisible = false + val adapter = UnitAdapter(requireContext(), dataList, "") + adapter.setItemEvent { i, unitItemBinding, viewHolder, sourceFileClass -> + unitItemBinding.root.setOnClickListener { + openEditActivity(sourceFileClass) + } } - } - adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 -> - whenNumberChanged?.invoke(i2) - if (i2 == 0) { - loadFiles() + adapter.setItemChangeEvent { changeType, i, sourceFileClass, i2 -> + whenNumberChanged?.invoke(i2) + if (i2 == 0) { + 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) { val temHandler = handler ?: Handler(Looper.getMainLooper()) temHandler.post { - viewBinding.swipeRefreshLayout.isVisible = false - viewBinding.progressBar.isVisible = false - viewBinding.unitError.isVisible = true - if (key != null) { - val source = - String.format(getString(R.string.not_find_units_name), key) - val spannableString = SpannableString(source) - val action = getString(R.string.not_find_units_action) - spannableString.setSpan(object : ClickableSpan() { - override fun onClick(widget: View) { - loadFiles() - } - }, source.indexOf(action), source.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) - viewBinding.unitError.movementMethod = LinkMovementMethod.getInstance() - viewBinding.unitError.text = spannableString - } else { - if (searchMode) { - viewBinding.unitError.text = getString(R.string.search_tip) - viewBinding.unitError.setOnClickListener { - loadFiles() - } + if (isAdded) { + viewBinding.swipeRefreshLayout.isVisible = false + viewBinding.progressBar.isVisible = false + viewBinding.unitError.isVisible = true + if (key != null) { + val source = + String.format(getString(R.string.not_find_units_name), key) + val spannableString = SpannableString(source) + val action = getString(R.string.not_find_units_action) + spannableString.setSpan(object : ClickableSpan() { + override fun onClick(widget: View) { + loadFiles() + } + }, source.indexOf(action), source.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE) + viewBinding.unitError.movementMethod = LinkMovementMethod.getInstance() + viewBinding.unitError.text = spannableString } 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()) executorService.submit { handler.post { - viewBinding.swipeRefreshLayout.isVisible = false - viewBinding.progressBar.isVisible = true - viewBinding.unitError.isVisible = false + if (isAdded) { + viewBinding.swipeRefreshLayout.isVisible = false + viewBinding.progressBar.isVisible = true + viewBinding.unitError.isVisible = false + } } dataList.clear() val data = modClass!!.modConfigurationManager?.readData() @@ -324,27 +335,30 @@ class AllUnitsFragment( notFindUnits(handler, searchMode = true) } else { handler.post { - viewBinding.swipeRefreshLayout.isVisible = true - viewBinding.progressBar.isVisible = false - viewBinding.unitError.isVisible = true - viewBinding.unitError.text = getString(R.string.search_tip) - viewBinding.unitError.setOnClickListener { - 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) { + if (isAdded) { + viewBinding.swipeRefreshLayout.isVisible = true + viewBinding.progressBar.isVisible = false + viewBinding.unitError.isVisible = true + viewBinding.unitError.text = getString(R.string.search_tip) + viewBinding.unitError.setOnClickListener { 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) } else { handler.post { - viewBinding.swipeRefreshLayout.isVisible = true - viewBinding.progressBar.isVisible = false - viewBinding.unitError.isVisible = true - viewBinding.unitError.text = getString(R.string.not_find_units_action) - viewBinding.unitError.setOnClickListener { - 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) { + if (isAdded) { + viewBinding.swipeRefreshLayout.isVisible = true + viewBinding.progressBar.isVisible = false + viewBinding.unitError.isVisible = true + viewBinding.unitError.text = getString(R.string.not_find_units_action) + viewBinding.unitError.setOnClickListener { 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) } } } diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/BannerManager.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/BannerManager.kt index 04ac8dd..93f88f9 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/BannerManager.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/BannerManager.kt @@ -41,10 +41,14 @@ class BannerManager private constructor() { override fun onResponse(call: Call, response: Response) { try { val data = response.body!!.string() - val finalBannerItemDataBean = + val finalBannerItemDataBean: BannerItemDataBean? = gson.fromJson(data, BannerItemDataBean::class.java) - handler.post { - apiCallBack.onResponse(finalBannerItemDataBean) + if (finalBannerItemDataBean == null) { + handler.post { apiCallBack.onFailure(IOException()) } + } else { + handler.post { + apiCallBack.onResponse(finalBannerItemDataBean) + } } } catch (e: Exception) { e.printStackTrace() diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/ServerConfiguration.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/ServerConfiguration.kt index 42c7bd0..2a19eb7 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/ServerConfiguration.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/web/ServerConfiguration.kt @@ -26,7 +26,7 @@ object ServerConfiguration { //电脑查 ip [ipconfig] 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 const val Success_Code = 0 const val Error_Code = 1