Search in sources :

Example 6 with CardBrowser

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

the class CardBrowserTest method changeDeckIntegrationTestDynamicAndNon.

@Test
public void changeDeckIntegrationTestDynamicAndNon() {
    addDeck("Hello");
    addDynamicDeck("World");
    HashSet<String> validNames = new HashSet<>();
    validNames.add("Default");
    validNames.add("Hello");
    CardBrowser b = getBrowserWithNotes(5);
    List<Deck> decks = b.getValidDecksForChangeDeck();
    for (Deck d : decks) {
        assertThat(validNames, hasItem(d.getString("name")));
    }
    assertThat("Additional unexpected decks were present", decks.size(), is(2));
}
Also used : Deck(com.ichi2.libanki.Deck) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with CardBrowser

use of com.ichi2.anki.CardBrowser in project Anki-Android by ankidroid.

the class AnkiDroidApp method onCreate.

/**
 * On application creation.
 */
@Override
public void onCreate() {
    super.onCreate();
    if (sInstance != null) {
        Timber.i("onCreate() called multiple times");
        // 5887 - fix crash.
        if (sInstance.getResources() == null) {
            Timber.w("Skipping re-initialisation - no resources. Maybe uninstalling app?");
            return;
        }
    }
    sInstance = this;
    // Get preferences
    SharedPreferences preferences = getSharedPrefs(this);
    // Setup logging and crash reporting
    mAcraCoreConfigBuilder = new CoreConfigurationBuilder(this);
    if (BuildConfig.DEBUG) {
        // Enable verbose error logging and do method tracing to put the Class name as log tag
        Timber.plant(new DebugTree());
        setDebugACRAConfig(preferences);
        List<ReferenceMatcher> referenceMatchers = new ArrayList<>();
        // Add known memory leaks to 'referenceMatchers'
        matchKnownMemoryLeaks(referenceMatchers);
        // AppWatcher manual install if not already installed
        if (!AppWatcher.INSTANCE.isInstalled()) {
            AppWatcher.INSTANCE.manualInstall(this);
        }
        // Show 'Leaks' app launcher. It has been removed by default via constants.xml.
        LeakCanary.INSTANCE.showLeakDisplayActivityLauncherIcon(true);
    } else {
        Timber.plant(new ProductionCrashReportingTree());
        setProductionACRAConfig(preferences);
        disableLeakCanary();
    }
    Timber.tag(TAG);
    Timber.d("Startup - Application Start");
    // Analytics falls back to a sensible default if this is not set.
    if (ACRA.isACRASenderServiceProcess() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        try {
            WebViewDebugging.setDataDirectorySuffix("acra");
        } catch (Exception e) {
            Timber.w(e, "Failed to set WebView data directory");
        }
    }
    // analytics after ACRA, they both install UncaughtExceptionHandlers but Analytics chains while ACRA does not
    UsageAnalytics.initialize(this);
    if (BuildConfig.DEBUG) {
        UsageAnalytics.setDryRun(true);
    }
    // Stop after analytics and logging are initialised.
    if (ACRA.isACRASenderServiceProcess()) {
        Timber.d("Skipping AnkiDroidApp.onCreate from ACRA sender process");
        return;
    }
    if (AdaptionUtil.isUserATestClient()) {
        UIUtils.showThemedToast(this.getApplicationContext(), getString(R.string.user_is_a_robot), false);
    }
    // make default HTML / JS debugging true for debug build and disable for unit/android tests
    if (BuildConfig.DEBUG && !AdaptionUtil.isRunningAsUnitTest()) {
        preferences.edit().putBoolean("html_javascript_debugging", true).apply();
    }
    CardBrowserContextMenu.ensureConsistentStateWithSharedPreferences(this);
    AnkiCardContextMenu.ensureConsistentStateWithSharedPreferences(this);
    NotificationChannels.setup(getApplicationContext());
    // Configure WebView to allow file scheme pages to access cookies.
    if (!acceptFileSchemeCookies()) {
        return;
    }
    // Forget the last deck that was used in the CardBrowser
    CardBrowser.clearLastDeckId();
    // Create the AnkiDroid directory if missing. Send exception report if inaccessible.
    if (Permissions.hasStorageAccessPermission(this)) {
        try {
            String dir = CollectionHelper.getCurrentAnkiDroidDirectory(this);
            CollectionHelper.initializeAnkiDroidDirectory(dir);
        } catch (StorageAccessException e) {
            Timber.e(e, "Could not initialize AnkiDroid directory");
            String defaultDir = CollectionHelper.getDefaultAnkiDroidDirectory(this);
            if (isSdCardMounted() && CollectionHelper.getCurrentAnkiDroidDirectory(this).equals(defaultDir)) {
                // Don't send report if the user is using a custom directory as SD cards trip up here a lot
                sendExceptionReport(e, "AnkiDroidApp.onCreate");
            }
        }
    }
    Timber.i("AnkiDroidApp: Starting Services");
    new BootService().onReceive(this, new Intent(this, BootService.class));
    // Register BroadcastReceiver NotificationService
    NotificationService ns = new NotificationService();
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.registerReceiver(ns, new IntentFilter(NotificationService.INTENT_ACTION));
}
Also used : IntentFilter(android.content.IntentFilter) ReferenceMatcher(shark.ReferenceMatcher) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) StorageAccessException(com.ichi2.anki.exception.StorageAccessException) Intent(android.content.Intent) NotificationService(com.ichi2.anki.services.NotificationService) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) ManuallyReportedException(com.ichi2.anki.exception.ManuallyReportedException) StorageAccessException(com.ichi2.anki.exception.StorageAccessException) CoreConfigurationBuilder(org.acra.config.CoreConfigurationBuilder) DebugTree(timber.log.Timber.DebugTree) BootService(com.ichi2.anki.services.BootService)

