Skip to content

Commit 5110340

Browse files
New Demo App
Bugfix left & center align Remove uneccesary code
1 parent 2c187d8 commit 5110340

28 files changed

+243
-484
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ FlowLayoutManager is a layoutManager that works with Android ___RecyclerView___
77

88
## Screenshots
99
<img src="https://github.com/simonebortolin/FlowLayoutManager/blob/master/image_1.png" alt="" width="200px"></a>
10+
<img src="https://github.com/simonebortolin/FlowLayoutManager/blob/master/image_2.png" alt="" width="200px"></a>
11+
<img src="https://github.com/simonebortolin/FlowLayoutManager/blob/master/image_3.png" alt="" width="200px"></a>
1012

1113
## Installation
1214

@@ -23,7 +25,7 @@ Step 1. Add it in your **root** build.gradle at the end of repositories:
2325
Step 2. Add the dependency
2426

2527
dependencies {
26-
compile 'com.github.simonebortolin:FlowLayoutManager:1.3.1'
28+
compile 'com.github.simonebortolin:FlowLayoutManager:1.4.0'
2729
}
2830

2931
Item per line limitation

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ android {
1010
targetSdkVersion androidTargetSdkVersion
1111
versionCode 1
1212
versionName "1.0"
13+
vectorDrawables.useSupportLibrary = true
1314
}
1415
buildTypes {
1516
release {
@@ -24,6 +25,9 @@ android {
2425
}
2526

2627
dependencies {
28+
implementation 'com.android.support:design:26.1.0'
29+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
30+
implementation 'com.android.support:support-vector-drawable:26.1.0'
2731
compile fileTree(include: ['*.jar'], dir: 'libs')
2832
testCompile 'junit:junit:4.12'
2933
compile(group: 'com.android.support', name: 'design', version: supportLibVersion)

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.xiaofeng.androidlibs">
3+
package="com.xiaofeng.androidlibs">
44

55
<application
66
android:allowBackup="true"
@@ -11,18 +11,13 @@
1111
<activity
1212
android:name=".MainActivity"
1313
android:label="@string/app_name"
14-
android:theme="@style/AppTheme.NoActionBar">
14+
android:theme="@style/AppTheme">
1515
<intent-filter>
16-
<action android:name="android.intent.action.MAIN"/>
16+
<action android:name="android.intent.action.MAIN" />
1717

18-
<category android:name="android.intent.category.LAUNCHER"/>
18+
<category android:name="android.intent.category.LAUNCHER" />
1919
</intent-filter>
2020
</activity>
21-
<activity
22-
android:name=".SettingsActivity"
23-
android:label="@string/title_activity_settings"
24-
android:parentActivityName=".MainActivity">
25-
</activity>
2621
</application>
2722

2823
</manifest>

app/src/main/assets/instruction.md

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

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
* Adapter for Demo item
1313
*/
1414
public class DemoAdapter extends RecyclerView.Adapter<DemoViewHolder> {
15-
List<String> items;
16-
private int maxLinesPerItem;
15+
private List<String> items;
1716
private boolean showMeta = false;
1817

1918
public DemoAdapter() {
2019
this.items = new LinkedList<>();
21-
maxLinesPerItem = 1;
2220
}
2321

24-
public DemoAdapter(int maxLinesPerItem, List<String> items) {
22+
public DemoAdapter(List<String> items) {
2523
this();
2624
this.items.addAll(items);
27-
this.maxLinesPerItem = maxLinesPerItem;
2825
}
2926

3027
@Override
3128
public DemoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
32-
return new DemoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.tag, parent, false)).setShowMeta(showMeta);
29+
return new DemoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.main_item, parent, false)).setShowMeta(showMeta);
3330
}
3431

