Skip to content

Commit

Permalink
Build91
Browse files Browse the repository at this point in the history
  - Added batch tags
  • Loading branch information
Hamza417 committed Aug 29, 2023
1 parent 7c945bd commit 30fec9e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ object BottomMenuConstants {
// Pair(R.drawable.ic_share, R.string.share),
Pair(R.drawable.ic_downloading, R.string.extract),
Pair(R.drawable.ic_text_snippet, R.string.data),
Pair(R.drawable.ic_tags, R.string.tags),
divider,
Pair(R.drawable.ic_checklist, R.string.checklist),
Pair(R.drawable.ic_select_all, R.string.select_all),
Expand All @@ -119,6 +120,7 @@ object BottomMenuConstants {
// Pair(R.drawable.ic_share, R.string.share),
Pair(R.drawable.ic_downloading, R.string.extract),
Pair(R.drawable.ic_text_snippet, R.string.data),
Pair(R.drawable.ic_tags, R.string.tags),
divider,
Pair(R.drawable.ic_checklist, R.string.checklist),
Pair(R.drawable.ic_select_all, R.string.select_all),
Expand Down
37 changes: 24 additions & 13 deletions app/src/main/java/app/simple/inure/decorations/views/TagChip.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ public TagChip(Context context, AttributeSet attrs, int defStyleAttr) {

private void init() {
setTypeface(TypeFace.INSTANCE.getMediumTypeFace(getContext()));
setTextColor(ColorStateList.valueOf(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()));

setTextColor(ColorStateList
.valueOf(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()));

setChipIconSize(getResources().getDimensionPixelSize(R.dimen.chip_icon_size));
setChipIconTint(ColorStateList.valueOf(ThemeManager.INSTANCE.getTheme().getIconTheme().getRegularIconColor()));

setChipIconTint(ColorStateList
.valueOf(ThemeManager.INSTANCE.getTheme().getIconTheme().getRegularIconColor()));

setChipBackgroundColor(new ColorStateList(new int[][] {
new int[] {
android.R.attr.state_checked
Expand All @@ -52,17 +54,19 @@ private void init() {
ThemeManager.INSTANCE.getTheme().getViewGroupTheme().getViewerBackground() // Background color
}
));

setShapeAppearanceModel(new ShapeAppearanceModel()
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED, AppearancePreferences.INSTANCE.getCornerRadius())
.build());

ViewUtils.INSTANCE.addShadow(this);
setRippleColor(ColorStateList.valueOf(AppearancePreferences.INSTANCE.getAccentColorLight(getContext())));
setRippleColor(ColorStateList
.valueOf(AppearancePreferences.INSTANCE.getAccentColorLight(getContext())));

if (!DevelopmentPreferences.INSTANCE.get(DevelopmentPreferences.removeStrokeFromChips)) {
setChipStrokeColor(ColorStateList.valueOf(AppearancePreferences.INSTANCE.getAccentColor()));
setChipStrokeColor(ColorStateList
.valueOf(AppearancePreferences.INSTANCE.getAccentColor()));
setChipStrokeWidth(1);
}
}
Expand All @@ -73,18 +77,22 @@ public void setChipColor(int color, boolean whiteText) {
android.R.attr.state_checked
},
new int[] {

}},
new int[] {
color, // Ripple color
color // Background color
}
));

setRippleColor(ColorStateList.valueOf(color));

if (whiteText) {
setTextColor(ColorStateList.valueOf(Color.WHITE));
} else {
setTextColor(ColorStateList.valueOf(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()));
setTextColor(ColorStateList
.valueOf(ThemeManager.INSTANCE.getTheme()
.getTextViewTheme().getPrimaryTextColor()));
}
}

Expand All @@ -94,14 +102,17 @@ public void setDefaultChipColor() {
android.R.attr.state_checked
},
new int[] {

}},
new int[] {
AppearancePreferences.INSTANCE.getAccentColor(), // Ripple color
ThemeManager.INSTANCE.getTheme().getViewGroupTheme().getViewerBackground() // Background color
ThemeManager.INSTANCE.getTheme()
.getViewGroupTheme().getViewerBackground() // Background color
}
));

setTextColor(ColorStateList.valueOf(ThemeManager.INSTANCE.getTheme().getTextViewTheme().getPrimaryTextColor()));