Example 8 with CardBrowser

use of com.ichi2.anki.CardBrowser in project Anki-Android by ankidroid.

the class CardBrowser method onResetProgress.

protected void onResetProgress() {
    // Show confirmation dialog before resetting card progress
    ConfirmationDialog dialog = new ConfirmationDialog();
    String title = getString(R.string.reset_card_dialog_title);
    String message = getString(R.string.reset_card_dialog_message);
    dialog.setArgs(title, message);
    Runnable confirm = () -> {
        Timber.i("CardBrowser:: ResetProgress button pressed");
        resetProgressNoConfirm(getSelectedCardIds());
    };
    dialog.setConfirm(confirm);
    showDialogFragment(dialog);
}
Also used : ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog)

Example 9 with CardBrowser

use of com.ichi2.anki.CardBrowser in project Anki-Android by ankidroid.

the class CardBrowser method editSelectedCardsTags.

private void editSelectedCardsTags(List<String> selectedTags, List<String> indeterminateTags) {
    List<Note> selectedNotes = getSelectedCardIds().stream().map(cardId -> getCol().getCard(cardId).note()).distinct().collect(Collectors.toList());
    for (Note note : selectedNotes) {
        List<String> previousTags = note.getTags();
        List<String> updatedTags = TagsUtil.getUpdatedTags(previousTags, selectedTags, indeterminateTags);
        note.setTagsFromStr(getCol().getTags().join(updatedTags));
    }
    Timber.i("CardBrowser:: editSelectedCardsTags: Saving note/s tags...");
    TaskManager.launchCollectionTask(new CollectionTask.UpdateMultipleNotes(selectedNotes), updateMultipleNotesHandler());
}
Also used : Note(com.ichi2.libanki.Note) CollectionTask(com.ichi2.async.CollectionTask)

Example 10 with CardBrowser

use of com.ichi2.anki.CardBrowser in project Anki-Android by ankidroid.

the class CardBrowserTest method checkIfSearchAllDecksWorks.

@Test
public void checkIfSearchAllDecksWorks() {
    addNoteUsingBasicModel("Hello", "World");
    long deck = addDeck("Test Deck");
    getCol().getDecks().select(deck);
    Card c2 = addNoteUsingBasicModel("Front", "Back").firstCard();
    c2.setDid(deck);
    c2.flush();
    CardBrowser cardBrowser = getBrowserWithNoNewCards();
    cardBrowser.searchCards("Hello");
    advanceRobolectricLooperWithSleep();
    assertThat("Card browser should have Test Deck as the selected deck", cardBrowser.getSelectedDeckNameForUi(), is("Test Deck"));
    assertThat("Result should be empty", cardBrowser.getCardCount(), is(0));
    cardBrowser.searchAllDecks();
    advanceRobolectricLooperWithSleep();
    assertThat("Result should contain one card", cardBrowser.getCardCount(), is(1));
}
Also used : Card(com.ichi2.libanki.Card) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 Intent (android.content.Intent)9 Deck (com.ichi2.libanki.Deck)9 Note (com.ichi2.libanki.Note)7 Card (com.ichi2.libanki.Card)6 MenuItem (android.view.MenuItem)5 CollectionTask (com.ichi2.async.CollectionTask)5 JSONObject (com.ichi2.utils.JSONObject)5 HashSet (java.util.HashSet)5 IntentFilter (android.content.IntentFilter)4 SharedPreferences (android.content.SharedPreferences)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 SearchView (androidx.appcompat.widget.SearchView)4 Bundle (android.os.Bundle)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 IntegerDialog (com.ichi2.anki.dialogs.IntegerDialog)3 SimpleMessageDialog (com.ichi2.anki.dialogs.SimpleMessageDialog)3 Consts (com.ichi2.libanki.Consts)3