Search in sources :

Example 11 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class FilteredDeckOptions method onCreate.

@Override
// Tracked as #5019 on github
@SuppressWarnings("deprecation")
protected void onCreate(Bundle icicle) {
    Themes.setThemeLegacy(this);
    super.onCreate(icicle);
    UsageAnalytics.sendAnalyticsScreenView(this);
    mCol = CollectionHelper.getInstance().getCol(this);
    if (mCol == null) {
        finish();
        return;
    }
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("did")) {
        mDeck = mCol.getDecks().get(extras.getLong("did"));
    } else {
        mDeck = mCol.getDecks().current();
    }
    registerExternalStorageListener();
    if (mCol == null || mDeck.getInt("dyn") != 1) {
        Timber.w("No Collection loaded or deck is not a dyn deck");
        finish();
        return;
    } else {
        mPref = new DeckPreferenceHack();
        mPref.registerOnSharedPreferenceChangeListener(this);
        this.addPreferencesFromResource(R.xml.cram_deck_options);
        this.buildLists();
        this.updateSummaries();
    }
    // Set the activity title to include the name of the deck
    String title = getResources().getString(R.string.deckpreferences_title);
    if (title.contains("XXX")) {
        try {
            title = title.replace("XXX", mDeck.getString("name"));
        } catch (JSONException e) {
            title = title.replace("XXX", "???");
        }
    }
    this.setTitle(title);
    // Add a home button to the actionbar
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Also used : Bundle(android.os.Bundle) JSONException(com.ichi2.utils.JSONException)

Example 12 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class DeckOptions method getOptionsGroupCount.

/**
 * Returns the number of decks using the options group of the current deck.
 */
private int getOptionsGroupCount() {
    int count = 0;
    long conf = mDeck.getLong("conf");
    for (Deck deck : mCol.getDecks().all()) {
        if (deck.getInt("dyn") == 1) {
            continue;
        }
        if (deck.getLong("conf") == conf) {
            count++;
        }
    }
    return count;
}
Also used : Deck(com.ichi2.libanki.Deck)

Example 13 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class DeckPicker method repairCollection.

// Callback method to handle repairing deck
public void repairCollection() {
    Timber.i("Repairing the Collection");
    TaskListener listener = repairCollectionTask();
    CollectionTask.launchCollectionTask(REPAIR_COLLECTION, listener);
}
Also used : TaskListener(com.ichi2.async.TaskListener)

Example 14 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK 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 15 with DECK

use of com.ichi2.anki.CardBrowser.Column.DECK in project AnkiChinaAndroid by ankichinateam.

the class DeckPicker method showBottomDialog.

private void showBottomDialog(MenuItem item) {
    if (!Permissions.hasStorageAccessPermission(this)) {
        firstCollectionOpen();
        return;
    }
    // 1、使用Dialog、设置style
    if (addMenuBottomDialog == null) {
        addMenuBottomDialog = new Dialog(this, R.style.DialogTheme);
        // 2、设置布局
        View view = View.inflate(this, R.layout.dialog_bottom, null);
        addMenuBottomDialog.setContentView(view);
        addMenuBottomDialog.setOnDismissListener(dialog1 -> item.setIcon(R.mipmap.tab_bar_add_selected));
        Window window = addMenuBottomDialog.getWindow();
        // addMenuBottomDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
        // 设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        WindowManager.LayoutParams lps = window.getAttributes();
        lps.verticalMargin = 0.1f;
        window.setAttributes(lps);
        // 设置弹出动画
        // window.setWindowAnimations(R.style.main_menu_animStyle);
        // 设置对话框大小
        final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 69, displayMetrics));
        addMenuBottomDialog.findViewById(R.id.ll_add_card).setOnClickListener(view1 -> {
            addMenuBottomDialog.dismiss();
            Timber.i("Adding Note");
            addNote();
        });
        addMenuBottomDialog.findViewById(R.id.ll_add_deck).setOnClickListener(view1 -> {
            addMenuBottomDialog.dismiss();
            mDialogEditText = new EditText(this);
            mDialogEditText.setSingleLine(true);
            // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter });
            new MaterialDialog.Builder(this).title(R.string.new_deck).positiveText(R.string.dialog_ok).customView(mDialogEditText, true).onPositive((dialog, which) -> {
                String deckName = mDialogEditText.getText().toString();
                if (Decks.isValidDeckName(deckName)) {
                    createNewDeck(deckName);
                } else {
                    Timber.i("configureFloatingActionsMenu::addDeckButton::onPositiveListener - Not creating invalid deck name '%s'", deckName);
                    UIUtils.showThemedToast(this, getString(R.string.invalid_deck_name), false);
                }
            }).negativeText(R.string.dialog_cancel).show();
        });
    }
    if (addMenuBottomDialog.isShowing()) {
        addMenuBottomDialog.dismiss();
        return;
    }
    item.setIcon(R.mipmap.tab_bar_add_normal);
    addMenuBottomDialog.show();
}
Also used : Window(android.view.Window) EditText(android.widget.EditText) ColorDrawable(android.graphics.drawable.ColorDrawable) DeckPickerBackupNoSpaceLeftDialog(com.ichi2.anki.dialogs.DeckPickerBackupNoSpaceLeftDialog) DeckPickerExportCompleteDialog(com.ichi2.anki.dialogs.DeckPickerExportCompleteDialog) Dialog(android.app.Dialog) DeckPickerNoSpaceLeftDialog(com.ichi2.anki.dialogs.DeckPickerNoSpaceLeftDialog) ExportDialog(com.ichi2.anki.dialogs.ExportDialog) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) DatabaseErrorDialog(com.ichi2.anki.dialogs.DatabaseErrorDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DeckPickerAnalyticsOptInDialog(com.ichi2.anki.dialogs.DeckPickerAnalyticsOptInDialog) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) SyncErrorDialog(com.ichi2.anki.dialogs.SyncErrorDialog) MediaCheckDialog(com.ichi2.anki.dialogs.MediaCheckDialog) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) NavigationBarItemView(com.google.android.material.navigation.NavigationBarItemView) View(android.view.View) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) TextView(android.widget.TextView) BottomNavigationMenuView(com.google.android.material.bottomnavigation.BottomNavigationMenuView) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager)

Aggregations

Deck (com.ichi2.libanki.Deck)100 Collection (com.ichi2.libanki.Collection)97 JSONObject (com.ichi2.utils.JSONObject)88 Test (org.junit.Test)80 JSONArray (com.ichi2.utils.JSONArray)55 Card (com.ichi2.libanki.Card)53 Note (com.ichi2.libanki.Note)50 ArrayList (java.util.ArrayList)47 RobolectricTest (com.ichi2.anki.RobolectricTest)44 DeckConfig (com.ichi2.libanki.DeckConfig)37 JSONException (com.ichi2.utils.JSONException)34 NonNull (androidx.annotation.NonNull)30 HashMap (java.util.HashMap)29 Model (com.ichi2.libanki.Model)23 Map (java.util.Map)22 Intent (android.content.Intent)21 Resources (android.content.res.Resources)18 TextView (android.widget.TextView)18 SharedPreferences (android.content.SharedPreferences)17 Cursor (android.database.Cursor)17