Search in sources :

Example 1 with REQUEST_BROWSE_CARDS

use of com.ichi2.anki.DeckPicker.REQUEST_BROWSE_CARDS in project AnkiChinaAndroid by ankichinateam.

the class DeckPicker method onActivityResult.

@SuppressWarnings("deprecation")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    Timber.i("on activity result:%s", requestCode);
    if (requestCode == REQUEST_PATH_UPDATE) {
        // The collection path was inaccessible on startup so just close the activity and let user restart
        finishWithoutAnimation();
    } else if (resultCode == RESULT_MEDIA_EJECTED) {
        this.onSdCardNotMounted();
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    } else if (resultCode == RESULT_UPDATE_REST_SPACE) {
        getAccount().getToken(getBaseContext(), new MyAccount.TokenCallback() {

            @Override
            public void onSuccess(String token) {
                OKHttpUtil.get(Consts.ANKI_CHINA_BASE + Consts.API_VERSION + "clouds/current", token, new Object[] { "nothing", false }, checkRestServerSpaceListener);
            }

            @Override
            public void onFail(String message) {
                handleGetTokenFailed(message);
            }
        });
        return;
    }
    if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(this), 4);
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(this), requestCode == SHOW_INFO_WELCOME ? 2 : 3);
        } else {
            finishWithAnimation(ActivityTransitionAnimation.DOWN);
        }
    } else if (requestCode == LOG_IN_FOR_SYNC) {
        mRefreshVipStateOnResume = true;
        mSyncOnResume = resultCode == RESULT_OK;
    } else if ((requestCode == REQUEST_REVIEW || requestCode == SHOW_STUDYOPTIONS) && resultCode == Reviewer.RESULT_NO_MORE_CARDS) {
        // Show a message when reviewing has finished
        if (getCol().getSched().count() == 0) {
            UIUtils.showSimpleSnackbar(this, R.string.studyoptions_congrats_finished, false);
        } else {
            UIUtils.showSimpleSnackbar(this, R.string.studyoptions_no_cards_due, false);
        }
        refreshDeckListUI(false);
    } else if (requestCode == REQUEST_BROWSE_CARDS) {
        // Store the selected deck after opening browser
        if (intent != null && intent.getBooleanExtra("allDecksSelected", false)) {
            AnkiDroidApp.getSharedPrefs(this).edit().putLong("browserDeckIdFromDeckPicker", -1L).apply();
        } else {
            long selectedDeck = getCol().getDecks().selected();
            AnkiDroidApp.getSharedPrefs(this).edit().putLong("browserDeckIdFromDeckPicker", selectedDeck).apply();
        }
    }
    if (requestCode == BE_VIP || requestCode == REFRESH_LOGIN_STATE_AND_TURN_TO_VIP_HTML || requestCode == SHOW_STUDYOPTIONS || requestCode == CHANGE_ACCOUNT) {
        mRefreshVipStateOnResume = true;
        mSyncOnResume = requestCode == CHANGE_ACCOUNT;
        mTurnToVipHtml = requestCode == REFRESH_LOGIN_STATE_AND_TURN_TO_VIP_HTML;
    } else {
        getSupportFragmentManager().getFragments();
        if (getSupportFragmentManager().getFragments().size() > 0) {
            List<Fragment> fragments = getSupportFragmentManager().getFragments();
            for (Fragment mFragment : fragments) {
                mFragment.onActivityResult(requestCode, resultCode, intent);
            }
        }
    }
}
Also used : SpannableString(android.text.SpannableString) Fragment(androidx.fragment.app.Fragment) AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment)

Example 2 with REQUEST_BROWSE_CARDS

