2
2
3
3
import android .graphics .Color ;
4
4
import android .os .Bundle ;
5
- import android .support .v7 .app .ActionBarActivity ;
5
+ import android .support .v7 .app .AppCompatActivity ;
6
6
import android .support .v7 .widget .Toolbar ;
7
7
import android .view .Menu ;
8
8
import android .view .MenuItem ;
9
9
import android .view .View ;
10
- import android .widget .AdapterView ;
11
10
12
- import com .mikepenz .aboutlibraries .Libs ;
11
+ import com .mikepenz .aboutlibraries .LibsBuilder ;
12
+ import com .mikepenz .fontawesome_typeface_library .FontAwesome ;
13
13
import com .mikepenz .google_material_typeface_library .GoogleMaterial ;
14
14
import com .mikepenz .iconics .IconicsDrawable ;
15
- import com .mikepenz .iconics .typeface .FontAwesome ;
16
15
import com .mikepenz .materialdrawer .Drawer ;
16
+ import com .mikepenz .materialdrawer .DrawerBuilder ;
17
+ import com .mikepenz .materialdrawer .holder .StringHolder ;
17
18
import com .mikepenz .materialdrawer .model .PrimaryDrawerItem ;
18
19
import com .mikepenz .materialdrawer .model .SectionDrawerItem ;
19
20
import com .mikepenz .materialdrawer .model .interfaces .IDrawerItem ;
23
24
import com .mikepenz .unsplash .network .UnsplashApi ;
24
25
25
26
26
- public class MainActivity extends ActionBarActivity {
27
+ public class MainActivity extends AppCompatActivity {
27
28
public enum Category {
28
29
ALL (1000 ),
29
30
FEATURED (1001 ),
@@ -42,7 +43,7 @@ private Category(int id) {
42
43
}
43
44
}
44
45
45
- public Drawer . Result result ;
46
+ public Drawer result ;
46
47
47
48
private OnFilterChangedListener onFilterChangedListener ;
48
49
@@ -59,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
59
60
toolbar .setTitleTextColor (Color .WHITE );
60
61
setSupportActionBar (toolbar );
61
62
62
- result = new Drawer ()
63
+ result = new DrawerBuilder ()
63
64
.withActivity (this )
64
65
.withToolbar (toolbar )
65
66
.withHeader (R .layout .header )
@@ -75,38 +76,41 @@ protected void onCreate(Bundle savedInstanceState) {
75
76
new PrimaryDrawerItem ().withName (R .string .category_technology ).withIdentifier (Category .TECHNOLOGY .id ).withIcon (GoogleMaterial .Icon .gmd_local_see )
76
77
)
77
78
.withOnDrawerItemClickListener (new Drawer .OnDrawerItemClickListener () {
79
+
78
80
@ Override
79
- public void onItemClick (AdapterView <?> adapterView , View view , int i , long l , IDrawerItem drawerItem ) {
81
+ public boolean onItemClick (View view , int position , IDrawerItem drawerItem ) {
80
82
if (drawerItem != null ) {
81
83
if (drawerItem instanceof Nameable ) {
82
- toolbar .setTitle (((Nameable ) drawerItem ).getNameRes ( ));
84
+ toolbar .setTitle (((Nameable ) drawerItem ).getName (). getText ( MainActivity . this ));
83
85
}
84
86
if (onFilterChangedListener != null ) {
85
87
onFilterChangedListener .onFilterChanged (drawerItem .getIdentifier ());
86
88
}
87
89
}
90
+
91
+ return false ;
88
92
}
89
93
})
90
94
.build ();
91
95
92
96
//disable scrollbar :D it's ugly
93
- result .getListView ().setVerticalScrollBarEnabled (false );
97
+ result .getRecyclerView ().setVerticalScrollBarEnabled (false );
94
98
}
95
99
96
100
/**
97
101
* @param images
98
102
*/
99
103
public void setCategoryCount (ImageList images ) {
100
104
if (result .getDrawerItems () != null && result .getDrawerItems ().size () == 9 && images != null && images .getData () != null ) {
101
- result .updateBadge (images .getData ().size () + "" , 0 );
102
- result .updateBadge (UnsplashApi .countFeatured (images .getData ()) + "" , 1 );
103
-
104
- result .updateBadge (UnsplashApi .countCategory (images .getData (), Category .BUILDINGS .id ) + "" , 3 );
105
- result .updateBadge (UnsplashApi .countCategory (images .getData (), Category .FOOD .id ) + "" , 4 );
106
- result .updateBadge (UnsplashApi .countCategory (images .getData (), Category .NATURE .id ) + "" , 5 );
107
- result .updateBadge (UnsplashApi .countCategory (images .getData (), Category .OBJECTS .id ) + "" , 6 );
108
- result .updateBadge (UnsplashApi .countCategory (images .getData (), Category .PEOPLE .id ) + "" , 7 );
109
- result .updateBadge (UnsplashApi .countCategory (images .getData (), Category .TECHNOLOGY .id ) + "" , 8 );
105
+ result .updateBadge (Category . ALL . id , new StringHolder ( images .getData ().size () + "" ) );
106
+ result .updateBadge (Category . FEATURED . id , new StringHolder ( UnsplashApi .countFeatured (images .getData ()) + "" ) );
107
+
108
+ result .updateBadge (Category . BUILDINGS . id , new StringHolder ( UnsplashApi .countCategory (images .getData (), Category .BUILDINGS .id ) + "" ) );
109
+ result .updateBadge (Category . FOOD . id , new StringHolder ( UnsplashApi .countCategory (images .getData (), Category .FOOD .id ) + "" ) );
110
+ result .updateBadge (Category . NATURE . id , new StringHolder ( UnsplashApi .countCategory (images .getData (), Category .NATURE .id ) + "" ) );
111
+ result .updateBadge (Category . OBJECTS . id , new StringHolder ( UnsplashApi .countCategory (images .getData (), Category .OBJECTS .id ) + "" ) );
112
+ result .updateBadge (Category . PEOPLE . id , new StringHolder ( UnsplashApi .countCategory (images .getData (), Category .PEOPLE .id ) + "" ) );
113
+ result .updateBadge (Category . TECHNOLOGY . id , new StringHolder ( UnsplashApi .countCategory (images .getData (), Category .TECHNOLOGY .id ) + "" ) );
110
114
}
111
115
}
112
116
@@ -115,8 +119,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
115
119
// Inflate the menu; this adds items to the action bar if it is present.
116
120
getMenuInflater ().inflate (R .menu .menu_main , menu );
117
121
118
- menu .findItem (R .id .action_open_source ).setIcon (new IconicsDrawable (this , FontAwesome .Icon .faw_github ).color (Color .WHITE ).actionBarSize ());
119
- menu .findItem (R .id .action_shuffle ).setIcon (new IconicsDrawable (this , GoogleMaterial .Icon .gmd_shuffle ).paddingDp (1 ).color (Color .WHITE ).actionBarSize ());
122
+ menu .findItem (R .id .action_open_source ).setIcon (new IconicsDrawable (this , FontAwesome .Icon .faw_github ).color (Color .WHITE ).actionBar ());
123
+ menu .findItem (R .id .action_shuffle ).setIcon (new IconicsDrawable (this , GoogleMaterial .Icon .gmd_shuffle ).paddingDp (1 ).color (Color .WHITE ).actionBar ());
120
124
121
125
return true ;
122
126
}
@@ -125,10 +129,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
125
129
public boolean onOptionsItemSelected (MenuItem item ) {
126
130
int id = item .getItemId ();
127
131
if (id == R .id .action_open_source ) {
128
- new Libs . Builder ()
132
+ new LibsBuilder ()
129
133
.withFields (R .string .class .getFields ())
130
134
.withActivityTitle (getString (R .string .action_open_source ))
131
- .withActivityTheme (R .style .MaterialDrawerTheme_ActionBar )
135
+ .withActivityTheme (R .style .MaterialDrawerTheme )
132
136
.withLibraries ("rxJava" , "rxAndroid" )
133
137
.start (this );
134
138
0 commit comments