From 660122ad0a576d9f4ad198ac3e86991225dac987 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Tue, 31 Jan 2023 11:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B4=A9=E6=BA=83=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E5=9C=A8=E4=BB=A3=E7=A0=81=E8=A1=A8=E5=86=85?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0demo=E5=AD=97=E6=AE=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/coldmint/rust/pro/ImporterActivity.kt | 120 ++++++++++-------- .../com/coldmint/rust/pro/RustApplication.kt | 13 +- .../rust/pro/fragments/UserInfoFragment.kt | 5 +- .../coldmint/rust/pro/tool/GlobalMethod.kt | 3 + .../rust/core/database/code/CodeInfo.kt | 1 + .../coldmint/rust/core/tool/AppOperator.kt | 38 +++--- 6 files changed, 106 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt index c8a7212..71ce742 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ImporterActivity.kt @@ -36,6 +36,10 @@ class ImporterActivity : BaseActivity() { private fun initView() { setTitle(R.string.file_importer) + val account = AppSettings.getValue(AppSettings.Setting.Account, "") + if (account.isNotBlank()) { + firebaseAnalytics.setUserId(account) + } startViewModel.initAllData() GlobalMethod.requestStoragePermissions(this) { if (it) { @@ -385,53 +389,71 @@ class ImporterActivity : BaseActivity() { } return@Runnable } - val parcelFileDescriptor = contentResolver.openFileDescriptor(uri!!, "r") - if (parcelFileDescriptor != null) { - val fileDescriptor = parcelFileDescriptor.fileDescriptor - val inputStream = FileInputStream(fileDescriptor) - val newFile = File(outputDirectory.absolutePath + "/" + fileName) - if (newFile.exists()) { - handler.post { - MaterialAlertDialogBuilder(this).setTitle(R.string.import_name) - .setCancelable(false) - .setMessage( - String.format( - getString(R.string.covers_the_import_mod), - fileName - ) - ).setPositiveButton( - R.string.dialog_ok - ) { dialog, which -> - newFile.delete() - importMod(outputDirectory) - } - .setNegativeButton(R.string.dialog_cancel, null).show() + try { + val parcelFileDescriptor = contentResolver.openFileDescriptor(uri!!, "r") + if (parcelFileDescriptor != null) { + val fileDescriptor = parcelFileDescriptor.fileDescriptor + val inputStream = FileInputStream(fileDescriptor) + val newFile = File(outputDirectory.absolutePath + "/" + fileName) + if (newFile.exists()) { + handler.post { + MaterialAlertDialogBuilder(this).setTitle(R.string.import_name) + .setCancelable(false) + .setMessage( + String.format( + getString(R.string.covers_the_import_mod), + fileName + ) + ).setPositiveButton( + R.string.dialog_ok + ) { dialog, which -> + newFile.delete() + importMod(outputDirectory) + } + .setNegativeButton(R.string.dialog_cancel, null).show() + } + return@Runnable } - return@Runnable - } - handler.post { - viewBinding.okButton.setText(R.string.importing) - viewBinding.okButton.setBackgroundColor( - GlobalMethod.getThemeColor( - this, - R.attr.colorPrimaryVariant - ) - ) - } - val result = copyFile(inputStream, newFile) - if (result) { handler.post { + viewBinding.okButton.setText(R.string.importing) + viewBinding.okButton.setBackgroundColor( + GlobalMethod.getThemeColor( + this, + R.attr.colorPrimaryVariant + ) + ) + } + val result = copyFile(inputStream, newFile) + if (result) { + handler.post { + handler.post { + viewBinding.okButton.setBackgroundColor( + GlobalMethod.getColorPrimary( + this + ) + ) + viewBinding.okButton.isVisible = false + Snackbar.make( + viewBinding.okButton, + String.format( + getString(R.string.import_complete), + fileName + ), Snackbar.LENGTH_LONG + ).show() + } + } + } else { handler.post { viewBinding.okButton.setBackgroundColor( GlobalMethod.getColorPrimary( this ) ) - viewBinding.okButton.isVisible = false + viewBinding.okButton.setText(R.string.import_name) Snackbar.make( viewBinding.okButton, String.format( - getString(R.string.import_complete), + getString(R.string.import_failed), fileName ), Snackbar.LENGTH_LONG ).show() @@ -439,26 +461,16 @@ class ImporterActivity : BaseActivity() { } } else { handler.post { - viewBinding.okButton.setBackgroundColor( - GlobalMethod.getColorPrimary( - this - ) - ) - viewBinding.okButton.setText(R.string.import_name) - Snackbar.make( - viewBinding.okButton, - String.format( - getString(R.string.import_failed), - fileName - ), Snackbar.LENGTH_LONG - ).show() + Toast.makeText(this, "parcelFileDescriptor为空", Toast.LENGTH_SHORT) + .show() } } - } else { - handler.post { - Toast.makeText(this, "parcelFileDescriptor为空", Toast.LENGTH_SHORT) - .show() - } + }catch (e:Exception){ + e.printStackTrace() + Snackbar.make( + viewBinding.okButton, + e.toString(), Snackbar.LENGTH_LONG + ).show() } }).start() } diff --git a/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt b/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt index cb71afa..273c0fc 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RustApplication.kt @@ -21,9 +21,20 @@ import java.util.* class RustApplication : Application() { + companion object { + private lateinit var instanceObject: RustApplication + + /** + * 获取实例对象 + */ + fun getInstance(): RustApplication { + return instanceObject + } + } override fun onCreate() { super.onCreate() + instanceObject = this AppSettings.initAppSettings(this) //动态颜色 val options = DynamicColorsOptions.Builder() @@ -35,7 +46,7 @@ class RustApplication : Application() { ) }.build() DynamicColors.applyToActivitiesIfAvailable(this, options) - LogCat.attachObserver(object : LogCatObserver{ + LogCat.attachObserver(object : LogCatObserver { override fun onReceiveLog(msg: String) { Firebase.crashlytics.log(msg) } diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt index 5c04b60..ad84fbd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/UserInfoFragment.kt @@ -28,7 +28,8 @@ class UserInfoFragment : BaseFragment() { * 加载列表 */ fun loadRecyclerView(permission: Int) { - val layoutManager = GridLayoutManager(requireContext(), 4) + + val layoutManager = GridLayoutManager(RustApplication.getInstance(), 4) viewBinding.recyclerView.layoutManager = layoutManager val dataList = ArrayList() dataList.add(CommunityServiceInfo(R.string.work_management, R.drawable.work_management)) @@ -45,7 +46,7 @@ class UserInfoFragment : BaseFragment() { dataList.add(CommunityServiceInfo(R.string.order_manager, R.drawable.order_manager)) } } - val adapter = CommunityServiceAdapter(requireContext(), dataList) + val adapter = CommunityServiceAdapter(RustApplication.getInstance(), dataList) adapter.setItemEvent { i, itemServiceBinding, viewHolder, communityServiceInfo -> itemServiceBinding.root.setOnClickListener { when (communityServiceInfo.titleRes) { diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt index e2db104..72e954c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt @@ -47,6 +47,9 @@ object GlobalMethod { const val DEFAULT_GAME_PACKAGE = "com.corrodinggames.rts" const val DEBUG_SIGN = "963dfd616924b27f9247a35e45bc130a" const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda" + const val Event_LOGOUT = "logOut" + const val Event_LOGIN = "logIn" + /** * 转dp diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/database/code/CodeInfo.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/database/code/CodeInfo.kt index 634ef88..3aa56a0 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/database/code/CodeInfo.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/database/code/CodeInfo.kt @@ -13,6 +13,7 @@ data class CodeInfo( @PrimaryKey val code: String, @ColumnInfo(name = "translate") val translate: String, @ColumnInfo(name = "description") val description: String, + @ColumnInfo(name = "demo") val demo: String = "", @ColumnInfo(name = "type") val type: String, @ColumnInfo(name = "add_version") val addVersion: Int, @ColumnInfo(name = "remove_version") val removeVersion: Int = 1, diff --git a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/AppOperator.kt b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/AppOperator.kt index b57c367..54dc691 100644 --- a/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/AppOperator.kt +++ b/assistantCoreLibrary/src/main/java/com/coldmint/rust/core/tool/AppOperator.kt @@ -145,25 +145,29 @@ object AppOperator { */ @SuppressLint("QueryPermissionsNeeded") fun openApp(context: Context, packageName: String) { - var mainAct: String? = null - val pkgMag = context.packageManager - val intent = Intent(Intent.ACTION_MAIN) - intent.addCategory(Intent.CATEGORY_LAUNCHER) - intent.flags = Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or Intent.FLAG_ACTIVITY_NEW_TASK - @SuppressLint("WrongConstant") val list = - pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES) - for (i in list.indices) { - val info = list[i] - if (info.activityInfo.packageName == packageName) { - mainAct = info.activityInfo.name - break + try { + var mainAct: String? = null + val pkgMag = context.packageManager + val intent = Intent(Intent.ACTION_MAIN) + intent.addCategory(Intent.CATEGORY_LAUNCHER) + intent.flags = Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or Intent.FLAG_ACTIVITY_NEW_TASK + @SuppressLint("WrongConstant") val list = + pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES) + for (i in list.indices) { + val info = list[i] + if (info.activityInfo.packageName == packageName) { + mainAct = info.activityInfo.name + break + } } + if (mainAct!!.isEmpty()) { + return + } + intent.component = ComponentName(packageName, mainAct) + context.startActivity(intent) + }catch (e:Exception){ + e.printStackTrace() } - if (mainAct!!.isEmpty()) { - return - } - intent.component = ComponentName(packageName, mainAct) - context.startActivity(intent) } /**