Search creator overlay, Fix crash Add topbar

This commit is contained in:
Kelvin 2023-12-20 18:08:40 +01:00
parent e722c0ce9a
commit 20862a27c8
8 changed files with 71 additions and 7 deletions

View file

@ -39,10 +39,12 @@ class SourcesFragment : MainFragment() {
override fun onShownWithView(parameter: Any?, isBack: Boolean) {
super.onShownWithView(parameter, isBack)
if(topBar is AddTopBarFragment)
if(topBar is AddTopBarFragment) {
(topBar as AddTopBarFragment).onAdd.clear();
(topBar as AddTopBarFragment).onAdd.subscribe {
startActivity(Intent(requireContext(), AddSourceOptionsActivity::class.java));
};
}
_view?.reloadSources();
}

View file

@ -188,6 +188,12 @@ class SubscriptionGroupFragment : MainFragment() {
filterCreators();
}
_topbar.setButtons(
Pair(R.drawable.ic_share) {
UIDialogs.toast(context, "Coming soon");
}
);
setGroup(null);
}

View file

@ -107,12 +107,14 @@ class SubscriptionGroupListFragment : MainFragment() {
updateGroups();
}
if(topBar is AddTopBarFragment)
if(topBar is AddTopBarFragment) {
(topBar as AddTopBarFragment).onAdd.clear();
(topBar as AddTopBarFragment).onAdd.subscribe {
_overlay?.let {
UISlideOverlays.showCreateSubscriptionGroup(it)
}
};
}
}
private fun updateGroups() {

View file

@ -33,6 +33,7 @@ import com.futo.platformplayer.states.StateApp
import com.futo.platformplayer.states.StateSubscriptions
import com.futo.platformplayer.views.AnyAdapterView
import com.futo.platformplayer.views.AnyAdapterView.Companion.asAny
import com.futo.platformplayer.views.SearchView
import com.futo.platformplayer.views.adapters.AnyAdapter
import com.futo.platformplayer.views.adapters.viewholders.CreatorBarViewHolder
import com.futo.platformplayer.views.adapters.viewholders.SelectableCreatorBarViewHolder
@ -47,9 +48,12 @@ import java.io.File
class CreatorSelectOverlay: ConstraintLayout {
private val _buttonSelect: Button;
private val _topbar: OverlayTopbar;
private val _searchBar: SearchView;
private val _recyclerCreators: AnyAdapterView<SelectableCreatorBarViewHolder.Selectable, SelectableCreatorBarViewHolder>;
private val _creators: ArrayList<SelectableCreatorBarViewHolder.Selectable> = arrayListOf();
private val _creatorsFiltered: ArrayList<SelectableCreatorBarViewHolder.Selectable> = arrayListOf();
private var _selected: MutableList<String> = mutableListOf();
@ -66,7 +70,7 @@ class CreatorSelectOverlay: ConstraintLayout {
else
_creators.addAll(subs
.map { SelectableCreatorBarViewHolder.Selectable(it.channel, false) });
_recyclerCreators.notifyContentChanged();
filterCreators();
}
constructor(context: Context, attrs: AttributeSet?): super(context, attrs) { }
init {
@ -74,7 +78,8 @@ class CreatorSelectOverlay: ConstraintLayout {
_topbar = findViewById(R.id.topbar);
_buttonSelect = findViewById(R.id.button_select);
val dp6 = 6.dp(resources);
_recyclerCreators = findViewById<RecyclerView>(R.id.recycler_creators).asAny(_creators, RecyclerView.HORIZONTAL) { creatorView ->
_searchBar = findViewById(R.id.search_bar);
_recyclerCreators = findViewById<RecyclerView>(R.id.recycler_creators).asAny(_creatorsFiltered, RecyclerView.HORIZONTAL) { creatorView ->
creatorView.itemView.setPadding(0, dp6, 0, dp6);
creatorView.onClick.subscribe {
if(it.channel.thumbnail == null) {
@ -99,7 +104,11 @@ class CreatorSelectOverlay: ConstraintLayout {
_topbar.onClose.subscribe {
onClose.emit();
}
_searchBar.onSearchChanged.subscribe {
filterCreators();
};
updateSelected();
filterCreators();
}
fun updateSelected() {
@ -113,6 +122,17 @@ class CreatorSelectOverlay: ConstraintLayout {
}
private fun filterCreators(withUpdate: Boolean = true) {
val query = _searchBar.textSearch.text.toString().lowercase();
val filteredEnabled = _creators.filter { query.isNullOrEmpty() || it.channel.name.lowercase().contains(query) };
//Optimize
_creatorsFiltered.clear();
_creatorsFiltered.addAll(filteredEnabled);
if(withUpdate)
_recyclerCreators.notifyContentChanged();
}
fun select() {
if(_creators.isEmpty())
return;

View file

@ -3,10 +3,13 @@ package com.futo.platformplayer.views.overlays
import android.content.Context
import android.util.AttributeSet
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.marginRight
import com.futo.platformplayer.R
import com.futo.platformplayer.constructs.Event0
import com.futo.platformplayer.dp
import com.futo.platformplayer.views.lists.VideoListEditorView
class OverlayTopbar : ConstraintLayout {
@ -16,6 +19,8 @@ class OverlayTopbar : ConstraintLayout {
private val _button_close: ImageView;
private val _button_list: LinearLayout;
val onClose = Event0();
constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) {
@ -24,6 +29,7 @@ class OverlayTopbar : ConstraintLayout {
_name = findViewById(R.id.text_name);
_meta = findViewById(R.id.text_meta);
_button_close = findViewById(R.id.button_close);
_button_list = findViewById(R.id.button_list);
val attrArr = context.obtainStyledAttributes(attrs, R.styleable.OverlayTopbar, 0, 0);
val attrText = attrArr.getText(R.styleable.OverlayTopbar_title) ?: "";
@ -42,4 +48,20 @@ class OverlayTopbar : ConstraintLayout {
_name.text = name;
_meta.text = meta;
}
fun setButtons(vararg buttons: Pair<Int, ()->Unit>) {
_button_list.removeAllViews();
val dp40 = 40.dp(resources);
val dp5 = 5.dp(resources);
for(button in buttons) {
_button_list.addView(ImageView(context).apply {
layoutParams = LinearLayout.LayoutParams(dp40, dp40)
setPadding(dp5, dp5, dp5 * 2, dp5);
setImageResource(button.first);
setOnClickListener {
button.second();
}
});
}
}
}

View file

@ -77,7 +77,7 @@ class SubscriptionBar : LinearLayout {
Settings.instance.subscriptions.showSubscriptionGroups = false;
Settings.instance.save();
reloadGroups();
UIDialogs.showDialogOk(context, R.drawable.ic_quiz, "Subscription groups can be re-enabled in settings")
}),
UIDialogs.Action("Create", {

View file

@ -16,11 +16,18 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<com.futo.platformplayer.views.SearchView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/topbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_creators"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/topbar"
app:layout_constraintTop_toBottomOf="@id/search_bar"
app:layout_constraintBottom_toTopOf="@id/container_select"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
@ -37,7 +44,8 @@
android:id="@+id/button_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_margin="10dp"
android:background="@drawable/background_button_primary"
android:text="Select" />
</LinearLayout>

View file

@ -40,6 +40,10 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/button_list"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/button_close"
android:layout_width="40dp"