Skip to content

Commit

Permalink
demo for swipe action
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Mar 4, 2020
1 parent 810c5ce commit 8f663ee
Show file tree
Hide file tree
Showing 12 changed files with 1,255 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ public static class ActionBuilder {
int mPaddingStartEnd = 0;
int mOrientation = VERTICAL;
boolean mReverseDrawOrder = false;
TimeInterpolator mSwipeMoveInterpolator = QMUIInterpolatorStaticHolder.LINEAR_INTERPOLATOR;
int mSwipePxPerMS = 3;
TimeInterpolator mSwipeMoveInterpolator = QMUIInterpolatorStaticHolder.ACCELERATE_INTERPOLATOR;
int mSwipePxPerMS = 2;

public ActionBuilder text(String text) {
mText = text;
Expand Down
2 changes: 2 additions & 0 deletions qmuidemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.VIBRATE" />

<application
android:name=".QDApplication"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import com.qmuiteam.qmuidemo.base.BaseFragmentActivity;
import com.qmuiteam.qmuidemo.fragment.QDWebExplorerFragment;
import com.qmuiteam.qmuidemo.fragment.components.QDPopupFragment;
import com.qmuiteam.qmuidemo.fragment.components.QDRecyclerViewSwipeActionFragment;
import com.qmuiteam.qmuidemo.fragment.components.swipeAction.QDRVSwipeMutiActionFragment;
import com.qmuiteam.qmuidemo.fragment.components.QDTabSegmentFixModeFragment;
import com.qmuiteam.qmuidemo.fragment.components.pullLayout.QDPullHorizontalTestFragment;
import com.qmuiteam.qmuidemo.fragment.components.pullLayout.QDPullRefreshAndLoadMoreTestFragment;
Expand Down Expand Up @@ -88,7 +88,7 @@
QDPullVerticalTestFragment.class,
QDPullHorizontalTestFragment.class,
QDPullRefreshAndLoadMoreTestFragment.class,
QDRecyclerViewSwipeActionFragment.class,
QDRVSwipeMutiActionFragment.class,
QDPopupFragment.class
})
@DefaultFirstFragment(HomeFragment.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Tencent is pleased to support the open source community by making QMUI_Android available.
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.qmuiteam.qmuidemo.fragment.components.swipeAction;

import android.view.LayoutInflater;
import android.view.View;

import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView;
import com.qmuiteam.qmui.widget.pullLayout.QMUIPullLayout;
import com.qmuiteam.qmuidemo.R;
import com.qmuiteam.qmuidemo.base.BaseFragment;
import com.qmuiteam.qmuidemo.fragment.components.pullLayout.QDPullHorizontalTestFragment;
import com.qmuiteam.qmuidemo.fragment.components.pullLayout.QDPullRefreshAndLoadMoreTestFragment;
import com.qmuiteam.qmuidemo.fragment.components.pullLayout.QDPullVerticalTestFragment;
import com.qmuiteam.qmuidemo.lib.annotation.Widget;
import com.qmuiteam.qmuidemo.manager.QDDataManager;
import com.qmuiteam.qmuidemo.model.QDItemDescription;

import butterknife.BindView;
import butterknife.ButterKnife;

@Widget(widgetClass = QMUIRVItemSwipeAction.class, iconRes = R.mipmap.icon_grid_rv_item_swipe_action)
public class QDRVSwipeActionFragment extends BaseFragment {
@BindView(R.id.topbar)
QMUITopBarLayout mTopBar;
@BindView(R.id.groupListView)
QMUIGroupListView mGroupListView;

private QDDataManager mQDDataManager;
private QDItemDescription mQDItemDescription;

@Override
protected View onCreateView() {
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_grouplistview, null);
ButterKnife.bind(this, root);

mQDDataManager = QDDataManager.getInstance();
mQDItemDescription = mQDDataManager.getDescription(this.getClass());
initTopBar();

initGroupListView();

return root;
}

private void initTopBar() {
mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popBackStack();
}
});

mTopBar.setTitle(mQDItemDescription.getName());
}

