Context should not be null, but handle the case for now.
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
eb2876324a
commit
b0a56a32e5
@ -1,6 +1,6 @@
|
|||||||
package bou.amine.apps.readerforselfossv2.android.fragments
|
package bou.amine.apps.readerforselfossv2.android.fragments
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
@ -13,9 +13,7 @@ import android.view.ViewGroup
|
|||||||
import bou.amine.apps.readerforselfossv2.android.HomeActivity
|
import bou.amine.apps.readerforselfossv2.android.HomeActivity
|
||||||
import bou.amine.apps.readerforselfossv2.android.R
|
import bou.amine.apps.readerforselfossv2.android.R
|
||||||
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
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.getHtmlDecoded
|
||||||
import bou.amine.apps.readerforselfossv2.utils.getIcon
|
import bou.amine.apps.readerforselfossv2.utils.getIcon
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
@ -38,16 +36,14 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
|
|
||||||
override val di: DI by closestDI()
|
override val di: DI by closestDI()
|
||||||
private val repository: Repository by instance()
|
private val repository: Repository by instance()
|
||||||
private val appSettingsService: AppSettingsService by instance()
|
|
||||||
|
|
||||||
private var selectedChip: Chip? = null
|
private var selectedChip: Chip? = null
|
||||||
|
|
||||||
@SuppressLint("ResourceAsColor")
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View {
|
||||||
val binding =
|
val binding =
|
||||||
bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding.inflate(
|
bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding.inflate(
|
||||||
inflater,
|
inflater,
|
||||||
@ -55,74 +51,118 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val context: Context? = context
|
||||||
|
|
||||||
val tagGroup = binding.tagsGroup
|
val tagGroup = binding.tagsGroup
|
||||||
val sourceGroup = binding.sourcesGroup
|
val sourceGroup = binding.sourcesGroup
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
if (context == null) {
|
||||||
val tags = repository.getTags()
|
dismiss()
|
||||||
|
Exception("FilterSheetFragment context is null").sendSilentlyWithAcraWithName("FilterSheetFragment > onCreateView")
|
||||||
|
} else {
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
val tags = repository.getTags()
|
||||||
|
|
||||||
tags.forEach { tag ->
|
tags.forEach { tag ->
|
||||||
val c = chipForTag(tag)
|
val c = Chip(context)
|
||||||
tagGroup.addView(c)
|
c.text = tag.tag
|
||||||
}
|
|
||||||
|
|
||||||
repository.getSources().forEach { source ->
|
val gd = GradientDrawable()
|
||||||
val c = Chip(requireContext())
|
val gdColor = try {
|
||||||
|
Color.parseColor(tag.color)
|
||||||
Glide.with(requireContext())
|
} catch (e: IllegalArgumentException) {
|
||||||
.load(source.getIcon(repository.baseUrl))
|
e.sendSilentlyWithAcraWithName("color issue " + tag.color)
|
||||||
.listener(object : RequestListener<Drawable?> {
|
resources.getColor(R.color.colorPrimary)
|
||||||
override fun onLoadFailed(
|
|
||||||
e: GlideException?,
|
|
||||||
model: Any?,
|
|
||||||
target: Target<Drawable?>?,
|
|
||||||
isFirstResource: Boolean
|
|
||||||
): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResourceReady(
|
|
||||||
resource: Drawable?,
|
|
||||||
model: Any?,
|
|
||||||
target: Target<Drawable?>?,
|
|
||||||
dataSource: DataSource?,
|
|
||||||
isFirstResource: Boolean
|
|
||||||
): Boolean {
|
|
||||||
c.chipIcon = resource
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}).preload()
|
|
||||||
|
|
||||||
c.text = source.title.getHtmlDecoded()
|
|
||||||
|
|
||||||
c.setOnCloseIconClickListener {
|
|
||||||
(it as Chip).isCloseIconVisible = false
|
|
||||||
selectedChip = null
|
|
||||||
repository.setSourceFilter(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.setOnClickListener {
|
|
||||||
if (selectedChip != null) {
|
|
||||||
selectedChip!!.isCloseIconVisible = false
|
|
||||||
}
|
}
|
||||||
(it as Chip).isCloseIconVisible = true
|
gd.setColor(gdColor)
|
||||||
selectedChip = it
|
gd.shape = GradientDrawable.RECTANGLE
|
||||||
repository.setSourceFilter(source)
|
gd.setSize(30, 30)
|
||||||
|
gd.cornerRadius = 30F
|
||||||
|
c.chipIcon = gd
|
||||||
|
|
||||||
repository.setTagFilter(null)
|
c.setOnCloseIconClickListener {
|
||||||
|
(it as Chip).isCloseIconVisible = false
|
||||||
|
selectedChip = null
|
||||||
|
repository.setTagFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.setOnClickListener {
|
||||||
|
if (selectedChip != null) {
|
||||||
|
selectedChip!!.isCloseIconVisible = false
|
||||||
|
}
|
||||||
|
(it as Chip).isCloseIconVisible = true
|
||||||
|
selectedChip = it
|
||||||
|
repository.setTagFilter(tag)
|
||||||
|
|
||||||
|
repository.setSourceFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repository.tagFilter.value?.equals(tag) == true) {
|
||||||
|
c.isCloseIconVisible = true
|
||||||
|
selectedChip = c
|
||||||
|
}
|
||||||
|
|
||||||
|
tagGroup.addView(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repository.getSources().forEach { source ->
|
||||||
|
val c = Chip(context)
|
||||||
|
|
||||||
if (repository.sourceFilter.value?.equals(source) == true) {
|
Glide.with(context)
|
||||||
c.isCloseIconVisible = true
|
.load(source.getIcon(repository.baseUrl))
|
||||||
selectedChip = c
|
.listener(object : RequestListener<Drawable?> {
|
||||||
|
override fun onLoadFailed(
|
||||||
|
e: GlideException?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable?>?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResourceReady(
|
||||||
|
resource: Drawable?,
|
||||||
|
model: Any?,
|
||||||
|
target: Target<Drawable?>?,
|
||||||
|
dataSource: DataSource?,
|
||||||
|
isFirstResource: Boolean
|
||||||
|
): Boolean {
|
||||||
|
c.chipIcon = resource
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}).preload()
|
||||||
|
|
||||||
|
c.text = source.title.getHtmlDecoded()
|
||||||
|
|
||||||
|
c.setOnCloseIconClickListener {
|
||||||
|
(it as Chip).isCloseIconVisible = false
|
||||||
|
selectedChip = null
|
||||||
|
repository.setSourceFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.setOnClickListener {
|
||||||
|
if (selectedChip != null) {
|
||||||
|
selectedChip!!.isCloseIconVisible = false
|
||||||
|
}
|
||||||
|
(it as Chip).isCloseIconVisible = true
|
||||||
|
selectedChip = it
|
||||||
|
repository.setSourceFilter(source)
|
||||||
|
|
||||||
|
repository.setTagFilter(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (repository.sourceFilter.value?.equals(source) == true) {
|
||||||
|
c.isCloseIconVisible = true
|
||||||
|
selectedChip = c
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceGroup.addView(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceGroup.addView(c)
|
binding.progressBar2.visibility = GONE
|
||||||
|
binding.filterView.visibility = VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.progressBar2.visibility = GONE
|
|
||||||
binding.filterView.visibility = VISIBLE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.floatingActionButton2.setOnClickListener {
|
binding.floatingActionButton2.setOnClickListener {
|
||||||
@ -133,49 +173,8 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun chipForTag(tag: SelfossModel.Tag): Chip {
|
|
||||||
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
|
|
||||||
selectedChip = null
|
|
||||||
repository.setTagFilter(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.setOnClickListener {
|
|
||||||
if (selectedChip != null) {
|
|
||||||
selectedChip!!.isCloseIconVisible = false
|
|
||||||
}
|
|
||||||
(it as Chip).isCloseIconVisible = true
|
|
||||||
selectedChip = it
|
|
||||||
repository.setTagFilter(tag)
|
|
||||||
|
|
||||||
repository.setSourceFilter(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repository.tagFilter.value?.equals(tag) == true) {
|
|
||||||
c.isCloseIconVisible = true
|
|
||||||
selectedChip = c
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "ModalBottomSheet"
|
const val TAG = "FilterModalBottomSheet"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user