endian11
2020-09-21 8eef2d05a5e785ec0728e9ccbf8f9c4f672409cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package safeluck.drive.evaluation.fragment.shop;
 
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
 
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
 
import java.util.ArrayList;
import java.util.Arrays;
 
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.bean.SysExamSettingLargeMenu;
 
/**
 * Created by YoKeyword on 16/2/4.
 */
public class ShopFragment extends SupportFragment {
    public static final String TAG = ShopFragment.class.getSimpleName();
    private static final String ARG_MENU = "arg_menu_large";
    private Toolbar mToolbar;
    private SysExamSettingLargeMenu mMenu;
 
    public static ShopFragment newInstance(SysExamSettingLargeMenu sysExamSettingLargeMenu) {
        Bundle args = new Bundle();
        args.putParcelable(ARG_MENU,sysExamSettingLargeMenu);
        ShopFragment fragment = new ShopFragment();
        fragment.setArguments(args);
        return fragment;
    }
 
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_shop, container, false);
        initView(view, savedInstanceState);
        return view;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        Bundle args = getArguments();
        if (args != null) {
            mMenu = args.getParcelable(ARG_MENU);
        }
    }
 
    private void initView(View view, Bundle savedInstanceState) {
        mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
 
        mToolbar.setTitle(mMenu.getMenuName());
        initToolbarNav(mToolbar);
 
        if (findChildFragment(MenuListFragment.class) == null) {
            ArrayList<String> listMenus = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.array_exam_rule_menu)));
            MenuListFragment menuListFragment = MenuListFragment.newInstance(listMenus);
            loadRootFragment(R.id.fl_list_container, menuListFragment);
            // false:  不加入回退栈;  false: 不显示动画
            loadRootFragment(R.id.fl_content_container, ContentFragment.newInstance(listMenus.get(0)), false, false);
        }
    }
 
    @Override
    public boolean onBackPressedSupport() {
        // ContentFragment是ShopFragment的栈顶子Fragment,会先调用ContentFragment的onBackPressedSupport方法
        Toast.makeText(_mActivity, "onBackPressedSupport-->return false, 上层处理"  , Toast.LENGTH_SHORT).show();
        return false;
    }
 
    /**
     * 替换加载 内容Fragment
     *
     * @param fragment
     */
    public void switchContentFragment(ContentFragment fragment) {
        SupportFragment contentFragment = findChildFragment(ContentFragment.class);
        if (contentFragment != null) {
            contentFragment.replaceFragment(fragment, false);
        }
    }
    protected void initToolbarNav(Toolbar toolbar) {
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop();
            }
        });
    }
}