Skip to content

Commit 457d05c

Browse files
Merge branch 'antondudakov-master'
2 parents 0b78fa3 + 73b2425 commit 457d05c

23 files changed

Lines changed: 1040 additions & 1132 deletions

File tree

.gitignore

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea/workspace.xml
5-
/.idea/libraries
62
.DS_Store
73
/captures
8-
9-
# Built application files
10-
*.apk
11-
*.ap_
12-
13-
# Files for the Dalvik VM
14-
*.dex
15-
16-
# Java class files
17-
*.class
4+
.idea/
5+
/*/.idea/
6+
.idea
187

198
# Generated files
209
bin/

.idea/compiler.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/xiaofeng/androidlibs/DemoAdapter.java

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,69 @@
1212
* Adapter for Demo item
1313
*/
1414
public class DemoAdapter extends RecyclerView.Adapter<DemoViewHolder> {
15-
List<String> items;
16-
private int maxLinesPerItem;
17-
private boolean showMeta = false;
18-
public DemoAdapter() {
19-
this.items = new LinkedList<>();
20-
maxLinesPerItem = 1;
21-
}
15+
List<String> items;
16+
private int maxLinesPerItem;
17+
private boolean showMeta = false;
2218

23-
public DemoAdapter(int maxLinesPerItem, List<String> items) {
24-
this();
25-
this.items.addAll(items);
26-
this.maxLinesPerItem = maxLinesPerItem;
27-
}
19+
public DemoAdapter() {
20+
this.items = new LinkedList<>();
21+
maxLinesPerItem = 1;
22+
}
2823

29-
@Override
30-
public DemoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
31-
return new DemoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.listitem_tag, parent, false)).setShowMeta(showMeta);
32-
}
24+
public DemoAdapter(int maxLinesPerItem, List<String> items) {
25+
this();
26+
this.items.addAll(items);
27+
this.maxLinesPerItem = maxLinesPerItem;
28+
}
3329

34-
@Override
35-
public void onBindViewHolder(final DemoViewHolder holder, final int position) {
36-
holder.setTagText(items.get(position));
37-
holder.tagSize.setClickable(false);
38-
holder.tagText.setClickable(false);
39-
holder.itemView.setOnClickListener(new View.OnClickListener() {
40-
@Override
41-
public void onClick(View v) {
42-
int adapterPosition = holder.getAdapterPosition();
43-
items.remove(adapterPosition);
44-
notifyItemRemoved(adapterPosition);
45-
}
46-
});
47-
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
48-
@Override
49-
public boolean onLongClick(View v) {
50-
int adapterPosition = holder.getAdapterPosition();
51-
List<String> newItems = DemoUtil.generate(1, 3, 14, maxLinesPerItem, true);
52-
items.addAll(adapterPosition, newItems);
53-
notifyItemRangeInserted(adapterPosition, newItems.size());
54-
return true;
55-
}
56-
});
57-
}
30+
@Override
31+
public DemoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
32+
return new DemoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.listitem_tag, parent, false)).setShowMeta(showMeta);
33+
}
5834

59-
@Override
60-
public int getItemCount() {
61-
return items.size();
62-
}
35+
@Override
36+
public void onBindViewHolder(final DemoViewHolder holder, final int position) {
37+
holder.setTagText(items.get(position));
38+
holder.tagSize.setClickable(false);
39+
holder.tagText.setClickable(false);
40+
// holder.tagSize.setText("(" + position + ")");
41+
// holder.tagSize.setVisibility(View.VISIBLE);
42+
holder.itemView.setOnClickListener(new View.OnClickListener() {
43+
@Override
44+
public void onClick(View v) {
45+
int adapterPosition = holder.getAdapterPosition();
46+
items.remove(adapterPosition);
47+
notifyItemRemoved(adapterPosition);
48+
}
49+
});
50+
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
51+
@Override
52+
public boolean onLongClick(View v) {
53+
int adapterPosition = holder.getAdapterPosition();
54+
List<String> newItems = DemoUtil.generate(1, 3, 14, maxLinesPerItem, true);
55+
items.addAll(adapterPosition, newItems);
56+
notifyItemRangeInserted(adapterPosition, newItems.size());
57+
return true;
58+
}
59+
});
60+
}
6361

