Search in sources :

Example 31 with Models

use of com.ichi2.libanki.Models in project Anki-Android by Ramblurr.

the class NoteService method updateJsonNoteFromMultimediaNote.

/**
 * Updates the JsonNote field values from MultimediaEditableNote When both notes are using the same Model, it updaes
 * the destination field values with source values. If models are different it throws an Exception
 *
 * @param mNoteSrc
 * @param mEditorNoteDst
 */
public static void updateJsonNoteFromMultimediaNote(final IMultimediaEditableNote noteSrc, final Note editorNoteDst) {
    if (noteSrc instanceof MultimediaEditableNote) {
        MultimediaEditableNote mmNote = (MultimediaEditableNote) noteSrc;
        if (mmNote.getModelId() != editorNoteDst.getMid()) {
            throw new RuntimeException("Source and Destination Note ID do not match.");
        }
        int totalFields = mmNote.getNumberOfFields();
        for (int i = 0; i < totalFields; i++) {
            editorNoteDst.values()[i] = mmNote.getField(i).getFormattedValue();
        }
    }
}
Also used : MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote)

Example 32 with Models

use of com.ichi2.libanki.Models in project Anki-Android by Ramblurr.

the class MultimediaCardEditorActivity method showModelSelectDialog.

private Dialog showModelSelectDialog() {
    StyledDialog dialog = null;
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
    // Use this array to know which ID is associated with each
    // Item(name)
    final ArrayList<Long> dialogIds = new ArrayList<Long>();
    ArrayList<JSONObject> models = mCol.getModels().all();
    Collections.sort(models, new JSONNameComparator());
    builder.setTitle(R.string.note_type);
    for (JSONObject m : models) {
        try {
            dialogItems.add(m.getString("name"));
            dialogIds.add(m.getLong("id"));
        } catch (JSONException e) {
            Log.e("Multimedia Editor", e.getMessage());
        }
    }
    // Convert to Array
    String[] items2 = new String[dialogItems.size()];
    dialogItems.toArray(items2);
    builder.setItems(items2, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int item) {
            long oldModelId;
            try {
                oldModelId = mCol.getModels().current().getLong("id");
            } catch (JSONException e) {
                Log.e("Multimedia Editor", e.getMessage());
                return;
            }
            long newId = dialogIds.get(item);
            if (oldModelId != newId) {
                changeCurrentModel(newId);
                createEditorUI(mNote);
            }
        }
    });
    dialog = builder.create();
    return dialog;
}
Also used : JSONNameComparator(com.ichi2.utils.JSONNameComparator) DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) SuppressLint(android.annotation.SuppressLint) JSONObject(org.json.JSONObject)

Example 33 with Models

use of com.ichi2.libanki.Models in project Anki-Android by Ramblurr.

the class CardEditor method onCreateDialog.

