修复BUG

This commit is contained in:
muqing 2024-08-19 07:48:53 +08:00
parent 5b09dc0a84
commit c3ac73c8f4
7 changed files with 89 additions and 237 deletions

View File

@ -95,7 +95,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation platform('com.google.firebase:firebase-bom:31.1.1')
//BUG的组件
implementation platform('com.google.firebase:firebase-bom:31.3.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-perf-ktx'

View File

@ -1,13 +1,8 @@
package com.coldmint.rust.pro
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.ShortcutInfo
import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
@ -47,11 +42,10 @@ import com.google.android.material.snackbar.Snackbar
import com.google.gson.Gson
import org.json.JSONObject
import java.io.File
import java.util.Arrays
import java.util.Locale
import java.util.concurrent.Executors
import java.util.zip.ZipEntry
@Suppress("ConstPropertyName")
class MainActivity : BaseActivity<ActivityMainBinding>() {
private lateinit var appBarConfiguration: AppBarConfiguration
@ -67,14 +61,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
companion object {
//仓库和社区碎片链接TabLayout间隔
const val linkInterval: Long = 195
const val hideViewDelay: Long = 150
}
/**
* 将Toolbar设置为ActionBar
*/
private fun useToolbarSetSupportActionBar() {
// private var time:Long=0;
}
/**
@ -264,7 +252,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val dataBase = menu.findItem(R.id.database_item)
val template = menu.findItem(R.id.template_item)
val codeTable = menu.findItem(R.id.code_table)
val mod = menu.findItem(R.id.mod_item)
// val mod = menu.findItem(R.id.mod_item)
val community = menu.findItem(R.id.community_item)
// val group = menu.findItem(R.id.user_group)
// group.setOnMenuItemClickListener {
@ -284,18 +272,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
template.isVisible = isActive
// help.isVisible = isActive
codeTable.isVisible = isActive
if (mod.isChecked) {
// viewBinding.mainButton.isVisible = isActive
}
if (isActive) {
//数据库
/* dataBase.setOnMenuItemClickListener {
viewBinding.mainButton.postOnAnimationDelayed({
// viewBinding.tabLayout.isVisible = false
viewBinding.mainButton.hide()
}, hideViewDelay)
false
}*/
/* dataBase.setOnMenuItemClickListener {
viewBinding.mainButton.postOnAnimationDelayed({
// viewBinding.tabLayout.isVisible = false
viewBinding.mainButton.hide()
}, hideViewDelay)
false
}*/
/* template.setOnMenuItemClickListener {
viewBinding.mainButton.postOnAnimationDelayed({
@ -331,49 +316,49 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
// 添加动态快捷方式
shortcutManager.addDynamicShortcuts(listOf(info))*/
val intent = Intent(this@MainActivity, CodeTableActivity::class.java)
/* intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)*/
/* intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)*/
startActivity(intent)
false
}
/*重要部分
viewBinding.mainButton.setOnClickListener {
val item = viewBinding.navaiagtion.checkedItem.toString()
val warehouseItem = getString(R.string.warehouse)
//final String database_item = getString(R.string.menu_title3);
val templateItem = getString(R.string.template_title)
when (item) {
warehouseItem -> {
val intent = Intent(this, CreationWizardActivity::class.java)
intent.putExtra("type", "mod")
startActivity(intent)
}
/*重要部分
viewBinding.mainButton.setOnClickListener {
val item = viewBinding.navaiagtion.checkedItem.toString()
val warehouseItem = getString(R.string.warehouse)
//final String database_item = getString(R.string.menu_title3);
val templateItem = getString(R.string.template_title)
when (item) {
warehouseItem -> {
val intent = Intent(this, CreationWizardActivity::class.java)
intent.putExtra("type", "mod")
startActivity(intent)
}
templateItem -> {
val intent = Intent(this, CreationWizardActivity::class.java)
intent.putExtra("type", "template")
startActivity(intent)
}
templateItem -> {
val intent = Intent(this, CreationWizardActivity::class.java)
intent.putExtra("type", "template")
startActivity(intent)
}
else -> {
}
}
}*/
else -> {
}
}
}*/
}
/* mod.setOnMenuItemClickListener {
GlobalMethod.requestStoragePermissions(this) {
if (it) {
viewBinding.mainButton.postOnAnimationDelayed({
// viewBinding.tabLayout.isVisible = true
if (isActive) {
viewBinding.mainButton.show()
/* mod.setOnMenuItemClickListener {
GlobalMethod.requestStoragePermissions(this) {
if (it) {
viewBinding.mainButton.postOnAnimationDelayed({
// viewBinding.tabLayout.isVisible = true
if (isActive) {
viewBinding.mainButton.show()
}
}, hideViewDelay)
}
}, hideViewDelay)
}
}
false
}*/
}
false
}*/
community.setOnMenuItemClickListener {
false
}
@ -449,7 +434,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK) {
val from = File(data!!.getStringExtra("File"))
if (data == null) {
return
}
val from = File(data.getStringExtra("File").toString())
val type = FileOperator.getFileType(from)
if (requestCode == 1) {
if ("rwmod" == type || "zip" == type) {
@ -458,13 +446,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (FileOperator.copyFile(from, to)) {
Snackbar.make(
viewBinding.root,
String.format(getString(R.string.import_complete), from.name),
String.format(Locale.getDefault(),getString(R.string.import_complete), from.name),
Snackbar.LENGTH_SHORT
).show()
} else {
Snackbar.make(
viewBinding.root,
String.format(getString(R.string.import_failed), from.name),
String.format(Locale.getDefault(),getString(R.string.import_failed), from.name),
Snackbar.LENGTH_SHORT
).show()
}
@ -503,6 +491,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
private fun importTemplate(formFile: File, templateDirectory: File) {
val handler = Handler(Looper.getMainLooper())
Thread(Runnable {
try {
//如果建立缓存完成,并且模板文件存在
val compressionManager = CompressionManager.instance
if (templateDirectory.exists()) {
@ -538,7 +528,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
handler.post {
Snackbar.make(
viewBinding.root,
String.format(
String.format(Locale.getDefault(),
getString(R.string.app_version_error),
formFile.name
), Snackbar.LENGTH_LONG
@ -549,7 +539,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (newInfo.versionNum < oldInfo.versionNum) {
handler.post {
MaterialAlertDialogBuilder(this).setTitle(oldInfo.name).setMessage(
String.format(
String.format(Locale.getDefault(),
getString(R.string.covers_the_import),
newInfo.versionName, oldInfo.versionName
)
@ -585,7 +575,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
handler.post {
Snackbar.make(
viewBinding.root,
String.format(
String.format(Locale.getDefault(),
getString(R.string.app_version_error),
formFile.name
), Snackbar.LENGTH_LONG
@ -613,7 +603,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
handler.post {
Snackbar.make(
viewBinding.root,
String.format(
String.format(Locale.getDefault(),
getString(R.string.import_complete),
formFile.name
), Snackbar.LENGTH_LONG
@ -624,25 +614,30 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
})
}catch (e: Exception){
error(e)
}
}).start()
}
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
val navController = findNavController(R.id.baseFragment)
//判断是否在第一个导航 社区或者仓库
if (navController.currentDestination?.id == navController.graph.startDestinationId) {
MaterialAlertDialogBuilder(this).setTitle(R.string.dialog_close).setMessage(
String.format(
String.format(Locale.getDefault(),
getString(R.string.exit_tip),
getString(R.string.app_name)
)
).setPositiveButton(R.string.dialog_ok) { _, _ ->
super.onBackPressed()
finish()
}.setNegativeButton(R.string.dialog_cancel) { _, _ ->
}.show()
} else {
super.onBackPressed()
finish()
}
}
/*
@ -770,18 +765,18 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
initNav()
observeStartViewModel()
//偏移fab
/* if (ImmersionBar.hasNavigationBar(this)) {
val layoutParams =
viewBinding.mainButton.layoutParams as CoordinatorLayout.LayoutParams
layoutParams.setMargins(
GlobalMethod.dp2px(16),
GlobalMethod.dp2px(16),
GlobalMethod.dp2px(16),
ImmersionBar.getNavigationBarHeight(this) + GlobalMethod.dp2px(16)
)
DebugHelper.printLog("导航适配", "已调整fab按钮的位置。")
}*/
checkAppUpdate()
/* if (ImmersionBar.hasNavigationBar(this)) {
val layoutParams =
viewBinding.mainButton.layoutParams as CoordinatorLayout.LayoutParams
layoutParams.setMargins(
GlobalMethod.dp2px(16),
GlobalMethod.dp2px(16),
GlobalMethod.dp2px(16),
ImmersionBar.getNavigationBarHeight(this) + GlobalMethod.dp2px(16)
)
DebugHelper.printLog("导航适配", "已调整fab按钮的位置。")
}*/
// checkAppUpdate() 禁用检查更新
} else {
startViewModel.initAllData()
}

View File

@ -9,7 +9,6 @@ import android.os.Bundle
import cat.ereza.customactivityoncrash.config.CaocConfig
import com.coldmint.rust.core.debug.LogCat
import com.coldmint.rust.core.debug.LogCatObserver
import com.muqing.wj
import com.coldmint.rust.pro.tool.AppSettings
import com.google.android.material.color.DynamicColors
import com.google.android.material.color.DynamicColorsOptions
@ -34,7 +33,6 @@ class RustApplication : Application() {
override fun onCreate() {
super.onCreate()
wj(this)
instanceObject = this

View File

@ -7,7 +7,6 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.coldmint.rust.pro.tool.AppSettings
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
@ -55,7 +54,11 @@ abstract class BaseFragment<T : ViewBinding> : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
firebaseAnalytics = Firebase.analytics
try {
firebaseAnalytics = Firebase.analytics
} catch (e: Exception) {
e.printStackTrace()
}
whenViewCreated(layoutInflater, savedInstanceState)
}
}

View File

@ -1,142 +0,0 @@
package com.muqing;
import android.content.Context;
import android.os.Build;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Objects;
/** @noinspection unused, ResultOfMethodCallIgnored, ResultOfMethodCallIgnored */
public class wj {
public static String filesdri;
public wj(Context context) {
wj.filesdri = Objects.requireNonNull(context.getExternalFilesDir("")).
getAbsolutePath() + "/";
// context.getFilesDir().toString() + "/";
}
/*
* 这里定义的是一个文件保存的方法写入到文件中所以是输出流
* */
public static boolean xrwb(String url, String text) {
if (text == null) {
text = "";
}
File file = new File(url);
//如果文件不存在创建文件
try {
File parentFile = file.getParentFile();
if (!Objects.requireNonNull(parentFile).isDirectory()) {
parentFile.mkdirs();
}
if (!file.exists())
file.createNewFile();
//创建FileOutputStream对象写入内容
FileOutputStream fos = new FileOutputStream(file);
//向文件中写入内容
fos.write(text.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static String dqwb(String url) {
try {
File file = new File(url);
if (!file.exists()) {
return null;
}
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
StringBuilder str = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
str.append(line);
}
br.close();
fis.close();
return str.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static boolean cz(String url) {
return new File(url).exists();
}
public static boolean sc(String url) {
File file = new File(url);
return file.delete();
}
public static boolean sc(File file, boolean bool) {
if (!bool) {
return file.delete();
}
if (file.exists()) {
File[] files = file.listFiles();
if (files != null) {
for (File a : files) {
// 递归调用删除子文件夹及其内容
// 删除文件
sc(a, a.isDirectory());
}
}
return sc(file, false); // 删除当前文件夹
}
return false;
}
public String convertToMd5(String url) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(url.getBytes());
StringBuilder hexString = new StringBuilder();
for (byte value : messageDigest) {
String hex = Integer.toHexString(0xFF & value);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
public static void fz(String sourceFilePath, String targetFilePath) {
File sourceFile = new File(sourceFilePath);
File targetFile = new File(targetFilePath);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try (InputStream in = Files.newInputStream(sourceFile.toPath());
OutputStream out = Files.newOutputStream(targetFile.toPath())) {
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buf)) > 0) {
out.write(buf, 0, bytesRead);
}
// 文件复制完成
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@ -4,10 +4,10 @@ data class TemplateInfo(
val appVersionNum: Int,
val description: String,
val developer: String,
@Deprecated(
"不要直接读取模板名称请使用getName方法",
ReplaceWith("getName()", "com.coldmint.rust.core"), DeprecationLevel.WARNING
)
// @Deprecated(
// "不要直接读取模板名称请使用getName方法",
// ReplaceWith("getName()", "com.coldmint.rust.core"), DeprecationLevel.WARNING
// ) 可惜你没有 getName() 方法
val name: String,
val update: String,
val versionName: String,

View File

@ -1,7 +1,4 @@
package com.coldmint.dialog
import android.app.Dialog
import android.content.Context
import android.view.View
/**