private void initGroupListView() {
QMUIGroupListView.newSection(getContext())
.addItemView(mGroupListView.createItemView(mQDDataManager.getName(
QDRVSwipeMutiActionFragment.class)), new View.OnClickListener() {
@Override
public void onClick(View v) {
QDRVSwipeMutiActionFragment fragment = new QDRVSwipeMutiActionFragment();
startFragment(fragment);
}
})
.addItemView(mGroupListView.createItemView(mQDDataManager.getName(
QDRVSwipeMutiActionOnlyIconFragment.class)), new View.OnClickListener() {
@Override
public void onClick(View v) {
QDRVSwipeMutiActionOnlyIconFragment fragment = new QDRVSwipeMutiActionOnlyIconFragment();
startFragment(fragment);
}
})
.addItemView(mGroupListView.createItemView(mQDDataManager.getName(
QDRVSwipeMutiActionWithIconFragment.class)), new View.OnClickListener() {
@Override
public void onClick(View v) {
QDRVSwipeMutiActionWithIconFragment fragment = new QDRVSwipeMutiActionWithIconFragment();
startFragment(fragment);
}
})
.addItemView(mGroupListView.createItemView(mQDDataManager.getName(
QDRVSwipeSingleDeleteActionFragment.class)), new View.OnClickListener() {
@Override
public void onClick(View v) {
QDRVSwipeSingleDeleteActionFragment fragment = new QDRVSwipeSingleDeleteActionFragment();
startFragment(fragment);
}
})
.addItemView(mGroupListView.createItemView(mQDDataManager.getName(
QDRVSwipeDeleteWithNoActionFragment.class)), new View.OnClickListener() {
@Override
public void onClick(View v) {
QDRVSwipeDeleteWithNoActionFragment fragment = new QDRVSwipeDeleteWithNoActionFragment();
startFragment(fragment);
}
})
.addItemView(mGroupListView.createItemView(mQDDataManager.getName(
QDRVSwipeUpDeleteFragment.class)), new View.OnClickListener() {
@Override
public void onClick(View v) {
QDRVSwipeUpDeleteFragment fragment = new QDRVSwipeUpDeleteFragment();
startFragment(fragment);
}
})
.addTo(mGroupListView);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Tencent is pleased to support the open source community by making QMUI_Android available.
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.qmuiteam.qmuidemo.fragment.components.swipeAction;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qmuiteam.qmui.recyclerView.QMUIRVItemSwipeAction;
import com.qmuiteam.qmui.recyclerView.QMUISwipeAction;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.pullLayout.QMUIPullLayout;
import com.qmuiteam.qmuidemo.R;
import com.qmuiteam.qmuidemo.base.BaseFragment;
import com.qmuiteam.qmuidemo.base.BaseRecyclerAdapter;
import com.qmuiteam.qmuidemo.base.RecyclerViewHolder;
import com.qmuiteam.qmuidemo.lib.Group;
import com.qmuiteam.qmuidemo.lib.annotation.Widget;
import com.qmuiteam.qmuidemo.manager.QDDataManager;
import com.qmuiteam.qmuidemo.model.QDItemDescription;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

@Widget(group = Group.Other, name = "Swipe Left: Delete With No Action")
public class QDRVSwipeDeleteWithNoActionFragment extends BaseFragment {
@BindView(R.id.topbar)
QMUITopBarLayout mTopBar;
@BindView(R.id.pull_layout)
QMUIPullLayout mPullLayout;
@BindView(R.id.recyclerView)
RecyclerView mRecyclerView;
private BaseRecyclerAdapter<String> mAdapter;

private QDItemDescription mQDItemDescription;

@Override
protected View onCreateView() {
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_pull_refresh_and_load_more_test_layout, null);
ButterKnife.bind(this, root);

QDDataManager QDDataManager = com.qmuiteam.qmuidemo.manager.QDDataManager.getInstance();
mQDItemDescription = QDDataManager.getDescription(this.getClass());
initTopBar();
initData();

return root;
}

private void initTopBar() {
mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popBackStack();
}
});

mTopBar.setTitle(mQDItemDescription.getName());
}

private void initData() {

mPullLayout.setActionListener(new QMUIPullLayout.ActionListener() {
@Override
public void onActionTriggered(@NonNull QMUIPullLayout.PullAction pullAction) {
mPullLayout.postDelayed(new Runnable() {
@Override
public void run() {
if (pullAction.getPullEdge() == QMUIPullLayout.PULL_EDGE_TOP) {
onRefreshData();
} else if (pullAction.getPullEdge() == QMUIPullLayout.PULL_EDGE_BOTTOM) {
onLoadMore();
}
mPullLayout.finishActionRun(pullAction);
}
}, 3000);
}
});

QMUIRVItemSwipeAction swipeAction = new QMUIRVItemSwipeAction(true, new QMUIRVItemSwipeAction.Callback() {
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
mAdapter.remove(viewHolder.getAdapterPosition());
}

@Override
public int getSwipeDirection(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
return QMUIRVItemSwipeAction.SWIPE_LEFT;
}

@Override
public void onClickAction(QMUIRVItemSwipeAction swipeAction, RecyclerView.ViewHolder selected, QMUISwipeAction action) {
super.onClickAction(swipeAction, selected, action);
mAdapter.remove(selected.getAdapterPosition());
Toast.makeText(getContext(),
"你点击了第 " + selected.getAdapterPosition() + " 个 item 的" + action.getText(),
Toast.LENGTH_SHORT).show();
swipeAction.clear();
}
});
swipeAction.attachToRecyclerView(mRecyclerView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
});

mAdapter = new BaseRecyclerAdapter<String>(getContext(), null) {
@Override
public int getItemLayoutId(int viewType) {
return android.R.layout.simple_list_item_1;
}

@Override
public void bindData(RecyclerViewHolder holder, int position, String item) {
holder.setText(android.R.id.text1, item);
}
};
mAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View itemView, int pos) {
Toast.makeText(getContext(), "click position=" + pos, Toast.LENGTH_SHORT).show();
}
});
mRecyclerView.setAdapter(mAdapter);
onDataLoaded();
}

private void onDataLoaded() {
List<String> data = new ArrayList<>(Arrays.asList("Helps", "Maintain", "Liver", "Health", "Function", "Supports", "Healthy", "Fat",
"Metabolism", "Nuturally", "Bracket", "Refrigerator", "Bathtub", "Wardrobe", "Comb", "Apron", "Carpet", "Bolster", "Pillow", "Cushion"));
Collections.shuffle(data);
mAdapter.setData(data);
}

private void onRefreshData() {
List<String> data = new ArrayList<>();
long id = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
data.add("onRefreshData-" + id + "-" + i);
}
mAdapter.prepend(data);
mRecyclerView.scrollToPosition(0);
}

private void onLoadMore() {
List<String> data = new ArrayList<>();
long id = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
data.add("onLoadMore-" + id + "-" + i);
}
mAdapter.append(data);
}
}
Loading

0 comments on commit 8f663ee

Please sign in to comment.