3532
@Override
@@ -62,18 +59,4 @@ public boolean onLongClick(View v) {
6259
public int getItemCount() {
6360
return items.size();
6461
}
65-
66-
public void newItems(int maxLinesPerItem, List<String> newItems) {
67-
this.maxLinesPerItem = maxLinesPerItem;
68-
items.clear();
69-
items.addAll(newItems);
70-
}
71-
72-
public int getMaxLinesPerItem() {
73-
return maxLinesPerItem;
74-
}
75-
76-
public void setShowMeta(boolean showMeta) {
77-
this.showMeta = showMeta;
78-
}
7962
}

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

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 67 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,83 @@
11
package com.xiaofeng.androidlibs;
22

3-
import android.content.Intent;
4-
import android.content.SharedPreferences;
53
import android.graphics.Rect;
64
import android.os.Bundle;
7-
import android.preference.PreferenceManager;
5+
import android.support.annotation.NonNull;
6+
import android.support.design.widget.BottomNavigationView;
87
import android.support.v7.app.AppCompatActivity;
98
import android.support.v7.widget.RecyclerView;
10-
import android.support.v7.widget.Toolbar;
11-
import android.view.Menu;
129
import android.view.MenuItem;
1310
import android.view.View;
1411

1512
import com.xiaofeng.flowlayoutmanager.Alignment;
1613
import com.xiaofeng.flowlayoutmanager.FlowLayoutManager;
1714

