This commit is contained in:
Vologhat
2023-06-27 22:17:43 +03:00
parent 409279eca0
commit b955ac355f
5 changed files with 44 additions and 10 deletions
@@ -18,6 +18,7 @@ import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.LayoutUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -35,6 +36,7 @@ public class CategorizedAdapter<T> extends RecyclerView.Adapter<CategorizedAdapt
private final List<T> mSelectedItems;
private final List<T> mDisabledItems;
private final List<T> mUnmovedItems;
final private List< T > mExceptions=new ArrayList<>();
private final IViewHolderBinder mBinder;
// Min and max counts
@@ -48,6 +50,12 @@ public class CategorizedAdapter<T> extends RecyclerView.Adapter<CategorizedAdapt
this.mBinder = binder;
}
public void setExceptions(T... exceptions)
{
mExceptions.clear();
mExceptions.addAll(Arrays.asList(exceptions));
}
public void setMinAndMaxCounts(int min, int max) {
this.mMinSelectedItems = min;
this.mMaxSelectedItems = max;
@@ -173,16 +181,23 @@ public class CategorizedAdapter<T> extends RecyclerView.Adapter<CategorizedAdapt
public boolean onItemMove(int fromPosition, int toPosition) {
if (toPosition == 0 || isUnmovedItem(toPosition))
return false;
switch (getTabType(fromPosition)) {
case SELECTED_STATE -> {
if (getTabType(toPosition) == DISABLED_STATE
&& mSelectedItems.size() == mMinSelectedItems)
if((getTabType(toPosition) == DISABLED_STATE
&& mSelectedItems.size() == mMinSelectedItems))
return false;
if (getItemViewType(toPosition) == CATEGORY_TITLE)
mDisabledItems.add(0, mSelectedItems.remove(fromPosition - 1));
else
Collections.swap(mSelectedItems, fromPosition - 1, toPosition - 1);
{
if(mExceptions.size()>0)
{
int q=0;
for(var ex:mExceptions)
if(mSelectedItems.contains(ex))++q;
if(q==1)return false;
}
mDisabledItems.add(0,mSelectedItems.remove(fromPosition-1));
}
else Collections.swap(mSelectedItems, fromPosition - 1, toPosition - 1);
}
case DISABLED_STATE -> {
if (getTabType(toPosition) == SELECTED_STATE
@@ -198,7 +213,6 @@ public class CategorizedAdapter<T> extends RecyclerView.Adapter<CategorizedAdapt
);
}
}
notifyItemMoved(fromPosition, toPosition);
return true;
}
@@ -123,7 +123,7 @@ public class DockBarEditorManager {
return mDisabledTabs;
}
private DockBarTab getTabByTag(String tag) {
public static DockBarTab getTabByTag(String tag) {
return switch (tag) {
case "tab_news" -> DockBarTab.valuesOf(
"tab_news",
@@ -82,6 +82,9 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
holder.bindMovingItem(tab.iconID, tab.titleID);
});
adapter.setMinAndMaxCounts(DockBarEditorManager.MIN_SELECTED_TABS, DockBarEditorManager.MAX_SELECTED_TABS);
adapter.setExceptions(
DockBarEditorManager.getTabByTag("tab_profile"),
DockBarEditorManager.getTabByTag("")/*settings*/);
var recyclerView = new RecyclerView(requireContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
@@ -2,7 +2,8 @@ package ru.vtosters.lite.ui.items;
import com.vk.core.fragments.FragmentImpl;
public class DockBarTab {
public class DockBarTab
{
public String tag;
public int iconID;
@@ -31,4 +32,10 @@ public class DockBarTab {
Class<?> fragmentClass) {
return new DockBarTab(tag, iconID, titleID, resID, fragmentClass);
}
@Override
public boolean equals(Object arg)
{
return this.id==((DockBarTab)arg).id;
}
}
@@ -1,6 +1,9 @@
package ru.vtosters.lite.ui.items;
public class SuperAppItem {
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
public class SuperAppItem
{
public String type;
public String title;
@@ -13,4 +16,11 @@ public class SuperAppItem {
public static SuperAppItem valuesOf(String type, String title) {
return new SuperAppItem(type, title);
}
@Override
public boolean equals(Object arg)
{
var item=(SuperAppItem)arg;
return this.type.equals(item.type)&&this.title.equals(item.title);
}
}