Skip to content
This repository was archived by the owner on Aug 21, 2018. It is now read-only.

Commit 026d870

Browse files
author
Leonard Maximus Irenous Mensah
authored
Merge pull request #56 from open-learning-exchange/maxi_courses
2 parents 52bc5bc + 7a71d91 commit 026d870

File tree

5 files changed

+179
-24
lines changed

5 files changed

+179
-24
lines changed

app/src/main/java/pbell/offline/ole/org/pbell/CouchViews.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@ public void map(Map<String, Object> document,Emitter emitter) {
6666
);
6767
return CourseListByMemberIdView;
6868
}
69+
public View ReadCourses(Database db) {
70+
View Courses = db.getView("Courses");
71+
Courses.setMap(
72+
new Mapper(){
73+
@Override
74+
public void map(Map<String, Object> document,Emitter emitter) {
75+
emitter.emit((String) document.get("CourseTitle"), (String) document.get("_id"));
76+
}
77+
}, "2"
78+
);
79+
return Courses;
80+
}
81+
public View ReadCourseSteps(Database db) {
82+
View CourseSteps = db.getView("Coursestep");
83+
CourseSteps.setMap(
84+
new Mapper(){
85+
@Override
86+
public void map(Map<String, Object> document,Emitter emitter) {
87+
emitter.emit((String) document.get("courseId"), (String) document.get("_id"));
88+
}
89+
}, "1"
90+
);
91+
return CourseSteps;
92+
}
6993
public View ReadMemberVisits(Database db) {
7094
View VisitsByMemberIdView = db.getView("visits");
7195
VisitsByMemberIdView.setMap(

app/src/main/java/pbell/offline/ole/org/pbell/FullscreenActivity.java

Lines changed: 117 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pbell.offline.ole.org.pbell;
22

3+
import android.annotation.SuppressLint;
34
import android.app.Dialog;
45
import android.app.DownloadManager;
56
import android.app.ProgressDialog;
@@ -71,6 +72,7 @@
7172
import com.google.gson.JsonObject;
7273
import com.google.gson.JsonParser;
7374

75+
import org.json.JSONArray;
7476
import org.json.JSONException;
7577
import org.json.JSONObject;
7678
import 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) {

app/src/main/java/pbell/offline/ole/org/pbell/FullscreenLogin.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pbell.offline.ole.org.pbell;
22

3+
import android.annotation.SuppressLint;
34
import android.app.Dialog;
45
import android.app.ProgressDialog;
56
import android.content.Context;
@@ -103,7 +104,8 @@ public class FullscreenLogin extends AppCompatActivity {
103104
private ProgressDialog mDialog;
104105
JSONObject jsonServerData;
105106
final Context context = this;
106-
String[] databaseList = {"members", "membercourseprogress", "meetups", "usermeetups", "assignments",
107+
String[] databaseList = {"members", "meetups", "usermeetups", "assignments",
108+
"assignmentpaper","courseanswer","coursequestion","courses","courseschedule","coursestep","membercourseprogress",
107109
"calendar", "groups", "invitations", "configurations", "requests", "shelf", "languages"};
108110
Replication[] push = new Replication[databaseList.length];
109111
Replication[] pull = new Replication[databaseList.length];
@@ -275,7 +277,7 @@ public void sendfeedbackToServer(ProgressDialog feedbackDialog){
275277
try {
276278
Manager manager = new Manager(androidContext, Manager.DEFAULT_OPTIONS);
277279
activitylog = manager.getDatabase("activitylog");
278-
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
280+
@SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
279281
String m_WLANMAC = wm.getConnectionInfo().getMacAddress();
280282
Document doc = activitylog.getExistingDocument(m_WLANMAC);
281283
Map<String, Object> properties = doc.getProperties();
@@ -354,7 +356,7 @@ public void sendfeedbackToServer(ProgressDialog feedbackDialog){
354356
try {
355357
Manager manager = new Manager(androidContext, Manager.DEFAULT_OPTIONS);
356358
activitylog = manager.getDatabase("activitylog");
357-
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
359+
@SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
358360
String m_WLANMAC = wm.getConnectionInfo().getMacAddress();
359361
Document doc = activitylog.getExistingDocument(m_WLANMAC);
360362
Map<String, Object> properties = doc.getProperties();
@@ -611,8 +613,7 @@ public boolean updateActivityLog() {
611613
try {
612614
manager = new Manager(androidContext, Manager.DEFAULT_OPTIONS);
613615
activityLog = manager.getDatabase("activitylog");
614-
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
615-
616+
@SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
616617
//This is for setting the MAC address if it is being run in a android emulator.
617618
String m_WLANMAC;
618619
m_WLANMAC = wm.getConnectionInfo().getMacAddress();
@@ -661,7 +662,7 @@ public String todaysDate(){
661662

662663
}
663664
public void getSyncURLDialog(){
664-
final WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
665+
@SuppressLint("WifiManagerLeak") final WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
665666
AlertDialog.Builder dialogB = new AlertDialog.Builder(this);
666667
dialogB.setView(R.layout.dialog_setup);
667668
dialogB.setCancelable(true);
@@ -743,7 +744,7 @@ public void onClick(DialogInterface int_dialog, int which) {
743744
}
744745
}
745746
public void setDateDialog(){
746-
final WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
747+
@SuppressLint("WifiManagerLeak") final WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
747748
AlertDialog.Builder dialogB = new AlertDialog.Builder(this);
748749
dialogB.setView(R.layout.dialog_date);
749750
dialogB.setCancelable(true);
@@ -1482,7 +1483,7 @@ private void updateUI() {
14821483
try {
14831484
Manager manager = new Manager(androidContext, Manager.DEFAULT_OPTIONS);
14841485
Database activitylog = manager.getDatabase("activitylog");
1485-
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
1486+
@SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
14861487
String m_WLANMAC = wm.getConnectionInfo().getMacAddress();
14871488
Document doc = activitylog.getDocument(m_WLANMAC);
14881489
///Map<String, Object> properties = doc.getProperties();

app/src/main/res/layout/activity_fullscreen.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,40 @@
376376
android:textSize="@dimen/title"
377377
android:textColor="@color/ole_yellow" />
378378
</LinearLayout>
379+
379380
<LinearLayout
380-
android:orientation="horizontal"
381+
android:id="@+id/layout_mycourses"
381382
android:layout_width="0dp"
382383
android:layout_height="match_parent"
383384
android:layout_weight="3.4"
385+
android:alpha="0.8"
384386
android:animateLayoutChanges="true"
385387
android:background="@color/ole_yellow"
386-
android:alpha="0.8"></LinearLayout>
388+
android:orientation="vertical">
389+
390+
<HorizontalScrollView
391+
android:layout_width="match_parent"
392+
android:layout_height="match_parent">
393+
394+
<LinearLayout
395+
android:id="@+id/layholder_courses"
396+
android:layout_width="wrap_content"
397+
android:layout_height="match_parent"
398+
android:orientation="horizontal">
399+
400+
</LinearLayout>
401+
</HorizontalScrollView>
402+
403+
<LinearLayout
404+
android:layout_width="match_parent"
405+
android:layout_height="match_parent"
406+
android:layout_weight="0.1"
407+
android:animateLayoutChanges="true"
408+
android:background="@drawable/rounded_corners_right"
409+
android:gravity="center"
410+
android:orientation="horizontal"
411+
android:textAlignment="center"></LinearLayout>
412+
</LinearLayout>
387413
<LinearLayout
388414
android:orientation="horizontal"
389415
android:layout_width="0dp"

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Wed Apr 12 18:58:45 EDT 2017
1+
#Mon May 08 19:00:31 GMT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)