Search in sources :

Example 1 with TAB_MAIN_STATE

use of com.ichi2.anki.SelfStudyActivity.TAB_MAIN_STATE in project AnkiChinaAndroid by ankichinateam.

the class SelfStudyActivity method showScreenDialog.

private void showScreenDialog() {
    InputMethodManager manager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
    if (manager != null && getCurrentFocus() != null) {
        manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
    View dialog = getLayoutInflater().inflate(R.layout.pop_window_screen_self_study, null);
    mPopupWindow = new PopupWindow(dialog, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    TextView studyTitle = dialog.findViewById(R.id.memory_title);
    TextView markTitle = dialog.findViewById(R.id.mark_title);
    TextView answerTitle = dialog.findViewById(R.id.answer_title);
    WarpLinearLayout studyLayout = dialog.findViewById(R.id.memory_layout);
    WarpLinearLayout markLayout = dialog.findViewById(R.id.mark_layout);
    WarpLinearLayout answerLayout = dialog.findViewById(R.id.answer_layout);
    studyLayout.setVisibility(mTabType != TAB_MARK_STATE && mTabType != TAB_ANSWER_STATE ? View.VISIBLE : View.GONE);
    studyTitle.setVisibility(studyLayout.getVisibility());
    markLayout.setVisibility(View.VISIBLE);
    markTitle.setVisibility(View.VISIBLE);
    answerLayout.setVisibility(mTabType != TAB_MARK_STATE && mTabType != TAB_STUDY_STATE ? View.VISIBLE : View.GONE);
    answerTitle.setVisibility(answerLayout.getVisibility());
    List<Button> studyButtonList = new ArrayList<>();
    for (int i = 0; i < mArrayStudy.length; i++) {
        View view = getLayoutInflater().inflate(R.layout.item_warp, null);
        Button button = view.findViewById(R.id.text);
        button.setSelected(mSelectedStudyButtonList.contains(i));
        button.setText(mArrayStudy[i]);
        button.setTag(i);
        button.setOnClickListener(v -> {
            if ((Integer) v.getTag() == 0) {
                for (int m = 1; m < studyButtonList.size(); m++) {
                    if (mSelectedStudyButtonList.contains(m)) {
                        mSelectedStudyButtonList.remove((Object) m);
                    }
                    studyButtonList.get(m).setSelected(false);
                }
            } else {
                studyButtonList.get(0).setSelected(false);
                if (mSelectedStudyButtonList.contains(0)) {
                    mSelectedStudyButtonList.remove((Object) 0);
                }
            }
            if (mSelectedStudyButtonList.contains(v.getTag())) {
                mSelectedStudyButtonList.remove(v.getTag());
            } else {
                mSelectedStudyButtonList.add((Integer) v.getTag());
            }
            v.setSelected(!v.isSelected());
        });
        studyButtonList.add(button);
        studyLayout.addView(view);
    }
    List<Button> markButtonList = new ArrayList<>();
    for (int i = 0; i < mArrayMark.length; i++) {
        View view = getLayoutInflater().inflate(R.layout.item_warp, null);
        Button button = view.findViewById(R.id.text);
        button.setSelected(mSelectedMarkButtonList.contains(i));
        button.setText(mArrayMark[i]);
        button.setTag(i);
        button.setOnClickListener(v -> {
            if ((Integer) v.getTag() == 0) {
                for (int m = 1; m < markButtonList.size(); m++) {
                    if (mSelectedMarkButtonList.contains(m)) {
                        mSelectedMarkButtonList.remove((Object) m);
                    }
                    markButtonList.get(m).setSelected(false);
                }
            } else {
                markButtonList.get(0).setSelected(false);
                if (mSelectedMarkButtonList.contains(0)) {
                    mSelectedMarkButtonList.remove((Object) 0);
                }
            }
            if (mSelectedMarkButtonList.contains(v.getTag())) {
                mSelectedMarkButtonList.remove(v.getTag());
            } else {
                mSelectedMarkButtonList.add((Integer) v.getTag());
            }
            v.setSelected(!v.isSelected());
        });
        markButtonList.add(button);
        markLayout.addView(view);
    }
    List<Button> answerButtonList = new ArrayList<>();
    for (int i = 0; i < mArrayAnswer.length; i++) {
        View view = getLayoutInflater().inflate(R.layout.item_warp, null);
        Button button = view.findViewById(R.id.text);
        button.setSelected(mSelectedAnswerButtonList.contains(i));
        button.setText(mArrayAnswer[i]);
        button.setTag(i);
        button.setOnClickListener(v -> {
            if ((Integer) v.getTag() == 0) {
                for (int m = 1; m < answerButtonList.size(); m++) {
                    if (mSelectedAnswerButtonList.contains(m)) {
                        mSelectedAnswerButtonList.remove((Object) m);
                    }
                    answerButtonList.get(m).setSelected(false);
                }
            } else {
                answerButtonList.get(0).setSelected(false);
                if (mSelectedAnswerButtonList.contains(0)) {
                    mSelectedAnswerButtonList.remove((Object) 0);
                }
            }
            if (mSelectedAnswerButtonList.contains(v.getTag())) {
                mSelectedAnswerButtonList.remove(v.getTag());
            } else {
                mSelectedAnswerButtonList.add((Integer) v.getTag());
            }
            v.setSelected(!v.isSelected());
        });
        answerButtonList.add(button);
        answerLayout.addView(view);
    }
    RangeSeekBar answerTimesSeekBar = dialog.findViewById(R.id.answer_times_seek_bar);
    answerTimesSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {

        @Override
        public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
            if (mTabType == TAB_CUSTOM_STATE) {
                ((TextView) dialog.findViewById(R.id.answer_times_num)).setText(leftValue == answerTimesSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "最近%.0f天", leftValue));
            } else {
                ((TextView) dialog.findViewById(R.id.answer_times_num)).setText(String.format(Locale.CHINA, "最近%.0f天", leftValue));
            }
            if (leftValue == answerTimesSeekBar.getMaxProgress()) {
                mRangeSearchAnswerFilter = "";
            } else {
                mRangeSearchAnswerFilter = String.format(Locale.CHINA, "(rated:%.0f)", leftValue);
            }
        }

        @Override
        public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }

        @Override
        public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }
    });
    answerTimesSeekBar.setRange(0, mTabType == TAB_CUSTOM_STATE ? 31 : 30);
    answerTimesSeekBar.setProgress(mTabType == TAB_CUSTOM_STATE ? 31 : 30);
    RangeSeekBar createTimeSeekBar = dialog.findViewById(R.id.create_time_seek_bar);
    createTimeSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {

        @Override
        public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
            ((TextView) dialog.findViewById(R.id.create_time_num)).setText(leftValue == createTimeSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "最近%.0f天", leftValue));
            if (leftValue == createTimeSeekBar.getMaxProgress()) {
                mRangeCreateTimeFilter = "";
            } else {
                mRangeCreateTimeFilter = String.format(Locale.CHINA, "(added:%.0f)", leftValue);
            }
        }

        @Override
        public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }

        @Override
        public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }
    });
    createTimeSeekBar.setRange(0, 366);
    createTimeSeekBar.setProgress(366);
    dialog.findViewById(R.id.answer_times_seek_layout).setVisibility(mTabType == TAB_ANSWER_STATE || mTabType == TAB_CUSTOM_STATE || mTabType == TAB_MAIN_STATE ? View.VISIBLE : View.GONE);
    RangeSeekBar reviewTimesSeekBar = dialog.findViewById(R.id.review_times_seek_bar);
    reviewTimesSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {

        @Override
        public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
            String rightStr = rightValue == reviewTimesSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "%.0f", rightValue);
            ((TextView) dialog.findViewById(R.id.review_times_num)).setText(String.format(Locale.CHINA, "%.0f-%s", leftValue, rightStr));
            if (rightValue == reviewTimesSeekBar.getMaxProgress()) {
                if (leftValue > 0) {
                    mRangeSearchReviewTimesFilter = String.format(Locale.CHINA, "(prop:reps>=%.0f)", leftValue);
                } else {
                    mRangeSearchReviewTimesFilter = "";
                }
            } else {
                mRangeSearchReviewTimesFilter = String.format(Locale.CHINA, "(prop:reps>=%.0f prop:reps<=%.0f)", leftValue, rightValue);
            }
        }

        @Override
        public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }

        @Override
        public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }
    });
    reviewTimesSeekBar.setRange(0, 20);
    reviewTimesSeekBar.setProgress(0, 20);
    RangeSeekBar forgetTimesSeekBar = dialog.findViewById(R.id.forget_times_seek_bar);
    forgetTimesSeekBar.setOnRangeChangedListener(new OnRangeChangedListener() {

        @Override
        public void onRangeChanged(RangeSeekBar view, float leftValue, float rightValue, boolean isFromUser) {
            String rightStr = rightValue == forgetTimesSeekBar.getMaxProgress() ? "不限" : String.format(Locale.CHINA, "%.0f", rightValue);
            ((TextView) dialog.findViewById(R.id.forget_times_num)).setText(String.format(Locale.CHINA, "%.0f-%s", leftValue, rightStr));
            if (rightValue == forgetTimesSeekBar.getMaxProgress()) {
                if (leftValue > 0) {
                    mRangeSearchForgetTimesFilter = String.format(Locale.CHINA, "(prop:lapses>=%.0f)", leftValue);
                } else {
                    mRangeSearchForgetTimesFilter = "";
                }
            } else {
                mRangeSearchForgetTimesFilter = String.format(Locale.CHINA, "(prop:lapses>=%.0f prop:lapses<=%.0f)", leftValue, rightValue);
            }
        }

        @Override
        public void onStartTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }

        @Override
        public void onStopTrackingTouch(RangeSeekBar view, boolean isLeft) {
        }
    });
    forgetTimesSeekBar.setRange(0, 10);
    forgetTimesSeekBar.setProgress(0, 10);
    Spinner deck_spinner = dialog.findViewById(R.id.deck_spinner);
    deck_spinner.setAdapter(mDropDownDeckAdapter);
    deck_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mSelectedDropDownDeckPosition = position;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // do nothing
        }
    });
    deck_spinner.setSelection(mSelectedDropDownDeckPosition);
    RelativeLayout tag_spinner = dialog.findViewById(R.id.tag_spinner);
    tag_spinner.setVisibility(mTabType == TAB_CUSTOM_STATE || mTabType == TAB_MAIN_STATE ? View.VISIBLE : View.GONE);
    TextView tag_selected = dialog.findViewById(R.id.tag_selected);
    tag_spinner.setOnClickListener(v -> showTagsDialog(tag_selected));
    Button reset = dialog.findViewById(R.id.reset);
    Button confirm = dialog.findViewById(R.id.confirm);
    reset.setOnClickListener(v -> {
        resetFilter();
        // 重置卡组选择
        deck_spinner.setSelection(mSelectedDropDownDeckPosition);
        for (int i = 1; i < studyLayout.getChildCount(); i++) {
            studyLayout.getChildAt(i).setSelected(false);
        }
        for (int i = 1; i < markLayout.getChildCount(); i++) {
            markLayout.getChildAt(i).setSelected(false);
        }
        for (int i = 1; i < answerLayout.getChildCount(); i++) {
            answerLayout.getChildAt(i).setSelected(false);
        }
        switch(mTabType) {
            case TAB_STUDY_STATE:
                studyLayout.getChildAt(1).performClick();
                break;
            case TAB_MARK_STATE:
                markLayout.getChildAt(1).performClick();
                break;
            case TAB_ANSWER_STATE:
                answerLayout.getChildAt(1).performClick();
                break;
            case TAB_CUSTOM_STATE:
            case TAB_MAIN_STATE:
                break;
        }
        forgetTimesSeekBar.setProgress(0, 10);
        reviewTimesSeekBar.setProgress(0, 20);
        answerTimesSeekBar.setProgress(mTabType == TAB_CUSTOM_STATE || mTabType == TAB_MAIN_STATE ? 31 : 30);
    });
    confirm.setOnClickListener(v -> {
        if (mTabType == TAB_MAIN_STATE) {
            for (int i = 0; i < mTabLayout.getTabCount(); i++) {
                mTabLayout.getTabAt(i).getCustomView().setSelected(false);
            }
        } else if (mTabType != TAB_CUSTOM_STATE) {
            mTabLayout.getTabAt(mSelectedTabIndex - 1).getCustomView().setSelected(false);
        }
        mRestrictOnTab = "";
        // 标签选择
        updateTagsSearchTerms();
        // 卡牌选择
        deckDropDownItemChanged(mSelectedDropDownDeckPosition);
        // 按钮选择
        updateButtonFilter();
        mPopupWindow.dismiss();
        searchCards();
    });
    mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    mPopupWindow.setOutsideTouchable(false);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOnDismissListener(() -> findViewById(R.id.shadeView).setVisibility(View.GONE));
    mPopupWindow.showAsDropDown(mToolbar, 0, 0);
    findViewById(R.id.shadeView).setVisibility(View.VISIBLE);
}
Also used : RangeSeekBar(com.jaygoo.widget.RangeSeekBar) OnRangeChangedListener(com.jaygoo.widget.OnRangeChangedListener) Spinner(android.widget.Spinner) ListPopupWindow(androidx.appcompat.widget.ListPopupWindow) PopupWindow(android.widget.PopupWindow) ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) WarpLinearLayout(com.ichi2.ui.WarpLinearLayout) ImageView(android.widget.ImageView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Button(android.widget.Button) RelativeLayout(android.widget.RelativeLayout) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) TextView(android.widget.TextView)

