feat(layout): 为平板电脑添加横向布局

- 新增 activity_edit.xml 和 edit_start.xml 横向布局文件
- 修改 EditActivity 中的抽屉逻辑,适应平板模式
- 更新 RankingFragment 中的排序芯片布局
This commit is contained in:
muqing 2025-01-20 14:36:32 +08:00
parent a5b7954edc
commit 64af11ffed
5 changed files with 307 additions and 49 deletions

View File

@ -1,5 +1,6 @@
package com.coldmint.rust.pro
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.graphics.Typeface
@ -8,6 +9,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.Menu
@ -47,6 +49,7 @@ import com.coldmint.rust.pro.interfaces.BookmarkListener
import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.tool.CompletionItemConverter
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.EditStartViewModel
import com.coldmint.rust.pro.viewmodel.EditViewModel
@ -58,7 +61,8 @@ import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
import jp.wasabeef.glide.transformations.BlurTransformation
import java.io.File
@Suppress("SameParameterValue")
@SuppressLint("StringFormatInvalid")
class EditActivity : BaseActivity<ActivityEditBinding>() {
private val viewModel by lazy {
ViewModelProvider(this)[EditViewModel::class.java]
@ -66,8 +70,10 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
private lateinit var turretCoordinateResults: ActivityResultLauncher<Intent>
private lateinit var rustLanguage: RustLanguage
private var fileAdapter: FileAdapter? = null
//是第一次启动嘛
private var isFirst = true
/**
* 编辑器左侧视图
*/
@ -181,8 +187,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
// }
// true
// }
viewModel.openedSourceFileListLiveData.observe(this)
{
viewModel.openedSourceFileListLiveData.observe(this) {
viewBinding.tabLayout.removeAllTabs()
viewBinding.tabLayout.isVisible = true
it.forEach { it ->
@ -225,9 +230,11 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
if (viewModel.openedSourceFileListLiveData.value.size > 1) {
popupMenu.menu.add(R.string.close)
}
popupMenu.setOnMenuItemClickListener {
when (title.toString()) {
popupMenu.setOnMenuItemClickListener { view ->
when (view.title.toString()) {
getString(R.string.close) -> {
Log.i("TAG", "loadMainObserve: ${openedSourceFile.file.absolutePath}")
if (openedSourceFile.isNeedSave()) {
CoreDialog(this).setTitle(R.string.edit_function)
.setMessage(R.string.text_changed)
@ -238,13 +245,16 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
viewModel.closeFile(openedSourceFile)
}.show()
} else {
// Log.i("TAG", "loadMainObserve: ${openedSourceFile.file.absolutePath}")
viewModel.closeFile(openedSourceFile)
}
}
getString(R.string.open_directory_of_file) -> {
// Log.i("TAG", "loadMainObserve: ${openedSourceFile.file.absolutePath}")
editStartViewModel.loadPathLiveData.value =
FileOperator.getSuperDirectory(openedSourceFile.file)
viewBinding.editDrawerlayout.openDrawer(GravityCompat.START)
openDrawer(GravityCompat.START)
}
}
false
@ -260,8 +270,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
}
}
viewModel.codeLiveData.observe(this)
{
viewModel.codeLiveData.observe(this) {
// rustLanguage.autoCompleteProvider.setSourceFolder(
// FileOperator.getSuperDirectory(
// viewModel.getNowOpenFilePath()
@ -638,7 +647,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
editStartViewModel.loadPathLiveData.value = file.absolutePath
} else {
viewModel.openFile(file.absolutePath)
viewBinding.editDrawerlayout.closeDrawer(GravityCompat.START)
closeDrawer(GravityCompat.START)
}
}
}
@ -819,7 +828,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
file.absolutePath,
FileOperator.getPrefixName(file)
)
viewBinding.editDrawerlayout.openDrawer(GravityCompat.START)
openDrawer(GravityCompat.START)
}.show()
} else {
Snackbar.make(
@ -1441,11 +1450,23 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
* 打开侧滑
*/
private fun openDrawer(gravity: Int) {
if (Tools.isTabletMode(this)) {
return
}
viewBinding.editDrawerlayout.openDrawer(gravity)
viewBinding.codeEditor.hideAutoCompleteWindow()
viewBinding.codeEditor.hideSoftInput()
}
/**
* 关闭侧滑
*/
private fun closeDrawer(gravity: Int) {
if (Tools.isTabletMode(this)) {
return
}
viewBinding.editDrawerlayout.closeDrawer(gravity)
}
override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityEditBinding {
return ActivityEditBinding.inflate(layoutInflater)

View File

@ -15,6 +15,7 @@ import com.coldmint.rust.pro.adapters.WebModAdapter
import com.coldmint.rust.pro.base.BaseFragment
import com.coldmint.rust.pro.databinding.FragmentRankingBinding
import com.coldmint.rust.pro.ui.StableLinearLayoutManager
import com.google.android.material.chip.Chip
import me.zhanghai.android.fastscroll.FastScrollerBuilder
@ -31,7 +32,7 @@ class RankingFragment : BaseFragment<FragmentRankingBinding>() {
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
linearLayoutManager = StableLinearLayoutManager(requireContext())
viewBinding.recyclerView.layoutManager = linearLayoutManager
/* viewBinding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
/* viewBinding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
val layoutManager = viewBinding.recyclerView.layoutManager
@ -52,35 +53,36 @@ class RankingFragment : BaseFragment<FragmentRankingBinding>() {
viewBinding.refreshLayout.setOnLoadMoreListener {
it.finishLoadMore(false) //传入false表示加载失败
}
/* viewBinding.swipeRefreshLayout.setOnRefreshListener {
/* viewBinding.swipeRefreshLayout.setOnRefreshListener {
loadMods()
viewBinding.swipeRefreshLayout.isRefreshing = false
}*/
viewBinding.downloadChip.setOnCheckedChangeListener { _, isChecked ->
for (i in 0 until viewBinding.chipGroup.childCount) {
val childView = viewBinding.chipGroup.getChildAt(i) as Chip
// 根据 Chip 的 ID 或 Tag 映射到对应的 SortMode
childView.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
sortMode = WebMod.SortMode.Download_Number
sortMode = when (i) {
0 -> WebMod.SortMode.Download_Number
1 -> WebMod.SortMode.Unit_Number
2 -> WebMod.SortMode.Coin_Number
3 -> WebMod.SortMode.Update_Number
else -> sortMode // 保持当前模式不变
}
loadMods()
}
for (j in 0 until viewBinding.chipGroup.childCount) {
val chip = viewBinding.chipGroup.getChildAt(j) as Chip
chip.isEnabled = chip != childView
}
}
if (i == 0) {
// childView.isChecked = true
childView.isEnabled = false
loadMods()
}
}
viewBinding.unitChip.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
sortMode = WebMod.SortMode.Unit_Number
loadMods()
}
}
viewBinding.coinChip.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
sortMode = WebMod.SortMode.Coin_Number
loadMods()
}
}
viewBinding.updateChip.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
sortMode = WebMod.SortMode.Update_Number
loadMods()
}
}
viewBinding.downloadChip.isChecked = true
}

