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));
}
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));
}
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);
}
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());
}
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));
}
Aggregations