diff --git a/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt b/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt index 4b54382..4a9f6cd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/CodeTableActivity.kt @@ -6,9 +6,12 @@ import android.text.Spannable import android.text.SpannableString import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan -import android.view.* +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuItem +import android.view.View +import android.widget.SearchView import androidx.core.view.isVisible -import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.database.code.CodeDataBase import com.coldmint.rust.core.database.code.CodeInfo import com.coldmint.rust.core.database.code.SectionInfo @@ -28,14 +31,16 @@ class CodeTableActivity : BaseActivity() { } } + /* - override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { - if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) { - ifNeedFinish() - return true + override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { + if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) { + ifNeedFinish() + return true + } + return super.onKeyDown(keyCode, event) } - return super.onKeyDown(keyCode, event) - } + */ fun ifNeedFinish() { @@ -133,13 +138,14 @@ class CodeTableActivity : BaseActivity() { spannableString.setSpan( object : ClickableSpan() { override fun onClick(p0: View) { + sea.setQuery("", false) loadData() } }, start, start + action.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE ) } - viewBinding.displayView.movementMethod = LinkMovementMethod.getInstance(); - viewBinding.displayView.highlightColor = Color.parseColor("#36969696"); + viewBinding.displayView.movementMethod = LinkMovementMethod.getInstance() + viewBinding.displayView.highlightColor = Color.parseColor("#36969696") viewBinding.displayView.text = spannableString } @@ -147,11 +153,26 @@ class CodeTableActivity : BaseActivity() { viewBinding.expandableListView.isVisible = false viewBinding.progressBar.isVisible = false } - - + lateinit var sea: SearchView override fun onCreateOptionsMenu(menu: Menu): Boolean { - val inflater = menuInflater - inflater.inflate(R.menu.menu_code_table, menu) +// val inflater = menuInflater + menuInflater.inflate(R.menu.menu_code_table, menu) + val findItem = menu.findItem(R.id.filter_units) + sea = findItem.actionView as SearchView + sea.queryHint = "请输入关键字" + sea.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String?): Boolean { + // 在这里执行搜索操作 + loadData(query) + return false + } + + override fun onQueryTextChange(newText: String?): Boolean { + // 在这里更新搜索结果列表 + loadData(newText) + return false + } + }) return true } @@ -159,6 +180,8 @@ class CodeTableActivity : BaseActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.filter_units -> { +// editisVisible(true) + /* InputDialog(this).setTitle(R.string.filter).setMessage(R.string.filter_tip) .setInputCanBeEmpty(false).setMaxNumber(20) .setPositiveButton(R.string.dialog_ok) { text -> @@ -170,8 +193,9 @@ class CodeTableActivity : BaseActivity() { true }.setNegativeButton(R.string.dialog_close) { - }.show() + }.show()*/ } + android.R.id.home -> { ifNeedFinish() return true @@ -180,6 +204,14 @@ class CodeTableActivity : BaseActivity() { return super.onOptionsItemSelected(item) } + + override fun onBackPressed() { + if (sea != null && !sea.isIconified) { + sea.isIconified = true + return + } + ifNeedFinish() + } override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCodeTableBinding { return ActivityCodeTableBinding.inflate(layoutInflater) } diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index 5aff312..c3b2d8d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -882,6 +882,7 @@ class FileManagerActivity : BaseActivity() { * 设置排序方式 * @param sortType SortType */ + fun setSortType(sortType: FileManagerViewModel.SortType) { if (this::menuBinding.isInitialized) { when (sortType) { diff --git a/app/src/main/java/com/coldmint/rust/pro/FileSort.kt b/app/src/main/java/com/coldmint/rust/pro/FileSort.kt index 5e2eae2..70d2fdf 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileSort.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileSort.kt @@ -1,37 +1,34 @@ +package com.coldmint.rust.pro +import com.coldmint.rust.pro.viewmodel.FileManagerViewModel import java.io.File -import java.util.* +import java.util.Collections -class FileSort(a: MutableList, manner: Int) { - val name = 0 - val time = 1 - val size = 2 - val type = 3 +class FileSort(a: MutableList,sortType: FileManagerViewModel.SortType) { //内置的类型排序筛选器数据 可以不用 但是类型排序必须要进行筛选才能正常排序 init { - when (manner) { - name -> sort_name(a) - time -> sort_time(a) - size -> sort_size(a) - type -> sort_type(a) + when (sortType) { + FileManagerViewModel.SortType.BY_NAME -> sort_name(a) + FileManagerViewModel.SortType.BY_LAST_MODIFIED -> sort_time(a) + FileManagerViewModel.SortType.BY_SIZE -> sort_size(a) + FileManagerViewModel.SortType.BY_TYPE -> sort_type(a) } + sort_front(a) // println(manner) - //一个内置的排序筛选器 也可以在外部调用 FileSort.sort_front(List a) 等静态的方法 + //一个内置的排序筛选器 也可以在外部调用 com.coldmint.rust.pro.FileSort.sort_front(List a) 等静态的方法 } companion object { //0表示 名称排序 1表示 时间排序 2表示 大小排序 3表示类型排序 - lateinit var type_list: Array - - fun sort_front(a: MutableList) { + private fun sort_front(a: MutableList) { Collections.sort(a, kotlin.Comparator { o1, o2 -> if (o1!!.isDirectory && o2!!.isFile) return@Comparator -1 - if (o1!!.isFile && o2!!.isDirectory) return@Comparator 1 + if (o1.isFile && o2!!.isDirectory) return@Comparator 1 else return@Comparator 0 }) } //文件夹在前面的排序算法 每次sort_name等排序方法前后或者都会调研次方法 - fun sort_name(a: MutableList) { + fun sort_name(a: MutableList) { Collections.sort(a, Comparator { o1, o2 -> if (o1!!.isDirectory && o2!!.isFile) return@Comparator -1 @@ -40,59 +37,36 @@ class FileSort(a: MutableList, manner: Int) { else o1.name.compareTo(o2!!.name) return@Comparator 0 }) - sort_front(a) } - fun sort_time(a: MutableList) { - Collections.sort(a, Comparator { f1, f2 -> + fun sort_time(a: MutableList) { + a.sortWith { f1, f2 -> val diff = f1!!.lastModified() - f2!!.lastModified() if (diff > 0) 1 else if (diff == 0L) 0 else -1 //如果 if 中修改为 返回-1 同时此处修改为返回 1 排序就会是递减 - }) - sort_front(a) + } } - fun sort_size(a: MutableList) { - Collections.sort(a, kotlin.Comparator { o1, o2 -> + fun sort_size(a: MutableList) { + a.sortWith { o1, o2 -> val diff = o1!!.length() - o2!!.length() if (diff > 0) 1 else if (diff == 0L) 0 else -1 - }) - sort_front(a) + } } - fun sort_type(a: MutableList) { + fun sort_type(a: MutableList) { //文件类型排序 按照后缀优先级 - sort_front(a) - //先进行文件夹在前面的排序算法 - Collections.sort(a, Comparator { o1, o2 -> - if (o1!!.isFile) { - val name = o1.name - val suffix = name.substring(name.lastIndexOf(".")) - //获取name文件名字的后缀 - val length = length(type_list, suffix) - //查找后缀是不是存在于 type_list数据中 如果存在返回存在位置 如果不存在则返回<0的值 - if (length >= 0) return@Comparator -1 - } else if (o2!!.isFile) { - val name = o2.name - val suffix = name.substring(name.lastIndexOf(".")) - //获取name文件名字的后缀 - val length = length(type_list, suffix) - //查找后缀是不是存在于 type_list数据中 如果存在返回存在位置 如果不存在则返回<0的值 - if (length >= 0) return@Comparator 1 - } - 0 - }) - } - private fun length(sz: Array, a: String): Int { - //引入外部数据sz 去进行筛选让后返回位置 - for (i in sz.indices) { - if (sz[i] == a) { - return i - } + a.sortWith { o1, o2 -> + val extension1 = o1?.extension?.lowercase() + val extension2 = o2?.extension?.lowercase() + // 定义文件类型的优先级顺序 + val typePriority = listOf("txt", "jpg", "png") + val typeIndex1 = typePriority.indexOf(extension1) + val typeIndex2 = typePriority.indexOf(extension2) + typeIndex1.compareTo(typeIndex2) } - return -1 } } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt index 68f9690..53f6610 100644 --- a/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/WebModInfoActivity.kt @@ -1,62 +1,25 @@ package com.coldmint.rust.pro -import android.annotation.SuppressLint -import android.app.DownloadManager -import android.content.Context import android.content.Intent -import android.net.Uri import android.os.Bundle import android.os.Environment -import android.util.Log import android.view.* -import android.view.inputmethod.EditorInfo -import android.widget.EditText -import android.widget.Toast -import androidx.core.app.NotificationManagerCompat -import androidx.core.view.isVisible -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.LinearLayoutManager -import com.afollestad.materialdialogs.LayoutMode -import com.afollestad.materialdialogs.MaterialDialog -import com.afollestad.materialdialogs.bottomsheets.BottomSheet -import com.afollestad.materialdialogs.bottomsheets.setPeekHeight -import com.afollestad.materialdialogs.customview.customView -import com.afollestad.materialdialogs.input.getInputField -import com.afollestad.materialdialogs.input.input -import com.bumptech.glide.Glide -import com.bumptech.glide.request.RequestOptions import com.coldmint.dialog.CoreDialog -import com.coldmint.rust.core.ModClass -import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.AppUpdateData -import com.coldmint.rust.core.dataBean.mod.WebModCommentData -import com.coldmint.rust.core.dataBean.mod.WebModInfoData -import com.coldmint.rust.core.dataBean.mod.WebModUpdateLogData -import com.coldmint.rust.core.dataBean.user.SpaceInfoData -import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.tool.AppOperator import com.coldmint.rust.core.tool.FileLoader -import com.coldmint.rust.core.tool.LineParser import com.coldmint.rust.core.tool.ProgressResponseBody import com.coldmint.rust.core.web.ServerConfiguration -import com.coldmint.rust.core.web.User import com.coldmint.rust.core.web.WebMod -import com.coldmint.rust.pro.adapters.CommentAdapter import com.coldmint.rust.pro.adapters.ModPageDetailsAdapter -import com.coldmint.rust.pro.databinding.ActivityWebModInfoBinding -import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.base.BaseActivity +import com.coldmint.rust.pro.databinding.ActivityWebModInfoBinding import com.coldmint.rust.pro.databinding.LoadFileLayoutBinding -import com.coldmint.rust.pro.dialog.CommentDialog +import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.GlobalMethod -import com.coldmint.rust.pro.tool.TextStyleMaker -import com.google.android.material.appbar.AppBarLayout import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayoutMediator import com.google.gson.Gson -import com.youth.banner.adapter.BannerImageAdapter -import com.youth.banner.holder.BannerImageHolder -import com.youth.banner.indicator.CircleIndicator import java.io.File import java.text.NumberFormat diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt index 25463b6..12b8599 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt @@ -4,15 +4,12 @@ import android.content.Context import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide -import com.bumptech.glide.request.RequestOptions import com.coldmint.dialog.CoreDialog import com.coldmint.rust.core.dataBean.ApiResponse import com.coldmint.rust.core.dataBean.mod.WebModCommentData import com.coldmint.rust.core.interfaces.ApiCallBack import com.coldmint.rust.core.tool.AppOperator -import com.coldmint.rust.core.web.Dynamic import com.coldmint.rust.core.web.ServerConfiguration import com.coldmint.rust.core.web.WebMod import com.coldmint.rust.pro.R @@ -68,12 +65,18 @@ class CommentAdapter(context: Context, dataList: MutableList val menu = GlobalMethod.createPopMenu(view) - menu.menu.add(R.string.copy) +// menu.menu.add(R.string.copy) menu.menu.add(R.string.delete_title) + menu.menu.add(R.string.report) menu.setOnMenuItemClickListener { val title = it.title when (title) { @@ -129,7 +132,15 @@ class CommentAdapter(context: Context, dataList: MutableList { + Snackbar.make( + context,view, + "暂不可用,请等待下一个版本!", + Snackbar.LENGTH_SHORT + ).show() + } } + true } menu.show() diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt index fff0af4..3d1b9e4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt @@ -1,28 +1,20 @@ package com.coldmint.rust.pro.adapters -import android.os.Build -import android.view.ViewGroup -import android.view.LayoutInflater -import com.coldmint.rust.pro.R import android.content.Context -import com.coldmint.rust.pro.tool.GlobalMethod import android.content.res.ColorStateList -import android.graphics.Color -import android.view.View +import android.view.LayoutInflater +import android.view.ViewGroup 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.R import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.FileItemBinding +import com.coldmint.rust.pro.tool.GlobalMethod 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 import java.io.File -import java.lang.StringBuilder -import java.text.SimpleDateFormat -import java.util.ArrayList class FileAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList), PopupTextProvider { @@ -89,6 +81,7 @@ class FileAdapter(context: Context, dataList: MutableList) : } override fun setNewDataList(dataList: MutableList) { +// FileSort(dataList, sortType) when (sortType) { FileManagerViewModel.SortType.BY_NAME -> { dataList.sortBy { @@ -125,6 +118,10 @@ class FileAdapter(context: Context, dataList: MutableList) : } } } + dataList.sortBy { + val name = it?.isFile ?: it?.isDirectory + name + } super.setNewDataList(dataList) } @@ -139,7 +136,7 @@ class FileAdapter(context: Context, dataList: MutableList) : override fun onBingView( data: File?, viewBinding: FileItemBinding, - viewHolder: BaseAdapter.ViewHolder, + viewHolder: ViewHolder, position: Int ) { if (data == null) { @@ -173,8 +170,7 @@ class FileAdapter(context: Context, dataList: MutableList) : } } } else { - val type = FileOperator.getFileType(data) - when (type) { + when (FileOperator.getFileType(data)) { "ini", "txt", "template", "log" -> viewBinding.fileIcon.setImageDrawable( GlobalMethod.tintDrawable( context.getDrawable(R.drawable.file), diff --git a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt index 461961a..b8235e4 100644 --- a/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt +++ b/app/src/main/java/com/coldmint/rust/pro/tool/GlobalMethod.kt @@ -12,16 +12,12 @@ import android.graphics.Color import android.graphics.Paint import android.graphics.drawable.Drawable import android.os.Build -import android.os.Handler -import android.os.Looper -import android.os.Message import android.util.TypedValue import android.view.Gravity import android.view.View import android.widget.PopupMenu import android.widget.TextView import android.widget.Toast -import androidx.core.content.ContextCompat.getSystemService import androidx.core.graphics.drawable.DrawableCompat import androidx.fragment.app.FragmentActivity import com.bumptech.glide.load.MultiTransformation @@ -36,8 +32,9 @@ import com.flask.colorpicker.builder.ColorPickerDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.permissionx.guolindev.PermissionX -import jp.wasabeef.glide.transformations.* -import jp.wasabeef.glide.transformations.internal.Utils +import jp.wasabeef.glide.transformations.BitmapTransformation +import jp.wasabeef.glide.transformations.CropCircleTransformation +import jp.wasabeef.glide.transformations.GrayscaleTransformation /*全局方法类*/ object GlobalMethod { diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt index 14ec478..647dfc2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt @@ -1,15 +1,12 @@ package com.coldmint.rust.pro.viewmodel import android.content.Context -import android.content.Intent import android.net.Uri import android.os.Build import android.os.Environment import android.provider.MediaStore -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 @@ -18,7 +15,6 @@ import com.coldmint.rust.pro.tool.BookmarkManager import com.yalantis.ucrop.util.FileUtils.getPath import kotlinx.coroutines.launch import java.io.File -import java.util.HashMap class FileManagerViewModel : BaseViewModel() { @@ -59,7 +55,7 @@ class FileManagerViewModel : BaseViewModel() { } /** - * 文件排序方式 + * 文件排序方式 名称 大小 类型 时间 */ enum class SortType { BY_NAME, BY_SIZE, BY_TYPE, BY_LAST_MODIFIED diff --git a/app/src/main/res/layout/activity_code_table.xml b/app/src/main/res/layout/activity_code_table.xml index b164318..88a602f 100644 --- a/app/src/main/res/layout/activity_code_table.xml +++ b/app/src/main/res/layout/activity_code_table.xml @@ -12,12 +12,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> - - diff --git a/app/src/main/res/layout/fragment_installed_template.xml b/app/src/main/res/layout/fragment_installed_template.xml index 614bda8..ec6634f 100644 --- a/app/src/main/res/layout/fragment_installed_template.xml +++ b/app/src/main/res/layout/fragment_installed_template.xml @@ -1,42 +1,41 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> - + android:layout_height="wrap_content"> - + - +