refactor(layout): 优化多个布局文件的结构和样式
-调整 TabLayout 属性以改善显示效果 - 移除不必要的 View 组件和布局嵌套 - 优化 ModFragment 中的代码结构 - 修复 UnitsActivity 中的 exitActivity 方法
This commit is contained in:
parent
64af11ffed
commit
1b69f434e8
|
@ -33,6 +33,7 @@ import kotlin.concurrent.thread
|
|||
class UnitsActivity : BaseActivity<ActivityUnitsBinding>() {
|
||||
private lateinit var modPageAdapter: ModPageAdapter
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
|
@ -190,7 +191,7 @@ class UnitsActivity : BaseActivity<ActivityUnitsBinding>() {
|
|||
/**
|
||||
* 关闭数据库链接并退出活动
|
||||
*/
|
||||
fun exitActivity() {
|
||||
private fun exitActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.annotation.SuppressLint
|
|||
import android.content.res.ColorStateList
|
||||
import android.os.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
@ -21,8 +23,10 @@ import com.coldmint.rust.pro.databinding.FragmentModBinding
|
|||
import com.coldmint.rust.pro.databinding.ModListItemBinding
|
||||
import com.coldmint.rust.pro.tool.AppSettings
|
||||
import com.coldmint.rust.pro.tool.GlobalMethod
|
||||
import com.coldmint.rust.pro.tool.Tools
|
||||
import com.coldmint.rust.pro.ui.StableLinearLayoutManager
|
||||
import com.coldmint.rust.pro.viewmodel.ModViewModel
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.divider.MaterialDividerItemDecoration
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
@ -41,8 +45,8 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
val needRecycling by lazy {
|
||||
if (GlobalMethod.isActive) {
|
||||
AppSettings.getValue(
|
||||
AppSettings.Setting.EnableRecoveryStation,
|
||||
true
|
||||
AppSettings.Setting.EnableRecoveryStation,
|
||||
true
|
||||
)
|
||||
} else {
|
||||
false
|
||||
|
@ -55,15 +59,15 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
* @param modClass ModClass
|
||||
*/
|
||||
fun delFile(
|
||||
handler: Handler,
|
||||
modClass: ModClass,
|
||||
index: Int? = null
|
||||
handler: Handler,
|
||||
modClass: ModClass,
|
||||
index: Int? = null
|
||||
) {
|
||||
val scope = CoroutineScope(Job())
|
||||
scope.launch {
|
||||
val targetFile = modClass.modFile
|
||||
val errorFolder =
|
||||
File(AppSettings.dataRootDirectory + "/modErrorReport/" + modClass.modName)
|
||||
File(AppSettings.dataRootDirectory + "/modErrorReport/" + modClass.modName)
|
||||
if (errorFolder.exists()) {
|
||||
FileOperator.delete_files(errorFolder)
|
||||
}
|
||||
|
@ -71,7 +75,7 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
requireActivity().applicationContext.dataDir.absolutePath + "/databases/"
|
||||
} else {
|
||||
FileOperator.getSuperDirectory(
|
||||
requireContext().cacheDir
|
||||
requireContext().cacheDir
|
||||
) + "/databases/"
|
||||
}
|
||||
val name = modClass.modName
|
||||
|
@ -87,8 +91,8 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
val removeFile: File
|
||||
if (targetFile.isDirectory) {
|
||||
removePath = AppSettings.getValue(
|
||||
AppSettings.Setting.RecoveryStationFolder,
|
||||
requireContext().filesDir.absolutePath + "/backup/"
|
||||
AppSettings.Setting.RecoveryStationFolder,
|
||||
requireContext().filesDir.absolutePath + "/backup/"
|
||||
).toString() + targetFile.name + "/"
|
||||
removeFile = File(removePath)
|
||||
if (!removeFile.exists()) {
|
||||
|
@ -96,8 +100,8 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
}
|
||||
} else {
|
||||
removePath = AppSettings.getValue(
|
||||
AppSettings.Setting.RecoveryStationFolder,
|
||||
requireContext().filesDir.absolutePath + "/backup/"
|
||||
AppSettings.Setting.RecoveryStationFolder,
|
||||
requireContext().filesDir.absolutePath + "/backup/"
|
||||
).toString() + targetFile.name
|
||||
removeFile = File(removePath)
|
||||
}
|
||||
|
@ -106,24 +110,24 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
}
|
||||
handler.post {
|
||||
Snackbar.make(
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
getString(R.string.recoverying_prompt),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
getString(R.string.recoverying_prompt),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
).show()
|
||||
}
|
||||
result = FileOperator.removeFiles(targetFile, removeFile)
|
||||
if (result) {
|
||||
handler.post {
|
||||
Snackbar.make(
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
requireContext().getString(R.string.recovery_prompt),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_SHORT
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
requireContext().getString(R.string.recovery_prompt),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
if (index != null) {
|
||||
modAdapter.removeItem(index)
|
||||
|
@ -132,32 +136,32 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
} else {
|
||||
handler.post {
|
||||
Snackbar.make(
|
||||
viewBinding.modList,
|
||||
getString(R.string.cut_failed),
|
||||
Snackbar.LENGTH_SHORT
|
||||
viewBinding.modList,
|
||||
getString(R.string.cut_failed),
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handler.post {
|
||||
Snackbar.make(
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
getString(R.string.del_moding_tip),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
getString(R.string.del_moding_tip),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
).show()
|
||||
}
|
||||
FileOperator.delete_files(targetFile)
|
||||
handler.post {
|
||||
Snackbar.make(
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
getString(R.string.del_completed),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_SHORT
|
||||
viewBinding.modList,
|
||||
String.format(
|
||||
getString(R.string.del_completed),
|
||||
modClass.modName
|
||||
),
|
||||
Snackbar.LENGTH_SHORT
|
||||
).show()
|
||||
if (index != null) {
|
||||
modAdapter.removeItem(index)
|
||||
|
@ -198,21 +202,19 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
if (isAdded) {
|
||||
modAdapter = ModAdapter(requireContext(), dataList)
|
||||
FastScrollerBuilder(viewBinding.modList).useMd2Style()
|
||||
.setPopupTextProvider(modAdapter).build()
|
||||
.setPopupTextProvider(modAdapter).build()
|
||||
modAdapter.setItemEvent { i, modListItemBinding, viewHolder, modClass ->
|
||||
|
||||
modListItemBinding.root.setOnClickListener {
|
||||
onClickItemWork(modListItemBinding, modClass)
|
||||
}
|
||||
|
||||
modListItemBinding.root.setOnLongClickListener {
|
||||
modAdapter.showDeleteItemDialog(
|
||||
modClass.modName,
|
||||
viewHolder.adapterPosition,
|
||||
onClickPositiveButton = { d, b ->
|
||||
delFile(handler, modClass, viewHolder.adapterPosition)
|
||||
false
|
||||
})
|
||||
modClass.modName,
|
||||
viewHolder.absoluteAdapterPosition,
|
||||
onClickPositiveButton = { d, b ->
|
||||
delFile(handler, modClass, viewHolder.absoluteAdapterPosition)
|
||||
false
|
||||
})
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -235,16 +237,16 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
fun onClickItemWork(viewBinding: ModListItemBinding, modClass: ModClass) {
|
||||
val context = requireContext()
|
||||
val modDialogBinding =
|
||||
ModDialogBinding.inflate(LayoutInflater.from(context))
|
||||
ModDialogBinding.inflate(LayoutInflater.from(context))
|
||||
val bottomSheetDialog =
|
||||
BottomSheetDialog(context)
|
||||
BottomSheetDialog(context)
|
||||
|
||||
|
||||
modDialogBinding.modNameView.text = viewBinding.modNameView.text
|
||||
modDialogBinding.modNameDescription.text = viewBinding.modIntroductionView.text
|
||||
val configurationManager = modClass.modConfigurationManager
|
||||
val configurationData: ModConfigurationData? =
|
||||
configurationManager?.readData()
|
||||
configurationManager?.readData()
|
||||
val works: MutableList<String> = ArrayList()
|
||||
if (modClass.modFile.isDirectory) {
|
||||
// val developerMode = AppSettings.getValue(AppSettings.Setting.DeveloperMode, false)
|
||||
|
@ -266,7 +268,7 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
works.add(getString(R.string.release))
|
||||
if (configurationData != null) {
|
||||
val title = configurationData.updateTitle
|
||||
if (!title.isEmpty()) {
|
||||
if (title.isNotEmpty()) {
|
||||
works.add(title)
|
||||
}
|
||||
|
||||
|
@ -282,11 +284,11 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
}
|
||||
works.add(getString(R.string.share_mod))
|
||||
val modActionAdapter = ModActionAdapter(
|
||||
context,
|
||||
works,
|
||||
modClass.modFile.path,
|
||||
this@ModFragment,
|
||||
bottomSheetDialog
|
||||
context,
|
||||
works,
|
||||
modClass.modFile.path,
|
||||
this@ModFragment,
|
||||
bottomSheetDialog
|
||||
)
|
||||
if (configurationData != null) {
|
||||
modActionAdapter.setModConfigurationData(configurationData)
|
||||
|
@ -296,13 +298,13 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
if (modClass.modIcon == null) {
|
||||
val drawable = context.getDrawable(R.drawable.image)
|
||||
modDialogBinding.modIcon.setImageDrawable(
|
||||
GlobalMethod.tintDrawable(
|
||||
drawable, ColorStateList.valueOf(
|
||||
GlobalMethod.getColorPrimary(
|
||||
requireContext()
|
||||
)
|
||||
GlobalMethod.tintDrawable(
|
||||
drawable, ColorStateList.valueOf(
|
||||
GlobalMethod.getColorPrimary(
|
||||
requireContext()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Glide.with(requireContext()).load(modClass.modIcon).into(modDialogBinding.modIcon)
|
||||
|
@ -310,16 +312,24 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
} else {
|
||||
val drawable = context.getDrawable(R.drawable.file)
|
||||
modDialogBinding.modIcon.setImageDrawable(
|
||||
GlobalMethod.tintDrawable(
|
||||
drawable, ColorStateList.valueOf(
|
||||
GlobalMethod.getColorPrimary(
|
||||
requireContext()
|
||||
)
|
||||
GlobalMethod.tintDrawable(
|
||||
drawable, ColorStateList.valueOf(
|
||||
GlobalMethod.getColorPrimary(
|
||||
requireContext()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
bottomSheetDialog.setContentView(modDialogBinding.root)
|
||||
val bottomSheet = bottomSheetDialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
|
||||
if (bottomSheet != null) {
|
||||
val behavior = BottomSheetBehavior.from(bottomSheet)
|
||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED // 默认展开
|
||||
behavior.isFitToContents = true // 使其填满屏幕
|
||||
behavior.peekHeight = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
}
|
||||
|
||||
bottomSheetDialog.show()
|
||||
}
|
||||
|
||||
|
@ -341,11 +351,11 @@ class ModFragment : BaseFragment<FragmentModBinding>() {
|
|||
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
|
||||
viewBinding.modList.layoutManager = StableLinearLayoutManager(requireContext())
|
||||
val divider = MaterialDividerItemDecoration(
|
||||
requireContext(),
|
||||
MaterialDividerItemDecoration.VERTICAL
|
||||
requireContext(),
|
||||
MaterialDividerItemDecoration.VERTICAL
|
||||
)
|
||||
viewBinding.modList.addItemDecoration(
|
||||
divider
|
||||
divider
|
||||
)
|
||||
viewBinding.swipeRefreshLayout.setOnRefreshListener {
|
||||
loadModList()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="0dp"
|
||||
|
@ -7,26 +8,9 @@
|
|||
android:layout_weight="1"
|
||||
android:background="?android:colorBackground">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/titleView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/actionBarSize"
|
||||
android:gravity="center"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?android:windowBackground"
|
||||
app:cardElevation="2dp">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/file_manager" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/titleView"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
|
|
@ -19,19 +19,10 @@
|
|||
android:id="@+id/tabLayout"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<!-- <com.google.android.material.tabs.TabItem-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="全部" />-->
|
||||
|
||||
<!-- <com.google.android.material.tabs.TabItem-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="最近" />-->
|
||||
|
||||
</com.google.android.material.tabs.TabLayout>
|
||||
app:tabGravity="center"
|
||||
app:tabMode="auto"
|
||||
app:tabMaxWidth="300dp"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
|
@ -51,6 +42,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/add" />
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/add" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -7,26 +8,9 @@
|
|||
android:layout_gravity="start"
|
||||
android:background="?android:colorBackground">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/titleView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/actionBarSize"
|
||||
android:gravity="center"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?android:windowBackground"
|
||||
app:cardElevation="2dp">
|
||||
|
||||
<TextView
|
||||
style="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/file_manager" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/titleView"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
@ -53,6 +37,7 @@
|
|||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_margin="16dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/add"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
|
@ -17,9 +18,11 @@
|
|||
android:id="@+id/modErrorIcon"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/empty_content"
|
||||
android:visibility="gone"
|
||||
app:tint="?attr/colorControlNormal" />
|
||||
app:tint="?attr/colorControlNormal"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/modError"
|
||||
|
@ -33,10 +36,10 @@
|
|||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone">
|
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
Loading…
Reference in New Issue
Block a user