Skip to content
This repository was archived by the owner on Jul 18, 2026. It is now read-only.

Commit 9fda12c

Browse files
authored
Merge pull request #111 from misaka10032w/develop
[Fix] 优化子评论展示及回复框样式等
2 parents 62d6239 + 8215c43 commit 9fda12c

15 files changed

Lines changed: 192 additions & 56 deletions

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ plugins {
1919
alias(libs.plugins.compose.compiler)
2020
id("com.mikepenz.aboutlibraries.plugin") version "12.2.4"
2121
id("com.github.ben-manes.versions") version "0.52.0"
22-
// alias(libs.plugins.compose.compiler)
2322
}
2423

2524
android {

app/src/main/java/com/yenaly/han1meviewer/ui/activity/DownloadActivity.kt

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.yenaly.han1meviewer.ui.activity
22

3+
import android.graphics.Color
34
import android.os.Build
45
import android.os.Bundle
56
import android.view.LayoutInflater
6-
import android.view.View
7+
import androidx.activity.SystemBarStyle
8+
import androidx.activity.enableEdgeToEdge
79
import androidx.core.text.parseAsHtml
810
import com.yenaly.han1meviewer.R
911
import com.yenaly.han1meviewer.databinding.ActivityDownloadBinding
@@ -32,6 +34,10 @@ class DownloadActivity : YenalyActivity<ActivityDownloadBinding>() {
3234

3335
override fun initData(savedInstanceState: Bundle?) {
3436
setSupportActionBar(binding.toolbar)
37+
enableEdgeToEdge(
38+
statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT),
39+
navigationBarStyle = SystemBarStyle.dark(Color.TRANSPARENT)
40+
)
3541
binding.toolbar.setNavigationOnClickListener {
3642
onBackPressedDispatcher.onBackPressed()
3743
}
@@ -63,25 +69,25 @@ class DownloadActivity : YenalyActivity<ActivityDownloadBinding>() {
6369
tab.setText(tabNameArray[position])
6470
}
6571

66-
binding.hanidock.hanidokitems = listOf(
67-
Hanidokitem.create {
68-
icon = R.drawable.ic_baseline_access_time_24
69-
text = R.string.title
70-
viewAction = View.OnClickListener {
71-
showShortToast("test")
72-
}
73-
},
74-
Hanidokitem.create {
75-
icon = R.drawable.baseline_add_24
76-
text = R.string.add
77-
subitems = listOf(
78-
Hanidokitem.create {
79-
icon = R.drawable.ic_baseline_access_time_24
80-
text = R.string.title
81-
}
82-
)
83-
}
84-
)
72+
// binding.hanidock.hanidokitems = listOf(
73+
// Hanidokitem.create {
74+
// icon = R.drawable.ic_baseline_access_time_24
75+
// text = R.string.title
76+
// viewAction = View.OnClickListener {
77+
// showShortToast("test")
78+
// }
79+
// },
80+
// Hanidokitem.create {
81+
// icon = R.drawable.baseline_add_24
82+
// text = R.string.add
83+
// subitems = listOf(
84+
// Hanidokitem.create {
85+
// icon = R.drawable.ic_baseline_access_time_24
86+
// text = R.string.title
87+
// }
88+
// )
89+
// }
90+
// )
8591
}
8692

8793
override fun finish() {

app/src/main/java/com/yenaly/han1meviewer/ui/activity/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class MainActivity : YenalyActivity<ActivityMainBinding>(), DrawerListener, Tool
270270
}
271271

272272
private fun removeAuthGuard() {
273-
val root = findViewById<ViewGroup>(R.id.dl_main) // 或者 R.id.root
273+
val root = findViewById<ViewGroup>(R.id.dl_main)
274274
val authGuard = findViewById<View>(R.id.auth_guard)
275275
root?.removeView(authGuard)
276276
}

app/src/main/java/com/yenaly/han1meviewer/ui/adapter/VideoCommentRvAdapter.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ class VideoCommentRvAdapter(
226226
commentPopup.hint =
227227
"""${context.getString(R.string.reply)}<b>@${item.username}</b>""".parseAsHtml()
228228
}
229-
XPopup.Builder(context).autoOpenSoftInput(true).asCustom(commentPopup).show()
229+
XPopup.Builder(context)
230+
.autoOpenSoftInput(true)
231+
.moveUpToKeyboard(false)
232+
.asCustom(commentPopup).show()
230233
}
231234
}
232235
}

app/src/main/java/com/yenaly/han1meviewer/ui/fragment/video/ChildCommentPopupFragment.kt

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package com.yenaly.han1meviewer.ui.fragment.video
22

