Java Code Examples for com.hippo.yorozuya.AssertUtils#assertNotNull()

The following examples show how to use com.hippo.yorozuya.AssertUtils#assertNotNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryInfoScene.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_info, container, false);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    InfoAdapter adapter = new InfoAdapter();
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL,
            AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setOnItemClickListener(this);
    return view;
}
 
Example 2
Source File: WebViewSignInScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    EhUtils.signOut(context);

    // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
    CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.flush();
        cookieManager.removeAllCookies(null);
        cookieManager.removeSessionCookies(null);
    } else {
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }

    mWebView = new WebView(context);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new LoginWebViewClient());
    mWebView.loadUrl(EhUrl.URL_SIGN_IN);
    return mWebView;
}
 
Example 3
Source File: QuickSearchScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_label_list, container, false);

    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(mRecyclerView, tip);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_search);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);
    tip.setText(R.string.no_quick_search);

    // drag & drop manager
    RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
    dragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));

    RecyclerView.Adapter adapter = new QuickSearchAdapter();
    adapter.setHasStableIds(true);
    adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
    mAdapter = adapter;

    final GeneralItemAnimator animator = new DraggableItemAnimator();
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setItemAnimator(animator);

    dragDropManager.attachRecyclerView(mRecyclerView);

    updateView();

    return view;
}
 
Example 4
Source File: DownloadLabelsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_label_list, container, false);

    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(mRecyclerView, tip);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_label);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);
    tip.setText(R.string.no_download_label);

    // drag & drop manager
    RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
    dragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));

    RecyclerView.Adapter adapter = new LabelAdapter();
    adapter.setHasStableIds(true);
    adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
    mAdapter = adapter;
    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setItemAnimator(animator);

    dragDropManager.attachRecyclerView(mRecyclerView);

    updateView();

    return view;
}
 
Example 5
Source File: DownloadsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    mDownloadManager = EhApplication.getDownloadManager(context);
    mDownloadManager.addDownloadInfoListener(this);

    if (savedInstanceState == null) {
        onInit();
    } else {
        onRestore(savedInstanceState);
    }
}
 
Example 6
Source File: GalleryDetailScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void ensurePopMenu() {
    if (mPopupMenu != null) {
        return;
    }

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    PopupMenu popup = new PopupMenu(context, mOtherActions, Gravity.TOP);
    mPopupMenu = popup;
    popup.getMenuInflater().inflate(R.menu.scene_gallery_detail, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_open_in_other_app:
                    String url = getGalleryDetailUrl(false);
                    Activity activity = getActivity2();
                    if (null != url && null != activity) {
                        UrlOpener.openUrl(activity, url, false);
                    }
                    break;
                case R.id.action_refresh:
                    if (mState != STATE_REFRESH && mState != STATE_REFRESH_HEADER) {
                        adjustViewVisibility(STATE_REFRESH, true);
                        request();
                    }
                    break;
            }
            return true;
        }
    });
}
 
Example 7
Source File: GalleryDetailScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void bindViewSecond() {
    GalleryDetail gd = mGalleryDetail;
    if (gd == null) {
        return;
    }
    if (mThumb == null || mTitle == null || mUploader == null || mCategory == null ||
            mLanguage == null || mPages == null || mSize == null || mPosted == null ||
            mFavoredTimes == null || mRatingText == null || mRating == null || mTorrent == null) {
        return;
    }

    Resources resources = getResources2();
    AssertUtils.assertNotNull(resources);

    mThumb.load(EhCacheKeyFactory.getThumbKey(gd.gid), gd.thumb);
    mTitle.setText(EhUtils.getSuitableTitle(gd));
    mUploader.setText(gd.uploader);
    mCategory.setText(EhUtils.getCategory(gd.category));
    mCategory.setTextColor(EhUtils.getCategoryColor(gd.category));
    updateDownloadText();

    mLanguage.setText(gd.language);
    mPages.setText(resources.getQuantityString(
            R.plurals.page_count, gd.pages, gd.pages));
    mSize.setText(gd.size);
    mPosted.setText(gd.posted);
    mFavoredTimes.setText(resources.getString(R.string.favored_times, gd.favoriteCount));

    mRatingText.setText(getAllRatingText(gd.rating, gd.ratingCount));
    mRating.setRating(gd.rating);

    updateFavoriteDrawable();

    mTorrent.setText(resources.getString(R.string.torrent_count, gd.torrentCount));

    bindTags(gd.tags);
    bindComments(gd.comments.comments);
    bindPreviews(gd);
}
 
