-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,255 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...n/java/com/qmuiteam/qmuidemo/fragment/components/swipeAction/QDRVSwipeActionFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
} | ||
} |
180 changes: 180 additions & 0 deletions
180
...muiteam/qmuidemo/fragment/components/swipeAction/QDRVSwipeDeleteWithNoActionFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.