64-
public void newItems(int maxLinesPerItem, List<String> newItems) {
65-
this.maxLinesPerItem = maxLinesPerItem;
66-
items.clear();
67-
items.addAll(newItems);
68-
}
62+
@Override
63+
public int getItemCount() {
64+
return items.size();
65+
}
6966

70-
public int getMaxLinesPerItem() {
71-
return maxLinesPerItem;
72-
}
67+
public void newItems(int maxLinesPerItem, List<String> newItems) {
68+
this.maxLinesPerItem = maxLinesPerItem;
69+
items.clear();
70+
items.addAll(newItems);
71+
}
7372

74-
public void setShowMeta(boolean showMeta) {
75-
this.showMeta = showMeta;
76-
}
73+
public int getMaxLinesPerItem() {
74+
return maxLinesPerItem;
75+
}
76+
77+
public void setShowMeta(boolean showMeta) {
78+
this.showMeta = showMeta;
79+
}
7780
}

app/src/main/java/com/xiaofeng/androidlibs/DemoUtil.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.xiaofeng.androidlibs;
22

3+
import android.util.Log;
4+
35
import java.util.ArrayList;
46
import java.util.List;
57
import java.util.Random;
@@ -13,8 +15,7 @@ public class DemoUtil {
1315
public static List<String> generate(int total, int minLen, int maxLen, int maxLinesPerItem, boolean randomOrder) {
1416
ArrayList<String> result = new ArrayList<>(total);
1517
StringBuilder sb = new StringBuilder();
16-
for (int i = 0; i < total; i ++) {
17-
sb.setLength(0);
18+
for (int i = 1; i <= total; i ++) {
1819
int lineCount = random.nextInt(maxLinesPerItem) + 1;
1920
List<String> lines = generate(lineCount, minLen, maxLen, randomOrder);
2021
boolean firstLine = true;
@@ -26,7 +27,7 @@ public static List<String> generate(int total, int minLen, int maxLen, int maxLi
2627
}
2728
sb.append(line);
2829
}
29-
result.add(sb.toString());
30+
result.add(sb.toString() + " (" + i + ")");
3031
}
3132
return result;
3233
}
@@ -42,11 +43,12 @@ public static List<String> generate(int total, int minLen, int maxLen, boolean r
4243
baseIndex = index % baseLen;
4344
len = random.nextInt(maxLen - minLen) + minLen;
4445
char baseChar = STRING_BASE.charAt(baseIndex);
45-
char[] chars = new char[len];
46-
for (int j = 0; j < len; j ++) {
47-
chars[j] = baseChar;
46+
Log.d("dbg", "generate: " + len);
47+
StringBuilder stringBuilder = new StringBuilder(len);
48+
for (int j = 0; j < len; j++) {
49+
stringBuilder.append((char) (random.nextInt(122 - 28) + 28));
4850
}
49-
result.add(new String(chars));
51+
result.add(stringBuilder.toString());
5052
}
5153
return result;
5254
}

app/src/main/java/com/xiaofeng/androidlibs/MainActivity.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919

2020
public class MainActivity extends AppCompatActivity {
2121

22-
RecyclerView recyclerView;
22+
private static final int REQ_CODE_SETTINGS = 101;
23+
RecyclerView recyclerView;
2324
FlowLayoutManager flowLayoutManager;
2425
MarkdownView markdownView;
25-
private static final int REQ_CODE_SETTINGS = 101;
2626
private boolean settingChanged = false;
2727
@Override
2828
protected void onCreate(Bundle savedInstanceState) {
2929
super.onCreate(savedInstanceState);
3030
setContentView(R.layout.app_bar_main);
31-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
32-
setSupportActionBar(toolbar);
31+
Toolbar toolbar = findViewById(R.id.toolbar);
32+
setSupportActionBar(toolbar);
3333
init();
3434
}
3535

3636
private void init() {
37-
recyclerView = (RecyclerView) findViewById(R.id.list);
38-
flowLayoutManager = new FlowLayoutManager().singleItemPerLine();
37+
recyclerView = findViewById(R.id.list);
38+
flowLayoutManager = new FlowLayoutManager().singleItemPerLine();
3939
flowLayoutManager.setAutoMeasureEnabled(true);
4040
recyclerView.setLayoutManager(flowLayoutManager);
41-
recyclerView.setAdapter(new DemoAdapter(1, DemoUtil.generate(2000, 3, 13, 1, false)));
41+
recyclerView.setAdapter(new DemoAdapter(1, DemoUtil.generate(32, 10, 60, 1, false)));
4242
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
4343
@Override
4444
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
@@ -47,8 +47,8 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle
4747
}
4848
});
4949