Example 8
Source File: WebViewSignInScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    EhUtils.signOut(context);

    // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
    CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.flush();
        cookieManager.removeAllCookies(null);
        cookieManager.removeSessionCookies(null);
    } else {
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }

    mWebView = new WebView(context);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new LoginWebViewClient());
    mWebView.loadUrl(EhUrl.URL_SIGN_IN);
    return mWebView;
}
 
Example 9
Source File: GalleryInfoScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private void handlerArgs(Bundle args) {
    if (args == null) {
        return;
    }
    GalleryDetail gd = args.getParcelable(KEY_GALLERY_DETAIL);
    if (gd == null) {
        return;
    }
    if (mKeys == null || mValues == null) {
        return;
    }

    Resources resources = getResources2();
    AssertUtils.assertNotNull(resources);
    mKeys.add(resources.getString(R.string.header_key));
    mValues.add(resources.getString(R.string.header_value));
    mKeys.add(resources.getString(R.string.key_gid));
    mValues.add(gd.gid);
    mKeys.add(resources.getString(R.string.key_token));
    mValues.add(gd.token);
    mKeys.add(resources.getString(R.string.key_url));
    mValues.add(EhUrl.getGalleryDetailUrl(gd.gid, gd.token));
    mKeys.add(resources.getString(R.string.key_title));
    mValues.add(gd.title);
    mKeys.add(resources.getString(R.string.key_title_jpn));
    mValues.add(gd.titleJpn);
    mKeys.add(resources.getString(R.string.key_thumb));
    mValues.add(gd.thumb);
    mKeys.add(resources.getString(R.string.key_category));
    mValues.add(EhUtils.getCategory(gd.category));
    mKeys.add(resources.getString(R.string.key_uploader));
    mValues.add(gd.uploader);
    mKeys.add(resources.getString(R.string.key_posted));
    mValues.add(gd.posted);
    mKeys.add(resources.getString(R.string.key_rating));
    mValues.add(Float.toString(gd.rating));
    mKeys.add(resources.getString(R.string.favorite_name));
    mValues.add(gd.favoriteName);
}
 
Example 10
Source File: CookieSignInScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_cookie_sign_in, container, false);
    mIpbMemberIdLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_member_id_layout);
    mIpbMemberId = mIpbMemberIdLayout.getEditText();
    AssertUtils.assertNotNull(mIpbMemberId);
    mIpbPassHashLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_pass_hash_layout);
    mIpbPassHash = mIpbPassHashLayout.getEditText();
    AssertUtils.assertNotNull(mIpbPassHash);
    mIgneousLayout = (TextInputLayout) ViewUtils.$$(view, R.id.igneous_layout);
    mIgneous = mIgneousLayout.getEditText();
    AssertUtils.assertNotNull(mIgneous);
    mOk = ViewUtils.$$(view, R.id.ok);

    mIpbPassHash.setOnEditorActionListener(this);

    mOk.setOnClickListener(this);

    // Try to get old version cookie info
    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    SharedPreferences sharedPreferences = context.getSharedPreferences("eh_info", 0);
    String ipbMemberId = sharedPreferences.getString("ipb_member_id", null);
    String ipbPassHash = sharedPreferences.getString("ipb_pass_hash", null);
    String igneous = sharedPreferences.getString("igneous", null);
    boolean getIt = false;
    if (!TextUtils.isEmpty(ipbMemberId)) {
        mIpbMemberId.setText(ipbMemberId);
        getIt = true;
    }
    if (!TextUtils.isEmpty(ipbPassHash)) {
        mIpbPassHash.setText(ipbPassHash);
        getIt = true;
    }
    if (!TextUtils.isEmpty(igneous)) {
        mIgneous.setText(igneous);
        getIt = true;
    }
    if (getIt) {
        showTip(R.string.found_cookies, LENGTH_SHORT);
    }

    return view;
}
 
