Skip to content

Commit

Permalink
* [bug] Fix: Note delete leads to crash due to IndexOutOfBoundExcepti…
Browse files Browse the repository at this point in the history
…on in TouchHelper

* Correct About screen's title text
* Show unavailability tooltip when clicking on disabled items (Discord/Open bounties)
*
  • Loading branch information
tuancoltech committed Jun 2, 2024
1 parent a85f62f commit ac76366
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ dependencies {
implementation 'com.airbnb.android:lottie:6.4.0'
implementation 'com.github.androidmads:QRGenerator:1.0.1'
implementation("io.coil-kt:coil:2.6.0")
implementation("com.github.skydoves:balloon:1.6.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ class NotesListAdapter(
notifyDataSetChanged()
}

fun getNotes(): List<Note> {
return notes
}

inner class NoteViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
private val binding by viewBinding {
AdapterTextNoteBinding.bind(itemView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class NotesFragment: Fragment() {
private val arkMediaPlayerViewModel: ArkMediaPlayerViewModel by activityViewModels()
private var notesAdapter: NotesListAdapter? = null

private var notes = listOf<Note>()

private var showingFloatingButtons = false

private val newTextNoteClickListener = View.OnClickListener {
Expand All @@ -72,7 +70,9 @@ class NotesFragment: Fragment() {

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val deletePosition = viewHolder.bindingAdapterPosition
val noteToDelete = notes[deletePosition].apply { pendingForDelete = true }
val noteToDelete = notesAdapter?.getNotes()?.getOrNull(deletePosition)?.apply {
pendingForDelete = true
} ?: return
binding.rvPinnedNotes.adapter?.notifyItemChanged(deletePosition)

CommonActionDialog(title = R.string.delete_note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dev.arkbuilders.arkmemo.ui.dialogs.CommonActionDialog
import dev.arkbuilders.arkmemo.ui.dialogs.DonateDialog
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.openLink
import dev.arkbuilders.arkmemo.utils.showAvailabilityToolTip
import dev.arkbuilders.arkmemo.utils.visible

open class SettingsFragmentV2: Fragment(R.layout.fragment_settings) {
Expand All @@ -22,7 +23,7 @@ open class SettingsFragmentV2: Fragment(R.layout.fragment_settings) {
binding.toolbarCustom.ivBack.setOnClickListener {
activity?.onBackPressedDispatcher?.onBackPressed()
}
binding.toolbarCustom.tvTitle.text = getString(R.string.settings)
binding.toolbarCustom.tvTitle.text = getString(R.string.about)
binding.toolbarCustom.tvTitle.visible()

binding.toolbarCustom.tvRightActionText.gone()
Expand All @@ -43,6 +44,10 @@ open class SettingsFragmentV2: Fragment(R.layout.fragment_settings) {
context?.openLink("https://t.me/ark_builders")
}

binding.tvDiscord.setOnClickListener {
it.showAvailabilityToolTip()
}

binding.tvDonatePatreon.setOnClickListener {
context?.openLink("https://www.patreon.com/ARKBuilders")
}
Expand All @@ -69,5 +74,13 @@ open class SettingsFragmentV2: Fragment(R.layout.fragment_settings) {
context?.openLink("https://www.ark-builders.dev/contribute/?tab=goodFirstIssue")
}

binding.tvBounties.setOnClickListener {
}

// if (binding.tvBounties.isEnabled) {
// binding.tvBounties.setOnClickListener {
// }
// }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.core.content.ContextCompat
import dev.arkbuilders.arkmemo.R
import dev.arkbuilders.arkmemo.databinding.LayoutSupportTextBinding
import dev.arkbuilders.arkmemo.utils.gone
import dev.arkbuilders.arkmemo.utils.setOnDebounceTouchListener
import dev.arkbuilders.arkmemo.utils.showAvailabilityToolTip

class SupportTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
ConstraintLayout(context, attrs) {
Expand All @@ -35,6 +37,10 @@ class SupportTextView @JvmOverloads constructor(context: Context, attrs: Attribu
if (!enabled) {
binding.tvText.setTextColor(ContextCompat.getColor(context, R.color.gray_400))
binding.tvText.isEnabled = false
setOnDebounceTouchListener { v, event ->
showAvailabilityToolTip()
binding.tvText.isEnabled = true
}
}

typedArray.recycle()
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/dev/arkbuilders/arkmemo/utils/ViewExt.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package dev.arkbuilders.arkmemo.utils

import android.view.MotionEvent
import android.view.View
import com.skydoves.balloon.ArrowPositionRules
import com.skydoves.balloon.Balloon
import com.skydoves.balloon.BalloonAnimation
import com.skydoves.balloon.BalloonSizeSpec
import com.skydoves.balloon.showAlignTop
import dev.arkbuilders.arkmemo.R

fun View.visible() {
this.visibility = View.VISIBLE
Expand All @@ -12,4 +19,36 @@ fun View.invisible() {

fun View.gone() {
this.visibility = View.GONE
}

fun View.setOnDebounceTouchListener(action: (v: View, e: MotionEvent) -> Unit) {
var isTouched = false
setOnTouchListener { v, e ->
if (!isTouched) {
isTouched = true
action(v, e)
postDelayed({ isTouched = false }, 500)
}
true

}
}

fun View.showAvailabilityToolTip() {
val balloon = Balloon.Builder(context)
.setWidthRatio(1.0f)
.setHeight(BalloonSizeSpec.WRAP)
.setText(context.getString(R.string.tips_will_be_available_soon))
.setTextColorResource(R.color.white)
.setTextSize(12f)
.setArrowPositionRules(ArrowPositionRules.ALIGN_ANCHOR)
.setArrowSize(10)
.setArrowPosition(0.5f)
.setPadding(12)
.setCornerRadius(8f)
.setWidthRatio(0.5f)
.setBackgroundColorResource(R.color.warning_300)
.setBalloonAnimation(BalloonAnimation.ELASTIC)
.build()
showAlignTop(balloon)
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="note">Note</string>
<string name="date">Date</string>
<string name="settings">Settings</string>
<string name="about">About</string>
<string name="path_pref_key">Path</string>
<string name="choose_folder">Choose folder to save your notes</string>
<string name="no_folder">No folder</string>
Expand Down Expand Up @@ -97,5 +98,6 @@
<string name="dialog_donate_qr_copy">Copy</string>
<string name="dialog_donate_qr_download">Download QR image</string>
<string name="toast_save_qr_success">QR saved at %s</string>
<string name="tips_will_be_available_soon">Will be available soon!</string>

</resources>

0 comments on commit ac76366

Please sign in to comment.