Commit 961e0703 authored by wangfugui's avatar wangfugui

在卡组选择的dialog中添加tab

parent 7b5ef321
package cn.garymb.ygomobile.deck_square;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import cn.garymb.ygomobile.lite.R;
public class DeckManageDialog extends DialogFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.dialog_deck_manager, container, false);
}
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ViewPager2 viewPager = view.findViewById(R.id.deck_view_pager);
TabLayout tabLayout = view.findViewById(R.id.deck_manager_tab_layout);
// Setup adapter
ViewPagerAdapter adapter = new ViewPagerAdapter(this);
viewPager.setAdapter(adapter);
// Connect TabLayout with ViewPager
new TabLayoutMediator(tabLayout, viewPager,
new TabLayoutMediator.TabConfigurationStrategy() {
@Override
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
tab.setText("Tab " + (position + 1));
}
}).attach();
}
@Override
public void onStart() {
super.onStart();
// Set dialog dimensions
Window window = getDialog().getWindow();
if (window != null) {
window.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
}
}
private static class ViewPagerAdapter extends FragmentStateAdapter {
public ViewPagerAdapter(@NonNull Fragment fragment) {
super(fragment);
}
@NonNull
@Override
public Fragment createFragment(int position) {
switch (position) {
case 0:
return new DeckSelectFragment();
case 1:
return new DeckSquareFragment();
case 2:
return new DeckSquareMyDeckFragment();
default:
throw new IllegalArgumentException();
}
}
@Override
public int getItemCount() {
return 3;
}
}
}
\ No newline at end of file
package cn.garymb.ygomobile.deck_square;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.FastScrollLinearLayoutManager;
import cn.garymb.ygomobile.lite.databinding.FragmentDeckSelectBinding;
//卡组选择的Fragment,选择后在卡组编辑页面中显示卡片
public class DeckSelectFragment extends Fragment {
private FragmentDeckSelectBinding binding;
private static final String TAG = DeckSquareListAdapter.class.getSimpleName();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentDeckSelectBinding.inflate(inflater, container, false);
binding.rvDeck.setLayoutManager(new FastScrollLinearLayoutManager(getContext()));
binding.rvType.setLayoutManager(new FastScrollLinearLayoutManager(getContext()));
binding.rvResultList.setLayoutManager(new FastScrollLinearLayoutManager(getContext()));
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
}
...@@ -75,6 +75,7 @@ import cn.garymb.ygomobile.bean.DeckType; ...@@ -75,6 +75,7 @@ import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.CardInfoEvent; import cn.garymb.ygomobile.bean.events.CardInfoEvent;
import cn.garymb.ygomobile.bean.events.DeckFile; import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.core.IrrlichtBridge; import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.deck_square.DeckManageDialog;
import cn.garymb.ygomobile.deck_square.DeckSquareActivity; import cn.garymb.ygomobile.deck_square.DeckSquareActivity;
import cn.garymb.ygomobile.deck_square.DeckSquareApiUtil; import cn.garymb.ygomobile.deck_square.DeckSquareApiUtil;
import cn.garymb.ygomobile.deck_square.DeckSquareFileUtil; import cn.garymb.ygomobile.deck_square.DeckSquareFileUtil;
...@@ -207,7 +208,14 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte ...@@ -207,7 +208,14 @@ public class DeckManagerFragment extends BaseFragemnt implements RecyclerViewIte
layoutView.findViewById(R.id.btn_nav_list).setOnClickListener((v) -> doMenu(R.id.action_card_list)); layoutView.findViewById(R.id.btn_nav_list).setOnClickListener((v) -> doMenu(R.id.action_card_list));
layoutView.findViewById(R.id.open_deck_square).setOnClickListener((v) -> doMenu(R.id.open_deck_square)); layoutView.findViewById(R.id.open_deck_square).setOnClickListener((v) -> doMenu(R.id.open_deck_square));
tv_deck.setOnClickListener(v -> tv_deck.setOnClickListener(v ->
YGODeckDialogUtil.dialogDeckSelect(getActivity(), AppsSettings.get().getLastDeckPath(), this)); {
new DeckManageDialog().show(
getActivity().getSupportFragmentManager(),
"pagerDialog"
);
}
);
// YGODeckDialogUtil.dialogDeckSelect(getActivity(), AppsSettings.get().getLastDeckPath(), this));
mContext = (BaseActivity) getActivity(); mContext = (BaseActivity) getActivity();
} }
......
...@@ -38,10 +38,12 @@ import cn.garymb.ygomobile.Constants; ...@@ -38,10 +38,12 @@ import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.DeckType; import cn.garymb.ygomobile.bean.DeckType;
import cn.garymb.ygomobile.bean.events.DeckFile; import cn.garymb.ygomobile.bean.events.DeckFile;
import cn.garymb.ygomobile.deck_square.DeckSquareApiUtil; import cn.garymb.ygomobile.deck_square.DeckSquareApiUtil;
import cn.garymb.ygomobile.deck_square.DeckSquareTabAdapter;
import cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse; import cn.garymb.ygomobile.deck_square.api_response.MyDeckResponse;
import cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail; import cn.garymb.ygomobile.deck_square.api_response.MyOnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.OnlineDeckDetail; import cn.garymb.ygomobile.deck_square.api_response.OnlineDeckDetail;
import cn.garymb.ygomobile.deck_square.api_response.SquareDeckResponse; import cn.garymb.ygomobile.deck_square.api_response.SquareDeckResponse;
import cn.garymb.ygomobile.ex_card.ExPackageTabAdapter;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.adapters.DeckListAdapter; import cn.garymb.ygomobile.ui.adapters.DeckListAdapter;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter; import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
...@@ -98,8 +100,8 @@ public class YGODeckDialogUtil { ...@@ -98,8 +100,8 @@ public class YGODeckDialogUtil {
ViewHolder viewHolder = new ViewHolder(context, selectDeckPath, onDeckMenuListener); ViewHolder viewHolder = new ViewHolder(context, selectDeckPath, onDeckMenuListener);
viewHolder.show(); viewHolder.show();
} }
private DeckSquareTabAdapter adapter;
//注册listener,发生点击卡组事件后,通知主界面进行对应的显示更新
public interface OnDeckMenuListener { public interface OnDeckMenuListener {
void onDeckSelect(DeckFile deckFile); void onDeckSelect(DeckFile deckFile);
...@@ -154,7 +156,7 @@ public class YGODeckDialogUtil { ...@@ -154,7 +156,7 @@ public class YGODeckDialogUtil {
*/ */
public ViewHolder(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) { public ViewHolder(Context context, String selectDeckPath, OnDeckMenuListener onDeckMenuListener) {
ygoDialog = new DialogPlus(context); ygoDialog = new DialogPlus(context);
ygoDialog.setContentView(R.layout.dialog_deck_select); ygoDialog.setContentView(R.layout.fragment_deck_select);
ygoDialog.setTitle(R.string.category_manager); ygoDialog.setTitle(R.string.category_manager);
allDeckList = new ArrayList<>(); allDeckList = new ArrayList<>();
......
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg3"> android:background="@drawable/bg3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa000000" />
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" android:id="@+id/appbar"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:paddingBottom="5dp">
<com.google.android.material.tabs.TabLayout
android:id="@+id/deck_manager_tab_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/deck_view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
...@@ -24,19 +24,24 @@ ...@@ -24,19 +24,24 @@
android:orientation="horizontal" android:orientation="horizontal"
android:weightSum="1"> android:weightSum="1">
<Button <LinearLayout
android:id="@+id/refresh_data" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="right|bottom" android:orientation="horizontal">
android:text="刷新"></Button>
<!-- <Button <Button
android:id="@+id/upload_deck" android:id="@+id/refresh_data"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center|bottom" android:layout_gravity="right|bottom"
android:text="上传卡组"></Button>--> android:text="刷新"></Button>
</LinearLayout>
<!-- <Button
android:id="@+id/upload_deck"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center|bottom"
android:text="上传卡组"></Button>-->
</FrameLayout> </FrameLayout>
<!--<com.google.android.material.floatingactionbutton.FloatingActionButton <!--<com.google.android.material.floatingactionbutton.FloatingActionButton
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment