Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
YuS1aN committed Mar 14, 2024
1 parent 6b16ed2 commit 86f6396
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EditTextDialogFragment : BaseDialogFragment() {
const val EDIT_FILE = 4

private const val ARGS_TITLE_RES = "1"
private const val ARGS_DEFAULT_TEXT = "2"
private const val ARGS_TEXT = "2"
private const val ARGS_ID = "3"
private const val ARGS_MAX_LINE = "4"

Expand All @@ -40,13 +40,13 @@ class EditTextDialogFragment : BaseDialogFragment() {
fun newInstance(
@StringRes titleRes: Int,
defaultText: String,
resultId: Int,
id: Int,
maxLine: Int = 1
): EditTextDialogFragment {
val args = Bundle()
args.putInt(ARGS_TITLE_RES, titleRes)
args.putString(ARGS_DEFAULT_TEXT, defaultText)
args.putInt(ARGS_ID, resultId)
args.putString(ARGS_TEXT, defaultText)
args.putInt(ARGS_ID, id)
args.putInt(ARGS_MAX_LINE, maxLine)
val fragment = EditTextDialogFragment()
fragment.arguments = args
Expand All @@ -73,10 +73,11 @@ class EditTextDialogFragment : BaseDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val arguments = arguments ?: return
val id = arguments.getInt(ARGS_ID)

binding.run {
tvTitle.setText(arguments.getInt(ARGS_TITLE_RES))
val defaultText = arguments.getString(ARGS_DEFAULT_TEXT, "")
val defaultText = arguments.getString(ARGS_TEXT)
etText.apply {
maxLines = arguments.getInt(ARGS_MAX_LINE, 1)
var type = InputType.TYPE_CLASS_TEXT
Expand All @@ -92,7 +93,7 @@ class EditTextDialogFragment : BaseDialogFragment() {
binding.etText.error = getString(R.string.error_input_text)
return@setOnClickListener
}
_result.value = Consumable(text.toString(), arguments.getInt(ARGS_ID))
_result.value = Consumable(text.toString(), id)
}
mhlText.post {
val size = dialog?.window?.displaySize() ?: return@post
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/me/kbai/zhenxunui/ui/common/PromptDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.kbai.zhenxunui.ui.common

import android.content.Context
import android.content.DialogInterface
import android.text.method.ScrollingMovementMethod
import android.view.View
import androidx.annotation.StringRes
import me.kbai.zhenxunui.base.BaseDialog
Expand All @@ -24,6 +25,8 @@ class PromptDialog(context: Context) : BaseDialog(context) {

override fun show() {
mBinding.run {
tvText.movementMethod = ScrollingMovementMethod.getInstance()

mParams.title?.let { tvTitle.text = it }
mParams.text?.let { tvText.text = it }
mParams.textRes?.let { tvText.setText(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,26 @@ class FileExplorerFragment : BaseFragment<FragmentFileExplorerBinding>() {
viewBinding.root.setOnTouchListener(null)
viewBinding.icLoading.root.isVisible = false

mEditingFile = file
EditTextDialogFragment.newInstance(
R.string.edit_file,
it.data.orEmpty(),
EditTextDialogFragment.EDIT_FILE,
Int.MAX_VALUE
).show(childFragmentManager)
//这里服务端返回数据有问题, 非文本内容读取失败后状态仍为success但数据为空
if (it.success() && it.data != null) {
//EditText内容过多会导致IME崩溃(Binder传输限制), 限制到约500K以内
if (it.data.length > 250_000) {
GlobalToast.showToast(R.string.text_too_long)
PromptDialog(requireContext())
.setText(it.data)
.show()
return@launchAndApiCollectIn
}
mEditingFile = file
EditTextDialogFragment.newInstance(
R.string.edit_file,
it.data,
EditTextDialogFragment.EDIT_FILE,
Int.MAX_VALUE
).show(childFragmentManager)
} else {
GlobalToast.showToast(it.message)
}
}
} else {
findNavController().navigate(
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/me/kbai/zhenxunui/widget/MaxHeightLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.annotation.AttrRes
import androidx.annotation.StyleRes
import androidx.core.content.res.use
import me.kbai.zhenxunui.R

class MaxHeightLayout @JvmOverloads constructor(
context: Context,
Expand All @@ -15,13 +17,19 @@ class MaxHeightLayout @JvmOverloads constructor(

private var mMaxHeight = -1

init {
context.obtainStyledAttributes(attrs, R.styleable.MaxHeightLayout).use {
mMaxHeight = it.getDimensionPixelSize(R.styleable.MaxHeightLayout_maxHeight, mMaxHeight)
}
}

fun setMaxHeight(maxHeight: Int) {
mMaxHeight = maxHeight
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val mode = MeasureSpec.getMode(heightMeasureSpec)
val heightSpec = if (mode == MeasureSpec.AT_MOST) {
val heightSpec = if (mode == MeasureSpec.AT_MOST && mMaxHeight >= 0) {
MeasureSpec.makeMeasureSpec(mMaxHeight, MeasureSpec.AT_MOST)
} else {
heightMeasureSpec
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/res/layout/dialog_prompt.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -19,13 +20,19 @@
android:textSize="@dimen/title_size_normal"
android:textStyle="bold" />

<TextView
android:id="@+id/tv_text"
<me.kbai.zhenxunui.widget.MaxHeightLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_wide"
android:textColor="@color/dn_black"
tools:text="114514" />
app:maxHeight="200dp">

<TextView
android:id="@+id/tv_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_wide"
android:textColor="@color/dn_black"
tools:text="114514" />
</me.kbai.zhenxunui.widget.MaxHeightLayout>

<LinearLayout
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@
<string name="new_file">创建文件</string>
<string name="new_folder">新建文件夹</string>
<string name="edit_file">编辑文件</string>
<string name="text_too_long">文本过长,暂不支持编辑</string>
</resources>
8 changes: 7 additions & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
<attr name="tableEnforceChildrenWidth" format="boolean" />
</declare-styleable>

<attr name="maxHeight" format="dimension" />

<declare-styleable name="ExpandLayout">
<attr name="expanded" format="boolean" />
<attr name="maxHeight" format="dimension" />
<attr name="maxHeight" />
<attr name="animationDuration" format="integer" />
</declare-styleable>

<declare-styleable name="MaxHeightLayout">
<attr name="maxHeight" />
</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@
<string name="new_file">New File</string>
<string name="new_folder">New Folder</string>
<string name="edit_file">Edit File</string>
<string name="text_too_long">The text is too long to edit</string>
</resources>

0 comments on commit 86f6396

Please sign in to comment.