use of com.ichi2.anki.DeckPicker in project Anki-Android by ankidroid.
the class DeckPicker method onCreate.
// ----------------------------------------------------------------------------
// ANDROID ACTIVITY METHODS
// ----------------------------------------------------------------------------
/**
* Called when the activity is first created.
*/
@Override
protected void onCreate(Bundle savedInstanceState) throws SQLException {
if (showedActivityFailedScreen(savedInstanceState)) {
return;
}
Timber.d("onCreate()");
mExportingDelegate = new ActivityExportingDelegate(this, this::getCol);
mCustomStudyDialogFactory = new CustomStudyDialogFactory(this::getCol, this).attachToActivity(this);
mContextMenuFactory = new DeckPickerContextMenu.Factory(this::getCol).attachToActivity(this);
// we need to restore here, as we need it before super.onCreate() is called.
restoreWelcomeMessage(savedInstanceState);
// Then set theme and content view
super.onCreate(savedInstanceState);
handleStartup();
setContentView(R.layout.homescreen);
View mainView = findViewById(android.R.id.content);
// check, if tablet layout
mStudyoptionsFrame = findViewById(R.id.studyoptions_fragment);
// set protected variable from NavigationDrawerActivity
mFragmented = mStudyoptionsFrame != null && mStudyoptionsFrame.getVisibility() == View.VISIBLE;
// Open StudyOptionsFragment if in fragmented mode
if (mFragmented && !mStartupError) {
loadStudyOptionsFragment(false);
}
registerExternalStorageListener();
// create inherited navigation drawer layout here so that it can be used by parent class
initNavigationDrawer(mainView);
setTitle(getResources().getString(R.string.app_name));
mDeckPickerContent = findViewById(R.id.deck_picker_content);
mRecyclerView = findViewById(R.id.files);
mNoDecksPlaceholder = findViewById(R.id.no_decks_placeholder);
mDeckPickerContent.setVisibility(View.GONE);
mNoDecksPlaceholder.setVisibility(View.GONE);
// specify a LinearLayoutManager and set up item dividers for the RecyclerView
mRecyclerViewLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mRecyclerViewLayoutManager);
TypedArray ta = this.obtainStyledAttributes(new int[] { R.attr.deckDivider });
Drawable divider = ta.getDrawable(0);
ta.recycle();
DividerItemDecoration dividerDecorator = new DividerItemDecoration(this, mRecyclerViewLayoutManager.getOrientation());
dividerDecorator.setDrawable(divider);
mRecyclerView.addItemDecoration(dividerDecorator);
// Add background to Deckpicker activity
View view = mFragmented ? findViewById(R.id.deckpicker_xl_view) : findViewById(R.id.root_layout);
boolean hasDeckPickerBackground = false;
try {
hasDeckPickerBackground = applyDeckPickerBackground(view);
} catch (OutOfMemoryError e) {
// 6608 - OOM should be catchable here.
Timber.w(e, "Failed to apply background - OOM");
UIUtils.showThemedToast(this, getString(R.string.background_image_too_large), false);
} catch (Exception e) {
Timber.w(e, "Failed to apply background");
UIUtils.showThemedToast(this, getString(R.string.failed_to_apply_background_image, e.getLocalizedMessage()), false);
}
// create and set an adapter for the RecyclerView
mDeckListAdapter = new DeckAdapter(getLayoutInflater(), this);
mDeckListAdapter.setDeckClickListener(mDeckClickListener);
mDeckListAdapter.setCountsClickListener(mCountsClickListener);
mDeckListAdapter.setDeckExpanderClickListener(mDeckExpanderClickListener);
mDeckListAdapter.setDeckLongClickListener(mDeckLongClickListener);
mDeckListAdapter.enablePartialTransparencyForBackground(hasDeckPickerBackground);
mRecyclerView.setAdapter(mDeckListAdapter);
mPullToSyncWrapper = findViewById(R.id.pull_to_sync_wrapper);
mPullToSyncWrapper.setDistanceToTriggerSync(SWIPE_TO_SYNC_TRIGGER_DISTANCE);
mPullToSyncWrapper.setOnRefreshListener(() -> {
Timber.i("Pull to Sync: Syncing");
mPullToSyncWrapper.setRefreshing(false);
sync();
});
mPullToSyncWrapper.getViewTreeObserver().addOnScrollChangedListener(() -> mPullToSyncWrapper.setEnabled(mRecyclerViewLayoutManager.findFirstCompletelyVisibleItemPosition() == 0));
// Setup the FloatingActionButtons, should work everywhere with min API >= 15
mFloatingActionMenu = new DeckPickerFloatingActionMenu(view, this);
mReviewSummaryTextView = findViewById(R.id.today_stats_text_view);
mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
new Onboarding.DeckPicker(this, mRecyclerViewLayoutManager).onCreate();
}
use of com.ichi2.anki.DeckPicker in project Anki-Android by ankidroid.
the class DeckPickerImportTest method importAddShowsImportDialog.
@Test
public void importAddShowsImportDialog() {
DeckPickerImport deckPicker = super.startActivityNormallyOpenCollectionWithIntent(DeckPickerImport.class, new Intent());
deckPicker.showImportDialog(ImportDialog.DIALOG_IMPORT_ADD_CONFIRM, "");
assertThat(deckPicker.getAsyncDialogFragmentClass(), Matchers.typeCompatibleWith(ImportDialog.class));
}
use of com.ichi2.anki.DeckPicker in project Anki-Android by ankidroid.
the class DeckPickerTest method notEnoughSpaceToBackupBeforeDowngradeShowsError.
@Test
public void notEnoughSpaceToBackupBeforeDowngradeShowsError() {
Class<DeckPickerNoSpaceForBackup> clazz = DeckPickerNoSpaceForBackup.class;
try (MockedStatic<InitialActivity> initialActivityMock = mockStatic(InitialActivity.class, Mockito.CALLS_REAL_METHODS)) {
initialActivityMock.when(() -> InitialActivity.getStartupFailureType(any())).thenAnswer((Answer<InitialActivity.StartupFailure>) invocation -> InitialActivity.StartupFailure.DATABASE_DOWNGRADE_REQUIRED);
InitialActivityWithConflictTest.setupForValid(getTargetContext());
DeckPickerNoSpaceForBackup deckPicker = super.startActivityNormallyOpenCollectionWithIntent(clazz, new Intent());
assertThat("A downgrade failed dialog should be shown", deckPicker.mDisplayedDowngradeFailed, is(true));
} finally {
InitialActivityWithConflictTest.setupForDefault();
}
}
use of com.ichi2.anki.DeckPicker in project Anki-Android by ankidroid.
the class DeckPickerTest method limitAppliedAfterReview.
@Test
public void limitAppliedAfterReview() {
Collection col = getCol();
AbstractSched sched = col.getSched();
DeckConfig dconf = col.getDecks().getConf(1);
assertNotNull(dconf);
dconf.getJSONObject("new").put("perDay", 10);
col.getDecks().save(dconf);
for (int i = 0; i < 11; i++) {
addNoteUsingBasicModel("Which card is this ?", Integer.toString(i));
}
// This set a card as current card
sched.getCard();
ensureCollectionLoadIsSynchronous();
DeckPicker deckPicker = super.startActivityNormallyOpenCollectionWithIntent(DeckPicker.class, new Intent());
assertEquals(10, deckPicker.mDueTree.get(0).getNewCount());
}
use of com.ichi2.anki.DeckPicker in project Anki-Android by Ramblurr.
the class DeckPicker method onStop.
@Override
protected void onStop() {
Log.i(AnkiDroidApp.TAG, "DeckPicker - onStop");
super.onStop();
if (!mDontSaveOnStop) {
if (isFinishing()) {
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_CLOSE_DECK, mCloseCollectionHandler, new TaskData(AnkiDroidApp.getCol()));
} else {
StudyOptionsFragment frag = getFragment();
if (!(frag != null && !frag.dbSaveNecessary())) {
UIUtils.saveCollectionInBackground();
}
}
}
}
Aggregations