优化文件排序方式,移除头像框

This commit is contained in:
coldmint 2022-07-29 23:19:07 +08:00
parent e7db8eeedc
commit e1c2b55a1c
24 changed files with 255 additions and 65 deletions

Binary file not shown.

View File

@ -68,7 +68,7 @@ android {
dependencies {
implementation 'com.luolc:emoji-rain:0.1.1'
// implementation 'com.luolc:emoji-rain:0.1.1'
implementation 'me.zhanghai.android.fastscroll:library:1.1.8'
// https://github.com/getActivity/MultiLanguages
implementation 'com.github.getActivity:MultiLanguages:8.0'

View File

@ -111,29 +111,29 @@ class EditUserInfoActivity : BaseActivity<ActivityEditUserInfoBinding>() {
}
private fun initAction() {
viewBinding.changeColorButton.setOnClickListener {
ColorPickerDialogBuilder
.with(this)
.setTitle(getString(R.string.choose_color))
.initialColor(Color.WHITE)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener {
//toast("onColorSelected: 0x" + Integer.toHexString(selectedColor));
}
.setPositiveButton(R.string.dialog_ok) { dialog, selectedColor, allColors ->
GlobalMethod.temColor = selectedColor
if (iconLink != null) {
Glide.with(this@EditUserInfoActivity)
.load(iconLink)
.apply(GlobalMethod.getRequestOptions(true, !GlobalMethod.isActive))
.into(viewBinding.iconView)
}
}
.setNegativeButton(R.string.dialog_cancel) { dialog, which -> }
.build()
.show()
}
// viewBinding.changeColorButton.setOnClickListener {
// ColorPickerDialogBuilder
// .with(this)
// .setTitle(getString(R.string.choose_color))
// .initialColor(Color.WHITE)
// .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
// .density(12)
// .setOnColorSelectedListener {
// //toast("onColorSelected: 0x" + Integer.toHexString(selectedColor));
// }
// .setPositiveButton(R.string.dialog_ok) { dialog, selectedColor, allColors ->
// GlobalMethod.temColor = selectedColor
// if (iconLink != null) {
// Glide.with(this@EditUserInfoActivity)
// .load(iconLink)
// .apply(GlobalMethod.getRequestOptions(true, !GlobalMethod.isActive))
// .into(viewBinding.iconView)
// }
// }
// .setNegativeButton(R.string.dialog_cancel) { dialog, which -> }
// .build()
// .show()
// }
viewBinding.userNameView.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

View File

@ -27,6 +27,7 @@ import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.adapters.FileAdapter
import com.coldmint.rust.pro.databinding.ActivityFileBinding
import com.coldmint.rust.pro.interfaces.BookmarkListener
import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.viewmodel.FileManagerViewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import me.zhanghai.android.fastscroll.FastScrollerBuilder
@ -899,6 +900,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
viewBinding.swipeRefreshLayout.isRefreshing = false
}
viewModel.loadFiles()
viewModel.loadSortType(this)
} else {
val bundle = intent.getBundleExtra("data")
if (bundle == null) {
@ -917,9 +919,14 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuBinding = MenuBinding.inflate(menu, menuInflater)
val value = viewModel.sortTypeLiveData.value
if (value != null) {
setSortType(value)
}
return true
}
/**
* 加载观察者
*/
@ -930,6 +937,9 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
viewBinding.fileError.isVisible = it
viewBinding.progressBar.isVisible = it
}
viewModel.sortTypeLiveData.observe(this) {
setSortType(it)
}
viewModel.fileListLiveData.observe(this) {
if (adapter == null) {
//创建实例(设置适配器)
@ -957,6 +967,34 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
}
}
/**
* 设置排序方式
* @param sortType SortType
*/
fun setSortType(sortType: FileManagerViewModel.SortType) {
if (this::menuBinding.isInitialized) {
when (sortType) {
FileManagerViewModel.SortType.BY_NAME -> {
menuBinding.actionSortByName.isChecked = true
}
FileManagerViewModel.SortType.BY_SIZE -> {
menuBinding.actionSortBySize.isChecked = true
}
FileManagerViewModel.SortType.BY_LAST_MODIFIED -> {
menuBinding.actionSortByLastModified.isChecked = true
}
FileManagerViewModel.SortType.BY_TYPE -> {
menuBinding.actionSortByType.isChecked = true
}
else -> {
menuBinding.actionSortByName.isChecked = true
}
}
adapter?.setSort(sortType)
viewModel.loadFiles(viewModel.getCurrentPath())
}
}
/**
* 加载页面标题
*/
@ -980,7 +1018,10 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
val menu: Menu,
val reloadFileItem: MenuItem,
val photoAlbumItem: MenuItem,
val systemFileManagerItem: MenuItem
val systemFileManagerItem: MenuItem,
val actionSortByName: MenuItem,
val actionSortByType: MenuItem,
val actionSortBySize: MenuItem, val actionSortByLastModified: MenuItem
) {
companion object {
//填充
@ -990,7 +1031,11 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
menu,
menu.findItem(R.id.reloadFile),
menu.findItem(R.id.photo_album),
menu.findItem(R.id.system_file_manager)
menu.findItem(R.id.system_file_manager),
menu.findItem(R.id.action_sort_by_name),
menu.findItem(R.id.action_sort_by_type),
menu.findItem(R.id.action_sort_by_size),
menu.findItem(R.id.action_sort_by_last_modified)
)
}
}