33
import android.app.Dialog
4+
import android.os.Build
45
import android.os.Bundle
56
import android.view.Gravity
67
import android.view.LayoutInflater
8+
import android.view.View
9+
import android.view.ViewGroup
10+
import android.view.WindowManager
711
import androidx.annotation.OptIn
812
import androidx.fragment.app.viewModels
913
import androidx.lifecycle.lifecycleScope
1014
import androidx.recyclerview.widget.LinearLayoutManager
1115
import com.google.android.material.badge.BadgeDrawable
1216
import com.google.android.material.badge.BadgeUtils
1317
import com.google.android.material.badge.ExperimentalBadgeUtils
18+
import com.google.android.material.bottomsheet.BottomSheetBehavior
19+
import com.google.android.material.bottomsheet.BottomSheetDialog
1420
import com.yenaly.han1meviewer.COMMENT_ID
1521
import com.yenaly.han1meviewer.R
1622
import com.yenaly.han1meviewer.databinding.PopUpFragmentChildCommentBinding
@@ -19,7 +25,6 @@ import com.yenaly.han1meviewer.ui.adapter.VideoCommentRvAdapter
1925
import com.yenaly.han1meviewer.ui.viewmodel.CommentViewModel
2026
import com.yenaly.han1meviewer.util.setGravity
2127
import com.yenaly.yenaly_libs.base.YenalyBottomSheetDialogFragment
22-
import com.yenaly.yenaly_libs.utils.appScreenHeight
2328
import com.yenaly.yenaly_libs.utils.arguments
2429
import com.yenaly.yenaly_libs.utils.dp
2530
import com.yenaly.yenaly_libs.utils.showShortToast
@@ -47,10 +52,10 @@ class ChildCommentPopupFragment :
4752
override fun initData(savedInstanceState: Bundle?, dialog: Dialog) {
4853
if (commentId == null) dialog.dismiss()
4954

50-
binding.root.minimumHeight = appScreenHeight / 2
55+
// binding.root.minimumHeight = appScreenHeight / 2
5156
binding.rvReply.layoutManager = LinearLayoutManager(context)
5257
binding.rvReply.adapter = replyAdapter
53-
58+
binding.rvReplyContainer.layoutParams.height = getWindowHeight() / 2
5459
viewModel.getCommentReply(commentId!!)
5560

5661
lifecycleScope.launch {
@@ -63,7 +68,9 @@ class ChildCommentPopupFragment :
6368

6469
is WebsiteState.Loading -> Unit
6570

66-
is WebsiteState.Success -> Unit
71+
is WebsiteState.Success -> {
72+
binding.rvReplyContainer.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
73+
}
6774
}
6875
}
6976
}
@@ -80,6 +87,7 @@ class ChildCommentPopupFragment :
8087
when (state) {
8188
is WebsiteState.Error -> {
8289
showShortToast(R.string.send_failed)
90+
replyAdapter.replyPopup?.enableSendButton()
8391
}
8492

8593
is WebsiteState.Loading -> {
@@ -88,6 +96,7 @@ class ChildCommentPopupFragment :
8896

8997
is WebsiteState.Success -> {
9098
showShortToast(R.string.send_success)
99+
replyAdapter.replyPopup?.enableSendButton()
91100
viewModel.getCommentReply(commentId!!)
92101
replyAdapter.replyPopup?.dismiss()
93102
}
@@ -108,7 +117,40 @@ class ChildCommentPopupFragment :
108117
}
109118
}
110119
}
111-
120+
override fun onStart() {
121+
super.onStart()
122+
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
123+
val bottomSheet = dialog?.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
124+
bottomSheet?.let { sheet ->
125+
val screenHeight = getWindowHeight()
126+
sheet.minimumHeight = screenHeight / 2
127+
val behavior = BottomSheetBehavior.from(sheet)
128+
behavior.isFitToContents = false
129+
behavior.peekHeight = screenHeight / 2
130+
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
131+
}
132+
}
133+
private fun getWindowHeight(): Int {
134+
val window = dialog?.window ?: return resources.displayMetrics.heightPixels
135+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
136+
window.windowManager.currentWindowMetrics.bounds.height()
137+
} else {
138+
@Suppress("DEPRECATION")
139+
window.windowManager.defaultDisplay.height
140+
}
141+
}
142+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
143+
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
144+
dialog.window?.apply {
145+
addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
146+
@Suppress("DEPRECATION")
147+
addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
148+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
149+
isNavigationBarContrastEnforced = false
150+
}
151+
}
152+
return dialog
153+
}
112154
@OptIn(ExperimentalBadgeUtils::class)
113155
private fun attachRedDotCount(count: Int) {
114156
val badgeDrawable = BadgeDrawable.create(requireContext())

app/src/main/java/com/yenaly/han1meviewer/ui/fragment/video/CommentFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ class CommentFragment : YenalyFragment<FragmentCommentBinding>(), StateLayoutMix
108108
} ?: showShortToast(R.string.there_is_a_small_issue)
109109
}
110110
binding.btnComment.setOnClickListener {
111-
XPopup.Builder(context).autoOpenSoftInput(true)
111+
XPopup.Builder(context)
112+
.autoOpenSoftInput(true)
113+
.moveUpToKeyboard(false)
112114
.setPopupCallback(object : SimpleCallback() {
113115
override fun beforeShow(popupView: BasePopupView?) {
114116
binding.btnComment.hide()
@@ -192,6 +194,7 @@ class CommentFragment : YenalyFragment<FragmentCommentBinding>(), StateLayoutMix
192194
when (state) {
193195
is WebsiteState.Error -> {
194196
showShortToast(R.string.send_failed)
197+
commentAdapter.replyPopup?.enableSendButton()
195198
}
196199

197200
is WebsiteState.Loading -> {
@@ -200,6 +203,7 @@ class CommentFragment : YenalyFragment<FragmentCommentBinding>(), StateLayoutMix
200203

201204
is WebsiteState.Success -> {
202205
showShortToast(R.string.send_success)
206+
commentAdapter.replyPopup?.enableSendButton()
203207
viewModel.getComment(commentTypePrefix, viewModel.code)
204208
commentAdapter.replyPopup?.dismiss()
205209
}

app/src/main/java/com/yenaly/han1meviewer/ui/popup/ReplyPopup.kt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.yenaly.han1meviewer.ui.popup
22

33
import android.content.Context
4-
import android.widget.EditText
4+
import android.os.Build
5+
import android.view.WindowInsets
56
import com.google.android.material.button.MaterialButton
7+
import com.google.android.material.textfield.TextInputEditText
68
import com.lxj.xpopup.core.BottomPopupView
79
import com.yenaly.han1meviewer.R
810
import com.yenaly.yenaly_libs.utils.unsafeLazy
@@ -14,7 +16,7 @@ import com.yenaly.yenaly_libs.utils.unsafeLazy
1416
*/
1517
class ReplyPopup(context: Context) : BottomPopupView(context) {
1618

17-
private val editText by unsafeLazy { findViewById<EditText>(R.id.et_comment) }
19+
private val editText by unsafeLazy { findViewById<TextInputEditText>(R.id.et_comment) }
1820
private val btnSend by unsafeLazy { findViewById<MaterialButton>(R.id.btn_send) }
1921

2022
private var commentPrefix: String? = null
@@ -27,8 +29,33 @@ class ReplyPopup(context: Context) : BottomPopupView(context) {
2729
editText.hint = hint
2830
commentPrefix?.let(editText::append)
2931
sendListener?.let(btnSend::setOnClickListener)
32+
//防止连续点击干出去好几个评论,评论区有时候出现好几个相同的评论,一猜就是APP发出去的,防止站长发现给加验证码。
33+
btnSend.setOnClickListener {
34+
btnSend.isEnabled = false
35+
sendListener?.onClick(it)
36+
}
37+
}
38+
/**
39+
* [onKeyboardHeightChange]方法在某些情况下只让出了IME高度,没有让出沉浸式导航栏高度
40+
*/
41+
@Suppress("DEPRECATION")
42+
override fun onKeyboardHeightChange(height: Int) {
43+
super.onKeyboardHeightChange(height)
44+
val insets = rootView.rootWindowInsets
45+
val navHeight = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
46+
insets?.getInsets(WindowInsets.Type.navigationBars())?.bottom ?: 0
47+
} else {
48+
if (height == 0) {
49+
insets?.systemWindowInsetBottom ?: 0
50+
} else {
51+
(insets?.systemWindowInsetBottom ?: 0) - height
52+
}
53+
}
54+
translationY = if (height > 0) -(height + navHeight).toFloat() else 0f
55+
}
56+
fun enableSendButton() {
57+
btnSend.isEnabled = true
3058
}
31-
3259
/**
3360
* 得到你输入的内容
3461
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="1024" android:viewportWidth="1024" android:width="24dp">
2+
3+
<path android:fillColor="#ffffff" android:pathData="M504.1,16.5c-278.3,0 -504,225.6 -504,504S225.8,1024.4 504.1,1024.4s504,-225.6 504,-504S782.4,16.5 504.1,16.5zM242.7,566.7l0,-94.7 525.4,0 -0,94.7L242.7,566.7z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@drawable/ic_baseline_disable_24" android:state_enabled="false" />
4+
<item android:drawable="@drawable/ic_baseline_send_24" android:state_enabled="true" />
5+
</selector>

app/src/main/res/layout/activity_download.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
android:layout_width="wrap_content"
4444
android:layout_height="wrap_content"
4545
android:layout_gravity="end|bottom"
46+
android:visibility="gone"
4647
android:layout_margin="16dp" />
4748

4849
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)