setTextColor(ColorStateList
.valueOf(ThemeManager.INSTANCE.getTheme()
.getTextViewTheme().getPrimaryTextColor()));
}
}
26 changes: 20 additions & 6 deletions app/src/main/java/app/simple/inure/ui/panels/Batch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import app.simple.inure.dialogs.menus.AppsMenu
import app.simple.inure.dialogs.miscellaneous.GenerateAppData.Companion.showGeneratedDataTypeSelector
import app.simple.inure.dialogs.miscellaneous.StoragePermission
import app.simple.inure.dialogs.miscellaneous.StoragePermission.Companion.showStoragePermissionDialog
import app.simple.inure.dialogs.tags.AddTag.Companion.showAddTagDialog
import app.simple.inure.extensions.fragments.ScopedFragment
import app.simple.inure.interfaces.adapters.AdapterCallbacks
import app.simple.inure.interfaces.fragments.SureCallbacks
Expand All @@ -41,19 +42,22 @@ import app.simple.inure.ui.viewers.XMLViewerTextView
import app.simple.inure.util.NullSafety.isNotNull
import app.simple.inure.util.PermissionUtils.checkStoragePermission
import app.simple.inure.viewmodels.panels.BatchViewModel
import app.simple.inure.viewmodels.panels.TagsViewModel

class Batch : ScopedFragment() {

private lateinit var recyclerView: CustomVerticalRecyclerView

private var adapterBatch: AdapterBatch? = null
private lateinit var batchViewModel: BatchViewModel
private lateinit var tagsViewModel: TagsViewModel

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_batch, container, false)

recyclerView = view.findViewById(R.id.batch_recycler_view)
batchViewModel = ViewModelProvider(requireActivity())[BatchViewModel::class.java]
tagsViewModel = ViewModelProvider(requireActivity())[TagsViewModel::class.java]

return view
}
Expand Down Expand Up @@ -177,12 +181,12 @@ class Batch : ScopedFragment() {
if (requireContext().checkStoragePermission()) {
childFragmentManager.showBatchExtract(adapterBatch?.getCurrentAppsList()!!)
} else {
childFragmentManager.showStoragePermissionDialog().setStoragePermissionCallbacks(
object : StoragePermission.Companion.StoragePermissionCallbacks {
override fun onStoragePermissionGranted() {
childFragmentManager.showBatchExtract(adapterBatch?.getCurrentAppsList()!!)
}
})
childFragmentManager.showStoragePermissionDialog()
.setStoragePermissionCallbacks(object : StoragePermission.Companion.StoragePermissionCallbacks {
override fun onStoragePermissionGranted() {
childFragmentManager.showBatchExtract(adapterBatch?.getCurrentAppsList()!!)
}
})
}
}
})
Expand All @@ -198,6 +202,16 @@ class Batch : ScopedFragment() {
}
}

R.drawable.ic_tags -> {
childFragmentManager.showAddTagDialog().onTag = {
tagsViewModel.addMultipleAppsToTag(adapterBatch?.getCurrentAppsList()!!, it) {
postDelayed {
showWarning(R.string.done, goBack = false)
}
}
}
}

R.drawable.ic_settings_power -> {
childFragmentManager.showBatchBatteryOptimization(adapterBatch?.getCurrentAppsList()!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import app.simple.inure.database.instances.TagsDatabase
import app.simple.inure.extensions.viewmodels.PackageUtilsViewModel
import app.simple.inure.models.BatchPackageInfo
import app.simple.inure.models.Tag
import app.simple.inure.util.ArrayUtils.toArrayList
import app.simple.inure.util.ConditionUtils.invert
Expand Down Expand Up @@ -73,6 +74,7 @@ class TagsViewModel(application: Application) : PackageUtilsViewModel(applicatio
withContext(Dispatchers.Main) {
function()
loadTags()
loadTagNames()
}
}
}
Expand All @@ -99,6 +101,7 @@ class TagsViewModel(application: Application) : PackageUtilsViewModel(applicatio
withContext(Dispatchers.Main) {
function()
loadTags()
loadTagNames()
}
}
}
Expand All @@ -114,6 +117,43 @@ class TagsViewModel(application: Application) : PackageUtilsViewModel(applicatio
tags.value?.remove(tag)
withContext(Dispatchers.Main) {
function()
loadTagNames()
}
}
}

fun addMultipleAppsToTag(currentAppsList: java.util.ArrayList<BatchPackageInfo>, it: String, function: () -> Unit) {
viewModelScope.launch(Dispatchers.IO) {
val database = TagsDatabase.getInstance(application.applicationContext)
val tags = database?.getTagDao()?.getTagsNameOnly()

if (tags.isNullOrEmpty().invert()) {
if (tags!!.contains(it)) {
database.getTagDao()!!.getTag(it).apply {
packages = packages.plus("," + currentAppsList.joinToString(",") {
it.packageInfo.packageName
})

// Remove duplicates
packages = packages.split(",").distinct().joinToString(",")

database.getTagDao()!!.updateTag(this)
}
} else {
database.getTagDao()!!.insertTag(Tag(it, currentAppsList.joinToString(",") {
it.packageInfo.packageName
}, -1))
}
} else {
database?.getTagDao()!!.insertTag(Tag(it, currentAppsList.joinToString(",") {
it.packageInfo.packageName
}, -1))
}

withContext(Dispatchers.Main) {
loadTags()
loadTagNames()
function()
}
}
}
Expand Down

0 comments on commit 30fec9e

Please sign in to comment.