View File

@ -90,10 +90,10 @@ class UserHomePageActivity : BaseActivity<ActivityUserHomePageBinding>() {
// }
// viewBinding.bubbleView.setDrawableList(dlist)
// viewBinding.bubbleView.startAnimation(5000, 5000,30)
viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_1_3)
viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_2_3)
viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_3_3)
viewBinding.emojiRainLayout.startDropping()
// viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_1_3)
// viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_2_3)
// viewBinding.emojiRainLayout.addEmoji(R.drawable.emoji_3_3)
// viewBinding.emojiRainLayout.startDropping()
}

View File

@ -12,8 +12,10 @@ import android.view.View
import androidx.core.view.isVisible
import com.bumptech.glide.Glide
import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.core.web.ServerConfiguration
import com.coldmint.rust.pro.base.BaseAdapter
import com.coldmint.rust.pro.databinding.FileItemBinding
import com.coldmint.rust.pro.viewmodel.FileManagerViewModel
import com.github.promeg.pinyinhelper.Pinyin
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import me.zhanghai.android.fastscroll.PopupTextProvider
@ -42,6 +44,8 @@ class FileAdapter(private val context: Context, dataList: MutableList<File?>) :
private set
private var sortType: FileManagerViewModel.SortType = FileManagerViewModel.SortType.BY_NAME
/**
* 清除选中目录
*/
@ -76,10 +80,50 @@ class FileAdapter(private val context: Context, dataList: MutableList<File?>) :
// }
// }
/**
* 设置排序方式
* @param sortType SortType
*/
fun setSort(sortType: FileManagerViewModel.SortType) {
this.sortType = sortType
}
override fun setNewDataList(dataList: MutableList<File?>) {
dataList.sortBy {
val name = it?.name ?: "#"
getInitial(name)
when (sortType) {
FileManagerViewModel.SortType.BY_NAME -> {
dataList.sortBy {
val name = it?.name ?: "#"
getInitial(name)
}
}
FileManagerViewModel.SortType.BY_SIZE -> {
dataList.sortBy {
val size = it?.length() ?: 0.toLong()
size
}
}
FileManagerViewModel.SortType.BY_TYPE -> {
dataList.sortBy {
val type = if (it != null) {
FileOperator.getFileType(it)
} else {
"#"
}
type
}
}
FileManagerViewModel.SortType.BY_LAST_MODIFIED -> {
dataList.sortBy {
val lastModified = it?.lastModified() ?: 0.toLong()
lastModified
}
}
else -> {
dataList.sortBy {
val name = it?.name ?: "#"
getInitial(name)
}
}
}
super.setNewDataList(dataList)
}
@ -161,7 +205,32 @@ class FileAdapter(private val context: Context, dataList: MutableList<File?>) :
override fun getPopupText(position: Int): String {
val file = dataList[position]
val name = file?.name ?: "#"
return getInitial(name).toString()
val data = when (sortType) {
FileManagerViewModel.SortType.BY_NAME -> {
val name = file?.name ?: "#"
getInitial(name)
}
FileManagerViewModel.SortType.BY_SIZE -> {
val size = file?.length() ?: 0.toLong()
size
}
FileManagerViewModel.SortType.BY_TYPE -> {
val type = if (file != null) {
FileOperator.getFileType(file)
} else {
"#"
}
type
}
FileManagerViewModel.SortType.BY_LAST_MODIFIED -> {
val lastModified = file?.lastModified() ?: 0.toLong()
ServerConfiguration.toStringTime(lastModified)
}
else -> {
val name = file?.name ?: "#"
getInitial(name)
}
}.toString()
return data
}
}

View File

