-
Notifications
You must be signed in to change notification settings - Fork 141
/
MainActivity.java
166 lines (153 loc) · 7.41 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package me.jingbin.byrecyclerview;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Arrays;
import java.util.List;
import me.jingbin.byrecyclerview.activity.AppBarLayoutActivity;
import me.jingbin.byrecyclerview.activity.FlexBoxActivity;
import me.jingbin.byrecyclerview.activity.HeaderFooterActivity;
import me.jingbin.byrecyclerview.activity.ItemClickActivity;
import me.jingbin.byrecyclerview.activity.ItemPayloadActivity;
import me.jingbin.byrecyclerview.activity.LoadMoreActivity;
import me.jingbin.byrecyclerview.activity.SecondTypeActivity;
import me.jingbin.byrecyclerview.activity.StateViewActivity;
import me.jingbin.byrecyclerview.activity.StickyRvCoordinatorActivity;
import me.jingbin.byrecyclerview.activity.StickyItemActivity;
import me.jingbin.byrecyclerview.activity.StickyRvActivity;
import me.jingbin.byrecyclerview.activity.StickyRvCoordinatorOriginalActivity;
import me.jingbin.byrecyclerview.databinding.ActivityMainBinding;
import me.jingbin.byrecyclerview.utils.WebUtil;
import me.jingbin.library.adapter.BaseByViewHolder;
import me.jingbin.library.adapter.BaseRecyclerAdapter;
import me.jingbin.library.decoration.SpacesItemDecoration;
import me.jingbin.library.view.OnItemFilterClickListener;
/**
* @author jingbin
* link to https://github.com/youlookwhat/ByRecyclerView
*/
public class MainActivity extends AppCompatActivity {
private final List<String> list = Arrays.asList(
"下拉刷新、加载更多",
"自动加载更多、松手加载更多",
"Add HeaderView/FooterView",
"设置StateView",
"item 点击/长按",
"item 局部刷新",
"adapter (多类型、databinding、ListView)",
"万能分割线",
"item 悬浮置顶",
"Skeleton 骨架图",
"CoordinatorLayout + RecyclerView 使用示例",
"FlexboxLayoutManager 显示处理",
"RecyclerView 嵌套滑动置顶",
"CoordinatorLayout 嵌套滑动置顶(惯性滑动方案)",
"CoordinatorLayout 嵌套滑动置顶(原始方案)"
);
private ActivityMainBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
binding.toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.icon_action_info));
setSupportActionBar(binding.toolbar);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.VERTICAL);
binding.recyclerView.setLayoutManager(layoutManager);
binding.recyclerView.setAdapter(new BaseRecyclerAdapter<String>(R.layout.item_main, list) {
@Override
protected void bindView(BaseByViewHolder<String> holder, String bean, int position) {
holder.setText(R.id.tv_sort, (position + 1) + "、");
holder.setText(R.id.tv_text, bean);
}
});
binding.recyclerView.addItemDecoration(new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL).setNoShowDivider(0, 0));
binding.recyclerView.setOnItemClickListener(new OnItemFilterClickListener() {
@Override
public void onSingleClick(View v, int position) {
switch (position) {
case 0:// 下拉刷新、加载更多
SecondTypeActivity.start(v.getContext(), "refreshLoadMore");
break;
case 1:// 自动加载更多、松手加载更多
startActivity(new Intent(MainActivity.this, LoadMoreActivity.class));
break;
case 2:// Add HeaderView/FooterView
startActivity(new Intent(MainActivity.this, HeaderFooterActivity.class));
break;
case 3:// 设置StateView
startActivity(new Intent(MainActivity.this, StateViewActivity.class));
break;
case 4:// item 点击/长按
startActivity(new Intent(MainActivity.this, ItemClickActivity.class));
break;
case 5:// item 局部刷新
startActivity(new Intent(MainActivity.this, ItemPayloadActivity.class));
break;
case 6:// adapter (多类型、databinding、ListView)
SecondTypeActivity.start(v.getContext(), "adapter");
break;
case 7:// 万能分割线
SecondTypeActivity.start(v.getContext(), "Divider");
break;
case 8:// item 悬浮置顶
startActivity(new Intent(MainActivity.this, StickyItemActivity.class));
break;
case 9:// Skeleton 骨架图
SecondTypeActivity.start(v.getContext(), "Skeleton");
break;
case 10:// CoordinatorLayout + RecyclerView 使用示例
startActivity(new Intent(MainActivity.this, AppBarLayoutActivity.class));
break;
case 11:// FlexboxLayoutManager
startActivity(new Intent(MainActivity.this, FlexBoxActivity.class));
break;
case 12:// RecyclerView 嵌套滑动置顶
startActivity(new Intent(MainActivity.this, StickyRvActivity.class));
break;
case 13:// CoordinatorLayout 嵌套滑动置顶
startActivity(new Intent(MainActivity.this, StickyRvCoordinatorActivity.class));
break;
case 14:// CoordinatorLayout 嵌套滑动置顶
startActivity(new Intent(MainActivity.this, StickyRvCoordinatorOriginalActivity.class));
break;
default:
break;
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.findItem(R.id.actionbar_update);
item.setTitle("更新:当前版本为" + BuildConfig.VERSION_NAME);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionbar_info:
WebUtil.openLink(MainActivity.this, "https://github.com/youlookwhat/ByRecyclerView");
break;
case R.id.actionbar_update:
WebUtil.openLink(MainActivity.this, "https://github.com/youlookwhat/download/blob/main/ByRecyclerView.apk");
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
super.onDestroy();
binding.recyclerView.destroy();
}
}