5
5
import android .support .v7 .app .AppCompatActivity ;
6
6
import android .support .v7 .widget .LinearLayoutManager ;
7
7
import android .support .v7 .widget .RecyclerView ;
8
+ import android .util .TypedValue ;
9
+
10
+ import java .lang .reflect .Field ;
11
+ import java .util .ArrayList ;
12
+ import java .util .Arrays ;
8
13
9
14
import io .neurolab .R ;
10
15
import io .neurolab .adapters .MeditationListAdapter ;
@@ -17,23 +22,45 @@ protected void onCreate(Bundle savedInstanceState) {
17
22
setContentView (R .layout .activity_meditation_list );
18
23
setTitle ("Meditations" );
19
24
getSupportActionBar ().setDisplayHomeAsUpEnabled (true );
25
+ ArrayList <Field > resFields ;
26
+ ArrayList <Field > finalList ;
27
+ Field [] finalFields ;
28
+ int resId ;
29
+ resFields = new ArrayList <>(Arrays .asList (R .raw .class .getFields ()));
30
+ finalList = new ArrayList <>();
31
+ for (int z = 0 ; z < resFields .size (); z ++) {
32
+ String name = resFields .get (z ).getName ();
33
+ TypedValue value = new TypedValue ();
34
+ resId = getResources ().getIdentifier (name , "raw" , getPackageName ());
35
+ getResources ().getValue (resId , value , true );
20
36
21
- RecyclerView meditationsRecyclerView = findViewById (R .id .meditation_recycler_view );
37
+ if ((getExtension (value .string .toString ()).indexOf (".csv" ) == -1 )) {
38
+ finalList .add (resFields .get (z ));
39
+ }
40
+ }
22
41
23
- MeditationListAdapter meditationListAdapter = new MeditationListAdapter (this , R .raw .class .getFields ());
42
+ finalFields = finalList .toArray (new Field [finalList .size ()]);
43
+ RecyclerView meditationsRecyclerView = findViewById (R .id .meditation_recycler_view );
44
+ MeditationListAdapter meditationListAdapter = new MeditationListAdapter (this , finalFields );
24
45
LinearLayoutManager linearLayoutManager = new LinearLayoutManager (
25
46
this , LinearLayoutManager .VERTICAL , false );
26
47
meditationsRecyclerView .setLayoutManager (linearLayoutManager );
27
48
meditationsRecyclerView .setAdapter (meditationListAdapter );
28
49
}
29
50
51
+ public String getExtension (String path ) {
52
+ String [] token = path .split ("/raw/" , 2 );
53
+ String ext = token [1 ];
54
+ return ext ;
55
+ }
56
+
30
57
@ Override
31
58
public boolean onSupportNavigateUp () {
32
59
onBackPressed ();
33
60
return true ;
34
61
}
35
62
36
- public void onBackPressed () {
63
+ public void onBackPressed () {
37
64
super .onBackPressed ();
38
65
startActivity (new Intent (this , MeditationHome .class ));
39
66
finish ();
0 commit comments