8
8
import com .brkrgcr .cheatsheet .R .array ;
9
9
import com .brkrgcr .cheatsheet .R .id ;
10
10
import com .brkrgcr .cheatsheet .R .layout ;
11
+ import com .google .gson .JsonArray ;
12
+ import com .koushikdutta .async .future .FutureCallback ;
13
+ import com .koushikdutta .ion .Ion ;
11
14
12
15
import android .app .Activity ;
13
16
import android .database .DataSetObserver ;
14
17
import android .os .Bundle ;
15
18
import android .support .annotation .Nullable ;
16
19
import android .support .v4 .app .Fragment ;
20
+ import android .support .v4 .app .FragmentManager ;
17
21
import android .util .Log ;
18
22
import android .view .LayoutInflater ;
19
23
import android .view .View ;
@@ -32,11 +36,15 @@ public class CheatSheetFragment extends Fragment {
32
36
private static final String TAG = "CodeFragment" ;
33
37
34
38
private MainActivity mMainActivity ;
39
+
40
+
35
41
36
42
public static final int INDEX = 2 ;
37
43
38
44
public static int ID ;
39
45
46
+ private JsonArray coming_Json_Array ;
47
+
40
48
private static int ROOT ;
41
49
/**
42
50
* CheatSheets
@@ -86,35 +94,40 @@ public View onCreateView(LayoutInflater inflater,
86
94
87
95
case 0 :
88
96
cheatSheetList .clear ();
89
- cheatSheetList .add ("Flask" );
90
- cheatSheetList .add ("Spring" );
91
- cheatSheetList .add ("Laravel" );
92
- cheatSheets .setAdapter (new ArrayAdapter <String >(getActivity (), android .R .layout .simple_list_item_1 , cheatSheetList ));
93
- Log .e ("Cheatsheet" , "Enter The Switch" +ROOT );
94
- break ;
95
- case 1 :
96
- cheatSheetList .clear ();
97
- cheatSheetList .add ("Java" );
98
- cheatSheetList .add ("Python" );
99
- cheatSheetList .add ("Ruby" );
100
- cheatSheets .setAdapter (new ArrayAdapter <String >(getActivity (), android .R .layout .simple_list_item_1 , cheatSheetList ));
101
- Log .e ("Cheatsheet" , "Enter The Switch" +ROOT );
102
- break ;
103
- case 2 :
104
- cheatSheetList .clear ();
105
- cheatSheetList .add ("Flask" );
106
- cheatSheetList .add ("Spring" );
107
- cheatSheetList .add ("Laravel" );
108
- cheatSheets .setAdapter (new ArrayAdapter <String >(getActivity (), android .R .layout .simple_list_item_1 , cheatSheetList ));
97
+ Ion .with (this ).load ("http://95.85.42.212:5000/v1/category/main" ).asJsonArray ().setCallback (new FutureCallback <JsonArray >() {
98
+
99
+ @ Override
100
+ public void onCompleted (Exception e , JsonArray result ) {
101
+ for (int i = 0 ; i < result .size (); i ++)
102
+ {
103
+
104
+ coming_Json_Array =result ;
105
+ String element_name =result .get (i ).getAsJsonObject ().get ("name" ).getAsString ();
106
+ cheatSheetList .add (element_name );
107
+ }
108
+ cheatSheets .setAdapter (new ArrayAdapter <String >(getActivity (), android .R .layout .simple_list_item_1 , cheatSheetList ));
109
+ }
110
+ });
111
+
109
112
Log .e ("Cheatsheet" , "Enter The Switch" +ROOT );
110
113
break ;
111
114
112
115
default :
113
116
cheatSheetList .clear ();
114
- cheatSheetList .add ("Flask" );
115
- cheatSheetList .add ("Spring" );
116
- cheatSheetList .add ("Laravel" );
117
- cheatSheets .setAdapter (new ArrayAdapter <String >(getActivity (), android .R .layout .simple_list_item_1 , cheatSheetList ));
117
+ String url ="http://95.85.42.212:5000/v1/category/list/" +Integer .toString (ROOT );
118
+ Ion .with (this ).load (url ).asJsonArray ().setCallback (new FutureCallback <JsonArray >() {
119
+
120
+ @ Override
121
+ public void onCompleted (Exception e , JsonArray result ) {
122
+ for (int i = 0 ; i < result .size (); i ++)
123
+ {
124
+ coming_Json_Array =result ;
125
+ String element_name =result .get (i ).getAsJsonObject ().get ("name" ).getAsString ();
126
+ cheatSheetList .add (element_name );
127
+ }
128
+ cheatSheets .setAdapter (new ArrayAdapter <String >(getActivity (), android .R .layout .simple_list_item_1 , cheatSheetList ));
129
+ }
130
+ });
118
131
Log .e ("Cheatsheet" , "Enter The Switch" +ROOT );
119
132
break ;
120
133
}
@@ -144,6 +157,15 @@ public void onItemClick(AdapterView<?> parent, View view,
144
157
145
158
// ListView Clicked item index
146
159
int itemPosition = position ;
160
+ int item_Id =coming_Json_Array .get (itemPosition ).getAsJsonObject ().get ("id" ).getAsInt ();
161
+
162
+ Bundle args =new Bundle ();
163
+ Fragment frag =new CheatSheetFragment ();
164
+ FragmentManager fragmentManager = getActivity ().getSupportFragmentManager ();
165
+ args .putInt (ARG_SECTION_NUMBER , item_Id );
166
+
167
+ frag .setArguments (args );
168
+ fragmentManager .beginTransaction ().replace (R .id .container , frag ).commit ();
147
169
148
170
// ListView Clicked item value
149
171
// String itemValue = (String) cheatSheets.getItemAtPosition(position);
0 commit comments