11package pbell .offline .ole .org .pbell ;
22
3+ import android .annotation .SuppressLint ;
34import android .app .Dialog ;
45import android .app .DownloadManager ;
56import android .app .ProgressDialog ;
7172import com .google .gson .JsonObject ;
7273import com .google .gson .JsonParser ;
7374
75+ import org .json .JSONArray ;
7476import org .json .JSONException ;
7577import org .json .JSONObject ;
7678import org .lightcouch .CouchDbClientAndroid ;
@@ -118,7 +120,7 @@ public class FullscreenActivity extends AppCompatActivity {
118120 boolean synchronizing = true ;
119121 JSONObject jsonData ;
120122 Database dbResources ;
121- int syncCnt , resourceNo , allresDownload , allhtmlDownload = 0 ;
123+ int syncCnt , resourceNo ,courseNo , allresDownload , allhtmlDownload = 0 ;
122124 AndroidContext androidContext ;
123125 Replication pull ;
124126 Manager manager ;
@@ -135,10 +137,9 @@ public class FullscreenActivity extends AppCompatActivity {
135137 String onlinecouchresource ;
136138
137139 CouchViews chViews = new CouchViews ();
138- String resourceIdList [];
139- String resourceTitleList [];
140- int rsLstCnt = 0 ;
141- Button [] libraryButtons ;
140+ String resourceIdList [],resourceTitleList [],courseIdList [],courseTitleList [];
141+ int rsLstCnt ,csLstCnt = 0 ;
142+ Button [] libraryButtons ,courseButtons ;
142143 Dialog dialog2 ;
143144 String OneByOneResID = "" ;
144145 int resButtonId ;
@@ -158,6 +159,8 @@ public class FullscreenActivity extends AppCompatActivity {
158159
159160 private List <Resource > resourceList = new ArrayList <Resource >();
160161 private List <String > resIDArrayList = new ArrayList <String >();
162+ private List <Resource > courseList = new ArrayList <Resource >();
163+ private List <String > courseIDArrayList = new ArrayList <String >();
161164 private ListView listView ;
162165 private CustomListAdapter adapter ;
163166 Boolean calbackStatus , syncALLInOneStarted = false ;
@@ -268,6 +271,7 @@ public void onReceive(Context context, Intent intent) {
268271 resourceList .clear ();
269272 resIDArrayList .clear ();
270273 LoadShelfResourceList ();
274+ LoadCourseList ();
271275
272276 ///Update user info
273277 updateUI ();
@@ -297,7 +301,7 @@ public void onClick(DialogInterface dialog, int id) {
297301 @ Override
298302 public void onClick (View v ) {
299303 final Fuel ful = new Fuel ();
300- final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
304+ @ SuppressLint ( "WifiManagerLeak" ) final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
301305 mDialog = new ProgressDialog (context );
302306 mDialog .setMessage ("Opening Courses please wait..." );
303307 mDialog .setCancelable (true );
@@ -345,7 +349,7 @@ public void failure(Request request, Response response, FuelError fuelError) {
345349 @ Override
346350 public void onClick (View v ) {
347351 final Fuel ful = new Fuel ();
348- final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
352+ @ SuppressLint ( "WifiManagerLeak" ) final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
349353 mDialog = new ProgressDialog (context );
350354 mDialog .setMessage ("Opening Meetups please wait..." );
351355 mDialog .setCancelable (true );
@@ -401,7 +405,7 @@ public void onClick(View v) {
401405 @ Override
402406 public void onClick (View v ) {
403407 final Fuel ful = new Fuel ();
404- final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
408+ @ SuppressLint ( "WifiManagerLeak" ) final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
405409 mDialog = new ProgressDialog (context );
406410 mDialog .setMessage ("Opening library please wait..." );
407411 mDialog .setCancelable (true );
@@ -466,7 +470,7 @@ public void onClick(View v) {
466470 @ Override
467471 public void onClick (View v ) {
468472 final Fuel ful = new Fuel ();
469- final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
473+ @ SuppressLint ( "WifiManagerLeak" ) final WifiManager wifiManager = (WifiManager ) FullscreenActivity .this .getSystemService (Context .WIFI_SERVICE );
470474 mDialog = new ProgressDialog (context );
471475 mDialog .setMessage ("Opening Course Progress please wait..." );
472476 mDialog .setCancelable (true );
@@ -766,6 +770,108 @@ public void onClick(View view) {
766770 }
767771 }
768772
773+ public void LoadCourseList () {
774+ String memberId = sys_usercouchId ;
775+ try {
776+ //maximus
777+ manager = new Manager (androidContext , Manager .DEFAULT_OPTIONS );
778+ Database db = manager .getExistingDatabase ("courses" );
779+ ///Database resource_Db = manager.getDatabase("resources");
780+ Query orderedQuery = chViews .ReadCourses (db ).createQuery ();
781+ orderedQuery .setDescending (true );
782+ QueryEnumerator results = orderedQuery .run ();
783+ courseIdList = new String [results .getCount ()];
784+ courseTitleList = new String [results .getCount ()];
785+ csLstCnt = 0 ;
786+ String mycourseId ="" ;
787+ String mycourseTitile ;
788+ String mycourseForgndColor ="#000000" ;
789+ String mycourseBackgndColor ="#FFFFFF" ;
790+ for (Iterator <QueryRow > it = results ; it .hasNext (); ) {
791+ QueryRow row = it .next ();
792+ String docId = (String ) row .getValue ();
793+ Document doc = db .getExistingDocument (docId );
794+ Map <String , Object > properties = doc .getProperties ();
795+ ArrayList courseMembers = (ArrayList ) properties .get ("members" );
796+ for (int cnt = 0 ; cnt < courseMembers .size (); cnt ++) {
797+ if (memberId .equals (courseMembers .get (cnt ).toString ())) {
798+ mycourseTitile = ((String ) properties .get ("CourseTitle" ));
799+ mycourseId = ((String ) properties .get ("_id" ));
800+ mycourseForgndColor = ((String ) properties .get ("foregroundColor" ));
801+ mycourseBackgndColor = ((String ) properties .get ("backgroundColor" ));
802+ courseIdList [csLstCnt ] = mycourseId ;
803+ courseTitleList [csLstCnt ] = mycourseTitile ;
804+ courseIDArrayList .add (mycourseId );
805+ }
806+ }
807+
808+ manager = new Manager (androidContext , Manager .DEFAULT_OPTIONS );
809+ Database coursestep_Db = manager .getExistingDatabase ("coursestep" );
810+ orderedQuery = chViews .ReadCourseSteps (coursestep_Db ).createQuery ();
811+ orderedQuery .setDescending (true );
812+ results = orderedQuery .run ();
813+ for (Iterator <QueryRow > item = results ; item .hasNext (); ) {
814+ row = item .next ();
815+ docId = (String ) row .getValue ();
816+ doc = coursestep_Db .getExistingDocument (docId );
817+ Map <String , Object > coursestep_properties = doc .getProperties ();
818+ if (mycourseId .equals ((String ) coursestep_properties .get ("members" ))) {
819+ ArrayList course_step_resourceId = (ArrayList ) coursestep_properties .get ("resourceId" );
820+ ArrayList course_step_resourceTitles = (ArrayList ) coursestep_properties .get ("resourceId" );
821+ String course_step_title = (String ) coursestep_properties .get ("title" );
822+ String course_step_id = (String ) coursestep_properties .get ("_id" );
823+ String course_step_descr = (String ) coursestep_properties .get ("description" );
824+ int course_step_No = (Integer ) coursestep_properties .get ("step" );
825+ }
826+ }
827+ csLstCnt ++;
828+ coursestep_Db .close ();
829+ }
830+
831+ LinearLayout row3 = (LinearLayout ) findViewById (R .id .layholder_courses );
832+ courseButtons = new Button [csLstCnt ];
833+ for (int ButtonCnt = 0 ; ButtonCnt < csLstCnt ; ButtonCnt ++) {
834+ courseButtons [ButtonCnt ] = new Button (this );
835+ courseButtons [ButtonCnt ].setText (courseTitleList [ButtonCnt ]);
836+ courseButtons [ButtonCnt ].setId (ButtonCnt );
837+ courseButtons [ButtonCnt ].setBackgroundColor (Color .parseColor (mycourseBackgndColor ));
838+ courseButtons [ButtonCnt ].setTextColor (Color .parseColor (mycourseForgndColor ));
839+ courseButtons [ButtonCnt ].setAllCaps (false );
840+ courseButtons [ButtonCnt ].setPadding (10 , 5 , 10 , 5 );
841+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
842+ libraryButtons [ButtonCnt ].setTextAlignment (View .TEXT_ALIGNMENT_CENTER );
843+ }
844+ LinearLayout .LayoutParams layoutParams = new LinearLayout .LayoutParams (170 , MATCH_PARENT );
845+ layoutParams .setMargins (1 , 0 , 1 , 0 ); // left, top, right, bottom
846+ GradientDrawable drawable = new GradientDrawable ();
847+ drawable .setShape (GradientDrawable .RECTANGLE );
848+ drawable .setStroke (2 , Color .WHITE );
849+ drawable .setCornerRadius (2 );
850+ drawable .setColor (getResources ().getColor (R .color .ole_black_blue ));
851+ courseButtons [ButtonCnt ].setBackgroundDrawable (drawable );
852+ courseButtons [ButtonCnt ].setLayoutParams (layoutParams );
853+ row3 .addView (courseButtons [ButtonCnt ]);
854+ courseButtons [ButtonCnt ].setOnClickListener (new View .OnClickListener () {
855+ @ Override
856+ public void onClick (View view ) {
857+ if (courseButtons [view .getId ()].getCurrentTextColor () == getResources ().getColor (R .color .ole_yellow )) {
858+ /// MaterialClickDialog(false, courseTitleList[view.getId()], courseIdList[view.getId()], view.getId());
859+ } else {
860+
861+ }
862+ }
863+
864+ });
865+ }
866+ //////////// Save list in Preferences
867+ db .close ();
868+
869+ } catch (Exception e ) {
870+ Log .d ("MyCouch" , "Error loading courses" );
871+ e .printStackTrace ();
872+ }
873+ }
874+
769875 public void MaterialClickDialog (boolean online , String title , String resId , int buttonPressedId ) {
770876 clicked_rs_status = online ;
771877 clicked_rs_title = title ;
@@ -1768,15 +1874,13 @@ public boolean updateActivityOpenedResources(String resource_name, String resour
17681874 try {
17691875 manager = new Manager (androidContext , Manager .DEFAULT_OPTIONS );
17701876 activityLog = manager .getDatabase ("activitylog" );
1771- WifiManager wm = (WifiManager ) getSystemService (Context .WIFI_SERVICE );
1772-
1877+ @ SuppressLint ("WifiManagerLeak" ) WifiManager wm = (WifiManager ) getSystemService (Context .WIFI_SERVICE );
17731878 //This is for setting the MAC address if it is being run in a android emulator.
17741879 String m_WLANMAC ;
17751880 m_WLANMAC = wm .getConnectionInfo ().getMacAddress ();
17761881 if (m_WLANMAC == null ) {
17771882 m_WLANMAC = "mymac" ;
17781883 }
1779-
17801884 Document retrievedDocument = activityLog .getDocument (m_WLANMAC );
17811885 Map <String , Object > properties = retrievedDocument .getProperties ();
17821886 if ((ArrayList <String >) properties .get ("female_opened" ) != null ) {
@@ -1883,7 +1987,7 @@ public boolean updateActivityRatingResources(float rate, String resourceid) {
18831987 try {
18841988 manager = new Manager (androidContext , Manager .DEFAULT_OPTIONS );
18851989 activityLog = manager .getDatabase ("activitylog" );
1886- WifiManager wm = (WifiManager ) getSystemService (Context .WIFI_SERVICE );
1990+ @ SuppressLint ( "WifiManagerLeak" ) WifiManager wm = (WifiManager ) getSystemService (Context .WIFI_SERVICE );
18871991 String m_WLANMAC = wm .getConnectionInfo ().getMacAddress ();
18881992 Document retrievedDocument = activityLog .getDocument (m_WLANMAC );
18891993 if (retrievedDocument != null ) {
0 commit comments