50-
markdownView = (MarkdownView)findViewById(R.id.instruction_mdown);
51-
markdownView.loadMarkdownFile("file:///android_asset/instruction.md");
50+
// markdownView = (MarkdownView)findViewById(R.id.instruction_mdown);
51+
// markdownView.loadMarkdownFile("file:///android_asset/instruction.md");
5252
loadSettingsFromSharedPref();
5353
}
5454

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<solid android:color="@color/colorPrimaryDark" />
5+
<stroke
6+
android:width="1dp"
7+
android:color="@color/colorAccent" />
8+
<corners android:radius="4dp" />
9+
10+
</shape>

app/src/main/res/layout/content_main.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
xmlns:tools="http://schemas.android.com/tools"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8+
android:orientation="vertical"
89
android:paddingBottom="@dimen/activity_vertical_margin"
910
android:paddingLeft="@dimen/activity_horizontal_margin"
1011
android:paddingRight="@dimen/activity_horizontal_margin"
1112
android:paddingTop="@dimen/activity_vertical_margin"
1213
app:layout_behavior="@string/appbar_scrolling_view_behavior"
1314
tools:context="com.xiaofeng.androidlibs.MainActivity"
14-
tools:showIn="@layout/app_bar_main"
15-
android:orientation="vertical">
15+
tools:showIn="@layout/app_bar_main">
1616
<FrameLayout
1717
android:layout_width="match_parent"
1818
android:layout_height="wrap_content"
19-
android:padding="8dp"
20-
android:background="@color/instructionBackground">
19+
android:background="@color/instructionBackground"
20+
android:padding="8dp">
2121
<us.feras.mdv.MarkdownView
2222
android:id="@+id/instruction_mdown"
2323
android:layout_width="match_parent"
@@ -28,5 +28,11 @@
2828
android:id="@+id/list"
2929
android:layout_width="match_parent"
3030
android:layout_height="match_parent"
31-
android:background="@color/colorAccent"/>
31+
android:background="?attr/colorPrimary"
32+
android:clipToPadding="false"
33+
android:fadeScrollbars="false"
34+
android:padding="48dp"
35+
android:scrollbarStyle="outsideOverlay"
36+
android:scrollbarThumbVertical="@color/colorPrimaryDark"
37+
android:scrollbars="vertical" />
3238
</LinearLayout>
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="horizontal"
43
android:layout_width="wrap_content"
54
android:layout_height="wrap_content"
6-
android:background="@color/colorPrimary"
5+
android:background="@drawable/tagbg"
6+
android:orientation="horizontal"
77
android:padding="10dp">
88
<TextView
99
android:id="@+id/tag_text"
1010
android:layout_width="wrap_content"
1111
android:layout_height="wrap_content"
1212
android:layout_marginRight="4dp"
13-
android:text="0000"/>
13+
android:text="0000"
14+
android:textColor="@android:color/white" />
1415
<TextView
1516
android:id="@+id/tag_count"
1617
android:layout_width="wrap_content"
1718
android:layout_height="wrap_content"
18-
android:text="(4)"/>
19+
android:text="(4)"
20+
android:textColor="@android:color/white" />
1921

2022
</LinearLayout>

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#3F51B5</color>
3+
<color name="colorPrimary">#9fa8da</color>
44
<color name="colorPrimaryDark">#303F9F</color>
55
<color name="colorAccent">#FF4081</color>
66
<color name="instructionBackground">#ffff99</color>

0 commit comments

Comments
 (0)