Search in sources :

Example 1 with DeckAdapter

use of com.ichi2.anki.widgets.DeckAdapter in project AnkiChinaAndroid by ankichinateam.

the class DeckPickerFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (mRoot != null) {
        return mRoot;
    }
    Timber.i("on create view in deck picker fragment");
    mRoot = inflater.inflate(R.layout.deck_picker, container, false);
    mToolbar = mRoot.findViewById(R.id.toolbar);
    mPullToSyncWrapper = mRoot.findViewById(R.id.pull_to_sync_wrapper);
    if (!Permissions.hasStorageAccessPermission(getAnkiActivity())) {
        mPullToSyncWrapper.setVisibility(View.GONE);
        mToolbar.setVisibility(View.GONE);
        mRoot.findViewById(R.id.no_permission_layout).setVisibility(View.VISIBLE);
        mRoot.findViewById(R.id.hint_button).setOnClickListener(v -> ActivityCompat.requestPermissions(getAnkiActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_STORAGE_PERMISSION));
    // return mRoot;
    }
    if (mToolbar != null) {
        setHasOptionsMenu(true);
        mToolbar.setNavigationIcon(null);
        mToolbar.setTitle("");
        mTabLayout = mToolbar.findViewById(R.id.tab_layout);
        mVipLogo = mToolbar.findViewById(R.id.vip_logo);
        mVipLogo.setOnClickListener(v -> onNavigationPressed());
        TabLayout.Tab tab = mTabLayout.newTab();
        View view = getLayoutInflater().inflate(R.layout.item_deckpicker_tab, null);
        ((TextView) view.findViewById(R.id.name)).setText("学习");
        tab.setCustomView(view);
        mTabLayout.addTab(tab);
        TabLayout.Tab tab2 = mTabLayout.newTab();
        View view2 = getLayoutInflater().inflate(R.layout.item_deckpicker_tab, null);
        ((TextView) view2.findViewById(R.id.name)).setText("笔记");
        tab2.setCustomView(view2);
        mTabLayout.addTab(tab2);
        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab == tab2) {
                    getAnkiActivity().openCardBrowser(ALL_DECKS_ID);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
    }
    // check, if tablet layout
    mStudyoptionsFrame = mRoot.findViewById(R.id.studyoptions_fragment);
    if (mFragmented) {
        loadStudyOptionsFragment(false);
    }
    mRecyclerView = mRoot.findViewById(R.id.files);
    mRecyclerViewLayoutManager = new LinearLayoutManager(getAnkiActivity());
    mRecyclerView.setLayoutManager(mRecyclerViewLayoutManager);
    View view = mFragmented ? mRoot.findViewById(R.id.deckpicker_view) : mRoot.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(getAnkiActivity(), getString(R.string.background_image_too_large), false);
    } catch (Exception e) {
        Timber.w(e, "Failed to apply background");
        UIUtils.showThemedToast(getAnkiActivity(), getString(R.string.failed_to_apply_background_image, e.getLocalizedMessage()), false);
    }
    // create and set an adapter for the RecyclerView
    mDeckListAdapter = new DeckAdapter(getLayoutInflater(), getAnkiActivity());
    mDeckListAdapter.setDeckClickListener(mDeckClickListener);
    mDeckListAdapter.setCountsClickListener(mCountsClickListener);
    mDeckListAdapter.setDeckExpanderClickListener(mDeckExpanderClickListener);
    mDeckListAdapter.setDeckLongClickListener(mDeckLongClickListener);
    mDeckListAdapter.enablePartialTransparencyForBackground(hasDeckPickerBackground);
    mDeckListAdapter.setMarketClickListener(v -> getAnkiActivity().openSourceMarket());
    mRecyclerView.setAdapter(mDeckListAdapter);
    mPullToSyncWrapper.setDistanceToTriggerSync(SWIPE_TO_SYNC_TRIGGER_DISTANCE);
    mPullToSyncWrapper.setOnRefreshListener(() -> {
        Timber.i("Pull to Sync: Syncing");
        mPullToSyncWrapper.setRefreshing(false);
        updateDeckList();
    // getAnkiActivity().sync();
    });
    mPullToSyncWrapper.getViewTreeObserver().addOnScrollChangedListener(() -> mPullToSyncWrapper.setEnabled(mRecyclerViewLayoutManager.findFirstCompletelyVisibleItemPosition() == 0));
    // Setup the FloatingActionButtons, should work everywhere with min API >= 15
    mActionsMenu = mRoot.findViewById(R.id.add_content_menu);
    mActionsMenu.findViewById(R.id.fab_expand_menu_button).setContentDescription(getString(R.string.menu_add));
    // configureFloatingActionsMenu();
    mReviewSummaryTextView = mRoot.findViewById(R.id.today_stats_text_view);
    // mRoot.findViewById(R.id.tv_resource).setOnClickListener(v -> getAnkiActivity().openSourceMarket());
    mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    fetchAds();
    return mRoot;
}
Also used : DeckAdapter(com.ichi2.anki.widgets.DeckAdapter) TabLayout(com.google.android.material.tabs.TabLayout) TextView(android.widget.TextView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ActionMenuView(android.widget.ActionMenuView) IOException(java.io.IOException) SQLException(android.database.SQLException) Nullable(androidx.annotation.Nullable)

Example 2 with DeckAdapter

use of com.ichi2.anki.widgets.DeckAdapter 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

SQLException (android.database.SQLException)2 View (android.view.View)2 TextView (android.widget.TextView)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 DeckAdapter (com.ichi2.anki.widgets.DeckAdapter)2 TypedArray (android.content.res.TypedArray)1 Drawable (android.graphics.drawable.Drawable)1 ActionMenuView (android.widget.ActionMenuView)1 ImageView (android.widget.ImageView)1 Nullable (androidx.annotation.Nullable)1 SearchView (androidx.appcompat.widget.SearchView)1 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)1 TabLayout (com.google.android.material.tabs.TabLayout)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 DeckRenameException (com.ichi2.libanki.backend.exception.DeckRenameException)1 CustomSyncServerUrlException (com.ichi2.libanki.sync.CustomSyncServerUrlException)1