Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #38 from schul-cloud/34-create-dashboard
Browse files Browse the repository at this point in the history
34 create dashboard
  • Loading branch information
Niklas Kiefer authored Jun 27, 2017
2 parents 3693d34 + 3026ed5 commit 45a6612
Show file tree
Hide file tree
Showing 18 changed files with 706 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ android {
res.srcDirs =
[
'src/main/res/layouts/courses',
'src/main/res/layouts/dashboard',
'src/main/res/layouts/homework',
'src/main/res/layouts/files',
'src/main/res/layouts/main',
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
android:label="@string/app_name">
</activity>

<activity
android:name=".ui.dashboard.DashboardActivity"
android:label="@string/app_name">
</activity>

<activity
android:name=".ui.courses.CourseActivity"
android:label="@string/app_name">
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/org/schulcloud/mobile/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.schulcloud.mobile.data.model.responseBodies.SignedUrlResponse;
import org.schulcloud.mobile.data.remote.RestService;
import org.schulcloud.mobile.util.JWTUtil;
import org.schulcloud.mobile.util.Pair;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -280,6 +281,10 @@ public Observable<List<Event>> getEvents() {
return mDatabaseHelper.getEvents().distinct();
}

public List<Event> getEventsForDay() {
return mDatabaseHelper.getEventsForDay();
}

/**** Homework ****/

public Observable<Homework> syncHomework() {
Expand All @@ -302,6 +307,10 @@ public Homework getHomeworkForId(String homeworkId) {
return mDatabaseHelper.getHomeworkForId(homeworkId);
}

public Pair<String, String> getOpenHomeworks() {
return mDatabaseHelper.getOpenHomeworks();
}

/**** Submissions ****/

public Observable<Submission> syncSubmissions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schulcloud.mobile.data.local;

import android.util.Log;

import org.schulcloud.mobile.data.model.AccessToken;
import org.schulcloud.mobile.data.model.Course;
import org.schulcloud.mobile.data.model.CurrentUser;
Expand All @@ -11,8 +13,17 @@
import org.schulcloud.mobile.data.model.Submission;
import org.schulcloud.mobile.data.model.Topic;
import org.schulcloud.mobile.data.model.User;
import org.schulcloud.mobile.util.Pair;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import javax.inject.Inject;
Expand Down Expand Up @@ -201,6 +212,54 @@ public Observable<List<Event>> getEvents() {
.map(events -> realm.copyFromRealm(events));
}

public List<Event> getEventsForDay() {
final Realm realm = mRealmProvider.get();
Collection<Event> events = realm.where(Event.class).findAll();

int weekday = new GregorianCalendar().get(Calendar.DAY_OF_WEEK);
Log.d("Weekday", Integer.toString(weekday));

List<Event> eventsForWeekday = new ArrayList<>();

for (Event event : events) {
if (event.included.size() > 0) {
if (getNumberForWeekday(event.included.first().getAttributes().getWkst()) == weekday) {
eventsForWeekday.add(event);
}
}
}

Collections.sort(eventsForWeekday, new Comparator<Event>() {
@Override
public int compare(Event o1, Event o2) {
return o1.start.compareTo(o2.start);
}
});

return eventsForWeekday;
}

public int getNumberForWeekday(String weekday) {
switch (weekday) {
case "SU":
return 1;
case "MO":
return 2;
case "TU":
return 3;
case "WE":
return 4;
case "TH":
return 5;
case "FR":
return 6;
case "SA":
return 7;
default:
return -1;
}
}

/**** NotificationService ****/

public Observable<Device> setDevices(final Collection<Device> newDevices) {
Expand Down Expand Up @@ -262,6 +321,40 @@ public Homework getHomeworkForId(String homeworkId) {
return realm.where(Homework.class).equalTo("_id", homeworkId).findFirst();
}

public Pair<String, String> getOpenHomeworks() {
final Realm realm = mRealmProvider.get();
Collection<Homework> homeworks = realm.where(Homework.class).findAll();

Date nextDueDate = null;
int amount = 0;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");

Calendar calendar = new GregorianCalendar(9999, 12, 31, 23, 59);
try {
nextDueDate = dateFormat.parse(dateFormat.format(calendar.getTime()));
} catch (ParseException e) {
e.printStackTrace();
}

for (Homework homework : homeworks) {
Date untilDate = null;
try {
untilDate = dateFormat.parse(homework.dueDate);
} catch (ParseException e) {
e.printStackTrace();
}

if (untilDate.after(new Date())) {
amount++;

if (untilDate.before(nextDueDate))
nextDueDate = untilDate;
}
}

return new Pair<String, String>(Integer.toString(amount), dateFormat.format(nextDueDate));
}

/**** Submissions ****/
public Observable<Submission> setSubmissions(final Collection<Submission> newSubmission) {
return Observable.create(subscriber -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.schulcloud.mobile.data.model;

import io.realm.RealmModel;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.RealmClass;

@RealmClass
public class CourseHomework implements RealmModel {
@PrimaryKey
public String _id;
public String schoolId;
public String name;
public String description;
public String color;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Homework implements RealmModel {
public String description;
public String availableDate;
public String dueDate;
public Course courseId;
public CourseHomework courseId;

@SerializedName("private")
public Boolean restricted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.schulcloud.mobile.ui.courses.CourseActivity;
import org.schulcloud.mobile.ui.courses.detailed.DetailedCourseFragment;
import org.schulcloud.mobile.ui.courses.detailed.TopicFragment;
import org.schulcloud.mobile.ui.dashboard.DashboardActivity;
import org.schulcloud.mobile.ui.homework.HomeworkActivity;
import org.schulcloud.mobile.ui.files.FileActivity;
import org.schulcloud.mobile.ui.homework.detailed.DetailedHomeworkFragment;
Expand Down Expand Up @@ -44,4 +45,6 @@ public interface ActivityComponent {
void inject (DetailedCourseFragment detailedCourseFragment);

void inject(TopicFragment topicFragment);

void inject(DashboardActivity dashboardActivity);
}
20 changes: 13 additions & 7 deletions app/src/main/java/org/schulcloud/mobile/ui/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.schulcloud.mobile.injection.component.DaggerConfigPersistentComponent;
import org.schulcloud.mobile.injection.module.ActivityModule;
import org.schulcloud.mobile.ui.courses.CourseActivity;
import org.schulcloud.mobile.ui.dashboard.DashboardActivity;
import org.schulcloud.mobile.ui.files.FileActivity;
import org.schulcloud.mobile.ui.homework.HomeworkActivity;
import org.schulcloud.mobile.ui.settings.SettingsActivity;
Expand All @@ -47,6 +48,7 @@ public class BaseActivity extends AppCompatActivity {
private PreferencesHelper mPreferencesHelper;
// Curently just nonsense Data and Logos, change here for the actual list
private String[] layers = {
"Dashboard",
"Meine Dateien",
"Meine Fächer",
"Hausaufgaben",
Expand All @@ -56,6 +58,7 @@ public class BaseActivity extends AppCompatActivity {
"Ausloggen",
};
private String[] resources = {
FontAwesome.FA_TH_LARGE,
FontAwesome.FA_FILE,
FontAwesome.FA_GRADUATION_CAP,
FontAwesome.FA_TASKS,
Expand Down Expand Up @@ -138,17 +141,20 @@ public void onDrawerClosed(View drawerView) {
private void openActivityForPos(int pos) {
Class c;
switch (pos) {
case 1: // files
case 1: // Dashboard
c = DashboardActivity.class;
break;
case 2: // files
mPreferencesHelper.clear("storageContext");
c = FileActivity.class;
break;
case 2: // homework
case 3: // Course
c = CourseActivity.class;
break;
case 3: // homework
case 4: // homework
c = HomeworkActivity.class;
break;
case 4: // contact
case 5: // contact
Intent mailIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:" +
getResources().getString(R.string.mail_to_mail) +
Expand All @@ -157,15 +163,15 @@ private void openActivityForPos(int pos) {
mailIntent.setData(data);
startActivity(mailIntent);
return;
case 5: // settings
case 6: // settings
c = SettingsActivity.class;
break;
case 6: // impressum
case 7: // impressum
c = BaseActivity.class;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://hpi.de/impressum.html"));
startActivity(browserIntent);
return;
case 7: // logout
case 8: // logout
// delete accessToken and currentUser
mPreferencesHelper.clear("jwt");
mPreferencesHelper.clear("currentUser");
Expand Down
Loading

0 comments on commit 45a6612

Please sign in to comment.