докбар
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
public class DockBarDragItem {
|
||||
|
||||
public boolean active;
|
||||
public int index;
|
||||
public DockBarTab dockBarTab;
|
||||
|
||||
public DockBarDragItem(boolean active, int index, DockBarTab dockBarTab) {
|
||||
this.active = active;
|
||||
this.index = index;
|
||||
this.dockBarTab = dockBarTab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.fragments.f.FriendsFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.Helper;
|
||||
|
||||
public class DockBarEditAdapter extends RecyclerView.Adapter<DockBarEditAdapter.DockBarEditViewHolder>
|
||||
implements IItemTouchHelper {
|
||||
|
||||
public static final int SELECTED_TAB_TYPE = 1;
|
||||
public static final int DISABLED_TAB_TYPE = 2;
|
||||
|
||||
public static DockBarEditHelper sDockBarEditHelper = DockBarEditHelper.getInstance();
|
||||
|
||||
private ItemTouchHelper mItemTouchHelper;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DockBarEditViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
LinearLayout container = new LinearLayout(parent.getContext());
|
||||
container.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
View tabItem = createTabItem();
|
||||
container.addView(tabItem, new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
View groupTitle = createGroupTitle();
|
||||
container.addView(groupTitle, new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
return new DockBarEditViewHolder(container);
|
||||
}
|
||||
|
||||
private View createTabItem() {
|
||||
LinearLayout container = new LinearLayout(Helper.GetContext());
|
||||
container.setTag("tab_item_container");
|
||||
container.setGravity(Gravity.CENTER_VERTICAL);
|
||||
container.setOrientation(LinearLayout.HORIZONTAL);
|
||||
container.setPadding(
|
||||
Helper.convertDpToPixel(12),
|
||||
Helper.convertDpToPixel(12),
|
||||
Helper.convertDpToPixel(12),
|
||||
Helper.convertDpToPixel(12)
|
||||
);
|
||||
container.setLayoutParams(new LinearLayout.LayoutParams(-1, Helper.convertDpToPixel(48)));
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Helper.GetContext().getTheme().resolveAttribute(R.attr.text_secondary, typedValue, true);
|
||||
|
||||
int textSecondary = typedValue.data;
|
||||
|
||||
Helper.GetContext().getTheme().resolveAttribute(R.attr.text_secondary, typedValue, true);
|
||||
|
||||
int textPrimary = typedValue.data;
|
||||
|
||||
ImageView icon = new ImageView(Helper.GetContext());
|
||||
icon.setTag("icon");
|
||||
icon.setImageTintList(ColorStateList.valueOf(textSecondary));
|
||||
icon.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
Helper.convertDpToPixel(24),
|
||||
Helper.convertDpToPixel(24)));
|
||||
container.addView(icon);
|
||||
|
||||
TextView title = new TextView(Helper.GetContext());
|
||||
title.setTag("title");
|
||||
title.setText("text");
|
||||
title.setTextSize(16.0f);
|
||||
title.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
title.setTextColor(textPrimary);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, -2);
|
||||
params.weight = 1;
|
||||
params.leftMargin = Helper.convertDpToPixel(16);
|
||||
container.addView(title, params);
|
||||
|
||||
// ImageView move = new ImageView(Helper.GetContext());
|
||||
// move.setTag("move");
|
||||
// move.setImageTintList(ColorStateList.valueOf(textSecondary));
|
||||
// move.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
// Helper.convertDpToPixel(24),
|
||||
// Helper.convertDpToPixel(24)));
|
||||
// container.addView(move);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private View createGroupTitle() {
|
||||
TextView title = new TextView(Helper.GetContext());
|
||||
title.setTag("group_title");
|
||||
title.setText("text");
|
||||
title.setTextSize(13.0f);
|
||||
title.setPadding(
|
||||
Helper.convertDpToPixel(16),
|
||||
Helper.convertDpToPixel(13),
|
||||
Helper.convertDpToPixel(16),
|
||||
Helper.convertDpToPixel(13)
|
||||
);
|
||||
title.setAllCaps(true);
|
||||
title.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
Helper.GetContext().getTheme().resolveAttribute(R.attr.text_secondary, typedValue, true);
|
||||
|
||||
int textPrimary = typedValue.data;
|
||||
|
||||
title.setTextColor(textPrimary);
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DockBarEditViewHolder holder, int position) {
|
||||
int viewType = sDockBarEditHelper.getItemType(position);
|
||||
DockBarTab item = new DockBarTab("tab_friends", R.drawable.ic_user_24, R.string.friends, R.id.menu_friends, FriendsFragment.class);
|
||||
Log.d("guzno", "bind");
|
||||
holder.bind(item);
|
||||
// if (viewType == 1) {
|
||||
// holder.bind(item);
|
||||
// //holder.bind(sDockBarEditHelper.getSelectedTab(position));
|
||||
// } else if (viewType == 2) {
|
||||
// holder.bind(item);
|
||||
// //holder.bind(DockBarInjector.sDockBarEditHelper.getDisabledTab(position));
|
||||
// } else if (viewType == RecyclerView.INVALID_TYPE) {
|
||||
// holder.bind(item);
|
||||
// //holder.bind(DockBarInjector.sDockBarEditHelper.getGroupTitle(position));
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return sDockBarEditHelper.getItemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemDismiss(int index) {
|
||||
sDockBarEditHelper.move(this, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemMove(int fromPosition, int toPosition) {
|
||||
int fromViewType = getItemType(fromPosition);
|
||||
int toViewType = getItemType(toPosition);
|
||||
|
||||
if (fromPosition < toPosition) {
|
||||
|
||||
if (fromViewType != toViewType) {
|
||||
sDockBarEditHelper.swapAndMigrate(this, fromPosition, toPosition);
|
||||
} else {
|
||||
List<DockBarTab> list = fromViewType == 1 ? sDockBarEditHelper.getSelectedTabs() : sDockBarEditHelper.getDisabledTabs();
|
||||
sDockBarEditHelper.swap(this, list, fromViewType, fromPosition, toPosition);
|
||||
}
|
||||
|
||||
} else if (toPosition != 0) {
|
||||
|
||||
if (fromViewType != toViewType){
|
||||
sDockBarEditHelper.swapAndMigrate(this, fromPosition, toPosition);
|
||||
} else {
|
||||
List<DockBarTab> list = fromViewType == 1 ? sDockBarEditHelper.getSelectedTabs() : sDockBarEditHelper.getDisabledTabs();
|
||||
sDockBarEditHelper.swap(this, list, fromViewType, fromPosition, toPosition);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setItemTouchHelper(ItemTouchHelper itemTouchHelper) {
|
||||
mItemTouchHelper = itemTouchHelper;
|
||||
}
|
||||
|
||||
public int getIndexByViewType(int position, int viewType) {
|
||||
return sDockBarEditHelper.getIndexByViewType(position, viewType);
|
||||
}
|
||||
|
||||
public int getItemType(int position) {
|
||||
return sDockBarEditHelper.getItemType(position);
|
||||
}
|
||||
|
||||
static class DockBarEditViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private LinearLayout mTabContainer;
|
||||
private ImageView mIcon;
|
||||
private TextView mTitle;
|
||||
// private ImageView mMove;
|
||||
|
||||
private TextView mGroupTitle;
|
||||
|
||||
public DockBarEditViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
mTabContainer = itemView.findViewWithTag("tab_item_container");
|
||||
mIcon = itemView.findViewWithTag("icon");
|
||||
mTitle = itemView.findViewWithTag("title");
|
||||
// mMove = itemView.findViewWithTag("move");
|
||||
|
||||
mGroupTitle = itemView.findViewWithTag("group_title");
|
||||
}
|
||||
|
||||
public void bind(DockBarTab tab) {
|
||||
Log.d("guzno", String.format("Bind data: { Icon: %d, Title: %s }", tab.iconID, Helper.GetContext().getString(tab.titleID)));
|
||||
mIcon.setImageResource(tab.iconID);
|
||||
mTitle.setText(tab.titleID);
|
||||
}
|
||||
|
||||
public void bind(String groupTitle) {
|
||||
mGroupTitle.setText(groupTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import me.grishka.appkit.fragments.ToolbarFragment;
|
||||
|
||||
public class DockBarEditFragment extends ToolbarFragment {
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
|
||||
private DockBarEditAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public View d(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
||||
super.b(bundle);
|
||||
|
||||
LinearLayout container = new LinearLayout(n());
|
||||
container.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
|
||||
|
||||
mRecyclerView = new RecyclerView(n());
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(n()));
|
||||
mAdapter = new DockBarEditAdapter();
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
container.addView(mRecyclerView, new LinearLayout.LayoutParams(-1, -1));
|
||||
|
||||
|
||||
|
||||
//ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(mAdapter));
|
||||
//itemTouchHelper.attachToRecyclerView(mRecyclerView);
|
||||
|
||||
//mAdapter.setItemTouchHelper(itemTouchHelper);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void a(View arg0, Bundle arg1) {
|
||||
Log.d("test", "Called onViewCreated method");
|
||||
o_(true);
|
||||
|
||||
super.a(arg0, arg1);
|
||||
|
||||
a("Редактор докбара");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.apps.AppsFragment;
|
||||
import com.vk.discover.DiscoverFeedFragment;
|
||||
import com.vk.menu.MenuFragment;
|
||||
import com.vk.newsfeed.NewsfeedFragment;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.vk.notifications.NotificationsFragment;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.fragments.GamesFragment;
|
||||
import com.vtosters.lite.fragments.PhotosFragment;
|
||||
import com.vtosters.lite.fragments.d.DocumentsViewFragment;
|
||||
import com.vtosters.lite.fragments.f.FriendsFragment;
|
||||
import com.vtosters.lite.fragments.h.GroupsFragment;
|
||||
import com.vtosters.lite.fragments.lives.LivesPostListFragment;
|
||||
import com.vtosters.lite.fragments.m.VideosFragment;
|
||||
import com.vtosters.lite.fragments.messages.dialogs.DialogsFragment;
|
||||
import com.vtosters.lite.fragments.money.MoneyTransfersFragment;
|
||||
|
||||
import ru.vtosters.lite.ui.fragments.MusicFragment;
|
||||
import ru.vtosters.lite.utils.Helper;
|
||||
|
||||
public class DockBarEditHelper {
|
||||
static final int MIN_SELECTED_TABS_LIMIT = 4;
|
||||
static final int MAX_SELECTED_TABS_LIMIT = 8;
|
||||
|
||||
private static DockBarEditHelper sInstance = new DockBarEditHelper();
|
||||
|
||||
public static DockBarEditHelper getInstance() {
|
||||
if (sInstance == null)
|
||||
sInstance = new DockBarEditHelper();
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private List<DockBarTab> mSelectedTabs = new ArrayList<>();
|
||||
private List<DockBarTab> mDisabledTabs = new ArrayList<>();
|
||||
private List<String> mGroups = Arrays.asList(
|
||||
"Выбранные элементы докбара",
|
||||
"Отключённые элементы"
|
||||
);
|
||||
|
||||
public DockBarEditHelper() {
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
File dockbar = new File(Helper.GetContext().getFilesDir(), "dockbar.json");
|
||||
|
||||
// if (!dockbar.exists()) {
|
||||
mSelectedTabs.add(new DockBarTab("tab_news", R.drawable.ic_newsfeed_28, R.string.newsfeed, R.id.tab_news, NewsfeedFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_discover", R.drawable.ic_search_28, R.string.search, R.id.tab_discover, DiscoverFeedFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_messages", R.drawable.ic_menu_messages_28, R.string.messages, R.id.tab_messages, DialogsFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_feedback", R.drawable.ic_menu_notifications_28, R.string.feedback, R.id.tab_feedback, NotificationsFragment.class));
|
||||
mSelectedTabs.add(new DockBarTab("tab_menu",R.drawable.ic_menu_more_28, R.string.menu, R.id.tab_menu, MenuFragment.class));
|
||||
|
||||
mDisabledTabs.add(new DockBarTab("tab_friends", R.drawable.ic_user_24, R.string.friends, R.id.menu_friends, FriendsFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_groups", R.drawable.ic_users_24, R.string.groups, R.id.menu_groups, GroupsFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_photos", R.drawable.ic_camera_24, R.string.photos, R.id.menu_photos, PhotosFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_audios", R.drawable.ic_music_24, R.string.music, R.id.menu_audios, MusicFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_videos", R.drawable.ic_video_24, R.string.videos, R.id.menu_videos, VideosFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_lives", R.drawable.ic_live_filter_24dp, R.string.sett_live, R.id.menu_lives, LivesPostListFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_games", R.drawable.ic_games_24, R.string.games, R.id.menu_games, GamesFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_fave", R.drawable.ic_favorite_24, R.string.fave_community_title, R.id.menu_fave, FriendsFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_documents", R.drawable.ic_document_24, R.string.docs, R.id.menu_documents, DocumentsViewFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_payments", R.drawable.ic_money_transfer_24, R.string.money_transfer_money_transfers, R.id.menu_payments, MoneyTransfersFragment.class));
|
||||
mDisabledTabs.add(new DockBarTab("tab_vk_apps", R.drawable.ic_services_24, R.string.menu_apps, R.id.menu_vk_apps, AppsFragment.class));
|
||||
/*} else {
|
||||
try {
|
||||
JSONObject json = new JSONObject(readFully(new FileInputStream(dockbar)));
|
||||
|
||||
JSONArray selected = json.getJSONArray("selected");
|
||||
for (int i = 0; i < selected.length(); i++) {
|
||||
JSONObject item = selected.getJSONObject(i);
|
||||
DockBarTab tab = new DockBarTab(
|
||||
item.getString("tag"),
|
||||
item.getInt("iconID"),
|
||||
item.getInt("titleID"),
|
||||
item.getInt("resID"),
|
||||
Class.forName(item.getString("fragmentClass"))
|
||||
);
|
||||
mSelectedTabs.add(tab);
|
||||
}
|
||||
|
||||
JSONArray disabled = json.getJSONArray("disabled");
|
||||
for (int i = 0; i < disabled.length(); i++) {
|
||||
JSONObject item = disabled.getJSONObject(i);
|
||||
DockBarTab tab = new DockBarTab(
|
||||
item.getString("tag"),
|
||||
item.getInt("iconID"),
|
||||
item.getInt("titleID"),
|
||||
item.getInt("resID"),
|
||||
Class.forName(item.getString("fragmentClass"))
|
||||
);
|
||||
mDisabledTabs.add(tab);
|
||||
}
|
||||
|
||||
} catch (JSONException | IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private static String readFully(InputStream is) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int len;
|
||||
while ((len = is.read(buffer)) > 0) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
return bos.toString();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
File cache = new File(Helper.GetContext().getFilesDir(), "dockbar.json");
|
||||
|
||||
JSONArray selected = new JSONArray();
|
||||
for (DockBarTab tab : mSelectedTabs) {
|
||||
JSONObject item = new JSONObject()
|
||||
.put("tag", tab.tag)
|
||||
.put("iconID", tab.iconID)
|
||||
.put("titleID", tab.titleID)
|
||||
.put("fragmentClass", tab.fragmentClass.getName());
|
||||
selected.put(item);
|
||||
}
|
||||
|
||||
JSONArray disabled = new JSONArray();
|
||||
for (DockBarTab tab : mDisabledTabs) {
|
||||
JSONObject item = new JSONObject()
|
||||
.put("tag", tab.tag)
|
||||
.put("iconID", tab.iconID)
|
||||
.put("titleID", tab.titleID)
|
||||
.put("fragmentClass", tab.fragmentClass.getName());
|
||||
disabled.put(item);
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("selected", selected).put("disabled", disabled);
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(cache);
|
||||
fos.write(json.toString().getBytes(StandardCharsets.UTF_8));
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void swap(DockBarEditAdapter adapter, List<DockBarTab> list, int itemType, int fromPosition, int toPosition) {
|
||||
int curr = adapter.getIndexByViewType(fromPosition, itemType);
|
||||
int target = adapter.getIndexByViewType(toPosition, itemType);
|
||||
if (fromPosition < toPosition) {
|
||||
for (int i = curr; i < target; i++) {
|
||||
Collections.swap(list, i, i + 1);
|
||||
}
|
||||
} else {
|
||||
for (int i = curr; i > target; i--) {
|
||||
Collections.swap(list, i, i - 1);
|
||||
}
|
||||
}
|
||||
adapter.notifyItemMoved(fromPosition, toPosition);
|
||||
}
|
||||
|
||||
public void swapAndMigrate(DockBarEditAdapter adapter, int fromPosition, int toPosition) {
|
||||
int curr = adapter.getIndexByViewType(fromPosition, adapter.getItemType(fromPosition));
|
||||
int target = adapter.getIndexByViewType(toPosition, adapter.getItemType(toPosition));
|
||||
if (fromPosition < toPosition) {
|
||||
|
||||
if (mSelectedTabs.size() <= MIN_SELECTED_TABS_LIMIT) return;
|
||||
|
||||
DockBarTab tab = mSelectedTabs.get(curr);
|
||||
mSelectedTabs.remove(tab);
|
||||
mDisabledTabs.add(tab);
|
||||
for (int i = mDisabledTabs.size() - 1; i > target; i--) {
|
||||
Collections.swap(mDisabledTabs, i, i - 1);
|
||||
}
|
||||
for (int i = 0; i < target; i++) {
|
||||
Collections.swap(mDisabledTabs, i, i + 1);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (mSelectedTabs.size() >= MAX_SELECTED_TABS_LIMIT) return;
|
||||
|
||||
DockBarTab tab = mDisabledTabs.get(curr);
|
||||
mDisabledTabs.remove(tab);
|
||||
mSelectedTabs.add(tab);
|
||||
for (int i = mSelectedTabs.size() - 1; i > 0; i--) {
|
||||
Collections.swap(mSelectedTabs, i, i - 1);
|
||||
}
|
||||
}
|
||||
adapter.notifyItemMoved(fromPosition, toPosition);
|
||||
}
|
||||
|
||||
public void move(DockBarEditAdapter adapter, int index) {
|
||||
if (getItemType(index) == 1) {
|
||||
DockBarTab item = mSelectedTabs.get(getIndexByViewType(index, 1));
|
||||
|
||||
mSelectedTabs.remove(item);
|
||||
|
||||
mDisabledTabs.add(item);
|
||||
|
||||
for (int i = mDisabledTabs.size() - 1; i > 0; i--) {
|
||||
Collections.swap(mDisabledTabs, i, i - 1);
|
||||
}
|
||||
|
||||
adapter.notifyItemRemoved(index);
|
||||
adapter.notifyItemInserted(getItemCount() - mDisabledTabs.size());
|
||||
}
|
||||
}
|
||||
|
||||
public int getItemCount() {
|
||||
return mSelectedTabs.size() + mDisabledTabs.size() + mGroups.size();
|
||||
}
|
||||
|
||||
public int getIndexByViewType(int position, int viewType) {
|
||||
if (viewType == DockBarEditAdapter.SELECTED_TAB_TYPE) {
|
||||
return position - 1;
|
||||
} else if (viewType == DockBarEditAdapter.DISABLED_TAB_TYPE) {
|
||||
return position - (mSelectedTabs.size() + mGroups.size());
|
||||
} else if (viewType == RecyclerView.INVALID_TYPE){
|
||||
return position != 0 ? 1 : 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public int getItemType(int position) {
|
||||
if (position == 0 || position == mSelectedTabs.size() + 1) {
|
||||
return RecyclerView.INVALID_TYPE;
|
||||
} else if (position - 1 < mSelectedTabs.size()) {
|
||||
return DockBarEditAdapter.SELECTED_TAB_TYPE;
|
||||
} else {
|
||||
return DockBarEditAdapter.DISABLED_TAB_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
public DockBarTab getSelectedTab(int pos) {
|
||||
return mSelectedTabs.get(getIndexByViewType(pos, 1));
|
||||
}
|
||||
|
||||
public DockBarTab getDisabledTab(int pos) {
|
||||
return mDisabledTabs.get(getIndexByViewType(pos, 2));
|
||||
}
|
||||
|
||||
public String getGroupTitle(int pos) {
|
||||
return mGroups.get(getIndexByViewType(pos, -1));
|
||||
}
|
||||
|
||||
public List<DockBarTab> getSelectedTabs() {
|
||||
return mSelectedTabs;
|
||||
}
|
||||
|
||||
public List<DockBarTab> getDisabledTabs() {
|
||||
return mDisabledTabs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
public class DockBarInjector {
|
||||
|
||||
public static DockBarEditHelper sDockBarEditHelper = DockBarEditHelper.getInstance();
|
||||
|
||||
public static void inject() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
public class DockBarTab {
|
||||
|
||||
public String tag;
|
||||
public int iconID;
|
||||
public int titleID;
|
||||
public int resID;
|
||||
public Class<?> fragmentClass;
|
||||
|
||||
public DockBarTab(String tag, int iconID, int titleID, int resID, Class<?> fragmentClass) {
|
||||
this.tag = tag;
|
||||
this.iconID = iconID;
|
||||
this.titleID = titleID;
|
||||
this.resID = resID;
|
||||
this.fragmentClass = fragmentClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
public interface IItemTouchHelper {
|
||||
|
||||
void onItemDismiss(int index);
|
||||
|
||||
boolean onItemMove(int fromPosition, int toPosition);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package ru.vtosters.lite.ui.fragments.dockbar;
|
||||
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class ItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||
|
||||
private DockBarEditAdapter mAdapter;
|
||||
|
||||
public ItemTouchHelperCallback(DockBarEditAdapter mAdapter) {
|
||||
this.mAdapter = mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongPressDragEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemViewSwipeEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
int pos = mAdapter.getItemType(viewHolder.getAdapterPosition());
|
||||
int dragFlags = pos != RecyclerView.INVALID_TYPE ? ItemTouchHelper.UP | ItemTouchHelper.DOWN : 0;
|
||||
int swipeFlags = pos == 1 ? ItemTouchHelper.START | ItemTouchHelper.END : 0;
|
||||
return makeMovementFlags(dragFlags, swipeFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
|
||||
RecyclerView.ViewHolder target) {
|
||||
if (mAdapter.getItemType(viewHolder.getAdapterPosition()) == RecyclerView.INVALID_TYPE)
|
||||
return false;
|
||||
return mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
mAdapter.onItemDismiss(viewHolder.getAdapterPosition());
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@
|
||||
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_READ"/>
|
||||
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_WRITE"/>
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||
<application android:allowBackup="false" android:debuggable="false" android:hardwareAccelerated="true" android:icon="@mipmap/vt_launcher" android:label="@string/app_name" android:largeHeap="true" android:name="com.vtosters.lite.VKApplication" android:networkSecurityConfig="@xml/network_security_config" android:resizeableActivity="true" android:roundIcon="@mipmap/vt_launcher_round" android:supportsRtl="true" android:theme="@style/BaseStyle">
|
||||
<application android:allowBackup="false" android:debuggable="true" android:hardwareAccelerated="true" android:icon="@mipmap/vt_launcher" android:label="@string/app_name" android:largeHeap="true" android:name="com.vtosters.lite.VKApplication" android:networkSecurityConfig="@xml/network_security_config" android:resizeableActivity="true" android:roundIcon="@mipmap/vt_launcher_round" android:supportsRtl="true" android:theme="@style/BaseStyle">
|
||||
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyBlTHhNGPj7ktPWrUo_d4YJs_Sn_zsISZg"/>
|
||||
<meta-data android:name="com.google.android.geo.API_SECRET" android:value="yu6ZAA0OWO3kmr4es7fGtSmiyfk="/>
|
||||
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id"/>
|
||||
|
||||
@@ -853,7 +853,7 @@
|
||||
|
||||
move-result-object v8
|
||||
|
||||
const-class v9, Lru/vtosters/lite/ui BEB;
|
||||
const-class v9, Lru/vtosters/lite/ui/fragments/dockbar/DockBarEditFragment;
|
||||
|
||||
invoke-direct {v5, v6, v7, v8, v9}, Lcom/vtosters/lite/fragments/SettingsListFragment$a;-><init>(IILjava/lang/Object;Ljava/lang/Class;)V
|
||||
|
||||
|
||||
Reference in New Issue
Block a user