Search in sources :

Example 6 with DeckPicker

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();
}
Also used : Drawable(android.graphics.drawable.Drawable) HostNumFactory(com.ichi2.anki.web.HostNumFactory) CustomStudyDialogFactory(com.ichi2.anki.dialogs.customstudy.CustomStudyDialogFactory) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) JSONException(com.ichi2.utils.JSONException) DeckRenameException(com.ichi2.libanki.backend.exception.DeckRenameException) CustomSyncServerUrlException(com.ichi2.libanki.sync.CustomSyncServerUrlException) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) SQLException(android.database.SQLException) DeckAdapter(com.ichi2.anki.widgets.DeckAdapter) CustomStudyDialogFactory(com.ichi2.anki.dialogs.customstudy.CustomStudyDialogFactory) TypedArray(android.content.res.TypedArray) ActivityExportingDelegate(com.ichi2.anki.export.ActivityExportingDelegate)

Example 7 with DeckPicker

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));
}
Also used : ImportDialog(com.ichi2.anki.dialogs.ImportDialog) Intent(android.content.Intent) Test(org.junit.Test)

Example 8 with DeckPicker

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();
    }
}
Also used : Arrays(java.util.Arrays) PackageManager(android.content.pm.PackageManager) AbstractSched(com.ichi2.libanki.sched.AbstractSched) DeckConfig(com.ichi2.libanki.DeckConfig) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Mockito.doReturn(org.mockito.Mockito.doReturn) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ParameterizedRobolectricTestRunner(org.robolectric.ParameterizedRobolectricTestRunner) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) DatabaseErrorDialog(com.ichi2.anki.dialogs.DatabaseErrorDialog) DB(com.ichi2.libanki.DB) Parameters(org.robolectric.ParameterizedRobolectricTestRunner.Parameters) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) BackendEmulatingOpenConflict(com.ichi2.testutils.BackendEmulatingOpenConflict) MockedStatic(org.mockito.MockedStatic) Storage(com.ichi2.libanki.Storage) DbUtils(com.ichi2.testutils.DbUtils) Matchers.is(org.hamcrest.Matchers.is) Mockito.any(org.mockito.Mockito.any) DialogFragment(androidx.fragment.app.DialogFragment) Mockito.mock(org.mockito.Mockito.mock) Context(android.content.Context) ResourceLoader(com.ichi2.utils.ResourceLoader) DeckPickerConfirmDeleteDeckDialog(com.ichi2.anki.dialogs.DeckPickerConfirmDeleteDeckDialog) Mockito.mockStatic(org.mockito.Mockito.mockStatic) RunWith(org.junit.runner.RunWith) Intent(android.content.Intent) HashMap(java.util.HashMap) Editor(android.content.SharedPreferences.Editor) Collection(com.ichi2.libanki.Collection) Mockito.spy(org.mockito.Mockito.spy) Parameter(org.robolectric.ParameterizedRobolectricTestRunner.Parameter) Answer(org.mockito.stubbing.Answer) Menu(android.view.Menu) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) Assert.assertNotNull(org.junit.Assert.assertNotNull) Robolectric(org.robolectric.Robolectric) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) File(java.io.File) BackupManagerTestUtilities(com.ichi2.testutils.BackupManagerTestUtilities) Mockito.verify(org.mockito.Mockito.verify) AnkiActivityUtils(com.ichi2.testutils.AnkiActivityUtils) Mockito(org.mockito.Mockito) UPGRADE_VERSION_KEY(com.ichi2.anki.DeckPicker.UPGRADE_VERSION_KEY) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) SharedPreferences(android.content.SharedPreferences) FrameworkSQLiteOpenHelperFactory(androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory) ActivityScenario(androidx.test.core.app.ActivityScenario) Assert.assertEquals(org.junit.Assert.assertEquals) Intent(android.content.Intent) Test(org.junit.Test)

Example 9 with DeckPicker

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());
}
Also used : AbstractSched(com.ichi2.libanki.sched.AbstractSched) Collection(com.ichi2.libanki.Collection) Intent(android.content.Intent) DeckConfig(com.ichi2.libanki.DeckConfig) Test(org.junit.Test)

Example 10 with DeckPicker

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();
            }
        }
    }
}
Also used : TaskData(com.ichi2.async.DeckTask.TaskData)

Aggregations

Intent (android.content.Intent)11 Resources (android.content.res.Resources)10 Bundle (android.os.Bundle)10 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)8 Collection (com.ichi2.libanki.Collection)8 SharedPreferences (android.content.SharedPreferences)7 View (android.view.View)6 TextView (android.widget.TextView)6 Context (android.content.Context)5 TypedArray (android.content.res.TypedArray)5 Drawable (android.graphics.drawable.Drawable)5 Menu (android.view.Menu)5 HostNumFactory (com.ichi2.anki.web.HostNumFactory)5 List (java.util.List)5 Window (android.view.Window)4 WindowManager (android.view.WindowManager)4 RelativeLayout (android.widget.RelativeLayout)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 ArrayList (java.util.ArrayList)4