18-
import us.feras.mdv.MarkdownView;
19-
2015
public class MainActivity extends AppCompatActivity {
2116

22-
private static final int REQ_CODE_SETTINGS = 101;
23-
RecyclerView recyclerView;
24-
FlowLayoutManager flowLayoutManager;
25-
MarkdownView markdownView;
26-
private boolean settingChanged = false;
27-
@Override
28-
protected void onCreate(Bundle savedInstanceState) {
29-
super.onCreate(savedInstanceState);
30-
setContentView(R.layout.main_app_bar);
31-
Toolbar toolbar = findViewById(R.id.toolbar);
32-
setSupportActionBar(toolbar);
33-
init();
34-
}
35-
36-
private void init() {
37-
recyclerView = findViewById(R.id.list);
38-
flowLayoutManager = new FlowLayoutManager().singleItemPerLine();
39-
flowLayoutManager.setAutoMeasureEnabled(true);
40-
recyclerView.setLayoutManager(flowLayoutManager);
41-
recyclerView.setAdapter(new DemoAdapter(1, DemoUtil.listWords()));
42-
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
43-
@Override
44-
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
45-
super.getItemOffsets(outRect, view, parent, state);
46-
outRect.set(5, 5, 5, 5);
47-
}
48-
});
49-
50-
// markdownView = (MarkdownView)findViewById(R.id.instruction_mdown);
51-
// markdownView.loadMarkdownFile("file:///android_asset/instruction.md");
52-
loadSettingsFromSharedPref();
53-
}
54-
55-
@Override
56-
public boolean onCreateOptionsMenu(Menu menu) {
57-
getMenuInflater().inflate(R.menu.main, menu);
58-
return super.onCreateOptionsMenu(menu);
59-
}
60-
61-
@Override
62-
public boolean onOptionsItemSelected(MenuItem item) {
63-
if (item.getItemId() == R.id.action_settings) {
64-
startActivityForResult(new Intent(this, SettingsActivity.class), REQ_CODE_SETTINGS);
65-
return true;
66-
}
67-
return super.onOptionsItemSelected(item);
68-
}
69-
70-
private void loadSettingsFromSharedPref() {
71-
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
72-
String itemsPerLineString = sharedPreferences.getString(getResources().getString(R.string.pref_key_max_items_per_line), getString(R.string.pref_max_items_per_line_default));
73-
int itemsPerLine = Integer.valueOf(itemsPerLineString);
74-
75-
String alignmentString = sharedPreferences.getString(getResources().getString(R.string.pref_key_alignment), getString(R.string.pref_alignment_default));
76-
77-
if (alignmentString.equals("0")) {
78-
flowLayoutManager.setAlignment(Alignment.LEFT);
79-
} else if (alignmentString.equals("2")) {
80-
flowLayoutManager.setAlignment(Alignment.RIGHT);
81-
} else {
82-
flowLayoutManager.setAlignment(Alignment.CENTER);
17+
RecyclerView recyclerView;
18+
FlowLayoutManager flowLayoutManager;
19+
RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
20+
@Override
21+
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
22+
super.getItemOffsets(outRect, view, parent, state);
23+
outRect.set(5, 5, 5, 5);
24+
}
25+
};
26+
27+
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
28+
= new BottomNavigationView.OnNavigationItemSelectedListener() {
29+
30+
@Override
31+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
32+
switch (item.getItemId()) {
33+
case R.id.navigation_left:
34+
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.LEFT);
35+
36+
recyclerView.setLayoutManager(flowLayoutManager);
37+
recyclerView.getAdapter().notifyDataSetChanged();
38+
recyclerView.addItemDecoration(itemDecoration);
39+
40+
return true;
41+
case R.id.navigation_center:
42+
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.CENTER);
43+
flowLayoutManager.setAutoMeasureEnabled(true);
44+
45+
recyclerView.setLayoutManager(flowLayoutManager);
46+
recyclerView.getAdapter().notifyDataSetChanged();
47+
recyclerView.addItemDecoration(itemDecoration);
48+
49+
return true;
50+
case R.id.navigation_rigth:
51+
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.RIGHT);
52+
flowLayoutManager.setAutoMeasureEnabled(true);
53+
54+
recyclerView.setLayoutManager(flowLayoutManager);
55+
recyclerView.getAdapter().notifyDataSetChanged();
56+
recyclerView.addItemDecoration(itemDecoration);
57+
58+
return true;
59+
}
60+
return false;
8361
}
84-
// boolean showMeta = sharedPreferences.getBoolean(getString(R.string.pref_key_show_meta), false);
85-
86-
flowLayoutManager.maxItemsPerLine(itemsPerLine);
87-
DemoAdapter demoAdapter = (DemoAdapter)recyclerView.getAdapter();
88-
// demoAdapter.setShowMeta(showMeta);
89-
String maxLinesPerItemString = sharedPreferences.getString(getString(R.string.pref_key_max_lines_per_item), getString(R.string.pref_max_lines_per_item_default));
90-
int maxLinesPerItem = Integer.valueOf(maxLinesPerItemString);
91-
demoAdapter.newItems(maxLinesPerItem, DemoUtil.listWords());
92-
recyclerView.getAdapter().notifyItemRangeChanged(0, recyclerView.getAdapter().getItemCount());
93-
}
94-
95-
@Override
96-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
97-
super.onActivityResult(requestCode, resultCode, data);
98-
if (requestCode == REQ_CODE_SETTINGS) {
99-
settingChanged = true;
100-
}
101-
}
102-
103-
@Override
104-
public void onWindowFocusChanged(boolean hasFocus) {
105-
super.onWindowFocusChanged(hasFocus);
106-
if (hasFocus) {
107-
if (settingChanged) {
108-
settingChanged = false;
109-
recyclerView.post(new Runnable() {
110-
@Override
111-
public void run() {
112-
loadSettingsFromSharedPref();
113-
}
114-
});
115-
}
116-
}
117-
}
62+
};
63+
64+
@Override
65+
protected void onCreate(Bundle savedInstanceState) {
66+
super.onCreate(savedInstanceState);
67+
setContentView(R.layout.main_activity);
68+
69+
BottomNavigationView navigation = findViewById(R.id.navigation);
70+
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
71+
72+
recyclerView = findViewById(R.id.list);
73+
flowLayoutManager = new FlowLayoutManager().setAlignment(Alignment.LEFT);
74+
flowLayoutManager.setAutoMeasureEnabled(true);
75+
recyclerView.setLayoutManager(flowLayoutManager);
76+
recyclerView.setAdapter(new DemoAdapter(DemoUtil.listWords()));
77+
recyclerView.getAdapter().notifyDataSetChanged();
78+
recyclerView.addItemDecoration(itemDecoration);
79+
80+
81+
}
82+
11883
}

0 commit comments

Comments
 (0)