Example 2 with TAB_MAIN_STATE

use of com.ichi2.anki.SelfStudyActivity.TAB_MAIN_STATE in project AnkiChinaAndroid by ankichinateam.

the class SelfStudyActivity method initTabLayout.

private void initTabLayout() {
    // mTabLayout.setTabMode(TabLayout.MODE_FIXED);
    LinearLayout linearLayout = (LinearLayout) mTabLayout.getChildAt(0);
    linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    linearLayout.setDividerDrawable(ContextCompat.getDrawable(this, // 设置分割线的样式
    R.drawable.divider_vertical));
    // 设置分割线间隔
    linearLayout.setDividerPadding((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18, getResources().getDisplayMetrics()));
    mTabLayout.removeAllTabs();
    if (mTabType == TAB_MAIN_STATE) {
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
    switch(mTabType) {
        case TAB_STUDY_STATE:
            addTab(mArrayStudy, mSelectedStudyButtonList);
            break;
        case TAB_MARK_STATE:
            addTab(mArrayMark, mSelectedMarkButtonList);
            break;
        case TAB_ANSWER_STATE:
            addTab(mArrayAnswer, mSelectedAnswerButtonList);
            break;
        case TAB_MAIN_STATE:
            addTab(mArrayMain, mSelectedMainButtonList);
            break;
        case TAB_CUSTOM_STATE:
            mTabLayout.setVisibility(View.GONE);
            new Handler().postDelayed(this::showScreenDialog, 500);
            break;
    }
    if (mTabType != TAB_CUSTOM_STATE) {
        Objects.requireNonNull(mTabLayout.getTabAt(0)).getCustomView().performClick();
    }
}
Also used : Handler(android.os.Handler) WarpLinearLayout(com.ichi2.ui.WarpLinearLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

WarpLinearLayout (com.ichi2.ui.WarpLinearLayout)2 Handler (android.os.Handler)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 PopupWindow (android.widget.PopupWindow)1 RelativeLayout (android.widget.RelativeLayout)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 ListPopupWindow (androidx.appcompat.widget.ListPopupWindow)1 SearchView (androidx.appcompat.widget.SearchView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 OnRangeChangedListener (com.jaygoo.widget.OnRangeChangedListener)1 RangeSeekBar (com.jaygoo.widget.RangeSeekBar)1 ArrayList (java.util.ArrayList)1