修复崩溃问题,在代码表内添加demo字段。

This commit is contained in:
Cold-Mint 2023-01-31 11:20:07 +08:00
parent b5ce0d7dc2
commit 660122ad0a
6 changed files with 106 additions and 74 deletions

View File

@ -36,6 +36,10 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
private fun initView() { private fun initView() {
setTitle(R.string.file_importer) setTitle(R.string.file_importer)
val account = AppSettings.getValue(AppSettings.Setting.Account, "")
if (account.isNotBlank()) {
firebaseAnalytics.setUserId(account)
}
startViewModel.initAllData() startViewModel.initAllData()
GlobalMethod.requestStoragePermissions(this) { GlobalMethod.requestStoragePermissions(this) {
if (it) { if (it) {
@ -385,53 +389,71 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
} }
return@Runnable return@Runnable
} }
val parcelFileDescriptor = contentResolver.openFileDescriptor(uri!!, "r") try {
if (parcelFileDescriptor != null) { val parcelFileDescriptor = contentResolver.openFileDescriptor(uri!!, "r")
val fileDescriptor = parcelFileDescriptor.fileDescriptor if (parcelFileDescriptor != null) {
val inputStream = FileInputStream(fileDescriptor) val fileDescriptor = parcelFileDescriptor.fileDescriptor
val newFile = File(outputDirectory.absolutePath + "/" + fileName) val inputStream = FileInputStream(fileDescriptor)
if (newFile.exists()) { val newFile = File(outputDirectory.absolutePath + "/" + fileName)
handler.post { if (newFile.exists()) {
MaterialAlertDialogBuilder(this).setTitle(R.string.import_name) handler.post {
.setCancelable(false) MaterialAlertDialogBuilder(this).setTitle(R.string.import_name)
.setMessage( .setCancelable(false)
String.format( .setMessage(
getString(R.string.covers_the_import_mod), String.format(
fileName getString(R.string.covers_the_import_mod),
) fileName
).setPositiveButton( )
R.string.dialog_ok ).setPositiveButton(
) { dialog, which -> R.string.dialog_ok
newFile.delete() ) { dialog, which ->
importMod(outputDirectory) newFile.delete()
} importMod(outputDirectory)
.setNegativeButton(R.string.dialog_cancel, null).show() }
.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 { 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 { handler.post {
viewBinding.okButton.setBackgroundColor( viewBinding.okButton.setBackgroundColor(
GlobalMethod.getColorPrimary( GlobalMethod.getColorPrimary(
this this
) )
) )
viewBinding.okButton.isVisible = false viewBinding.okButton.setText(R.string.import_name)
Snackbar.make( Snackbar.make(
viewBinding.okButton, viewBinding.okButton,
String.format( String.format(
getString(R.string.import_complete), getString(R.string.import_failed),
fileName fileName
), Snackbar.LENGTH_LONG ), Snackbar.LENGTH_LONG
).show() ).show()
@ -439,26 +461,16 @@ class ImporterActivity : BaseActivity<ActivityImporterBinding>() {
} }
} else { } else {
handler.post { handler.post {
viewBinding.okButton.setBackgroundColor( Toast.makeText(this, "parcelFileDescriptor为空", Toast.LENGTH_SHORT)
GlobalMethod.getColorPrimary( .show()
this
)
)
viewBinding.okButton.setText(R.string.import_name)
Snackbar.make(
viewBinding.okButton,
String.format(
getString(R.string.import_failed),
fileName
), Snackbar.LENGTH_LONG
).show()
} }
} }
} else { }catch (e:Exception){
handler.post { e.printStackTrace()
Toast.makeText(this, "parcelFileDescriptor为空", Toast.LENGTH_SHORT) Snackbar.make(
.show() viewBinding.okButton,
} e.toString(), Snackbar.LENGTH_LONG
).show()
} }
}).start() }).start()
} }

View File

@ -21,9 +21,20 @@ import java.util.*
class RustApplication : Application() { class RustApplication : Application() {
companion object {
private lateinit var instanceObject: RustApplication
/**
* 获取实例对象
*/
fun getInstance(): RustApplication {
return instanceObject
}
}
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
instanceObject = this
AppSettings.initAppSettings(this) AppSettings.initAppSettings(this)
//动态颜色 //动态颜色
val options = DynamicColorsOptions.Builder() val options = DynamicColorsOptions.Builder()
@ -35,7 +46,7 @@ class RustApplication : Application() {
) )
}.build() }.build()
DynamicColors.applyToActivitiesIfAvailable(this, options) DynamicColors.applyToActivitiesIfAvailable(this, options)
LogCat.attachObserver(object : LogCatObserver{ LogCat.attachObserver(object : LogCatObserver {
override fun onReceiveLog(msg: String) { override fun onReceiveLog(msg: String) {
Firebase.crashlytics.log(msg) Firebase.crashlytics.log(msg)
} }

View File

@ -28,7 +28,8 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
* 加载列表 * 加载列表
*/ */
fun loadRecyclerView(permission: Int) { fun loadRecyclerView(permission: Int) {
val layoutManager = GridLayoutManager(requireContext(), 4)
val layoutManager = GridLayoutManager(RustApplication.getInstance(), 4)
viewBinding.recyclerView.layoutManager = layoutManager viewBinding.recyclerView.layoutManager = layoutManager
val dataList = ArrayList<CommunityServiceInfo>() val dataList = ArrayList<CommunityServiceInfo>()
dataList.add(CommunityServiceInfo(R.string.work_management, R.drawable.work_management)) dataList.add(CommunityServiceInfo(R.string.work_management, R.drawable.work_management))
@ -45,7 +46,7 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
dataList.add(CommunityServiceInfo(R.string.order_manager, R.drawable.order_manager)) 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 -> adapter.setItemEvent { i, itemServiceBinding, viewHolder, communityServiceInfo ->
itemServiceBinding.root.setOnClickListener { itemServiceBinding.root.setOnClickListener {
when (communityServiceInfo.titleRes) { when (communityServiceInfo.titleRes) {

View File

@ -47,6 +47,9 @@ object GlobalMethod {
const val DEFAULT_GAME_PACKAGE = "com.corrodinggames.rts" const val DEFAULT_GAME_PACKAGE = "com.corrodinggames.rts"
const val DEBUG_SIGN = "963dfd616924b27f9247a35e45bc130a" const val DEBUG_SIGN = "963dfd616924b27f9247a35e45bc130a"
const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda" const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda"
const val Event_LOGOUT = "logOut"
const val Event_LOGIN = "logIn"
/** /**
* 转dp * 转dp

View File

@ -13,6 +13,7 @@ data class CodeInfo(
@PrimaryKey val code: String, @PrimaryKey val code: String,
@ColumnInfo(name = "translate") val translate: String, @ColumnInfo(name = "translate") val translate: String,
@ColumnInfo(name = "description") val description: String, @ColumnInfo(name = "description") val description: String,
@ColumnInfo(name = "demo") val demo: String = "",
@ColumnInfo(name = "type") val type: String, @ColumnInfo(name = "type") val type: String,
@ColumnInfo(name = "add_version") val addVersion: Int, @ColumnInfo(name = "add_version") val addVersion: Int,
@ColumnInfo(name = "remove_version") val removeVersion: Int = 1, @ColumnInfo(name = "remove_version") val removeVersion: Int = 1,

View File

@ -145,25 +145,29 @@ object AppOperator {
*/ */
@SuppressLint("QueryPermissionsNeeded") @SuppressLint("QueryPermissionsNeeded")
fun openApp(context: Context, packageName: String) { fun openApp(context: Context, packageName: String) {
var mainAct: String? = null try {
val pkgMag = context.packageManager var mainAct: String? = null
val intent = Intent(Intent.ACTION_MAIN) val pkgMag = context.packageManager
intent.addCategory(Intent.CATEGORY_LAUNCHER) val intent = Intent(Intent.ACTION_MAIN)
intent.flags = Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or Intent.FLAG_ACTIVITY_NEW_TASK intent.addCategory(Intent.CATEGORY_LAUNCHER)
@SuppressLint("WrongConstant") val list = intent.flags = Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or Intent.FLAG_ACTIVITY_NEW_TASK
pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES) @SuppressLint("WrongConstant") val list =
for (i in list.indices) { pkgMag.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES)
val info = list[i] for (i in list.indices) {
if (info.activityInfo.packageName == packageName) { val info = list[i]
mainAct = info.activityInfo.name if (info.activityInfo.packageName == packageName) {
break 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)
} }
/** /**