refactor CategorizedAdapter, DockBarEditor, SuperAppEditor
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.Gravity;
|
||||
@@ -12,20 +9,21 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.ui.components.IItemMovingListener;
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.ui.components.IItemMovingListener;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.CategorizedViewHolder> implements IItemMovingListener {
|
||||
public class CategorizedAdapter< T > extends RecyclerView.Adapter< CategorizedAdapter.CategorizedViewHolder > implements IItemMovingListener {
|
||||
|
||||
// Adapter item types
|
||||
public static final int MOVING_ITEM = -0x1;
|
||||
@@ -35,18 +33,20 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
public static final int SELECTED_STATE = -0x1;
|
||||
public static final int DISABLED_STATE = -0x2;
|
||||
|
||||
private final List mSelectedItems;
|
||||
private final List mDisabledItems;
|
||||
private final List mUnmovedItems;
|
||||
// Data of items
|
||||
private final List< T > mSelectedItems;
|
||||
private final List< T > mDisabledItems;
|
||||
private final List< T > mUnmovedItems;
|
||||
private final IViewHolderBinder mBinder;
|
||||
|
||||
// Min and max counts
|
||||
private int mMinSelectedItems = -1;
|
||||
private int mMaxSelectedItems = -1;
|
||||
|
||||
public CategorizedAdapter(List selectedItems, List disabledItems, IViewHolderBinder binder) {
|
||||
public CategorizedAdapter(List< T > selectedItems, List< T > disabledItems, IViewHolderBinder binder) {
|
||||
this.mSelectedItems = selectedItems;
|
||||
this.mDisabledItems = disabledItems;
|
||||
this.mUnmovedItems = new ArrayList();
|
||||
this.mUnmovedItems = new ArrayList<>();
|
||||
this.mBinder = binder;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
this.mMaxSelectedItems = max;
|
||||
}
|
||||
|
||||
public void addUnmovedItem(Object item) {
|
||||
public void addUnmovedItem(T item) {
|
||||
mUnmovedItems.add(item);
|
||||
}
|
||||
|
||||
@@ -68,31 +68,25 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
}
|
||||
|
||||
public boolean isUnmovedItem(int index) {
|
||||
if (getItemViewType(index) == MOVING_ITEM) {
|
||||
Object curr;
|
||||
if (getTabType(index) == SELECTED_STATE) {
|
||||
curr = mSelectedItems.get(index - 1);
|
||||
return mUnmovedItems.contains(curr);
|
||||
} else {
|
||||
curr = mDisabledItems.get(index - mSelectedItems.size() - 2);
|
||||
return mUnmovedItems.contains(curr);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return getItemViewType(index) == MOVING_ITEM
|
||||
&& mUnmovedItems.contains(
|
||||
getTabType(index) == SELECTED_STATE
|
||||
? mSelectedItems.get(index - 1)
|
||||
: mDisabledItems.get(index - mSelectedItems.size() - 2));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CategorizedViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
||||
FrameLayout container = new FrameLayout(getGlobalContext());
|
||||
container.addView(newCategoryTitle(), new FrameLayout.LayoutParams(-1, -2));
|
||||
container.addView(newMovingItem(), new FrameLayout.LayoutParams(-1, -2));
|
||||
container.addView(newCategoryTitle(), LayoutUtils.createFrame(-1, -2));
|
||||
container.addView(newMovingItem(), LayoutUtils.createFrame(-1, -2));
|
||||
return new CategorizedViewHolder(container);
|
||||
}
|
||||
|
||||
private View newMovingItem() {
|
||||
LinearLayout container = new LinearLayout(getGlobalContext());
|
||||
container.setTag("container");
|
||||
var container = new LinearLayout(getGlobalContext());
|
||||
container.setId(R.id.container);
|
||||
container.setGravity(Gravity.CENTER_VERTICAL);
|
||||
container.setOrientation(LinearLayout.HORIZONTAL);
|
||||
container.setPadding(
|
||||
@@ -101,23 +95,23 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
dp2px(12),
|
||||
dp2px(12)
|
||||
);
|
||||
container.setLayoutParams(new LinearLayout.LayoutParams(-1, dp2px(48)));
|
||||
container.setLayoutParams(LayoutUtils.createLinear(-1, dp2px(48)));
|
||||
container.setVisibility(View.INVISIBLE);
|
||||
|
||||
ImageView icon = new ImageView(getGlobalContext());
|
||||
icon.setTag("icon");
|
||||
var icon = new ImageView(getGlobalContext());
|
||||
icon.setId(R.id.icon);
|
||||
icon.setImageTintList(ColorStateList.valueOf(ThemesUtils.getAccentColor()));
|
||||
icon.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
dp2px(24),
|
||||
dp2px(24)));
|
||||
container.addView(icon);
|
||||
|
||||
TextView name = new TextView(getGlobalContext());
|
||||
name.setTag("name");
|
||||
var name = new TextView(getGlobalContext());
|
||||
name.setId(R.id.name);
|
||||
name.setTextSize(16.0f);
|
||||
name.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
name.setTextColor(ThemesUtils.getTextAttr());
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-1, -2);
|
||||
var params = LayoutUtils.createLinear(-1, -2);
|
||||
params.weight = 1;
|
||||
params.leftMargin = dp2px(16);
|
||||
container.addView(name, params);
|
||||
@@ -126,13 +120,13 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
}
|
||||
|
||||
private View newCategoryTitle() {
|
||||
LinearLayout container = new LinearLayout(getGlobalContext());
|
||||
container.setTag("category_title_container");
|
||||
container.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
|
||||
var container = new LinearLayout(getGlobalContext());
|
||||
container.setId(R.id.title_container);
|
||||
container.setLayoutParams(LayoutUtils.createLinear(-1, -2));
|
||||
container.setVisibility(View.INVISIBLE);
|
||||
|
||||
TextView title = new TextView(getGlobalContext());
|
||||
title.setTag("category_title");
|
||||
var title = new TextView(getGlobalContext());
|
||||
title.setId(R.id.title);
|
||||
title.setTextSize(13.0f);
|
||||
title.setPadding(
|
||||
dp2px(16),
|
||||
@@ -142,14 +136,14 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
);
|
||||
title.setAllCaps(true);
|
||||
title.setTextColor(ThemesUtils.getTextAttr());
|
||||
container.addView(title, new LinearLayout.LayoutParams(-2, -2));
|
||||
container.addView(title, LayoutUtils.createLinear(-2, -2));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CategorizedViewHolder viewHolder, int i) {
|
||||
if (getItemViewType(i) == MOVING_ITEM)
|
||||
if(getItemViewType(i) == MOVING_ITEM)
|
||||
mBinder.bind(viewHolder, i);
|
||||
else
|
||||
viewHolder.bindCategory(i == 0);
|
||||
@@ -162,57 +156,47 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
|
||||
@Override
|
||||
public void onItemDismiss(int index) {
|
||||
if (getItemViewType(index) == MOVING_ITEM) {
|
||||
Object curr;
|
||||
if (getTabType(index) == SELECTED_STATE) {
|
||||
curr = mSelectedItems.get(index - 1);
|
||||
mSelectedItems.remove(curr);
|
||||
mDisabledItems.add(0, curr);
|
||||
if(getItemViewType(index) == MOVING_ITEM) {
|
||||
if(getTabType(index) == SELECTED_STATE) {
|
||||
mDisabledItems.add(0, mSelectedItems.remove(index - 1));
|
||||
notifyItemMoved(index, mSelectedItems.size() + 1);
|
||||
} else {
|
||||
curr = mDisabledItems.get(index - mSelectedItems.size() - 2);
|
||||
mDisabledItems.remove(curr);
|
||||
mSelectedItems.add(0, curr);
|
||||
mSelectedItems.add(0, mDisabledItems.remove(index - mSelectedItems.size() - 2));
|
||||
notifyItemRemoved(index);
|
||||
notifyItemInserted(1);
|
||||
notifyItemInserted(1); // first element is the title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemMove(int fromPosition, int toPosition) {
|
||||
if (toPosition == 0 || isUnmovedItem(toPosition))
|
||||
if(toPosition == 0 || isUnmovedItem(toPosition))
|
||||
return false;
|
||||
|
||||
Object curr;
|
||||
if (getTabType(fromPosition) == SELECTED_STATE) {
|
||||
var min = mSelectedItems.size() == mMinSelectedItems;
|
||||
if (getTabType(toPosition) == DISABLED_STATE && min)
|
||||
return false;
|
||||
curr = mSelectedItems.get(fromPosition - 1);
|
||||
if (getItemViewType(toPosition) == CATEGORY_TITLE) {
|
||||
if (min)
|
||||
switch(getTabType(fromPosition)) {
|
||||
case SELECTED_STATE:
|
||||
if(getTabType(toPosition) == DISABLED_STATE
|
||||
&& mSelectedItems.size() == mMinSelectedItems)
|
||||
return false;
|
||||
mSelectedItems.remove(fromPosition - 1);
|
||||
mDisabledItems.add(0, curr);
|
||||
} else {
|
||||
Collections.swap(mSelectedItems, fromPosition - 1, toPosition - 1);
|
||||
}
|
||||
} else if (getTabType(fromPosition) == DISABLED_STATE) {
|
||||
var max = mSelectedItems.size() == mMaxSelectedItems;
|
||||
if (getTabType(toPosition) == SELECTED_STATE && max)
|
||||
return false;
|
||||
curr = mDisabledItems.get(fromPosition - mSelectedItems.size() - 2);
|
||||
if (getItemViewType(toPosition) == CATEGORY_TITLE) {
|
||||
if (max)
|
||||
if(getItemViewType(toPosition) == CATEGORY_TITLE)
|
||||
mDisabledItems.add(0, mSelectedItems.remove(fromPosition - 1));
|
||||
else
|
||||
Collections.swap(mSelectedItems, fromPosition - 1, toPosition - 1);
|
||||
break;
|
||||
|
||||
case DISABLED_STATE:
|
||||
if(getTabType(toPosition) == SELECTED_STATE
|
||||
&& mSelectedItems.size() == mMaxSelectedItems)
|
||||
return false;
|
||||
mDisabledItems.remove(0);
|
||||
mSelectedItems.add(curr);
|
||||
} else {
|
||||
Collections.swap(mDisabledItems,
|
||||
fromPosition - mSelectedItems.size() - 2,
|
||||
toPosition - mSelectedItems.size() - 2);
|
||||
}
|
||||
if(getItemViewType(toPosition) == CATEGORY_TITLE)
|
||||
mSelectedItems.add(mDisabledItems.remove(fromPosition - mSelectedItems.size() - 2));
|
||||
else
|
||||
Collections.swap(
|
||||
mDisabledItems,
|
||||
fromPosition - mSelectedItems.size() - 2,
|
||||
toPosition - mSelectedItems.size() - 2
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
notifyItemMoved(fromPosition, toPosition);
|
||||
@@ -235,17 +219,17 @@ public class CategorizedAdapter extends RecyclerView.Adapter<CategorizedAdapter.
|
||||
public CategorizedViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
mMovingItemContainer = itemView.findViewWithTag("container");
|
||||
mCategoryTitleContainer = itemView.findViewWithTag("category_title_container");
|
||||
mMovingItemContainer = itemView.findViewById(R.id.container);
|
||||
mCategoryTitleContainer = itemView.findViewById(R.id.title_container);
|
||||
|
||||
mIcon = mMovingItemContainer.findViewWithTag("icon");
|
||||
mName = mMovingItemContainer.findViewWithTag("name");
|
||||
mIcon = mMovingItemContainer.findViewById(R.id.icon);
|
||||
mName = mMovingItemContainer.findViewById(R.id.name);
|
||||
|
||||
mCategoryTitle = mCategoryTitleContainer.findViewWithTag("category_title");
|
||||
mCategoryTitle = mCategoryTitleContainer.findViewById(R.id.title);
|
||||
}
|
||||
|
||||
public void bindMovingItem(int iconId, int textId) {
|
||||
if (iconId != -1)
|
||||
if(iconId != -1)
|
||||
mIcon.setImageResource(iconId);
|
||||
else
|
||||
mIcon.setVisibility(View.GONE);
|
||||
|
||||
@@ -102,12 +102,12 @@ public class StickerPackAdapter extends RecyclerView.Adapter<StickerPackAdapter.
|
||||
super(view);
|
||||
|
||||
mContainer = (LinearLayout) view;
|
||||
mSwitch = view.findViewWithTag("choose_btn");
|
||||
mStickerPreview = view.findViewWithTag("photo");
|
||||
mUpdateButton = view.findViewWithTag("button_update");
|
||||
mDeleteButton = view.findViewWithTag("action_delete");
|
||||
mName = view.findViewWithTag("vkim_cancel");
|
||||
mStickersCount = view.findViewWithTag("vkim_cancel_label_text");
|
||||
mSwitch = view.findViewById(R.id.choose_btn);
|
||||
mStickerPreview = view.findViewById(R.id.photo);
|
||||
mUpdateButton = view.findViewById(R.id.button_update);
|
||||
mDeleteButton = view.findViewById(R.id.action_delete);
|
||||
mName = view.findViewById(R.id.vkim_cancel);
|
||||
mStickersCount = view.findViewById(R.id.vkim_cancel_label_text);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
package ru.vtosters.lite.ui.components;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.superapp;
|
||||
import static ru.vtosters.lite.utils.Preferences.useNewSettings;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme_notifs;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import com.vk.apps.AppsFragment;
|
||||
import com.vk.discover.DiscoverFragment;
|
||||
import com.vk.fave.fragments.FaveTabFragment;
|
||||
@@ -34,22 +24,31 @@ import com.vtosters.lite.fragments.t2.c.DialogsFragment;
|
||||
import com.vtosters.lite.fragments.y2.VideoCatalogFragment;
|
||||
import com.vtosters.lite.general.fragments.GamesFragment;
|
||||
import com.vtosters.lite.general.fragments.PhotosFragment;
|
||||
import ru.vtosters.lite.ui.items.DockBarTab;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ru.vtosters.lite.ui.items.DockBarTab;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
|
||||
import static ru.vtosters.lite.utils.Preferences.*;
|
||||
|
||||
public class DockBarEditorManager {
|
||||
public static final int MIN_SELECTED_TABS = 3;
|
||||
public static final int MAX_SELECTED_TABS = 9;
|
||||
|
||||
private static final List< String > ALL_TAGS = Arrays.asList(
|
||||
"tab_news", "tab_superapps", "tab_messages", "tab_feedback", "tab_profile",
|
||||
"tab_friends", "tab_groups", "tab_photos", "tab_audios", "tab_videos",
|
||||
"tab_lives", "tab_games", "tab_liked", "tab_fave", "tab_documents",
|
||||
"tab_payments", "tab_vk_apps", "tab_settings");
|
||||
|
||||
private static DockBarEditorManager sInstance;
|
||||
private final List<DockBarTab> mSelectedTabs = new ArrayList<>();
|
||||
private final List<DockBarTab> mDisabledTabs = new ArrayList<>();
|
||||
private final List< DockBarTab > mSelectedTabs = new ArrayList<>();
|
||||
private final List< DockBarTab > mDisabledTabs = new ArrayList<>();
|
||||
|
||||
public DockBarEditorManager() {
|
||||
init();
|
||||
@@ -62,10 +61,10 @@ public class DockBarEditorManager {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (vkme()) {
|
||||
if(vkme()) {
|
||||
mSelectedTabs.add(getTabByTag("tab_settings"));
|
||||
if (vkme_notifs()) {
|
||||
if (milkshake()) {
|
||||
if(vkme_notifs()) {
|
||||
if(milkshake()) {
|
||||
mSelectedTabs.add(getTabByTag("tab_feedback"));
|
||||
} else {
|
||||
mSelectedTabs.add(getTabByTag("tab_friends"));
|
||||
@@ -78,44 +77,36 @@ public class DockBarEditorManager {
|
||||
|
||||
checkOldConfig();
|
||||
|
||||
String[] selectedTabsTags = getPreferences().getString("dockbar_tabs", "tab_news,tab_superapps,tab_messages,tab_friends,tab_profile")
|
||||
var selectedTabsTags = getPreferences()
|
||||
.getString("dockbar_tabs",
|
||||
"tab_news,tab_superapps,tab_messages,tab_friends,tab_profile")
|
||||
.split(",");
|
||||
parseSelectedTabs(selectedTabsTags);
|
||||
}
|
||||
|
||||
private void checkOldConfig() {
|
||||
File config = new File(getGlobalContext().getFilesDir(), "dockbar.json");
|
||||
if (config.exists()) config.deleteOnExit();
|
||||
if(config.exists()) config.deleteOnExit();
|
||||
}
|
||||
|
||||
private void parseSelectedTabs(String[] selectedTabsTags) {
|
||||
List<String> allTags = new ArrayList<>(Arrays.asList("tab_news", "tab_superapps", "tab_messages", "tab_feedback", "tab_profile",
|
||||
"tab_friends", "tab_groups", "tab_photos", "tab_audios", "tab_videos", "tab_lives", "tab_games", "tab_liked",
|
||||
"tab_fave", "tab_documents", "tab_payments", "tab_vk_apps", "tab_settings"));
|
||||
var allTags = new ArrayList<>(ALL_TAGS);
|
||||
|
||||
for (String tag : selectedTabsTags) {
|
||||
for(String tag : selectedTabsTags) {
|
||||
mSelectedTabs.add(getTabByTag(tag));
|
||||
allTags.remove(tag);
|
||||
}
|
||||
|
||||
for (String tag : allTags) {
|
||||
for(String tag : allTags) {
|
||||
mDisabledTabs.add(getTabByTag(tag));
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
getPreferences().edit().putString("dockbar_tabs", mSelectedTabs.stream()
|
||||
.map(tab -> tab.tag)
|
||||
.collect(Collectors.joining(",")))
|
||||
.commit();
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (DockBarTab tab : mSelectedTabs) {
|
||||
sb.append(tab.tag).append(",");
|
||||
}
|
||||
getPreferences().edit().putString("dockbar_tabs", sb.toString()).commit();
|
||||
}
|
||||
var sb = new StringBuilder();
|
||||
for(DockBarTab tab : mSelectedTabs)
|
||||
sb.append(tab.tag).append(",");
|
||||
getPreferences().edit().putString("dockbar_tabs", sb.toString()).commit();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
@@ -125,16 +116,16 @@ public class DockBarEditorManager {
|
||||
.commit();
|
||||
}
|
||||
|
||||
public List<DockBarTab> getSelectedTabs() {
|
||||
public List< DockBarTab > getSelectedTabs() {
|
||||
return mSelectedTabs;
|
||||
}
|
||||
|
||||
public List<DockBarTab> getDisabledTabs() {
|
||||
public List< DockBarTab > getDisabledTabs() {
|
||||
return mDisabledTabs;
|
||||
}
|
||||
|
||||
private DockBarTab getTabByTag(String tag) {
|
||||
switch (tag) {
|
||||
switch(tag) {
|
||||
case "tab_news":
|
||||
return DockBarTab.valuesOf(
|
||||
"tab_news",
|
||||
|
||||
@@ -25,6 +25,7 @@ import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
|
||||
import ru.vtosters.lite.ui.components.DockBarEditorManager;
|
||||
import ru.vtosters.lite.ui.components.ItemMovingCallback;
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
|
||||
public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
|
||||
@@ -33,38 +34,40 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
public View onCreateContent(@NonNull LayoutInflater inflater, @Nullable Bundle bundle) {
|
||||
setTitle(R.string.dockbar_editor);
|
||||
|
||||
FrameLayout content = new FrameLayout(getContext());
|
||||
var content = new FrameLayout(getContext());
|
||||
|
||||
LinearLayout container = new LinearLayout(getContext());
|
||||
var container = new LinearLayout(getContext());
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
content.addView(container, new FrameLayout.LayoutParams(-1, -1));
|
||||
content.addView(container, LayoutUtils.createFrame(-1, -1));
|
||||
|
||||
LinearLayout buttonsContainer = new LinearLayout(getContext());
|
||||
var buttonsContainer = new LinearLayout(getContext());
|
||||
buttonsContainer.setPadding(
|
||||
dp2px(13),
|
||||
dp2px(10),
|
||||
dp2px(13),
|
||||
dp2px(10)
|
||||
);
|
||||
container.addView(buttonsContainer, new LinearLayout.LayoutParams(-1, -2));
|
||||
container.addView(buttonsContainer, LayoutUtils.createLinear(-1, -2));
|
||||
|
||||
TextView save = new TextView(new ContextThemeWrapper(getContext(), R.style.VKUIButton_Primary));
|
||||
var manager = DockBarEditorManager.getInstance();
|
||||
|
||||
var save = new TextView(new ContextThemeWrapper(getContext(), R.style.VKUIButton_Primary));
|
||||
save.setText(requireContext().getString(R.string.save));
|
||||
save.setOnClickListener(v -> {
|
||||
DockBarEditorManager.getInstance().save();
|
||||
manager.save();
|
||||
restartApplication();
|
||||
});
|
||||
|
||||
new TextViewHook().inject(save, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams saveParams = new LinearLayout.LayoutParams(0, -2);
|
||||
var saveParams = LayoutUtils.createLinear(0, -2);
|
||||
saveParams.weight = 1.0f;
|
||||
buttonsContainer.addView(save, saveParams);
|
||||
|
||||
View divider = new View(getContext());
|
||||
buttonsContainer.addView(divider, new LinearLayout.LayoutParams(dp2px(10), 0));
|
||||
var divider = new View(getContext());
|
||||
buttonsContainer.addView(divider, LayoutUtils.createLinear(dp2px(10), 0));
|
||||
|
||||
TextView reset = new TextView(new ContextThemeWrapper(getContext(), R.style.VKUIButton_Primary));
|
||||
var reset = new TextView(new ContextThemeWrapper(getContext(), R.style.VKUIButton_Primary));
|
||||
reset.setText(requireContext().getString(R.string.reset));
|
||||
reset.setOnClickListener(v -> {
|
||||
DockBarEditorManager.getInstance().reset();
|
||||
@@ -73,12 +76,11 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
|
||||
new TextViewHook().inject(reset, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams resetParams = new LinearLayout.LayoutParams(0, -2);
|
||||
var resetParams = LayoutUtils.createLinear(0, -2);
|
||||
resetParams.weight = 1.0f;
|
||||
buttonsContainer.addView(reset, resetParams);
|
||||
|
||||
DockBarEditorManager manager = DockBarEditorManager.getInstance();
|
||||
var adapter = new CategorizedAdapter(manager.getSelectedTabs(), manager.getDisabledTabs(), (holder, pos) -> {
|
||||
var adapter = new CategorizedAdapter<>(manager.getSelectedTabs(), manager.getDisabledTabs(), (holder, pos) -> {
|
||||
var tab = pos <= manager.getSelectedTabs().size()
|
||||
? manager.getSelectedTabs().get(pos - 1)
|
||||
: manager.getDisabledTabs().get(pos - manager.getSelectedTabs().size() - 2);
|
||||
@@ -90,7 +92,7 @@ public class DockBarEditorFragment extends BaseToolbarFragment {
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
var params = new LinearLayout.LayoutParams(-1, -1);
|
||||
var params = LayoutUtils.createLinear(-1, -1);
|
||||
params.gravity = Gravity.CENTER;
|
||||
container.addView(recyclerView, params);
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package ru.vtosters.lite.ui.fragments;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
@@ -12,16 +8,13 @@ import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.hooks.TextViewHook;
|
||||
import ru.vtosters.lite.ui.adapters.CategorizedAdapter;
|
||||
import ru.vtosters.lite.ui.components.ItemMovingCallback;
|
||||
@@ -29,6 +22,9 @@ import ru.vtosters.lite.ui.components.SuperAppEditorManager;
|
||||
import ru.vtosters.lite.utils.LayoutUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplication;
|
||||
|
||||
public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
|
||||
@CallSuper
|
||||
@@ -36,13 +32,13 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
public View onCreateContent(@NonNull LayoutInflater inflater, @Nullable Bundle bundle) {
|
||||
setTitle(R.string.superapp_editor);
|
||||
|
||||
FrameLayout content = new FrameLayout(getContext());
|
||||
var content = new FrameLayout(getContext());
|
||||
|
||||
LinearLayout container = new LinearLayout(getContext());
|
||||
var container = new LinearLayout(getContext());
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
content.addView(container, new FrameLayout.LayoutParams(-1, -1));
|
||||
content.addView(container, LayoutUtils.createFrame(-1, -1));
|
||||
|
||||
TextView message = new TextView(getContext());
|
||||
var message = new TextView(getContext());
|
||||
message.setText(R.string.superapp_editor_message);
|
||||
message.setTextSize(16.0f);
|
||||
message.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
@@ -55,7 +51,7 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
);
|
||||
container.addView(message, LayoutUtils.createLinear(-1, -2));
|
||||
|
||||
LinearLayout buttonsContainer = new LinearLayout(getContext());
|
||||
var buttonsContainer = new LinearLayout(getContext());
|
||||
buttonsContainer.setPadding(
|
||||
dp2px(13),
|
||||
dp2px(10),
|
||||
@@ -64,7 +60,7 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
);
|
||||
container.addView(buttonsContainer, new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
TextView save = new TextView(new ContextThemeWrapper(getContext(), com.vtosters.lite.R.style.VKUIButton_Primary));
|
||||
var save = new TextView(new ContextThemeWrapper(getContext(), R.style.VKUIButton_Primary));
|
||||
save.setText(R.string.save);
|
||||
save.setOnClickListener(v -> {
|
||||
SuperAppEditorManager.getInstance().save();
|
||||
@@ -73,14 +69,14 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
|
||||
new TextViewHook().inject(save, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams saveParams = new LinearLayout.LayoutParams(0, -2);
|
||||
var saveParams = LayoutUtils.createLinear(0, -2);
|
||||
saveParams.weight = 1.0f;
|
||||
buttonsContainer.addView(save, saveParams);
|
||||
|
||||
View divider = new View(getContext());
|
||||
var divider = new View(getContext());
|
||||
buttonsContainer.addView(divider, new LinearLayout.LayoutParams(dp2px(10), 0));
|
||||
|
||||
TextView reset = new TextView(new ContextThemeWrapper(getContext(), com.vtosters.lite.R.style.VKUIButton_Primary));
|
||||
var reset = new TextView(new ContextThemeWrapper(getContext(), R.style.VKUIButton_Primary));
|
||||
reset.setText(R.string.reset);
|
||||
reset.setOnClickListener(v -> {
|
||||
SuperAppEditorManager.getInstance().reset();
|
||||
@@ -89,44 +85,31 @@ public class SuperAppEditorFragment extends BaseToolbarFragment {
|
||||
|
||||
new TextViewHook().inject(reset, 0, false);
|
||||
|
||||
LinearLayout.LayoutParams resetParams = new LinearLayout.LayoutParams(0, -2);
|
||||
var resetParams = LayoutUtils.createLinear(0, -2);
|
||||
resetParams.weight = 1.0f;
|
||||
buttonsContainer.addView(reset, resetParams);
|
||||
|
||||
SuperAppEditorManager manager = SuperAppEditorManager.getInstance();
|
||||
var adapter = new CategorizedAdapter(manager.getSelectedTabs(), manager.getDisabledTabs(), (holder, pos) -> {
|
||||
var manager = SuperAppEditorManager.getInstance();
|
||||
var adapter = new CategorizedAdapter<>(manager.getSelectedTabs(), manager.getDisabledTabs(), (holder, pos) -> {
|
||||
var item = pos <= manager.getSelectedTabs().size()
|
||||
? manager.getSelectedTabs().get(pos - 1)
|
||||
: manager.getDisabledTabs().get(pos - manager.getSelectedTabs().size() - 2);
|
||||
holder.bindMovingItem(item.title);
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
manager.getSelectedTabs().forEach(item -> {
|
||||
if (item.type.equals("menu"))
|
||||
adapter.addUnmovedItem(item);
|
||||
});
|
||||
|
||||
manager.getDisabledTabs().forEach(item -> {
|
||||
if (item.type.equals("menu"))
|
||||
adapter.addUnmovedItem(item);
|
||||
});
|
||||
} else {
|
||||
for (var item : manager.getSelectedTabs()) {
|
||||
if (item.type.equals("menu"))
|
||||
adapter.addUnmovedItem(item);
|
||||
}
|
||||
for(var item : manager.getSelectedTabs())
|
||||
if(item.type.equals("menu"))
|
||||
adapter.addUnmovedItem(item);
|
||||
|
||||
for (var item : manager.getDisabledTabs()) {
|
||||
if (item.type.equals("menu"))
|
||||
adapter.addUnmovedItem(item);
|
||||
}
|
||||
}
|
||||
for(var item : manager.getDisabledTabs())
|
||||
if(item.type.equals("menu"))
|
||||
adapter.addUnmovedItem(item);
|
||||
|
||||
var recyclerView = new RecyclerView(requireContext());
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
var params = new LinearLayout.LayoutParams(-1, -1);
|
||||
var params = LayoutUtils.createLinear(-1, -1);
|
||||
params.gravity = Gravity.CENTER;
|
||||
container.addView(recyclerView, params);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user