Skip to content

Commit

Permalink
Build91
Browse files Browse the repository at this point in the history
  - Fixed the crash that unexpectedly occurred
  • Loading branch information
Hamza417 committed Aug 29, 2023
1 parent 9ab7bc2 commit 15ee405
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 11 deletions.
24 changes: 22 additions & 2 deletions app/src/main/java/app/simple/inure/adapters/ui/AdapterTags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import app.simple.inure.util.ConditionUtils.isZero
import app.simple.inure.util.DateUtils.toDate
import app.simple.inure.util.RecyclerViewUtils

class AdapterTags(val tags: ArrayList<Tag>, private val function: (String) -> Unit)
class AdapterTags(val tags: ArrayList<Tag>, private val tagsCallback: TagsCallback)
: RecyclerView.Adapter<VerticalListViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VerticalListViewHolder {
Expand Down Expand Up @@ -47,7 +47,12 @@ class AdapterTags(val tags: ArrayList<Tag>, private val function: (String) -> Un
holder.date.text = tags[position - 1].dateAdded.toDate()

holder.container.setOnClickListener {
function(tags[position - 1].tag)
tagsCallback.onTagClicked(tags[position - 1])
}

holder.container.setOnLongClickListener {
tagsCallback.onTagLongClicked(tags[position - 1])
true
}
}
}
Expand All @@ -65,6 +70,14 @@ class AdapterTags(val tags: ArrayList<Tag>, private val function: (String) -> Un
}
}

fun removeTag(tag: Tag) {
val idx = tags.indexOf(tag)
tags.remove(tag)
notifyItemRemoved(idx + 1)
notifyItemRangeChanged(0, tags.size)
notifyItemChanged(0) // Update header
}

inner class Holder(itemView: View) : VerticalListViewHolder(itemView) {
val tag: TypeFaceTextView = itemView.findViewById(R.id.tag)
val recyclerView: RecyclerView = itemView.findViewById(R.id.recycler_view)
Expand All @@ -90,4 +103,11 @@ class AdapterTags(val tags: ArrayList<Tag>, private val function: (String) -> Un
params.isFullSpan = true
}
}