@Override
protected Dialog onCreateDialog(int id) {
    StyledDialog dialog = null;
    Resources res = getResources();
    StyledDialog.Builder builder = new StyledDialog.Builder(this);
    switch(id) {
        case DIALOG_TAGS_SELECT:
            builder.setTitle(R.string.card_details_tags);
            builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (mAddNote) {
                        try {
                            JSONArray ja = new JSONArray();
                            for (String t : selectedTags) {
                                ja.put(t);
                            }
                            mCol.getModels().current().put("tags", ja);
                            mCol.getModels().setChanged();
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        mEditorNote.setTags(selectedTags);
                    }
                    mCurrentTags = selectedTags;
                    updateTags();
                }
            });
            builder.setNegativeButton(res.getString(R.string.cancel), null);
            mNewTagEditText = (EditText) new EditText(this);
            mNewTagEditText.setHint(R.string.add_new_tag);
            InputFilter filter = new InputFilter() {

                public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                    for (int i = start; i < end; i++) {
                        if (source.charAt(i) == ' ' || source.charAt(i) == ',') {
                            return "";
                        }
                    }
                    return null;
                }
            };
            mNewTagEditText.setFilters(new InputFilter[] { filter });
            ImageView mAddTextButton = new ImageView(this);
            mAddTextButton.setImageResource(R.drawable.ic_addtag);
            mAddTextButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String tag = mNewTagEditText.getText().toString();
                    if (tag.length() != 0) {
                        if (mEditorNote.hasTag(tag)) {
                            mNewTagEditText.setText("");
                            return;
                        }
                        selectedTags.add(tag);
                        actualizeTagDialog(mTagsDialog);
                        mNewTagEditText.setText("");
                    }
                }
            });
            FrameLayout frame = new FrameLayout(this);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            params.rightMargin = 10;
            mAddTextButton.setLayoutParams(params);
            frame.addView(mNewTagEditText);
            frame.addView(mAddTextButton);
            builder.setView(frame, false, true);
            dialog = builder.create();
            mTagsDialog = dialog;
            break;
        case DIALOG_DECK_SELECT:
            ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>();
            // Use this array to know which ID is associated with each
            // Item(name)
            final ArrayList<Long> dialogDeckIds = new ArrayList<Long>();
            ArrayList<JSONObject> decks = mCol.getDecks().all();
            Collections.sort(decks, new JSONNameComparator());
            builder.setTitle(R.string.deck);
            for (JSONObject d : decks) {
                try {
                    if (d.getInt("dyn") == 0) {
                        dialogDeckItems.add(d.getString("name"));
                        dialogDeckIds.add(d.getLong("id"));
                    }
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            }
            // Convert to Array
            String[] items = new String[dialogDeckItems.size()];
            dialogDeckItems.toArray(items);
            builder.setItems(items, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    long newId = dialogDeckIds.get(item);
                    if (mCurrentDid != newId) {
                        if (mAddNote) {
                            try {
                                // TODO: mEditorNote.setDid(newId);
                                mEditorNote.model().put("did", newId);
                                mCol.getModels().setChanged();
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                        }
                        mCurrentDid = newId;
                        updateDeck();
                    }
                }
            });
            dialog = builder.create();
            mDeckSelectDialog = dialog;
            break;
        case DIALOG_MODEL_SELECT:
            ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
            // Use this array to know which ID is associated with each
            // Item(name)
            final ArrayList<Long> dialogIds = new ArrayList<Long>();
            ArrayList<JSONObject> models = mCol.getModels().all();
            Collections.sort(models, new JSONNameComparator());
            builder.setTitle(R.string.note_type);
            for (JSONObject m : models) {
                try {
                    dialogItems.add(m.getString("name"));
                    dialogIds.add(m.getLong("id"));
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }
            }
            // Convert to Array
            String[] items2 = new String[dialogItems.size()];
            dialogItems.toArray(items2);
            builder.setItems(items2, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    long oldModelId;
                    try {
                        oldModelId = mCol.getModels().current().getLong("id");
                    } catch (JSONException e) {
                        throw new RuntimeException(e);
                    }
                    long newId = dialogIds.get(item);
                    if (oldModelId != newId) {
                        mCol.getModels().setCurrent(mCol.getModels().get(newId));
                        JSONObject cdeck = mCol.getDecks().current();
                        try {
                            cdeck.put("mid", newId);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        mCol.getDecks().save(cdeck);
                        int size = mEditFields.size();
                        String[] oldValues = new String[size];
                        for (int i = 0; i < size; i++) {
                            oldValues[i] = mEditFields.get(i).getText().toString();
                        }
                        setNote();
                        resetEditFields(oldValues);
                        mTimerHandler.removeCallbacks(checkDuplicatesRunnable);
                        duplicateCheck(false);
                    }
                }
            });
            dialog = builder.create();
            break;
        case DIALOG_RESET_CARD:
            builder.setTitle(res.getString(R.string.reset_card_dialog_title));
            builder.setMessage(res.getString(R.string.reset_card_dialog_message));
            builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // for (long cardId :
                // mDeck.getCardsFromFactId(mEditorNote.getId())) {
                // mDeck.cardFromId(cardId).resetCard();
                // }
                // mDeck.reset();
                // setResult(Reviewer.RESULT_EDIT_CARD_RESET);
                // mCardReset = true;
                // Themes.showThemedToast(CardEditor.this,
                // getResources().getString(
                // R.string.reset_card_dialog_confirmation), true);
                }
            });
            builder.setNegativeButton(res.getString(R.string.no), null);
            builder.setCancelable(true);
            dialog = builder.create();
            break;
        case DIALOG_INTENT_INFORMATION:
            dialog = createDialogIntentInformation(builder, res);
    }
    return dialog;
}
Also used : DialogInterface(android.content.DialogInterface) Builder(com.ichi2.themes.StyledDialog.Builder) StyledDialog(com.ichi2.themes.StyledDialog) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Spanned(android.text.Spanned) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OnClickListener(android.content.DialogInterface.OnClickListener) JSONObject(org.json.JSONObject) FrameLayout(android.widget.FrameLayout) Builder(com.ichi2.themes.StyledDialog.Builder) OnClickListener(android.content.DialogInterface.OnClickListener) Resources(android.content.res.Resources)

