Search in sources :

Example 6 with EasyRecyclerView

use of com.hippo.easyrecyclerview.EasyRecyclerView in project EhViewer by seven332.

the class GalleryCommentsScene method onCreateView3.

@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();
    Assert.assertNotNull(context);
    Resources resources = context.getResources();
    int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
    Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
    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, LinearLayoutManager.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider), LayoutUtils.dp2pix(context, 1));
    decoration.setShowLastDivider(true);
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
    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;
}
Also used : Context(android.content.Context) Drawable(android.graphics.drawable.Drawable) ViewTransition(com.hippo.view.ViewTransition) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) LinearDividerItemDecoration(com.hippo.easyrecyclerview.LinearDividerItemDecoration) LinkifyTextView(com.hippo.widget.LinkifyTextView) ImageView(android.widget.ImageView) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) View(android.view.View) TextView(android.widget.TextView) ObservedTextView(com.hippo.widget.ObservedTextView) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) LinkifyTextView(com.hippo.widget.LinkifyTextView) TextView(android.widget.TextView) ObservedTextView(com.hippo.widget.ObservedTextView) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) Resources(android.content.res.Resources) Nullable(android.support.annotation.Nullable)

Example 7 with EasyRecyclerView

use of com.hippo.easyrecyclerview.EasyRecyclerView in project EhViewer by seven332.

the class DownloadLabelsScene method onCreateView3.

@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();
    Assert.assertNotNull(context);
    Drawable drawable = DrawableManager.getDrawable(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);
    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    RecyclerViewTouchActionGuardManager guardManager = new RecyclerViewTouchActionGuardManager();
    guardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    guardManager.setEnabled(true);
    // drag & drop manager
    RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
    dragDropManager.setDraggingItemShadowDrawable((NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
    // swipe manager
    RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
    RecyclerView.Adapter adapter = new LabelAdapter();
    adapter.setHasStableIds(true);
    // wrap for dragging
    adapter = dragDropManager.createWrappedAdapter(adapter);
    // wrap for swiping
    adapter = swipeManager.createWrappedAdapter(adapter);
    mAdapter = adapter;
    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
    animator.setSupportsChangeAnimations(false);
    mRecyclerView.hasFixedSize();
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setItemAnimator(animator);
    guardManager.attachRecyclerView(mRecyclerView);
    swipeManager.attachRecyclerView(mRecyclerView);
    dragDropManager.attachRecyclerView(mRecyclerView);
    updateView();
    return view;
}
Also used : Context(android.content.Context) RecyclerViewSwipeManager(com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager) ViewTransition(com.hippo.view.ViewTransition) Drawable(android.graphics.drawable.Drawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) SwipeDismissItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RecyclerViewTouchActionGuardManager(com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager) TextView(android.widget.TextView) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager) Nullable(android.support.annotation.Nullable)

Example 8 with EasyRecyclerView

use of com.hippo.easyrecyclerview.EasyRecyclerView in project EhViewer by seven332.

the class DownloadsScene method onItemLongClick.

@Override
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
    EasyRecyclerView recyclerView = mRecyclerView;
    if (recyclerView == null) {
        return false;
    }
    if (!recyclerView.isInCustomChoice()) {
        recyclerView.intoCustomChoiceMode();
    }
    recyclerView.toggleItemChecked(position);
    return true;
}
Also used : EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView)

Example 9 with EasyRecyclerView

use of com.hippo.easyrecyclerview.EasyRecyclerView in project EhViewer by seven332.

the class DownloadsScene method onClickSecondaryFab.