@ -44,7 +44,7 @@ class AppSettings private constructor(val mContext: Context) {
private val editor: SharedPreferences.Editor = sharedPreferences.edit()
enum class Setting {
DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan
DatabaseDirectory, DatabasePath, TemplateDirectory, AppLanguage, DeveloperMode, CustomSymbol, AutoCreateNomedia, OnlyLoadConantLanguageTemple, NightMode, GamePackage, KeepRwmodFile, EnableRecoveryStation, RecoveryStationFileSaveDays, RecoveryStationFolder, IndependentFolder, SetGameStorage, PackDirectory, IdentifiersPromptNumber, UserName, UseJetBrainsMonoFont, AppID, Account, PassWord, ExpirationTime, CheckBetaUpdate, UpdateData, ShareTip, AgreePolicy, EnglishEditingMode, NightModeFollowSystem, UseMobileNetwork, MapFolder, ModFolder, UseTheCommunityAsTheLaunchPage, AutoSave, ServerAddress, Token, LoginStatus, DynamicColor, ExperiencePlan, FileSortType
}
@ -289,7 +289,8 @@ class AppSettings private constructor(val mContext: Context) {
map[Setting.AutoSave] = mContext.getString(R.string.setting_auto_save)
map[Setting.ServerAddress] = mContext.getString(R.string.setting_server_address)
map[Setting.DynamicColor] = mContext.getString(R.string.setting_dynamic_color)
map[Setting.ExperiencePlan] = mContext.getString(R.string.experience_the_plan)
map[Setting.ExperiencePlan] = mContext.getString(R.string.setting_experience_the_plan)
map[Setting.FileSortType] = mContext.getString(R.string.setting_file_sort_type)
//仅保存不可显示
map[Setting.SetGameStorage] = "SetGameStorage"
map[Setting.AppID] = "AppId"

View File

@ -42,7 +42,6 @@ object GlobalMethod {
const val DEFAULT_GAME_PACKAGE = "com.corrodinggames.rts"
const val DEBUG_SIGN = "963dfd616924b27f9247a35e45bc130a"
const val RELEASE_SIGN = "5320b24894fe7ed449842a81a2dfceda"
var temColor = Color.RED
/**
@ -53,7 +52,7 @@ object GlobalMethod {
//变换列表
val transformations = ArrayList<BitmapTransformation>()
if (circleCrop) {
transformations.add(CropCircleWithBorderTransformation(Utils.toDp(4), temColor))
transformations.add(CropCircleTransformation())
}
if (grayscale) {
transformations.add(GrayscaleTransformation())

View File

@ -1,11 +1,15 @@
package com.coldmint.rust.pro.viewmodel
import android.content.Context
import android.os.Environment
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.coldmint.rust.core.tool.AppOperator
import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.R
import com.coldmint.rust.pro.base.BaseViewModel
import com.coldmint.rust.pro.tool.AppSettings
import kotlinx.coroutines.launch
import java.io.File
@ -19,6 +23,13 @@ class FileManagerViewModel : BaseViewModel() {
DEFAULT, SELECT_DIRECTORY, EXPORT_FILE, SELECT_FILE
}
/**
* 文件排序方式
*/
enum class SortType {
BY_NAME, BY_SIZE, BY_TYPE, BY_LAST_MODIFIED
}
private var directs = Environment.getExternalStorageDirectory().absolutePath
//根目录
@ -31,6 +42,41 @@ class FileManagerViewModel : BaseViewModel() {
MutableLiveData(rootPath)
}
/**
* 文件排序方式
*/
val sortTypeLiveData: MutableLiveData<SortType> by lazy {
MutableLiveData(SortType.BY_NAME)
}
/**
* 从设置中读取排序方式
*/
fun loadSortType(context: Context) {
val appSettings = AppSettings.getInstance(context)
//从设置中读取排序方式
val sortType = appSettings.getValue(
AppSettings.Setting.FileSortType,
context.getString(R.string.setting_file_list_action_sort_by_name)
)
when (sortType) {
context.getString(R.string.setting_file_list_action_sort_by_name) -> {
sortTypeLiveData.value = SortType.BY_NAME
}
context.getString(R.string.setting_file_list_action_sort_by_last_modified) -> {
sortTypeLiveData.value = SortType.BY_LAST_MODIFIED
}
context.getString(R.string.setting_file_list_action_sort_by_size) -> {
sortTypeLiveData.value = SortType.BY_SIZE
}
context.getString(R.string.setting_file_list_action_sort_by_type) -> {
sortTypeLiveData.value = SortType.BY_TYPE
}
else -> {
sortTypeLiveData.value = SortType.BY_NAME
}
}
}
/**
* 获取当前打开的目录
@ -40,6 +86,7 @@ class FileManagerViewModel : BaseViewModel() {
return currentPathLiveData.value ?: rootPath
}
/**
* 加载状态
*/

View File

@ -241,6 +241,7 @@ class StartViewModel(application: Application) : BaseAndroidViewModel(applicatio
appSettings.initSetting(AppSettings.Setting.AutoSave, true)
appSettings.initSetting(AppSettings.Setting.AgreePolicy, false)
appSettings.initSetting(AppSettings.Setting.LoginStatus, false)
appSettings.initSetting(AppSettings.Setting.FileSortType,context.getString(R.string.setting_file_list_action_sort_by_name))
//如果启用动态颜色
appSettings.initSetting(
AppSettings.Setting.DynamicColor,

View File

@ -139,26 +139,26 @@
</com.google.android.material.textfield.TextInputLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<!-- <RelativeLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="8dp">-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/profile_picture_box_color" />
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_centerVertical="true"-->
<!-- android:text="@string/profile_picture_box_color" />-->
<Button
android:id="@+id/changeColorButton"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="@string/choose_color" />
<!-- <Button-->
<!-- android:id="@+id/changeColorButton"-->
<!-- style="@style/Widget.Material3.Button.OutlinedButton"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_alignParentEnd="true"-->
<!-- android:text="@string/choose_color" />-->
</RelativeLayout>
<!-- </RelativeLayout>-->
<LinearLayout
android:layout_width="match_parent"

View File

@ -254,10 +254,6 @@
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
<com.luolc.emojirain.EmojiRainLayout
android:id="@+id/emojiRainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"

View File

@ -2,7 +2,7 @@
<!-- 语言条目 -->
<string-array name="language_entries">
<item>简体中文</item>
<!-- <item>繁體中文</item>-->
<!-- <item>繁體中文</item>-->
<item>English</item>
<item>日本語</item>
<item>Россия</item>
@ -10,12 +10,25 @@
<string-array name="language_values">
<item>zh</item>
<!-- <item>zh_TW</item>-->
<!-- <item>zh_TW</item>-->
<item>en</item>
<item>ja</item>
<item>ru</item>
</string-array>
<string-array name="file_sort_entries">
<item>@string/file_list_action_sort_by_name</item>
<item>@string/file_list_action_sort_by_type</item>
<item>@string/file_list_action_sort_by_size</item>
<item>@string/file_list_action_sort_by_last_modified</item>
</string-array>
<string-array name="file_sort_values">
<item>@string/setting_file_list_action_sort_by_name</item>
<item>@string/setting_file_list_action_sort_by_type</item>
<item>@string/setting_file_list_action_sort_by_size</item>
<item>@string/setting_file_list_action_sort_by_last_modified</item>
</string-array>
<string-array name="update_type_entries">
<item>@string/web_link</item>
<item>@string/qq_group</item>

View File

@ -855,7 +855,13 @@
<string name="file_list_action_sort_by_type">类型</string>
<string name="file_list_action_sort_by_size">大小</string>
<string name="file_list_action_sort_by_last_modified">修改时间</string>
<string name="setting_file_list_action_sort_by_name" translatable="false">ByName</string>
<string name="setting_file_list_action_sort_by_type" translatable="false">ByType</string>
<string name="setting_file_list_action_sort_by_size" translatable="false">BySize</string>
<string name="setting_file_list_action_sort_by_last_modified" translatable="false">ByLastModified</string>
<string name="file_sort_type">文件排序方式</string>
<string name="setting_file_sort_type" translatable="false">FileSortType</string>
<!-- <string name="search_suggestions_null">无搜索建议。</string>-->
<!-- <string name="search_suggestions_number">共%1$d个搜索建议。</string>-->
<!-- <string name="search_suggestions_number">共%1$d个搜索建议。</string>-->
</resources>

View File

@ -5,7 +5,7 @@
<PreferenceCategory app:title="@string/messages_header">
<rikka.preference.SimpleMenuPreference
app:defaultValue="简体中文"
app:defaultValue="zh"
app:entries="@array/language_entries"
app:entryValues="@array/language_values"
app:key="@string/setting_app_language"
@ -45,6 +45,15 @@
app:summary="@string/use_the_community_as_the_launch_page_tip" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/file_manager">
<rikka.preference.SimpleMenuPreference
app:entries="@array/file_sort_entries"
app:entryValues="@array/file_sort_values"
app:key="@string/setting_file_sort_type"
app:title="@string/file_sort_type"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/data_transfer">

View File

@ -2,4 +2,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coldmint.rust.core">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

View File

@ -75,6 +75,9 @@ object ServerConfiguration {
(-2).toLong() -> {
ForeverTime
}
(0).toLong() -> {
"#"
}
else -> {
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
formatter.format(longTime)