Example 34 with Models

use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.

the class NoteEditor method onCollectionLoaded.

// Finish initializing the activity after the collection has been correctly loaded
@Override
protected void onCollectionLoaded(Collection col) {
    super.onCollectionLoaded(col);
    Intent intent = getIntent();
    Timber.d("NoteEditor() onCollectionLoaded: caller: %d", mCaller);
    registerExternalStorageListener();
    View mainView = findViewById(android.R.id.content);
    mToolbar = findViewById(R.id.editor_toolbar);
    mToolbar.setFormatListener(formatter -> {
        View currentFocus = getCurrentFocus();
        if (!(currentFocus instanceof FieldEditText)) {
            return;
        }
        modifyCurrentSelection(formatter, (FieldEditText) currentFocus);
    });
    enableToolbar(mainView);
    mFieldsLayoutContainer = findViewById(R.id.CardEditorEditFieldsLayout);
    mTagsButton = findViewById(R.id.CardEditorTagText);
    mCardsButton = findViewById(R.id.CardEditorCardsText);
    mCardsButton.setOnClickListener(v -> {
        Timber.i("NoteEditor:: Cards button pressed. Opening template editor");
        showCardTemplateEditor();
    });
    mAedictIntent = false;
    mCurrentEditedCard = null;
    switch(mCaller) {
        case CALLER_NOCALLER:
            Timber.e("no caller could be identified, closing");
            finishWithoutAnimation();
            return;
        case CALLER_REVIEWER:
            mCurrentEditedCard = AbstractFlashcardViewer.getEditorCard();
            if (mCurrentEditedCard == null) {
                finishWithoutAnimation();
                return;
            }
            mEditorNote = mCurrentEditedCard.note();
            mAddNote = false;
            break;
        case CALLER_STUDYOPTIONS:
        case CALLER_DECKPICKER:
        case CALLER_REVIEWER_ADD:
        case CALLER_CARDBROWSER_ADD:
        case CALLER_CARDEDITOR:
            mAddNote = true;
            break;
        case CALLER_CARDBROWSER_EDIT:
            mCurrentEditedCard = CardBrowser.sCardBrowserCard;
            if (mCurrentEditedCard == null) {
                finishWithoutAnimation();
                return;
            }
            mEditorNote = mCurrentEditedCard.note();
            mAddNote = false;
            break;
        case CALLER_CARDEDITOR_INTENT_ADD:
            {
                fetchIntentInformation(intent);
                if (mSourceText == null) {
                    finishWithoutAnimation();
                    return;
                }
                if ("Aedict Notepad".equals(mSourceText[0]) && addFromAedict(mSourceText[1])) {
                    finishWithoutAnimation();
                    return;
                }
                mAddNote = true;
                break;
            }
        default:
            break;
    }
    // Note type Selector
    mNoteTypeSpinner = findViewById(R.id.note_type_spinner);
    ArrayList<Model> models = getCol().getModels().all();
    Collections.sort(models, NamedJSONComparator.instance);
    final ArrayList<String> modelNames = new ArrayList<>(models.size());
    mAllModelIds = new ArrayList<>(models.size());
    for (JSONObject m : models) {
        modelNames.add(m.getString("name"));
        mAllModelIds.add(m.getLong("id"));
    }
    ArrayAdapter<String> noteTypeAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, modelNames);
    mNoteTypeSpinner.setAdapter(noteTypeAdapter);
    noteTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Deck Selector
    TextView deckTextView = findViewById(R.id.CardEditorDeckText);
    // If edit mode and more than one card template distinguish between "Deck" and "Card deck"
    if (!mAddNote && mEditorNote.model().getJSONArray("tmpls").length() > 1) {
        deckTextView.setText(R.string.CardEditorCardDeck);
    }
    mNoteDeckSpinner = findViewById(R.id.note_deck_spinner);
    ArrayList<Deck> decks = getCol().getDecks().all();
    Collections.sort(decks, DeckComparator.instance);
    final ArrayList<String> deckNames = new ArrayList<>(decks.size());
    mAllDeckIds = new ArrayList<>(decks.size());
    for (Deck d : decks) {
        // add current deck and all other non-filtered decks to deck list
        long thisDid = d.getLong("id");
        if (d.getInt("dyn") == 0 || (!mAddNote && mCurrentEditedCard != null && mCurrentEditedCard.getDid() == thisDid)) {
            deckNames.add(d.getString("name"));
            mAllDeckIds.add(thisDid);
        }
    }
    ArrayAdapter<String> noteDeckAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, deckNames);
    mNoteDeckSpinner.setAdapter(noteDeckAdapter);
    noteDeckAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mNoteDeckSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            // Timber.i("NoteEditor:: onItemSelected() fired on mNoteDeckSpinner with pos = %d", pos);
            mCurrentDid = mAllDeckIds.get(pos);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // Do Nothing
        }
    });
    mCurrentDid = intent.getLongExtra(EXTRA_DID, mCurrentDid);
    setDid(mEditorNote);
    setNote(mEditorNote, FieldChangeType.onActivityCreation(shouldReplaceNewlines()));
    if (mAddNote) {
        mNoteTypeSpinner.setOnItemSelectedListener(new SetNoteTypeListener());
        setTitle(R.string.menu_add_note);
        // set information transferred by intent
        String contents = null;
        String[] tags = intent.getStringArrayExtra(EXTRA_TAGS);
        if (mSourceText != null) {
            if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) {
                contents = mSourceText[1].replaceFirst("\\[", "\u001f" + mSourceText[0] + "\u001f");
                contents = contents.substring(0, contents.length() - 1);
            } else if (mEditFields.size() > 0) {
                mEditFields.get(0).setText(mSourceText[0]);
                if (mEditFields.size() > 1) {
                    mEditFields.get(1).setText(mSourceText[1]);
                }
            }
        } else {
            contents = intent.getStringExtra(EXTRA_CONTENTS);
        }
        if (contents != null) {
            setEditFieldTexts(contents);
        }
        if (tags != null) {
            setTags(tags);
        }
    } else {
        mNoteTypeSpinner.setOnItemSelectedListener(new EditNoteTypeListener());
        setTitle(R.string.cardeditor_title_edit_card);
    }
    findViewById(R.id.CardEditorTagButton).setOnClickListener(v -> {
        Timber.i("NoteEditor:: Tags button pressed... opening tags editor");
        showTagsDialog();
    });
    if (!mAddNote && mCurrentEditedCard != null) {
        Timber.i("onCollectionLoaded() Edit note activity successfully started with card id %d", mCurrentEditedCard.getId());
    }
    if (mAddNote) {
        Timber.i("onCollectionLoaded() Edit note activity successfully started in add card mode with node id %d", mEditorNote.getId());
    }
    // don't open keyboard if not adding note
    if (!mAddNote) {
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
    // set focus to FieldEditText 'first' on startup like Anki desktop
    if (mEditFields != null && !mEditFields.isEmpty()) {
        mEditFields.getFirst().requestFocus();
    }
}
Also used : ArrayList(java.util.ArrayList) Deck(com.ichi2.libanki.Deck) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) JSONObject(com.ichi2.utils.JSONObject) Model(com.ichi2.libanki.Model) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Example 35 with Models