@Override
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
    Context context = getContext2();
    Activity activity = getActivity2();
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == context || null == activity || null == recyclerView) {
        return;
    }
    if (0 == position) {
        recyclerView.checkAll();
    } else {
        List<DownloadInfo> list = mList;
        if (list == null) {
            return;
        }
        LongList gidList = null;
        List<DownloadInfo> downloadInfoList = null;
        // Start, Stop, Delete
        boolean collectGid = position == 1 || position == 2 || position == 3;
        // Delete or Move
        boolean collectDownloadInfo = position == 3 || position == 4;
        if (collectGid) {
            gidList = new LongList();
        }
        if (collectDownloadInfo) {
            downloadInfoList = new LinkedList<>();
        }
        SparseBooleanArray stateArray = recyclerView.getCheckedItemPositions();
        for (int i = 0, n = stateArray.size(); i < n; i++) {
            if (stateArray.valueAt(i)) {
                DownloadInfo info = list.get(stateArray.keyAt(i));
                if (collectDownloadInfo) {
                    downloadInfoList.add(info);
                }
                if (collectGid) {
                    gidList.add(info.gid);
                }
            }
        }
        switch(position) {
            case 1:
                {
                    // Start
                    Intent intent = new Intent(activity, DownloadService.class);
                    intent.setAction(DownloadService.ACTION_START_RANGE);
                    intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
                    activity.startService(intent);
                    // Cancel check mode
                    recyclerView.outOfCustomChoiceMode();
                    break;
                }
            case 2:
                {
                    // Stop
                    if (null != mDownloadManager) {
                        mDownloadManager.stopRangeDownload(gidList);
                    }
                    // Cancel check mode
                    recyclerView.outOfCustomChoiceMode();
                    break;
                }
            case 3:
                {
                    // Delete
                    CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context, getString(R.string.download_remove_dialog_message_2, gidList.size()), getString(R.string.download_remove_dialog_check_text), Settings.getRemoveImageFiles());
                    DeleteRangeDialogHelper helper = new DeleteRangeDialogHelper(downloadInfoList, gidList, builder);
                    builder.setTitle(R.string.download_remove_dialog_title).setPositiveButton(android.R.string.ok, helper).show();
                    break;
                }
            case 4:
                {
                    // Move
                    List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(context).getLabelList();
                    List<String> labelList = new ArrayList<>(labelRawList.size() + 1);
                    labelList.add(getString(R.string.default_download_label_name));
                    for (int i = 0, n = labelRawList.size(); i < n; i++) {
                        labelList.add(labelRawList.get(i).getLabel());
                    }
                    String[] labels = labelList.toArray(new String[labelList.size()]);
                    MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList);
                    new AlertDialog.Builder(context).setTitle(R.string.download_move_dialog_title).setItems(labels, helper).show();
                    break;
                }
        }
    }
}
Also used : Context(android.content.Context) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) MainActivity(com.hippo.ehviewer.ui.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent) LongList(com.hippo.yorozuya.collect.LongList) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) DownloadService(com.hippo.ehviewer.download.DownloadService) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) SparseBooleanArray(android.util.SparseBooleanArray) List(java.util.List) LongList(com.hippo.yorozuya.collect.LongList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder)

Example 10 with EasyRecyclerView

use of com.hippo.easyrecyclerview.EasyRecyclerView in project EhViewer by seven332.

the class DownloadsScene method onItemClick.

@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
    Activity activity = getActivity2();
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == activity || null == recyclerView) {
        return false;
    }
    if (recyclerView.isInCustomChoice()) {
        recyclerView.toggleItemChecked(position);
        return true;
    } else {
        List<DownloadInfo> list = mList;
        if (list == null) {
            return false;
        }
        if (position < 0 && position >= list.size()) {
            return false;
        }
        Intent intent = new Intent(activity, GalleryActivity.class);
        intent.setAction(GalleryActivity.ACTION_EH);
        intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position));
        startActivity(intent);
        return true;
    }
}
Also used : EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) MainActivity(com.hippo.ehviewer.ui.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent)

Aggregations

EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)14 RecyclerView (android.support.v7.widget.RecyclerView)10 Context (android.content.Context)8 View (android.view.View)8 TextView (android.widget.TextView)8 Nullable (android.support.annotation.Nullable)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 SuppressLint (android.annotation.SuppressLint)5 Drawable (android.graphics.drawable.Drawable)5 ViewTransition (com.hippo.view.ViewTransition)5 LinearDividerItemDecoration (com.hippo.easyrecyclerview.LinearDividerItemDecoration)4 Activity (android.app.Activity)3 Resources (android.content.res.Resources)3 GeneralItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator)3 SwipeDismissItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator)3 RecyclerViewSwipeManager (com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager)3 RecyclerViewTouchActionGuardManager (com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager)3 MainActivity (com.hippo.ehviewer.ui.MainActivity)3 SimpleRatingView (com.hippo.ehviewer.widget.SimpleRatingView)3 LoadImageView (com.hippo.widget.LoadImageView)3