33import android .content .Context ;
44import android .content .Intent ;
55import android .content .res .Configuration ;
6- import android .os .AsyncTask ;
76import android .os .Bundle ;
87import android .support .annotation .Nullable ;
98import android .support .v4 .app .Fragment ;
1413import android .view .View ;
1514import android .view .ViewGroup ;
1615
16+ import java .util .ArrayList ;
17+ import java .util .List ;
18+
1719import io .pslab .R ;
1820import io .pslab .activity .AccelerometerActivity ;
1921import io .pslab .activity .BarometerActivity ;
3436import io .pslab .adapters .ApplicationAdapter ;
3537import io .pslab .items .ApplicationItem ;
3638
37- import java .util .ArrayList ;
38- import java .util .List ;
39-
4039
4140/**
4241 * Created by viveksb007 on 29/3/17.
@@ -97,7 +96,7 @@ public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGrou
9796 intent = new Intent (context , GasSensorActivity .class );
9897 if (applicationName .equals (getString (R .string .dust_sensor )))
9998 intent = new Intent (context , DustSensorActivity .class );
100- if (applicationName .equals (getString (R .string .sound_meter )))
99+ if (applicationName .equals (getString (R .string .sound_meter )))
101100 intent = new Intent (context , SoundMeterActivity .class );
102101 if (intent != null )
103102 startActivity (intent );
@@ -106,7 +105,7 @@ public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGrou
106105 == Configuration .ORIENTATION_PORTRAIT ? 1 : 2 ;
107106
108107 initiateViews (view , rows );
109- new loadList (). execute ();
108+
110109 return view ;
111110 }
112111
@@ -117,17 +116,16 @@ private void initiateViews(View view, int rows) {
117116 RecyclerView listView = view .findViewById (R .id .applications_recycler_view );
118117 RecyclerView .LayoutManager mLayoutManager = new GridLayoutManager (context , rows );
119118 listView .setLayoutManager (mLayoutManager );
120- listView . setItemAnimator ( new DefaultItemAnimator () );
121- listView . setAdapter ( applicationAdapter );
119+ new LoadList (). doTask ( listView );
120+
122121 }
123122
124123 /**
125- * Generate an array of Application Items and add them to the adapter in background
124+ * Generate an array of Application Items and add them to the adapter
126125 */
127- private class loadList extends AsyncTask < Void , Void , Void > {
126+ private class LoadList {
128127
129- @ Override
130- protected Void doInBackground (Void ... params ) {
128+ private void doTask (RecyclerView listView ) {
131129
132130 int [] descriptions = new int []{
133131 R .string .oscilloscope_description ,
@@ -196,13 +194,9 @@ protected Void doInBackground(Void... params) {
196194 applicationItemList .add (new ApplicationItem (
197195 getString (R .string .sound_meter ), R .drawable .tile_icon_gas , getString (descriptions [15 ])
198196 ));
199- return null ;
200- }
197+ listView . setItemAnimator ( new DefaultItemAnimator ()) ;
198+ listView . setAdapter ( applicationAdapter );
201199
202- @ Override
203- protected void onPostExecute (Void aVoid ) {
204- super .onPostExecute (aVoid );
205- applicationAdapter .notifyDataSetChanged ();
206200 }
207201 }
208202
0 commit comments