From 86c50d48815a28c445360d1b3d51580e62eb4a4f Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sun, 4 Dec 2022 22:46:21 +0100 Subject: [PATCH] Loading sources and tags. --- .../android/HomeActivity.kt | 6 + .../android/fragments/FilterSheetFragment.kt | 149 ++++++++++++++++++ .../drawable/ic_baseline_filter_alt_24.xml | 5 + .../src/main/res/layout/filter_fragment.xml | 72 +++++++++ androidApp/src/main/res/menu/home_menu.xml | 10 +- .../src/main/res/values-ca-rES/strings.xml | 3 + .../src/main/res/values-de-rDE/strings.xml | 3 + .../src/main/res/values-es-rES/strings.xml | 3 + .../src/main/res/values-fa-rIR/strings.xml | 3 + .../src/main/res/values-fr-rFR/strings.xml | 3 + .../src/main/res/values-gl-rES/strings.xml | 3 + .../src/main/res/values-in-rID/strings.xml | 3 + .../src/main/res/values-it-rIT/strings.xml | 3 + .../src/main/res/values-ko-rKR/strings.xml | 3 + .../src/main/res/values-night/strings.xml | 3 + .../src/main/res/values-nl-rNL/strings.xml | 3 + .../src/main/res/values-pt-rBR/strings.xml | 3 + .../src/main/res/values-pt-rPT/strings.xml | 3 + .../src/main/res/values-si-rLK/strings.xml | 3 + .../src/main/res/values-tr-rTR/strings.xml | 3 + .../src/main/res/values-zh-rCN/strings.xml | 3 + .../src/main/res/values-zh-rTW/strings.xml | 3 + androidApp/src/main/res/values/strings.xml | 3 + 23 files changed, 294 insertions(+), 2 deletions(-) create mode 100644 androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt create mode 100644 androidApp/src/main/res/drawable/ic_baseline_filter_alt_24.xml create mode 100644 androidApp/src/main/res/layout/filter_fragment.xml diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 29c575f..80b24cb 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -29,6 +29,7 @@ import bou.amine.apps.readerforselfossv2.android.adapters.ItemListAdapter import bou.amine.apps.readerforselfossv2.android.adapters.ItemsAdapter import bou.amine.apps.readerforselfossv2.android.background.LoadingWorker import bou.amine.apps.readerforselfossv2.android.databinding.ActivityHomeBinding +import bou.amine.apps.readerforselfossv2.android.fragments.FilterSheetFragment import bou.amine.apps.readerforselfossv2.android.settings.SettingsActivity import bou.amine.apps.readerforselfossv2.android.utils.bottombar.maybeShow import bou.amine.apps.readerforselfossv2.android.utils.bottombar.removeBadge @@ -835,6 +836,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { + R.id.action_filter -> { + val filterSheetFragment = FilterSheetFragment() + filterSheetFragment.show(supportFragmentManager, FilterSheetFragment.TAG) + return true + } R.id.refresh -> { needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message) { Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show() diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt new file mode 100644 index 0000000..53a803d --- /dev/null +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt @@ -0,0 +1,149 @@ +package bou.amine.apps.readerforselfossv2.android.fragments + +import android.annotation.SuppressLint +import android.graphics.Color +import android.graphics.drawable.Drawable +import android.graphics.drawable.GradientDrawable +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE +import android.view.ViewGroup +import bou.amine.apps.readerforselfossv2.android.R +import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName +import bou.amine.apps.readerforselfossv2.repository.Repository +import bou.amine.apps.readerforselfossv2.service.AppSettingsService +import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded +import bou.amine.apps.readerforselfossv2.utils.getIcon +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.google.android.material.chip.Chip +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import org.kodein.di.DI +import org.kodein.di.DIAware +import org.kodein.di.android.x.closestDI +import org.kodein.di.instance + + +class FilterSheetFragment : BottomSheetDialogFragment(), DIAware { + + override val di: DI by closestDI() + private val repository: Repository by instance() + private val appSettingsService: AppSettingsService by instance() + + private var tagChip: Chip? = null + private var sourceChip: Chip? = null + + @SuppressLint("ResourceAsColor") + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val binding = + bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding.inflate( + inflater, + container, + false + ) + + val tagGroup = binding.tagsGroup + val sourceGroup = binding.sourcesGroup + + CoroutineScope(Dispatchers.Main).launch { + repository.getTags().forEach { tag -> + val c = Chip(requireContext()) + c.text = tag.tag + + val gd = GradientDrawable() + val gdColor = try { + Color.parseColor(tag.color) + } catch (e: IllegalArgumentException) { + e.sendSilentlyWithAcraWithName("color issue " + tag.color) + resources.getColor(R.color.colorPrimary) + } + gd.setColor(gdColor) + gd.shape = GradientDrawable.RECTANGLE + gd.setSize(30, 30) + gd.cornerRadius = 30F + c.chipIcon = gd + + c.setOnCloseIconClickListener { + (it as Chip).isCloseIconVisible = false + tagChip = null + } + + c.setOnClickListener { + if (tagChip != null) { + tagChip!!.isCloseIconVisible = false + } + (it as Chip).isCloseIconVisible = true + tagChip = it + } + tagGroup.addView(c) + } + + repository.getSources().forEach { source -> + val c = Chip(requireContext()) + + Glide.with(requireContext()) + .load(source.getIcon(repository.baseUrl)) + .listener(object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target?, + isFirstResource: Boolean + ): Boolean { + return false + } + + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + c.chipIcon = resource + return false + } + }).preload() + + c.text = source.title.getHtmlDecoded() + + c.setOnCloseIconClickListener { + (it as Chip).isCloseIconVisible = false + sourceChip = null + } + + c.setOnClickListener { + if (sourceChip != null) { + sourceChip!!.isCloseIconVisible = false + } + (it as Chip).isCloseIconVisible = true + sourceChip = it + } + sourceGroup.addView(c) + } + + binding.progressBar2.visibility = GONE + binding.filterView.visibility = VISIBLE + } + + return binding.root + } + + companion object { + const val TAG = "ModalBottomSheet" + } + + +} \ No newline at end of file diff --git a/androidApp/src/main/res/drawable/ic_baseline_filter_alt_24.xml b/androidApp/src/main/res/drawable/ic_baseline_filter_alt_24.xml new file mode 100644 index 0000000..3925260 --- /dev/null +++ b/androidApp/src/main/res/drawable/ic_baseline_filter_alt_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/androidApp/src/main/res/layout/filter_fragment.xml b/androidApp/src/main/res/layout/filter_fragment.xml new file mode 100644 index 0000000..80a8354 --- /dev/null +++ b/androidApp/src/main/res/layout/filter_fragment.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/androidApp/src/main/res/menu/home_menu.xml b/androidApp/src/main/res/menu/home_menu.xml index 537909c..73be4c9 100644 --- a/androidApp/src/main/res/menu/home_menu.xml +++ b/androidApp/src/main/res/menu/home_menu.xml @@ -8,11 +8,17 @@ app:showAsAction="ifRoom|collapseActionView" app:actionViewClass="androidx.appcompat.widget.SearchView" /> + + + android:orderInCategory="2" + app:showAsAction="ifRoom"/> A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-de-rDE/strings.xml b/androidApp/src/main/res/values-de-rDE/strings.xml index c9d6640..f5c9846 100644 --- a/androidApp/src/main/res/values-de-rDE/strings.xml +++ b/androidApp/src/main/res/values-de-rDE/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-es-rES/strings.xml b/androidApp/src/main/res/values-es-rES/strings.xml index fd68002..e5e496d 100644 --- a/androidApp/src/main/res/values-es-rES/strings.xml +++ b/androidApp/src/main/res/values-es-rES/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-fa-rIR/strings.xml b/androidApp/src/main/res/values-fa-rIR/strings.xml index 568519a..f79dc97 100644 --- a/androidApp/src/main/res/values-fa-rIR/strings.xml +++ b/androidApp/src/main/res/values-fa-rIR/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-fr-rFR/strings.xml b/androidApp/src/main/res/values-fr-rFR/strings.xml index 777ba1d..590209d 100644 --- a/androidApp/src/main/res/values-fr-rFR/strings.xml +++ b/androidApp/src/main/res/values-fr-rFR/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-gl-rES/strings.xml b/androidApp/src/main/res/values-gl-rES/strings.xml index 300cb75..c56870f 100644 --- a/androidApp/src/main/res/values-gl-rES/strings.xml +++ b/androidApp/src/main/res/values-gl-rES/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-in-rID/strings.xml b/androidApp/src/main/res/values-in-rID/strings.xml index 5496c77..8bd35bd 100644 --- a/androidApp/src/main/res/values-in-rID/strings.xml +++ b/androidApp/src/main/res/values-in-rID/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-it-rIT/strings.xml b/androidApp/src/main/res/values-it-rIT/strings.xml index dca5595..7449dc2 100644 --- a/androidApp/src/main/res/values-it-rIT/strings.xml +++ b/androidApp/src/main/res/values-it-rIT/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-ko-rKR/strings.xml b/androidApp/src/main/res/values-ko-rKR/strings.xml index 88f5aa8..e62f637 100644 --- a/androidApp/src/main/res/values-ko-rKR/strings.xml +++ b/androidApp/src/main/res/values-ko-rKR/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-night/strings.xml b/androidApp/src/main/res/values-night/strings.xml index a0a75f3..8123eec 100644 --- a/androidApp/src/main/res/values-night/strings.xml +++ b/androidApp/src/main/res/values-night/strings.xml @@ -5,4 +5,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources \ No newline at end of file diff --git a/androidApp/src/main/res/values-nl-rNL/strings.xml b/androidApp/src/main/res/values-nl-rNL/strings.xml index 04e928d..da0255a 100644 --- a/androidApp/src/main/res/values-nl-rNL/strings.xml +++ b/androidApp/src/main/res/values-nl-rNL/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-pt-rBR/strings.xml b/androidApp/src/main/res/values-pt-rBR/strings.xml index df02f11..f2c12e1 100644 --- a/androidApp/src/main/res/values-pt-rBR/strings.xml +++ b/androidApp/src/main/res/values-pt-rBR/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-pt-rPT/strings.xml b/androidApp/src/main/res/values-pt-rPT/strings.xml index f566de5..8883d04 100644 --- a/androidApp/src/main/res/values-pt-rPT/strings.xml +++ b/androidApp/src/main/res/values-pt-rPT/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-si-rLK/strings.xml b/androidApp/src/main/res/values-si-rLK/strings.xml index 48bc1a1..2c7081f 100644 --- a/androidApp/src/main/res/values-si-rLK/strings.xml +++ b/androidApp/src/main/res/values-si-rLK/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-tr-rTR/strings.xml b/androidApp/src/main/res/values-tr-rTR/strings.xml index 3ed200d..b29e0c4 100644 --- a/androidApp/src/main/res/values-tr-rTR/strings.xml +++ b/androidApp/src/main/res/values-tr-rTR/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-zh-rCN/strings.xml b/androidApp/src/main/res/values-zh-rCN/strings.xml index 6ddf691..ce78ba2 100644 --- a/androidApp/src/main/res/values-zh-rCN/strings.xml +++ b/androidApp/src/main/res/values-zh-rCN/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values-zh-rTW/strings.xml b/androidApp/src/main/res/values-zh-rTW/strings.xml index ef9357b..4a73bea 100644 --- a/androidApp/src/main/res/values-zh-rTW/strings.xml +++ b/androidApp/src/main/res/values-zh-rTW/strings.xml @@ -138,4 +138,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index fcb6613..9622851 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -141,4 +141,7 @@ A crash occured. Sending the details to the developper. "Disable automatic bug reporting. " + Filters + Tags + Sources