mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
more viewbindings + result fix + more tests
This commit is contained in:
parent
c946115900
commit
f209c7286e
12 changed files with 214 additions and 140 deletions
|
@ -12,8 +12,14 @@ import com.lagradost.cloudstream3.databinding.FragmentHomeTvBinding
|
|||
import com.lagradost.cloudstream3.databinding.FragmentSearchBinding
|
||||
import com.lagradost.cloudstream3.databinding.FragmentSearchTvBinding
|
||||
import com.lagradost.cloudstream3.databinding.HomeResultGridBinding
|
||||
import com.lagradost.cloudstream3.databinding.HomeScrollViewBinding
|
||||
import com.lagradost.cloudstream3.databinding.HomeScrollViewTvBinding
|
||||
import com.lagradost.cloudstream3.databinding.HomepageParentBinding
|
||||
import com.lagradost.cloudstream3.databinding.HomepageParentTvBinding
|
||||
import com.lagradost.cloudstream3.databinding.RepositoryItemBinding
|
||||
import com.lagradost.cloudstream3.databinding.RepositoryItemTvBinding
|
||||
import com.lagradost.cloudstream3.databinding.SearchResultGridBinding
|
||||
import com.lagradost.cloudstream3.databinding.SearchResultGridExpandedBinding
|
||||
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
||||
import com.lagradost.cloudstream3.utils.TestingUtils
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
@ -85,6 +91,17 @@ class ExampleInstrumentedTest {
|
|||
|
||||
testAllLayouts<HomeResultGridBinding>(activity, R.layout.home_result_grid_expanded, R.layout.home_result_grid)
|
||||
//testAllLayouts<HomeResultGridExpandedBinding>(activity, R.layout.home_result_grid_expanded, R.layout.home_result_grid) ??? fails ???
|
||||
|
||||
testAllLayouts<SearchResultGridExpandedBinding>(activity, R.layout.search_result_grid, R.layout.search_result_grid_expanded)
|
||||
testAllLayouts<SearchResultGridBinding>(activity, R.layout.search_result_grid, R.layout.search_result_grid_expanded)
|
||||
|
||||
|
||||
// testAllLayouts<HomeScrollViewBinding>(activity, R.layout.home_scroll_view, R.layout.home_scroll_view_tv)
|
||||
// testAllLayouts<HomeScrollViewTvBinding>(activity, R.layout.home_scroll_view, R.layout.home_scroll_view_tv)
|
||||
|
||||
testAllLayouts<HomepageParentTvBinding>(activity, R.layout.homepage_parent_tv, R.layout.homepage_parent)
|
||||
testAllLayouts<HomepageParentBinding>(activity, R.layout.homepage_parent_tv, R.layout.homepage_parent)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
package com.lagradost.cloudstream3.ui.home
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import com.lagradost.cloudstream3.databinding.HomeResultGridBinding
|
||||
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
|
||||
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.IsBottomLayout
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.background_card
|
||||
import kotlinx.android.synthetic.main.home_result_grid_expanded.view.*
|
||||
|
||||
class HomeChildItemAdapter(
|
||||
val cardList: MutableList<SearchResponse>,
|
||||
private val overrideLayout: Int? = null,
|
||||
|
||||
private val nextFocusUp: Int? = null,
|
||||
private val nextFocusDown: Int? = null,
|
||||
private val clickCallback: (SearchClickCallback) -> Unit,
|
||||
|
@ -26,11 +24,13 @@ class HomeChildItemAdapter(
|
|||
var hasNext: Boolean = false
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val layout = overrideLayout
|
||||
?: if (parent.context.IsBottomLayout()) R.layout.home_result_grid_expanded else R.layout.home_result_grid
|
||||
val layout = if (parent.context.IsBottomLayout()) R.layout.home_result_grid_expanded else R.layout.home_result_grid
|
||||
|
||||
val root = LayoutInflater.from(parent.context).inflate(layout, parent, false)
|
||||
val binding = HomeResultGridBinding.bind(root)
|
||||
|
||||
return CardViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(layout, parent, false),
|
||||
binding,
|
||||
clickCallback,
|
||||
itemCount,
|
||||
nextFocusUp,
|
||||
|
@ -69,14 +69,14 @@ class HomeChildItemAdapter(
|
|||
|
||||
class CardViewHolder
|
||||
constructor(
|
||||
itemView: View,
|
||||
val binding: HomeResultGridBinding,
|
||||
private val clickCallback: (SearchClickCallback) -> Unit,
|
||||
var itemCount: Int,
|
||||
private val nextFocusUp: Int? = null,
|
||||
private val nextFocusDown: Int? = null,
|
||||
private val isHorizontal: Boolean = false
|
||||
) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(card: SearchResponse, position: Int) {
|
||||
|
||||
|
@ -87,7 +87,7 @@ class HomeChildItemAdapter(
|
|||
else -> null
|
||||
}
|
||||
|
||||
(itemView.background_card)?.apply {
|
||||
binding.backgroundCard.apply {
|
||||
val min = 114.toPx
|
||||
val max = 180.toPx
|
||||
|
||||
|
@ -119,7 +119,7 @@ class HomeChildItemAdapter(
|
|||
itemView.tag = position
|
||||
|
||||
if (position == 0) { // to fix tv
|
||||
itemView.background_card?.nextFocusLeftId = R.id.nav_rail_view
|
||||
binding.backgroundCard.nextFocusLeftId = R.id.nav_rail_view
|
||||
}
|
||||
//val ani = ScaleAnimation(0.9f, 1.0f, 0.9f, 1f)
|
||||
//ani.fillAfter = true
|
||||
|
|
|
@ -10,18 +10,12 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.lagradost.cloudstream3.HomePageList
|
||||
import com.lagradost.cloudstream3.LoadResponse
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.HomepageParentBinding
|
||||
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
|
||||
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
|
||||
import com.lagradost.cloudstream3.ui.search.SearchFragment.Companion.filterSearchResponse
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.isRecyclerScrollable
|
||||
import kotlinx.android.synthetic.main.activity_main_tv.*
|
||||
import kotlinx.android.synthetic.main.activity_main_tv.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
import kotlinx.android.synthetic.main.fragment_home.view.*
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.*
|
||||
import kotlinx.android.synthetic.main.fragment_home_head_tv.view.*
|
||||
import kotlinx.android.synthetic.main.homepage_parent.view.*
|
||||
|
||||
class LoadClickCallback(
|
||||
val action: Int = 0,
|
||||
|
@ -37,12 +31,17 @@ open class ParentItemAdapter(
|
|||
private val expandCallback: ((String) -> Unit)? = null,
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return ParentViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(
|
||||
|
||||
val root = LayoutInflater.from(parent.context).inflate(
|
||||
if (isTvSettings()) R.layout.homepage_parent_tv else R.layout.homepage_parent,
|
||||
parent,
|
||||
false
|
||||
),
|
||||
)
|
||||
|
||||
val binding = HomepageParentBinding.bind(root)
|
||||
|
||||
return ParentViewHolder(
|
||||
binding,
|
||||
clickCallback,
|
||||
moreInfoClickCallback,
|
||||
expandCallback
|
||||
|
@ -153,14 +152,14 @@ open class ParentItemAdapter(
|
|||
|
||||
class ParentViewHolder
|
||||
constructor(
|
||||
itemView: View,
|
||||
val binding: HomepageParentBinding,
|
||||
private val clickCallback: (SearchClickCallback) -> Unit,
|
||||
private val moreInfoClickCallback: (HomeViewModel.ExpandableHomepageList) -> Unit,
|
||||
private val expandCallback: ((String) -> Unit)? = null,
|
||||
) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
val title: TextView = itemView.home_child_more_info
|
||||
private val recyclerView: RecyclerView = itemView.home_child_recyclerview
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
val title: TextView = binding.homeChildMoreInfo
|
||||
private val recyclerView: RecyclerView = binding.homeChildRecyclerview
|
||||
|
||||
fun update(expand: HomeViewModel.ExpandableHomepageList) {
|
||||
val info = expand.list
|
||||
|
|
|
@ -409,10 +409,7 @@ class HomeParentItemAdapterPreview(
|
|||
// setPageTransformer(null)
|
||||
|
||||
if (adapter == null)
|
||||
adapter = HomeScrollAdapter(
|
||||
if (isTvSettings()) R.layout.home_scroll_view_tv else R.layout.home_scroll_view,
|
||||
if (isTvSettings()) true else null
|
||||
)
|
||||
adapter = HomeScrollAdapter()
|
||||
}
|
||||
previewAdapter = previewViewpager?.adapter as? HomeScrollAdapter?
|
||||
// previewViewpager?.registerOnPageChangeCallback(previewCallback)
|
||||
|
|
|
@ -2,24 +2,18 @@ package com.lagradost.cloudstream3.ui.home
|
|||
|
||||
import android.content.res.Configuration
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.core.view.isGone
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.lagradost.cloudstream3.LoadResponse
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.HomeScrollViewBinding
|
||||
import com.lagradost.cloudstream3.databinding.HomeScrollViewTvBinding
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
import kotlinx.android.synthetic.main.home_scroll_view.view.home_scroll_preview
|
||||
import kotlinx.android.synthetic.main.home_scroll_view.view.home_scroll_preview_tags
|
||||
import kotlinx.android.synthetic.main.home_scroll_view.view.home_scroll_preview_title
|
||||
|
||||
|
||||
class HomeScrollAdapter(
|
||||
@LayoutRes val layout: Int = R.layout.home_scroll_view,
|
||||
private val forceHorizontalPosters: Boolean? = null
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
class HomeScrollAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
private var items: MutableList<LoadResponse> = mutableListOf()
|
||||
var hasMoreItems: Boolean = false
|
||||
|
||||
|
@ -45,9 +39,16 @@ class HomeScrollAdapter(
|
|||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val binding = if(isTvSettings()) {
|
||||
HomeScrollViewBinding.inflate(inflater,parent,false)
|
||||
} else {
|
||||
HomeScrollViewTvBinding.inflate(inflater,parent,false)
|
||||
}
|
||||
|
||||
return CardViewHolder(
|
||||
LayoutInflater.from(parent.context).inflate(layout, parent, false),
|
||||
forceHorizontalPosters
|
||||
binding,
|
||||
//forceHorizontalPosters
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -61,22 +62,30 @@ class HomeScrollAdapter(
|
|||
|
||||
class CardViewHolder
|
||||
constructor(
|
||||
itemView: View,
|
||||
private val forceHorizontalPosters: Boolean? = null
|
||||
val binding: ViewBinding,
|
||||
//private val forceHorizontalPosters: Boolean? = null
|
||||
) :
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(card: LoadResponse) {
|
||||
card.apply {
|
||||
val isHorizontal =
|
||||
(forceHorizontalPosters == true) || ((forceHorizontalPosters != false) && itemView.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
|
||||
binding is HomeScrollViewTvBinding || itemView.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
|
||||
val posterUrl = if (isHorizontal) backgroundPosterUrl ?: posterUrl else posterUrl
|
||||
?: backgroundPosterUrl
|
||||
itemView.home_scroll_preview_tags?.text = tags?.joinToString(" • ") ?: ""
|
||||
itemView.home_scroll_preview_tags?.isGone = tags.isNullOrEmpty()
|
||||
itemView.home_scroll_preview?.setImage(posterUrl, posterHeaders)
|
||||
itemView.home_scroll_preview_title?.text = name
|
||||
val posterUrl = if (isHorizontal) card.backgroundPosterUrl ?: card.posterUrl else card.posterUrl
|
||||
?: card.backgroundPosterUrl
|
||||
|
||||
when(binding) {
|
||||
is HomeScrollViewBinding -> {
|
||||
binding.homeScrollPreview.setImage(posterUrl)
|
||||
binding.homeScrollPreviewTags.apply {
|
||||
text = card.tags?.joinToString(" • ") ?: ""
|
||||
isGone = card.tags.isNullOrEmpty()
|
||||
}
|
||||
binding.homeScrollPreviewTitle.text = card.name
|
||||
}
|
||||
is HomeScrollViewTvBinding -> {
|
||||
binding.homeScrollPreview.setImage(posterUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class PageAdapter(
|
|||
binding.textRating.apply {
|
||||
setTextColor(ColorStateList.valueOf(fg))
|
||||
}
|
||||
binding.textRatingHolder.backgroundTintList = ColorStateList.valueOf(bg)
|
||||
binding.textRating.backgroundTintList = ColorStateList.valueOf(bg)
|
||||
binding.watchProgress.apply {
|
||||
progressTintList = ColorStateList.valueOf(fg)
|
||||
progressBackgroundTintList = ColorStateList.valueOf(bg)
|
||||
|
@ -111,16 +111,6 @@ class PageAdapter(
|
|||
}
|
||||
|
||||
binding.imageText.text = item.name
|
||||
|
||||
val showRating = (item.personalRating ?: 0) != 0
|
||||
binding.textRatingHolder.isVisible = showRating
|
||||
if (showRating) {
|
||||
// We want to show 8.5 but not 8.0 hence the replace
|
||||
val rating = ((item.personalRating ?: 0).toDouble() / 10).toString()
|
||||
.replace(".0", "")
|
||||
|
||||
binding.textRating.text = "★ $rating"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ class ViewpagerAdapter(
|
|||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
|
||||
setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||
val diff = scrollY - oldScrollY
|
||||
if (diff == 0) return@setOnScrollChangeListener
|
||||
|
||||
|
|
|
@ -16,22 +16,13 @@ import com.lagradost.cloudstream3.R
|
|||
import com.lagradost.cloudstream3.SearchQuality
|
||||
import com.lagradost.cloudstream3.SearchResponse
|
||||
import com.lagradost.cloudstream3.isMovieType
|
||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual
|
||||
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.background_card
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.imageText
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.imageView
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.search_item_download_play
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.text_flag
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.text_is_dub
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.text_is_sub
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.text_quality
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.title_shadow
|
||||
import kotlinx.android.synthetic.main.home_result_grid.view.watchProgress
|
||||
|
||||
object SearchResultBuilder {
|
||||
private val showCache: MutableMap<String, Boolean> = mutableMapOf()
|
||||
|
@ -59,19 +50,21 @@ object SearchResultBuilder {
|
|||
nextFocusDown: Int? = null,
|
||||
colorCallback : ((Palette) -> Unit)? = null
|
||||
) {
|
||||
val cardView: ImageView = itemView.imageView
|
||||
val cardText: TextView? = itemView.imageText
|
||||
val cardView: ImageView = itemView.findViewById(R.id.imageView)
|
||||
val cardText: TextView? = itemView.findViewById(R.id.imageText)
|
||||
|
||||
val textIsDub: TextView? = itemView.text_is_dub
|
||||
val textIsSub: TextView? = itemView.text_is_sub
|
||||
val textFlag: TextView? = itemView.text_flag
|
||||
val textQuality: TextView? = itemView.text_quality
|
||||
val shadow: View? = itemView.title_shadow
|
||||
val textIsDub: TextView? = itemView.findViewById(R.id.text_is_dub)
|
||||
val textIsSub: TextView? = itemView.findViewById(R.id.text_is_sub)
|
||||
val textFlag: TextView? = itemView.findViewById(R.id.text_flag)
|
||||
val rating: TextView? = itemView.findViewById(R.id.text_rating)
|
||||
|
||||
val bg: CardView = itemView.background_card
|
||||
val textQuality: TextView? = itemView.findViewById(R.id.text_quality)
|
||||
val shadow: View? = itemView.findViewById(R.id.title_shadow)
|
||||
|
||||
val bar: ProgressBar? = itemView.watchProgress
|
||||
val playImg: ImageView? = itemView.search_item_download_play
|
||||
val bg: CardView = itemView.findViewById(R.id.background_card)
|
||||
|
||||
val bar: ProgressBar? = itemView.findViewById(R.id.watchProgress)
|
||||
val playImg: ImageView? = itemView.findViewById(R.id.search_item_download_play)
|
||||
|
||||
// Do logic
|
||||
|
||||
|
@ -80,12 +73,25 @@ object SearchResultBuilder {
|
|||
textIsDub?.isVisible = false
|
||||
textIsSub?.isVisible = false
|
||||
textFlag?.isVisible = false
|
||||
rating?.isVisible = false
|
||||
|
||||
val showSub = showCache[textIsDub?.context?.getString(R.string.show_sub_key)] ?: false
|
||||
val showDub = showCache[textIsDub?.context?.getString(R.string.show_dub_key)] ?: false
|
||||
val showTitle = showCache[cardText?.context?.getString(R.string.show_title_key)] ?: false
|
||||
val showHd = showCache[textQuality?.context?.getString(R.string.show_hd_key)] ?: false
|
||||
|
||||
if(card is SyncAPI.LibraryItem) {
|
||||
val showRating = (card.personalRating ?: 0) != 0
|
||||
rating?.isVisible = showRating
|
||||
if (showRating) {
|
||||
// We want to show 8.5 but not 8.0 hence the replace
|
||||
val ratingText = ((card.personalRating ?: 0).toDouble() / 10).toString()
|
||||
.replace(".0", "")
|
||||
|
||||
rating?.text = ratingText
|
||||
}
|
||||
}
|
||||
|
||||
shadow?.isVisible = showTitle
|
||||
|
||||
when (card.quality) {
|
||||
|
|
|
@ -2,19 +2,28 @@ package com.lagradost.cloudstream3.utils
|
|||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import android.widget.AbsListView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ListView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.*
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.marginRight
|
||||
import androidx.core.view.marginTop
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.BottomSelectionDialogBinding
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
import kotlinx.android.synthetic.main.add_account_input.*
|
||||
import kotlinx.android.synthetic.main.add_account_input.text1
|
||||
import kotlinx.android.synthetic.main.bottom_selection_dialog_direct.*
|
||||
|
||||
object SingleSelectionHelper {
|
||||
fun Activity?.showOptionSelectStringRes(
|
||||
|
@ -82,6 +91,7 @@ object SingleSelectionHelper {
|
|||
}
|
||||
|
||||
fun Activity?.showDialog(
|
||||
binding: BottomSelectionDialogBinding,
|
||||
dialog: Dialog,
|
||||
items: List<String>,
|
||||
selectedIndex: List<Int>,
|
||||
|
@ -95,39 +105,39 @@ object SingleSelectionHelper {
|
|||
if (this == null) return
|
||||
|
||||
val realShowApply = showApply || isMultiSelect
|
||||
val listView = dialog.listview1//.findViewById<ListView>(R.id.listview1)!!
|
||||
val textView = dialog.text1//.findViewById<TextView>(R.id.text1)!!
|
||||
val applyButton = dialog.apply_btt//.findViewById<TextView>(R.id.apply_btt)
|
||||
val cancelButton = dialog.cancel_btt//findViewById<TextView>(R.id.cancel_btt)
|
||||
val listView = binding.listview1//.findViewById<ListView>(R.id.listview1)!!
|
||||
val textView = binding.text1//.findViewById<TextView>(R.id.text1)!!
|
||||
val applyButton = binding.applyBtt//.findViewById<TextView>(R.id.apply_btt)
|
||||
val cancelButton = binding.cancelBtt//findViewById<TextView>(R.id.cancel_btt)
|
||||
val applyHolder =
|
||||
dialog.apply_btt_holder//.findViewById<LinearLayout>(R.id.apply_btt_holder)
|
||||
binding.applyBttHolder//.findViewById<LinearLayout>(R.id.apply_btt_holder)
|
||||
|
||||
applyHolder?.isVisible = realShowApply
|
||||
applyHolder.isVisible = realShowApply
|
||||
if (!realShowApply) {
|
||||
val params = listView.layoutParams as LinearLayout.LayoutParams
|
||||
params.setMargins(listView.marginLeft, listView.marginTop, listView.marginRight, 0)
|
||||
listView.layoutParams = params
|
||||
}
|
||||
|
||||
textView?.text = name
|
||||
textView?.isGone = name.isBlank()
|
||||
textView.text = name
|
||||
textView.isGone = name.isBlank()
|
||||
|
||||
val arrayAdapter = ArrayAdapter<String>(this, itemLayout)
|
||||
arrayAdapter.addAll(items)
|
||||
|
||||
listView?.adapter = arrayAdapter
|
||||
listView.adapter = arrayAdapter
|
||||
if (isMultiSelect) {
|
||||
listView?.choiceMode = AbsListView.CHOICE_MODE_MULTIPLE
|
||||
listView.choiceMode = AbsListView.CHOICE_MODE_MULTIPLE
|
||||
} else {
|
||||
listView?.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
||||
listView.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
||||
}
|
||||
|
||||
for (select in selectedIndex) {
|
||||
listView?.setItemChecked(select, true)
|
||||
listView.setItemChecked(select, true)
|
||||
}
|
||||
|
||||
selectedIndex.minOrNull()?.let {
|
||||
listView?.setSelection(it)
|
||||
listView.setSelection(it)
|
||||
}
|
||||
|
||||
// var lastSelectedIndex = if(selectedIndex.isNotEmpty()) selectedIndex.first() else -1
|
||||
|
@ -136,7 +146,7 @@ object SingleSelectionHelper {
|
|||
dismissCallback.invoke()
|
||||
}
|
||||
|
||||
listView?.setOnItemClickListener { _, _, which, _ ->
|
||||
listView.setOnItemClickListener { _, _, which, _ ->
|
||||
// lastSelectedIndex = which
|
||||
if (realShowApply) {
|
||||
if (!isMultiSelect) {
|
||||
|
@ -148,7 +158,7 @@ object SingleSelectionHelper {
|
|||
}
|
||||
}
|
||||
if (realShowApply) {
|
||||
applyButton?.setOnClickListener {
|
||||
applyButton.setOnClickListener {
|
||||
val list = ArrayList<Int>()
|
||||
for (index in 0 until listView.count) {
|
||||
if (listView.checkedItemPositions[index])
|
||||
|
@ -157,7 +167,7 @@ object SingleSelectionHelper {
|
|||
callback.invoke(list)
|
||||
dialog.dismissSafe(this)
|
||||
}
|
||||
cancelButton?.setOnClickListener {
|
||||
cancelButton.setOnClickListener {
|
||||
dialog.dismissSafe(this)
|
||||
}
|
||||
}
|
||||
|
@ -213,13 +223,26 @@ object SingleSelectionHelper {
|
|||
) {
|
||||
if (this == null) return
|
||||
|
||||
val binding: BottomSelectionDialogBinding = BottomSelectionDialogBinding.inflate(
|
||||
LayoutInflater.from(this)
|
||||
)
|
||||
val builder =
|
||||
AlertDialog.Builder(this, R.style.AlertDialogCustom)
|
||||
.setView(R.layout.bottom_selection_dialog)
|
||||
.setView(binding.root)
|
||||
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
showDialog(dialog, items, selectedIndex, name, true, true, callback, dismissCallback)
|
||||
showDialog(
|
||||
binding,
|
||||
dialog,
|
||||
items,
|
||||
selectedIndex,
|
||||
name,
|
||||
showApply = true,
|
||||
isMultiSelect = true,
|
||||
callback,
|
||||
dismissCallback
|
||||
)
|
||||
}
|
||||
|
||||
fun Activity?.showDialog(
|
||||
|
@ -232,13 +255,19 @@ object SingleSelectionHelper {
|
|||
) {
|
||||
if (this == null) return
|
||||
|
||||
val binding: BottomSelectionDialogBinding = BottomSelectionDialogBinding.inflate(
|
||||
LayoutInflater.from(this)
|
||||
)
|
||||
val builder =
|
||||
AlertDialog.Builder(this, R.style.AlertDialogCustom)
|
||||
.setView(R.layout.bottom_selection_dialog)
|
||||
.setView(binding.root)
|
||||
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
|
||||
|
||||
showDialog(
|
||||
binding,
|
||||
dialog,
|
||||
items,
|
||||
listOf(selectedIndex),
|
||||
|
@ -260,12 +289,18 @@ object SingleSelectionHelper {
|
|||
callback: (Int) -> Unit,
|
||||
) {
|
||||
if (this == null) return
|
||||
|
||||
val binding: BottomSelectionDialogBinding = BottomSelectionDialogBinding.inflate(
|
||||
LayoutInflater.from(this)
|
||||
)
|
||||
|
||||
val builder =
|
||||
BottomSheetDialog(this)
|
||||
builder.setContentView(R.layout.bottom_selection_dialog)
|
||||
builder.setContentView(binding.root)
|
||||
|
||||
builder.show()
|
||||
showDialog(
|
||||
binding,
|
||||
builder,
|
||||
items,
|
||||
listOf(selectedIndex),
|
||||
|
@ -285,13 +320,19 @@ object SingleSelectionHelper {
|
|||
): BottomSheetDialog {
|
||||
val builder =
|
||||
BottomSheetDialog(this)
|
||||
builder.setContentView(R.layout.bottom_selection_dialog_direct)
|
||||
|
||||
val binding: BottomSelectionDialogBinding = BottomSelectionDialogBinding.inflate(
|
||||
LayoutInflater.from(this)
|
||||
)
|
||||
|
||||
//builder.setContentView(R.layout.bottom_selection_dialog_direct)
|
||||
builder.setContentView(binding.root)
|
||||
builder.show()
|
||||
showDialog(
|
||||
binding,
|
||||
builder,
|
||||
items,
|
||||
listOf(),
|
||||
emptyList(),
|
||||
name,
|
||||
showApply = false,
|
||||
isMultiSelect = false,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout 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:id="@+id/search_result_root"
|
||||
|
@ -75,6 +75,12 @@
|
|||
style="@style/SubButton"
|
||||
android:layout_gravity="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_rating"
|
||||
style="@style/RatingButton"
|
||||
android:layout_gravity="end"
|
||||
|
||||
tools:text="7.7" />
|
||||
<TextView
|
||||
android:id="@+id/text_flag"
|
||||
style="@style/SearchBox"
|
||||
|
@ -85,6 +91,18 @@
|
|||
tools:text="🇸🇪"
|
||||
tools:visibility="visible" />
|
||||
</LinearLayout>
|
||||
<androidx.core.widget.ContentLoadingProgressBar
|
||||
android:id="@+id/watchProgress"
|
||||
style="@android:style/Widget.Material.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="5dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginBottom="-1.5dp"
|
||||
android:progressBackgroundTint="?attr/colorPrimary"
|
||||
android:progressTint="?attr/colorPrimary"
|
||||
android:visibility="gone"
|
||||
tools:progress="50"
|
||||
tools:visibility="visible" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
|
@ -58,29 +58,12 @@
|
|||
style="@style/SubButton"
|
||||
android:layout_gravity="end" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/text_rating_holder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_margin="2dp"
|
||||
android:backgroundTint="@color/ratingColorBg"
|
||||
android:elevation="0dp"
|
||||
android:visibility="gone"
|
||||
app:cardCornerRadius="@dimen/rounded_image_radius"
|
||||
app:cardElevation="0dp"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_rating"
|
||||
style="@style/SearchBox"
|
||||
android:layout_margin="0dp"
|
||||
android:minWidth="40dp"
|
||||
android:textColor="@color/ratingColor"
|
||||
|
||||
tools:text="★ 7.7" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
style="@style/RatingButton"
|
||||
android:layout_gravity="end"
|
||||
tools:text="7.7" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_flag"
|
||||
|
@ -93,6 +76,15 @@
|
|||
tools:visibility="visible" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:focusable="false"
|
||||
android:visibility="gone"
|
||||
android:clickable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:id="@+id/title_shadow"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<androidx.core.widget.ContentLoadingProgressBar
|
||||
android:id="@+id/watchProgress"
|
||||
|
|
|
@ -125,8 +125,13 @@
|
|||
<item name="android:textColor">@color/subColorText</item>
|
||||
</style>
|
||||
|
||||
<!--<style name="RatingButton" parent="@style/SearchBox">
|
||||
<item name="android:background">@drawable/rating_bg_color</item>
|
||||
<item name="android:textColor">@color/ratingColor</item>
|
||||
</style>-->
|
||||
|
||||
<style name="RatingButton" parent="@style/SearchBox">
|
||||
<item name="android:minWidth">30dp</item>
|
||||
<item name="android:minWidth">40dp</item>
|
||||
<item name="android:background">@drawable/rating_bg_color</item>
|
||||
<item name="drawableTint">@color/ratingColor</item>
|
||||
<item name="android:textColor">@color/ratingColor</item>
|
||||
|
|
Loading…
Reference in a new issue