From 30fec9e8cffbd746b54a4d252f1e9ea8750fb447 Mon Sep 17 00:00:00 2001 From: Hamza417 Date: Tue, 29 Aug 2023 20:16:17 +0530 Subject: [PATCH] Build91 - Added batch tags --- .../inure/constants/BottomMenuConstants.kt | 2 + .../inure/decorations/views/TagChip.java | 37 +++++++++++------ .../java/app/simple/inure/ui/panels/Batch.kt | 26 +++++++++--- .../inure/viewmodels/panels/TagsViewModel.kt | 40 +++++++++++++++++++ 4 files changed, 86 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/app/simple/inure/constants/BottomMenuConstants.kt b/app/src/main/java/app/simple/inure/constants/BottomMenuConstants.kt index 514e16d2f..b45f76e4c 100644 --- a/app/src/main/java/app/simple/inure/constants/BottomMenuConstants.kt +++ b/app/src/main/java/app/simple/inure/constants/BottomMenuConstants.kt @@ -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), @@ -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), diff --git a/app/src/main/java/app/simple/inure/decorations/views/TagChip.java b/app/src/main/java/app/simple/inure/decorations/views/TagChip.java index 82f849a31..340cd8af0 100644 --- a/app/src/main/java/app/simple/inure/decorations/views/TagChip.java +++ b/app/src/main/java/app/simple/inure/decorations/views/TagChip.java @@ -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 @@ -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); } } @@ -73,7 +77,7 @@ public void setChipColor(int color, boolean whiteText) { android.R.attr.state_checked }, new int[] { - + }}, new int[] { color, // Ripple color @@ -81,10 +85,14 @@ public void setChipColor(int color, boolean whiteText) { } )); + 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())); } } @@ -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())); } } diff --git a/app/src/main/java/app/simple/inure/ui/panels/Batch.kt b/app/src/main/java/app/simple/inure/ui/panels/Batch.kt index 95f2fa8aa..cd5ea76bd 100644 --- a/app/src/main/java/app/simple/inure/ui/panels/Batch.kt +++ b/app/src/main/java/app/simple/inure/ui/panels/Batch.kt @@ -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 @@ -41,6 +42,7 @@ 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() { @@ -48,12 +50,14 @@ class Batch : ScopedFragment() { 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 } @@ -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()!!) + } + }) } } }) @@ -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()!!) } diff --git a/app/src/main/java/app/simple/inure/viewmodels/panels/TagsViewModel.kt b/app/src/main/java/app/simple/inure/viewmodels/panels/TagsViewModel.kt index fa0a30020..17dc28f4f 100644 --- a/app/src/main/java/app/simple/inure/viewmodels/panels/TagsViewModel.kt +++ b/app/src/main/java/app/simple/inure/viewmodels/panels/TagsViewModel.kt @@ -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 @@ -73,6 +74,7 @@ class TagsViewModel(application: Application) : PackageUtilsViewModel(applicatio withContext(Dispatchers.Main) { function() loadTags() + loadTagNames() } } } @@ -99,6 +101,7 @@ class TagsViewModel(application: Application) : PackageUtilsViewModel(applicatio withContext(Dispatchers.Main) { function() loadTags() + loadTagNames() } } } @@ -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, 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() } } }