companion object {
interface TagsCallback {
fun onTagClicked(tag: Tag)
fun onTagLongClicked(tag: Tag)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
Expand Down Expand Up @@ -57,7 +58,8 @@ protected void attachLayoutAnimationParameters(View child, ViewGroup.LayoutParam
animationParams.column = columns - 1 - (invertedIndex % columns);
animationParams.row = animationParams.rowsCount - 1 - invertedIndex / columns;
} else {
throw new IllegalStateException("GridRecyclerView must have a GridLayoutManager");
// throw new IllegalStateException("GridRecyclerView must have a GridLayoutManager");
Log.e("GridRecyclerView", "attachLayoutAnimationParameters: GridRecyclerView must have a GridLayoutManager");
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/app/simple/inure/dialogs/tags/AddTag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import app.simple.inure.decorations.ripple.DynamicRippleTextView
import app.simple.inure.decorations.typeface.TypeFaceTextView
import app.simple.inure.decorations.views.TagsRecyclerView
import app.simple.inure.extensions.fragments.ScopedDialogFragment
import app.simple.inure.popups.tags.PopupTagsMenu
import app.simple.inure.popups.tags.PopupTagMenu
import app.simple.inure.themes.manager.ThemeManager
import app.simple.inure.util.TextViewUtils.doOnTextChanged
import app.simple.inure.util.ViewUtils.gone
Expand Down Expand Up @@ -77,7 +77,7 @@ class AddTag : ScopedDialogFragment() {
}

override fun onTagLongClicked(tag: String) {
PopupTagsMenu(requireView(), object : PopupTagsMenu.Companion.TagsMenuCallback {
PopupTagMenu(requireView(), object : PopupTagMenu.Companion.TagsMenuCallback {
override fun onDeleteClicked() {
tagsViewModel?.removeTag(tag, packageInfo) {
this@apply.removeTag(tag)
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/app/simple/inure/popups/tags/PopupTagMenu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package app.simple.inure.popups.tags

import android.view.LayoutInflater
import android.view.View
import app.simple.inure.R
import app.simple.inure.constants.Misc
import app.simple.inure.decorations.ripple.DynamicRippleTextView
import app.simple.inure.extensions.popup.BasePopupWindow
import app.simple.inure.extensions.popup.PopupLinearLayout

class PopupTagMenu(view: View, tagsMenuCallback: TagsMenuCallback) : BasePopupWindow() {

private val delete: DynamicRippleTextView

init {
val containerView = LayoutInflater.from(view.context)
.inflate(R.layout.popup_tag_menu, PopupLinearLayout(view.context), true)

delete = containerView.findViewById(R.id.delete)

delete.setOnClickListener {
tagsMenuCallback.onDeleteClicked()
dismiss()
}

init(containerView, view, Misc.xOffset, Misc.yOffset)
}

companion object {
interface TagsMenuCallback {
fun onDeleteClicked()
}
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/app/simple/inure/popups/tags/PopupTagsMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ import app.simple.inure.extensions.popup.PopupLinearLayout

class PopupTagsMenu(view: View, tagsMenuCallback: TagsMenuCallback) : BasePopupWindow() {

private val open: DynamicRippleTextView
private val delete: DynamicRippleTextView

init {
val containerView = LayoutInflater.from(view.context)
.inflate(R.layout.popup_tag_menu, PopupLinearLayout(view.context), true)
.inflate(R.layout.popup_tags_menu, PopupLinearLayout(view.context), true)

open = containerView.findViewById(R.id.open)
delete = containerView.findViewById(R.id.delete)

open.setOnClickListener {
tagsMenuCallback.onOpenClicked()
dismiss()
}

delete.setOnClickListener {
tagsMenuCallback.onDeleteClicked()
dismiss()
Expand All @@ -28,6 +35,7 @@ class PopupTagsMenu(view: View, tagsMenuCallback: TagsMenuCallback) : BasePopupW

companion object {
interface TagsMenuCallback {
fun onOpenClicked()
fun onDeleteClicked()
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/app/simple/inure/ui/panels/AppInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import app.simple.inure.factories.panels.PackageInfoFactory
import app.simple.inure.glide.util.ImageLoader.loadAPKIcon
import app.simple.inure.glide.util.ImageLoader.loadAppIcon
import app.simple.inure.interfaces.fragments.SureCallbacks
import app.simple.inure.popups.tags.PopupTagsMenu
import app.simple.inure.popups.tags.PopupTagMenu
import app.simple.inure.preferences.AccessibilityPreferences
import app.simple.inure.preferences.AppInformationPreferences
import app.simple.inure.preferences.DevelopmentPreferences
Expand Down Expand Up @@ -172,7 +172,7 @@ class AppInfo : ScopedFragment() {
}

override fun onTagLongClicked(tag: String) {
PopupTagsMenu(requireView(), object : PopupTagsMenu.Companion.TagsMenuCallback {
PopupTagMenu(requireView(), object : PopupTagMenu.Companion.TagsMenuCallback {
override fun onDeleteClicked() {
tagsViewModel.removeTag(tag, packageInfo) {
this@apply.removeTag(tag)
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/java/app/simple/inure/ui/panels/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import app.simple.inure.adapters.ui.AdapterTags
import app.simple.inure.constants.BottomMenuConstants
import app.simple.inure.decorations.overscroll.CustomVerticalRecyclerView
import app.simple.inure.extensions.fragments.ScopedFragment
import app.simple.inure.models.Tag
import app.simple.inure.popups.tags.PopupTagsMenu
import app.simple.inure.ui.subpanels.TaggedApps
import app.simple.inure.viewmodels.panels.TagsViewModel

Expand All @@ -37,9 +39,25 @@ class Tags : ScopedFragment() {
postponeEnterTransition()

tagsViewModel?.getTags()?.observe(viewLifecycleOwner) {
val adapter = AdapterTags(it) {
openFragmentSlide(TaggedApps.newInstance(it), "tagged_apps")
}
val adapter = AdapterTags(it, object : AdapterTags.Companion.TagsCallback {
override fun onTagClicked(tag: Tag) {
openFragmentSlide(TaggedApps.newInstance(tag.tag), "tagged_apps")
}

override fun onTagLongClicked(tag: Tag) {
PopupTagsMenu(requireView(), object : PopupTagsMenu.Companion.TagsMenuCallback {
override fun onOpenClicked() {
openFragmentSlide(TaggedApps.newInstance(tag.tag), "tagged_apps")
}

override fun onDeleteClicked() {
tagsViewModel?.deleteTag(tag) {
(recyclerView.adapter as AdapterTags).removeTag(tag)
}
}
})
}
})

recyclerView.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL).apply {
gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,15 @@ class TagsViewModel(application: Application) : PackageUtilsViewModel(applicatio
fun refresh() {
loadTags()
}

fun deleteTag(tag: Tag, function: () -> Unit) {
viewModelScope.launch(Dispatchers.IO) {
val database = TagsDatabase.getInstance(application.applicationContext)
database?.getTagDao()?.deleteTag(tag)
tags.value?.remove(tag)
withContext(Dispatchers.Main) {
function()
}
}
}
}
42 changes: 42 additions & 0 deletions app/src/main/res/layout/popup_tags_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<merge 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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/popup_padding"
tools:parentTag="android.widget.LinearLayout">

<app.simple.inure.decorations.ripple.DynamicRippleTextView
android:id="@+id/open"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:fontFamily="@font/lato_bold"
android:maxLines="1"
android:paddingHorizontal="30dp"
android:paddingVertical="20dp"
android:text="@string/open"
android:textSize="@dimen/popup_text_size"
app:appFontStyle="bold"
app:textColorStyle="primary" />

<app.simple.inure.decorations.ripple.DynamicRippleTextView
android:id="@+id/delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_marginTop="@dimen/popup_item_gap_length"
android:focusable="true"
android:fontFamily="@font/lato_bold"
android:maxLines="1"
android:paddingHorizontal="30dp"
android:paddingVertical="20dp"
android:text="@string/delete"
android:textSize="@dimen/popup_text_size"
app:appFontStyle="bold"
app:textColorStyle="primary" />

</merge>

0 comments on commit 15ee405

Please sign in to comment.