Example 11
Source File: DownloadLabelsScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public LabelAdapter() {
    mInflater = getLayoutInflater2();
    AssertUtils.assertNotNull(mInflater);
}
 
Example 12
Source File: GalleryPreviewsScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public GalleryPreviewAdapter() {
    mInflater = getLayoutInflater2();
    AssertUtils.assertNotNull(mInflater);
}
 
Example 13
Source File: GalleryInfoScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public InfoAdapter() {
    mInflater = getLayoutInflater2();
    AssertUtils.assertNotNull(mInflater);
}
 
Example 14
Source File: SignInScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_login, container, false);

    View loginForm = ViewUtils.$$(view, R.id.login_form);
    mProgress = ViewUtils.$$(view, R.id.progress);
    mUsernameLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.username_layout);
    mUsername = mUsernameLayout.getEditText();
    AssertUtils.assertNotNull(mUsername);
    mPasswordLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.password_layout);
    mPassword = mPasswordLayout.getEditText();
    AssertUtils.assertNotNull(mPassword);
    mRegister = ViewUtils.$$(loginForm, R.id.register);
    mSignIn = ViewUtils.$$(loginForm, R.id.sign_in);
    mSignInViaWebView = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_webview);
    mSignInViaCookies = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_cookies);
    mSkipSigningIn = (TextView) ViewUtils.$$(loginForm, R.id.skip_signing_in);

    mSignInViaWebView.setPaintFlags(mSignInViaWebView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    mSignInViaCookies.setPaintFlags(mSignInViaCookies.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    mSkipSigningIn.setPaintFlags(mSignInViaCookies.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

    mPassword.setOnEditorActionListener(this);

    mRegister.setOnClickListener(this);
    mSignIn.setOnClickListener(this);
    mSignInViaWebView.setOnClickListener(this);
    mSignInViaCookies.setOnClickListener(this);
    mSkipSigningIn.setOnClickListener(this);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    EhApplication application = (EhApplication) context.getApplicationContext();
    if (application.containGlobalStuff(mRequestId)) {
        mSigningIn = true;
        // request exist
        showProgress(false);
    }

    return view;
}
 
Example 15
Source File: GalleryDetailScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
private String getAllRatingText(float rating, int ratingCount) {
    Resources resources = getResources2();
    AssertUtils.assertNotNull(resources);
    return resources.getString(R.string.rating_text, getRatingText(rating, resources), rating, ratingCount);
}
 
Example 16
Source File: GalleryListScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    mClient = EhApplication.getEhClient(context);
    mDownloadManager = EhApplication.getDownloadManager(context);
    mFavouriteStatusRouter = EhApplication.getFavouriteStatusRouter(context);

    mDownloadInfoListener = new DownloadManager.DownloadInfoListener() {
        @Override
        public void onAdd(@NonNull DownloadInfo info, @NonNull List<DownloadInfo> list, int position) {
            if (mAdapter != null) {
                mAdapter.notifyDataSetChanged();
            }
        }
        @Override
        public void onUpdate(@NonNull DownloadInfo info, @NonNull List<DownloadInfo> list) { }
        @Override
        public void onUpdateAll() { }
        @Override
        public void onReload() {
            if (mAdapter != null) {
                mAdapter.notifyDataSetChanged();
            }
        }
        @Override
        public void onChange() {
            if (mAdapter != null) {
                mAdapter.notifyDataSetChanged();
            }
        }
        @Override
        public void onRenameLabel(String from, String to) { }
        @Override
        public void onRemove(@NonNull DownloadInfo info, @NonNull List<DownloadInfo> list, int position) {
            if (mAdapter != null) {
                mAdapter.notifyDataSetChanged();
            }
        }
        @Override
        public void onUpdateLabels() { }
    };
    mDownloadManager.addDownloadInfoListener(mDownloadInfoListener);

    mFavouriteStatusRouterListener = (gid, slot) -> {
        if (mAdapter != null) {
            mAdapter.notifyDataSetChanged();
        }
    };
    mFavouriteStatusRouter.addListener(mFavouriteStatusRouterListener);

    if (savedInstanceState == null) {
        onInit();
    } else {
        onRestore(savedInstanceState);
    }
}
 
Example 17
Source File: DownloadsScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_download, container, false);

    View content = ViewUtils.$$(view, R.id.content);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view);
    FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(content, tip);

    Context context = getContext2();
    AssertUtils.assertNotNull(content);
    Resources resources = context.getResources();

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_download);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mAdapter = new DownloadAdapter();
    mAdapter.setHasStableIds(true);
    mRecyclerView.setAdapter(mAdapter);
    mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
    mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
    mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener());
    // Cancel change animation
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }
    int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);
    if (mInitPosition >= 0) {
        mRecyclerView.scrollToPosition(mInitPosition);
        mInitPosition = -1;
    }

    fastScroller.attachToRecyclerView(mRecyclerView);
    HandlerDrawable handlerDrawable = new HandlerDrawable();
    handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
    fastScroller.setHandlerDrawable(handlerDrawable);
    fastScroller.setOnDragHandlerListener(this);

    mFabLayout.setExpanded(false, false);
    mFabLayout.setHidePrimaryFab(true);
    mFabLayout.setAutoCancel(false);
    mFabLayout.setOnClickFabListener(this);
    addAboveSnackView(mFabLayout);

    updateView();

    guide();

    return view;
}
 