use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.

the class DeckPicker method showStartupScreensAndDialogs.

public void showStartupScreensAndDialogs(SharedPreferences preferences, int skip) {
    if (!BackupManager.enoughDiscSpace(CollectionHelper.getCurrentAnkiDroidDirectory(this))) {
        Timber.i("Not enough space to do backup");
        showDialogFragment(DeckPickerNoSpaceLeftDialog.newInstance());
    } else if (preferences.getBoolean("noSpaceLeft", false)) {
        Timber.i("No space left");
        showDialogFragment(DeckPickerBackupNoSpaceLeftDialog.newInstance());
        preferences.edit().remove("noSpaceLeft").apply();
    } else if ("".equals(preferences.getString("lastVersion", ""))) {
        Timber.i("Fresh install");
        preferences.edit().putString("lastVersion", VersionUtils.getPkgVersionName()).apply();
        onFinishedStartup();
    } else if (skip < 2 && !preferences.getString("lastVersion", "").equals(VersionUtils.getPkgVersionName())) {
        Timber.i("AnkiDroid is being updated and a collection already exists.");
        // The user might appreciate us now, see if they will help us get better?
        if (!preferences.contains(UsageAnalytics.ANALYTICS_OPTIN_KEY)) {
            showDialogFragment(DeckPickerAnalyticsOptInDialog.newInstance());
        }
        // For upgrades, we check if we are upgrading
        // to a version that contains additions to the database integrity check routine that we would
        // like to run on all collections. A missing version number is assumed to be a fresh
        // installation of AnkiDroid and we don't run the check.
        long current = VersionUtils.getPkgVersionCode();
        Timber.i("Current AnkiDroid version: %s", current);
        long previous;
        if (preferences.contains(UPGRADE_VERSION_KEY)) {
            // Upgrading currently installed app
            previous = getPreviousVersion(preferences, current);
        } else {
            // Fresh install
            previous = current;
        }
        preferences.edit().putLong(UPGRADE_VERSION_KEY, current).apply();
        // It is rebuilt on the next sync or media check
        if (previous < 20300200) {
            Timber.i("Deleting media database");
            File mediaDb = new File(CollectionHelper.getCurrentAnkiDroidDirectory(this), "collection.media.ad.db2");
            if (mediaDb.exists()) {
                mediaDb.delete();
            }
        }
        // Recommend the user to do a full-sync if they're upgrading from before 2.3.1beta8
        if (previous < 20301208) {
            Timber.i("Recommend the user to do a full-sync");
            mRecommendFullSync = true;
        }
        // Fix "font-family" definition in templates created by AnkiDroid before 2.6alhpa23
        if (previous < 20600123) {
            Timber.i("Fixing font-family definition in templates");
            try {
                Models models = getCol().getModels();
                for (Model m : models.all()) {
                    String css = m.getString("css");
                    if (css.contains("font-familiy")) {
                        m.put("css", css.replace("font-familiy", "font-family"));
                        models.save(m);
                    }
                }
                models.flush();
            } catch (JSONException e) {
                Timber.e(e, "Failed to upgrade css definitions.");
            }
        }
        // Check if preference upgrade or database check required, otherwise go to new feature screen
        int upgradePrefsVersion = AnkiDroidApp.CHECK_PREFERENCES_AT_VERSION;
        int upgradeDbVersion = AnkiDroidApp.CHECK_DB_AT_VERSION;
        // Specifying a checkpoint in the future is not supported, please don't do it!
        if (current < upgradePrefsVersion) {
            Timber.e("Checkpoint in future produced.");
            UIUtils.showSimpleSnackbar(this, "Invalid value for CHECK_PREFERENCES_AT_VERSION", false);
            onFinishedStartup();
            return;
        }
        if (current < upgradeDbVersion) {
            Timber.e("Invalid value for CHECK_DB_AT_VERSION");
            UIUtils.showSimpleSnackbar(this, "Invalid value for CHECK_DB_AT_VERSION", false);
            onFinishedStartup();
            return;
        }
        // Skip full DB check if the basic check is OK
        // TODO: remove this variable if we really want to do the full db check on every user
        boolean skipDbCheck = false;
        // noinspection ConstantConditions
        if ((!skipDbCheck && previous < upgradeDbVersion) || previous < upgradePrefsVersion) {
            if (previous < upgradePrefsVersion) {
                Timber.i("showStartupScreensAndDialogs() running upgradePreferences()");
                upgradePreferences(previous);
            }
            // noinspection ConstantConditions
            if (!skipDbCheck && previous < upgradeDbVersion) {
                Timber.i("showStartupScreensAndDialogs() running integrityCheck()");
                // #5852 - since we may have a warning about disk space, we don't want to force a check database
                // and show a warning before the user knows what is happening.
                new MaterialDialog.Builder(this).title(R.string.integrity_check_startup_title).content(R.string.integrity_check_startup_content).positiveText(R.string.integrity_check_positive).negativeText(R.string.close).onPositive((materialDialog, dialogAction) -> integrityCheck()).onNeutral((materialDialog, dialogAction) -> this.restartActivity()).onNegative((materialDialog, dialogAction) -> this.restartActivity()).canceledOnTouchOutside(false).cancelable(false).build().show();
            } else if (previous < upgradePrefsVersion) {
                Timber.i("Updated preferences with no integrity check - restarting activity");
                // If integrityCheck() doesn't occur, but we did update preferences we should restart DeckPicker to
                // proceed
                this.restartActivity();
            }
        } else {
            // If no changes are required we go to the new features activity
            // There the "lastVersion" is set, so that this code is not reached again
            // if (VersionUtils.isReleaseVersion()) {
            // Timber.i("Displaying new features");
            // Intent infoIntent = new Intent(this, Info.class);
            // infoIntent.putExtra(Info.TYPE_EXTRA, Info.TYPE_NEW_VERSION);
            // 
            // if (skip != 0) {
            // startActivityForResultWithAnimation(infoIntent, SHOW_INFO_NEW_VERSION,
            // ActivityTransitionAnimation.LEFT);
            // } else {
            // startActivityForResultWithoutAnimation(infoIntent, SHOW_INFO_NEW_VERSION);
            // }
            // } else {
            Timber.i("Dev Build - not showing 'new features'");
            // Don't show new features dialog for development builds
            preferences.edit().putString("lastVersion", VersionUtils.getPkgVersionName()).apply();
            String ver = getResources().getString(R.string.updated_version, VersionUtils.getPkgVersionName());
            UIUtils.showSnackbar(this, ver, true, -1, null, findViewById(R.id.root_layout), null);
            showStartupScreensAndDialogs(preferences, 2);
        // }
        }
    } else {
        // this is the main call when there is nothing special required
        Timber.i("No startup screens required");
        onFinishedStartup();
    }
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) DialogHandler(com.ichi2.anki.dialogs.DialogHandler) NavigationBarItemView(com.google.android.material.navigation.NavigationBarItemView) Manifest(android.Manifest) Decks(com.ichi2.libanki.Decks) Handler(android.os.Handler) JSONException(com.ichi2.utils.JSONException) Fragment(androidx.fragment.app.Fragment) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ContextCompat(androidx.core.content.ContextCompat) DeckPickerBackupNoSpaceLeftDialog(com.ichi2.anki.dialogs.DeckPickerBackupNoSpaceLeftDialog) IntentFilter(android.content.IntentFilter) StringRes(androidx.annotation.StringRes) Nullable(androidx.annotation.Nullable) Message(android.os.Message) HostNumFactory(com.ichi2.anki.web.HostNumFactory) Consts(com.ichi2.libanki.Consts) OKHttpUtil(com.ichi2.utils.OKHttpUtil) MobclickAgent(com.umeng.analytics.MobclickAgent) DeckPickerExportCompleteDialog(com.ichi2.anki.dialogs.DeckPickerExportCompleteDialog) Models(com.ichi2.libanki.Models) SimpleDateFormat(java.text.SimpleDateFormat) Dialog(android.app.Dialog) SdCardReceiver(com.ichi2.anki.receiver.SdCardReceiver) URL_PRIVATE(com.ichi2.libanki.Consts.URL_PRIVATE) ArrayList(java.util.ArrayList) CustomSyncServerUrlException(com.ichi2.libanki.sync.CustomSyncServerUrlException) SpannableStringBuilder(android.text.SpannableStringBuilder) DeckPickerNoSpaceLeftDialog(com.ichi2.anki.dialogs.DeckPickerNoSpaceLeftDialog) Calendar(java.util.Calendar) Toast(android.widget.Toast) Menu(android.view.Menu) Connection(com.ichi2.async.Connection) Response(okhttp3.Response) AnkiPackageImporter(com.ichi2.libanki.importer.AnkiPackageImporter) Call(okhttp3.Call) CHECK_MEDIA(com.ichi2.async.CollectionTask.TASK_TYPE.CHECK_MEDIA) FragmentManager(androidx.fragment.app.FragmentManager) Beta(com.tencent.bugly.beta.Beta) SpannableString(android.text.SpannableString) ALL_DECKS_ID(com.ichi2.anki.SelfStudyActivity.ALL_DECKS_ID) URL_USER_PROTOCOL(com.ichi2.libanki.Consts.URL_USER_PROTOCOL) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) EditText(android.widget.EditText) AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment) PackageManager(android.content.pm.PackageManager) Date(java.util.Date) WindowManager(android.view.WindowManager) UnderlineSpan(android.text.style.UnderlineSpan) UsageAnalytics(com.ichi2.anki.analytics.UsageAnalytics) ClickableSpan(android.text.style.ClickableSpan) ExportDialog(com.ichi2.anki.dialogs.ExportDialog) DeviceID(com.ichi2.libanki.DeviceID) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) Permissions(com.ichi2.utils.Permissions) AnkiChinaSyncer(com.ichi2.libanki.sync.AnkiChinaSyncer) JSONObject(org.json.JSONObject) NOT_LOGIN_ANKI_CHINA(com.ichi2.anki.MyAccount.NOT_LOGIN_ANKI_CHINA) View(android.view.View) TaskData(com.ichi2.async.TaskData) SyncStatus(com.ichi2.utils.SyncStatus) FIND_EMPTY_CARDS(com.ichi2.async.CollectionTask.TASK_TYPE.FIND_EMPTY_CARDS) ParseException(java.text.ParseException) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) BroadcastReceiver(android.content.BroadcastReceiver) DatabaseErrorDialog(com.ichi2.anki.dialogs.DatabaseErrorDialog) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) List(java.util.List) TextView(android.widget.TextView) RelativeLayout(android.widget.RelativeLayout) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) ViewPropertyAnimator(android.view.ViewPropertyAnimator) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Window(android.view.Window) VersionUtils(com.ichi2.utils.VersionUtils) Context(android.content.Context) TaskListener(com.ichi2.async.TaskListener) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) GravityEnum(com.afollestad.materialdialogs.GravityEnum) DeckPickerAnalyticsOptInDialog(com.ichi2.anki.dialogs.DeckPickerAnalyticsOptInDialog) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) Collection(com.ichi2.libanki.Collection) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) MenuItem(android.view.MenuItem) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) CHECK_DATABASE(com.ichi2.async.CollectionTask.TASK_TYPE.CHECK_DATABASE) Lifecycle(androidx.lifecycle.Lifecycle) REPAIR_COLLECTION(com.ichi2.async.CollectionTask.TASK_TYPE.REPAIR_COLLECTION) WidgetStatus(com.ichi2.widget.WidgetStatus) MotionEvent(android.view.MotionEvent) SyncErrorDialog(com.ichi2.anki.dialogs.SyncErrorDialog) Model(com.ichi2.libanki.Model) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) Bugly(com.tencent.bugly.Bugly) LOAD_COLLECTION_COMPLETE(com.ichi2.async.CollectionTask.TASK_TYPE.LOAD_COLLECTION_COMPLETE) UMConfigure(com.umeng.commonsdk.UMConfigure) PlatformConfig(com.umeng.socialize.PlatformConfig) ActivityCompat(androidx.core.app.ActivityCompat) CollectionTask(com.ichi2.async.CollectionTask) BottomNavigationMenuView(com.google.android.material.bottomnavigation.BottomNavigationMenuView) Color(android.graphics.Color) MediaCheckDialog(com.ichi2.anki.dialogs.MediaCheckDialog) LOAD_DECK_COUNTS(com.ichi2.async.CollectionTask.TASK_TYPE.LOAD_DECK_COUNTS) VisibleForTesting(androidx.annotation.VisibleForTesting) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Resources(android.content.res.Resources) SpannableStringBuilder(android.text.SpannableStringBuilder) Model(com.ichi2.libanki.Model) JSONException(com.ichi2.utils.JSONException) Models(com.ichi2.libanki.Models) SpannableString(android.text.SpannableString) File(java.io.File)

Aggregations

JSONObject (com.ichi2.utils.JSONObject)48 Model (com.ichi2.libanki.Model)28 JSONArray (com.ichi2.utils.JSONArray)26 Test (org.junit.Test)26 Collection (com.ichi2.libanki.Collection)25 RobolectricTest (com.ichi2.anki.RobolectricTest)16 Note (com.ichi2.libanki.Note)16 JSONException (com.ichi2.utils.JSONException)13 ArrayList (java.util.ArrayList)13 Card (com.ichi2.libanki.Card)11 Models (com.ichi2.libanki.Models)11 SuppressLint (android.annotation.SuppressLint)10 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)7 ModelManager (com.ichi2.libanki.ModelManager)7 File (java.io.File)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 ContentValues (android.content.ContentValues)5 NonNull (androidx.annotation.NonNull)5