Search in sources :

Example 1 with CustomStudyDialogFactory

use of com.ichi2.anki.dialogs.customstudy.CustomStudyDialogFactory 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)

Aggregations

TypedArray (android.content.res.TypedArray)1 SQLException (android.database.SQLException)1 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 TextView (android.widget.TextView)1 SearchView (androidx.appcompat.widget.SearchView)1 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 CustomStudyDialogFactory (com.ichi2.anki.dialogs.customstudy.CustomStudyDialogFactory)1 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)1 ActivityExportingDelegate (com.ichi2.anki.export.ActivityExportingDelegate)1 HostNumFactory (com.ichi2.anki.web.HostNumFactory)1 DeckAdapter (com.ichi2.anki.widgets.DeckAdapter)1 DeckRenameException (com.ichi2.libanki.backend.exception.DeckRenameException)1 CustomSyncServerUrlException (com.ichi2.libanki.sync.CustomSyncServerUrlException)1 JSONException (com.ichi2.utils.JSONException)1