View File

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/editDrawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<com.google.android.material.appbar.MaterialToolbar
android:id="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<include layout="@layout/edit_start" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:contentDescription="@string/action"
android:visibility="gone"
app:tabMode="scrollable"
app:tabTextAppearance="@style/TabLayoutTextStyle"
tools:visibility="visible" />
<io.github.rosemoe.sora.widget.CodeEditor
android:id="@+id/codeEditor"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="visible"
tools:ignore="NestedWeights" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/searchLayout"
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/find">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/findEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/replaceLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/replace"
android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/replaceEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<Button
android:id="@+id/lastButton"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/last" />
<Button
android:id="@+id/nextButton"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/next" />
<Button
android:id="@+id/replaceButton"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/replace" />
<Button
android:id="@+id/allButton"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/all"
android:visibility="gone" />
<Button
android:id="@+id/closeButton"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/close" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<androidx.recyclerview.widget.RecyclerView
android:id="@id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
<ProgressBar
android:id="@+id/myProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<!-- <include layout="@layout/edit_end" />-->
</androidx.drawerlayout.widget.DrawerLayout>

View File

@ -0,0 +1,60 @@
<?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"
android:layout_height="match_parent"
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">
<TextView
android:id="@+id/unableOpenView"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/unable_to_open_this_directory" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fileList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="@drawable/add"
android:visibility="gone" />
</RelativeLayout>
</merge>

View File

@ -35,6 +35,7 @@
android:layout_height="wrap_content"
android:scrollbars="none">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:singleLine="true"