Example 18
Source File: GalleryListScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
                          @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_list, container, false);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Resources resources = context.getResources();

    mHideActionFabSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mShowActionFab = true;

    View mainLayout = ViewUtils.$$(view, R.id.main_layout);
    ContentLayout contentLayout = (ContentLayout) ViewUtils.$$(mainLayout, R.id.content_layout);
    mRecyclerView = contentLayout.getRecyclerView();
    FastScroller fastScroller = contentLayout.getFastScroller();
    RefreshLayout refreshLayout = contentLayout.getRefreshLayout();
    mSearchLayout = (SearchLayout) ViewUtils.$$(mainLayout, R.id.search_layout);
    mSearchBar = (SearchBar) ViewUtils.$$(mainLayout, R.id.search_bar);
    mFabLayout = (FabLayout) ViewUtils.$$(mainLayout, R.id.fab_layout);
    mSearchFab = ViewUtils.$$(mainLayout, R.id.search_fab);

    int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
    int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);

    mViewTransition = new ViewTransition(contentLayout, mSearchLayout);

    mHelper = new GalleryListHelper();
    contentLayout.setHelper(mHelper);
    contentLayout.getFastScroller().setOnDragHandlerListener(this);

    mAdapter = new GalleryListAdapter(inflater, resources,
            mRecyclerView, Settings.getListMode());
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.addOnScrollListener(mOnScrollListener);

    fastScroller.setPadding(fastScroller.getPaddingLeft(), fastScroller.getPaddingTop() + paddingTopSB,
            fastScroller.getPaddingRight(), fastScroller.getPaddingBottom());

    refreshLayout.setHeaderTranslationY(paddingTopSB);

    mLeftDrawable = new DrawerArrowDrawable(context, AttrResources.getAttrColor(context, R.attr.drawableColorPrimary));
    mRightDrawable = new AddDeleteDrawable(context, AttrResources.getAttrColor(context, R.attr.drawableColorPrimary), null);
    mSearchBar.setLeftDrawable(mLeftDrawable);
    mSearchBar.setRightDrawable(mRightDrawable);
    mSearchBar.setHelper(this);
    mSearchBar.setOnStateChangeListener(this);
    setSearchBarHint(context, mSearchBar);
    setSearchBarSuggestionProvider(mSearchBar);

    mSearchLayout.setHelper(this);
    mSearchLayout.setPadding(mSearchLayout.getPaddingLeft(), mSearchLayout.getPaddingTop() + paddingTopSB,
            mSearchLayout.getPaddingRight(), mSearchLayout.getPaddingBottom() + paddingBottomFab);

    mSourceBar = (RadioGroup) ViewUtils.$$(mainLayout, R.id.source_bar);
    bindSource(mSourceBar);
    mFabLayout.setAutoCancel(true);
    mFabLayout.setExpanded(false);
    mFabLayout.setHidePrimaryFab(false);
    mFabLayout.setOnClickFabListener(this);
    mFabLayout.setOnExpandListener(this);
    addAboveSnackView(mFabLayout);

    mActionFabDrawable = new AddDeleteDrawable(context, resources.getColor(R.color.primary_drawable_dark), currentSource);
    mFabLayout.getPrimaryFab().setImageDrawable(mActionFabDrawable);

    mSearchFab.setOnClickListener(this);

    mSearchBarMover = new SearchBarMover(this, mSearchBar, mRecyclerView, mSearchLayout);

    // Update list url builder
    onUpdateUrlBuilder();

    // Restore state
    int newState = mState;
    mState = STATE_NORMAL;
    setState(newState, false);

    // Only refresh for the first time
    if (!mHasFirstRefresh) {
        mHasFirstRefresh = true;
        mHelper.firstRefresh();
    }

    guideQuickSearch();
    return view;
}
 