use of com.ichi2.anki.DeckPicker.REQUEST_BROWSE_CARDS in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }
    mStudyOptionsView = inflater.inflate(R.layout.studyoptions_fragment, container, false);
    initOption();
    // we need to restore here, as we need it before super.onCreate() is called.
    // Open Collection on UI thread while splash screen is showing
    mToolbar = mStudyOptionsView.findViewById(R.id.toolbar);
    if (mToolbar != null) {
        mToolbar.inflateMenu(R.menu.study_options_fragment);
        mToolbar.setNavigationOnClickListener(v -> onNavigationPressed());
        // TextView title = mToolbar.findViewById(R.id.toolbar_title);
        // title.setOnClickListener(v -> getAnkiActivity().startActivityForResultWithAnimation(new Intent(getAnkiActivity(), CardBrowser.class), REQUEST_BROWSE_CARDS, ActivityTransitionAnimation.LEFT));
        // title.setVisibility(View.VISIBLE);
        // title.setText("卡牌浏览器");
        mTabLayout = mToolbar.findViewById(R.id.tab_layout);
        TabLayout.Tab tab = mTabLayout.newTab();
        View view = getLayoutInflater().inflate(R.layout.item_deckinfo_tab, null);
        ((TextView) view.findViewById(R.id.name)).setText("学习");
        tab.setCustomView(view);
        mTabLayout.addTab(tab);
        TabLayout.Tab tab2 = mTabLayout.newTab();
        View view2 = getLayoutInflater().inflate(R.layout.item_deckinfo_tab, null);
        ((TextView) view2.findViewById(R.id.name)).setText("笔记");
        tab2.setCustomView(view2);
        mTabLayout.addTab(tab2);
        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab == tab2) {
                    getAnkiActivity().openCardBrowser();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
        configureToolbar();
    }
    // refreshInterface(true);
    // displaySyncBadge();
    // check, if tablet layout
    mStudyoptionsFrame = mStudyOptionsView.findViewById(R.id.studyoptions_fragment);
    // set protected variable from NavigationDrawerActivity
    // mFragmented = mStudyoptionsFrame != null && mStudyoptionsFrame.getVisibility() == View.VISIBLE;
    mFragmented = false;
    if (mFragmented) {
        loadStudyOptionsFragment(false);
    }
    mRecyclerView = mStudyOptionsView.findViewById(R.id.files);
    // mNoDecksPlaceholder.setVisibility(View.GONE);
    // specify a LinearLayoutManager and set up item dividers for the RecyclerView
    mRecyclerViewLayoutManager = new LinearLayoutManager(getAnkiActivity());
    mRecyclerView.setLayoutManager(mRecyclerViewLayoutManager);
    TypedArray ta = getContext().obtainStyledAttributes(new int[] { R.attr.deckDivider });
    Drawable divider = ta.getDrawable(0);
    ta.recycle();
    // DividerItemDecoration dividerDecorator = new DividerItemDecoration(getAnkiActivity(), mRecyclerViewLayoutManager.getOrientation());
    // dividerDecorator.setDrawable(divider);
    // 
    // mRecyclerView.addItemDecoration(dividerDecorator);
    // create and set an adapter for the RecyclerView
    mDeckListAdapter = new DeckInfoListAdapter(getLayoutInflater(), getAnkiActivity());
    mDeckListAdapter.setDeckClickListener(mDeckClickListener);
    mDeckListAdapter.setCountsClickListener(mCountsClickListener);
    mDeckListAdapter.setDeckExpanderClickListener(mDeckExpanderClickListener);
    mDeckListAdapter.setDeckLongClickListener(mDeckLongClickListener);
    mRecyclerView.setAdapter(mDeckListAdapter);
    mNoSubDeckHint = mStudyOptionsView.findViewById(R.id.text_no_child);
    mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    return mStudyOptionsView;
}
Also used : TabLayout(com.google.android.material.tabs.TabLayout) TypedArray(android.content.res.TypedArray) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) DeckInfoListAdapter(com.ichi2.anki.widgets.DeckInfoListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable)

Aggregations

TypedArray (android.content.res.TypedArray)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 Fragment (androidx.fragment.app.Fragment)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 TabLayout (com.google.android.material.tabs.TabLayout)1 AsyncDialogFragment (com.ichi2.anki.dialogs.AsyncDialogFragment)1 DeckInfoListAdapter (com.ichi2.anki.widgets.DeckInfoListAdapter)1