Example 19
Source File: GalleryCommentsScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
                          @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_comments, container, false);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
    mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
    mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Resources resources = context.getResources();
    int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mAdapter = new CommentAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context,
            RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setShowLastDivider(true);
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
            mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + paddingBottomFab);
    // Cancel change animator
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof DefaultItemAnimator) {
        ((DefaultItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }

    mSendImage.setOnClickListener(this);
    mFab.setOnClickListener(this);

    addAboveSnackView(mEditPanel);
    addAboveSnackView(mFabLayout);

    mViewTransition = new ViewTransition(mRecyclerView, tip);

    updateView(false);

    return view;
}
 
Example 20
Source File: HistoryScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_history, container, false);
    View content = ViewUtils.$$(view, R.id.content);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view);
    FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(content, tip);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Resources resources = context.getResources();

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_history);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    RecyclerViewTouchActionGuardManager guardManager = new RecyclerViewTouchActionGuardManager();
    guardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    guardManager.setEnabled(true);
    RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
    mAdapter = new HistoryAdapter();
    mAdapter.setHasStableIds(true);
    mAdapter = swipeManager.createWrappedAdapter(mAdapter);
    mRecyclerView.setAdapter(mAdapter);
    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
    animator.setSupportsChangeAnimations(false);
    mRecyclerView.setItemAnimator(animator);
    AutoStaggeredGridLayoutManager layoutManager = new AutoStaggeredGridLayoutManager(
            0, StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
    layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);
    guardManager.attachRecyclerView(mRecyclerView);
    swipeManager.attachRecyclerView(mRecyclerView);

    fastScroller.attachToRecyclerView(mRecyclerView);
    HandlerDrawable handlerDrawable = new HandlerDrawable();
    handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
    fastScroller.setHandlerDrawable(handlerDrawable);

    updateLazyList();
    updateView(false);

    return view;
}