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 #32 from schul-cloud/52-show-courses
Browse files Browse the repository at this point in the history
course view
  • Loading branch information
Niklas Kiefer authored Jun 22, 2017
2 parents 4835b1a + a9800c3 commit 1e8ca96
Show file tree
Hide file tree
Showing 36 changed files with 1,551 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ android {
main {
res.srcDirs =
[
'src/main/res/layouts/courses',
'src/main/res/layouts/homework',
'src/main/res/layouts/files',
'src/main/res/layouts/main',
Expand Down Expand Up @@ -145,6 +146,10 @@ dependencies {
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
apt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"

// Picasso
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'

compile "com.google.dagger:dagger:$DAGGER_VERSION"
//Required by Dagger2
apt daggerCompiler
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,31 @@
android:label="@string/app_name">
</activity>

<activity
android:name=".ui.courses.CourseActivity"
android:label="@string/app_name">
</activity>

<service android:name=".data.sync.CourseSyncService"/>

<receiver
android:name=".data.sync.CourseSyncService$SyncOnConnectionAvailable"
android:enabled="false">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>

<service android:name=".data.sync.TopicSyncService"/>

<receiver
android:name=".data.sync.TopicSyncService$SyncOnConnectionAvailable"
android:enabled="false">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>

<service android:name=".data.sync.UserSyncService"/>

<receiver
Expand Down
49 changes: 48 additions & 1 deletion app/src/main/java/org/schulcloud/mobile/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

import android.util.Log;

import org.schulcloud.mobile.R;
import org.schulcloud.mobile.data.local.DatabaseHelper;
import org.schulcloud.mobile.data.local.PreferencesHelper;
import org.schulcloud.mobile.data.model.AccessToken;
import org.schulcloud.mobile.data.model.Contents;
import org.schulcloud.mobile.data.model.Course;
import org.schulcloud.mobile.data.model.CurrentUser;
import org.schulcloud.mobile.data.model.Device;
import org.schulcloud.mobile.data.model.Directory;
import org.schulcloud.mobile.data.model.Event;
import org.schulcloud.mobile.data.model.File;
import org.schulcloud.mobile.data.model.Homework;
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.data.model.requestBodies.CallbackRequest;
import org.schulcloud.mobile.data.model.requestBodies.Credentials;
import org.schulcloud.mobile.data.model.requestBodies.DeviceRequest;
import org.schulcloud.mobile.data.model.requestBodies.SignedUrlRequest;
import org.schulcloud.mobile.data.model.responseBodies.DeviceResponse;
import org.schulcloud.mobile.data.model.responseBodies.FeathersResponse;
import org.schulcloud.mobile.data.model.responseBodies.FilesResponse;
import org.schulcloud.mobile.data.model.responseBodies.SignedUrlResponse;
import org.schulcloud.mobile.data.remote.RestService;
Expand Down Expand Up @@ -320,4 +323,48 @@ public Observable<List<Submission>> getSubmissions() {
public Submission getSubmissionForId(String homeworkId) {
return mDatabaseHelper.getSubmissionForId(homeworkId);
}

/**** Courses ****/

public Observable<Course> syncCourses() {
return mRestService.getCourses(getAccessToken())
.concatMap(new Func1<FeathersResponse<Course>, Observable<Course>>() {
@Override
public Observable<Course> call(FeathersResponse<Course> courses) {
mDatabaseHelper.clearTable(Course.class);
return mDatabaseHelper.setCourses(courses.data);
}
})
.doOnError(Throwable::printStackTrace);
}

public Observable<List<Course>> getCourses() {
return mDatabaseHelper.getCourses().distinct();
}

public Course getCourseForId(String courseId) {
return mDatabaseHelper.getCourseForId(courseId);
}

/**** Topics ****/

public Observable<Topic> syncTopics(String courseId) {
return mRestService.getTopics(getAccessToken(), courseId)
.concatMap(new Func1<FeathersResponse<Topic>, Observable<Topic>>() {
@Override
public Observable<Topic> call(FeathersResponse<Topic> topics) {
mDatabaseHelper.clearTable(Topic.class);
return mDatabaseHelper.setTopics(topics.data);
}
})
.doOnError(Throwable::printStackTrace);
}

public Observable<List<Topic>> getTopics() {
return mDatabaseHelper.getTopics().distinct();
}

public List<Contents> getContents(String topicId) {
return mDatabaseHelper.getContents(topicId).contents;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.schulcloud.mobile.data.local;

import org.schulcloud.mobile.data.model.AccessToken;
import org.schulcloud.mobile.data.model.Course;
import org.schulcloud.mobile.data.model.CurrentUser;
import org.schulcloud.mobile.data.model.Device;
import org.schulcloud.mobile.data.model.Directory;
import org.schulcloud.mobile.data.model.Event;
import org.schulcloud.mobile.data.model.File;
import org.schulcloud.mobile.data.model.Homework;
import org.schulcloud.mobile.data.model.Submission;
import org.schulcloud.mobile.data.model.Topic;
import org.schulcloud.mobile.data.model.User;

import java.util.Collection;
Expand Down Expand Up @@ -291,4 +293,70 @@ public Submission getSubmissionForId(String homeworkId) {
final Realm realm = mRealmProvider.get();
return realm.where(Submission.class).equalTo("homeworkId", homeworkId).findFirst();
}

/**** Courses ****/

public Observable<Course> setCourses(final Collection<Course> newCourse) {
return Observable.create(subscriber -> {
if (subscriber.isUnsubscribed()) return;
Realm realm = null;

try {
realm = mRealmProvider.get();
realm.executeTransaction(realm1 -> realm1.copyToRealmOrUpdate(newCourse));
} catch (Exception e) {
Timber.e(e, "There was an error while adding in Realm.");
subscriber.onError(e);
} finally {
if (realm != null) {
realm.close();
}
}
});
}

public Observable<List<Course>> getCourses() {
final Realm realm = mRealmProvider.get();
return realm.where(Course.class).findAllAsync().asObservable()
.filter(course -> course.isLoaded())
.map(course -> realm.copyFromRealm(course));
}

public Course getCourseForId(String courseId) {
final Realm realm = mRealmProvider.get();
return realm.where(Course.class).equalTo("_id", courseId).findFirst();
}

/**** Topics ****/

public Observable<Topic> setTopics(final Collection<Topic> newTopic) {
return Observable.create(subscriber -> {
if (subscriber.isUnsubscribed()) return;
Realm realm = null;

try {
realm = mRealmProvider.get();
realm.executeTransaction(realm1 -> realm1.copyToRealmOrUpdate(newTopic));
} catch (Exception e) {
Timber.e(e, "There was an error while adding in Realm.");
subscriber.onError(e);
} finally {
if (realm != null) {
realm.close();
}
}
});
}

public Observable<List<Topic>> getTopics() {
final Realm realm = mRealmProvider.get();
return realm.where(Topic.class).findAllAsync().asObservable()
.filter(topic -> topic.isLoaded())
.map(topic -> realm.copyFromRealm(topic));
}

public Topic getContents(String topicId) {
final Realm realm = mRealmProvider.get();
return realm.where(Topic.class).equalTo("_id", topicId).findFirst();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.schulcloud.mobile.data.model;

import io.realm.RealmObject;

public class Content extends RealmObject{
public String text;
public String materialId;
}
10 changes: 10 additions & 0 deletions app/src/main/java/org/schulcloud/mobile/data/model/Contents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.schulcloud.mobile.data.model;

import io.realm.RealmObject;

public class Contents extends RealmObject {
public String component;
public String title;
public Boolean hidden;
public Content content;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.schulcloud.mobile.data.model;

import io.realm.RealmList;
import io.realm.RealmModel;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.RealmClass;
Expand All @@ -12,4 +13,11 @@ public class Course implements RealmModel {
public String name;
public String description;
public String color;
public RealmList<Times> times;
public String startDate;
public String untilDate;
public Boolean gradeSystem;
public RealmList<User> substitutionIds;
public RealmList<User> teacherIds;
public RealmList<User> userIds;
}
16 changes: 16 additions & 0 deletions app/src/main/java/org/schulcloud/mobile/data/model/Times.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.schulcloud.mobile.data.model;


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

@RealmClass
public class Times implements RealmModel {
@PrimaryKey
public Integer weekday;
public Integer startTime;
public Integer duration;
public String eventId;
public String room;
}
15 changes: 15 additions & 0 deletions app/src/main/java/org/schulcloud/mobile/data/model/Topic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.schulcloud.mobile.data.model;

import io.realm.RealmList;
import io.realm.RealmObject;

public class Topic extends RealmObject {
public String _id;
public String name;
public String description;
public String date;
public String time;
public String courseId;
public Boolean hidden;
public RealmList<Contents> contents;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.schulcloud.mobile.data.model.responseBodies;

import java.util.List;

public class FeathersResponse <T>{
public List<T> data;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package org.schulcloud.mobile.data.remote;

import org.schulcloud.mobile.data.model.AccessToken;
import org.schulcloud.mobile.data.model.Course;
import org.schulcloud.mobile.data.model.CurrentUser;
import org.schulcloud.mobile.data.model.Device;
import org.schulcloud.mobile.data.model.Event;
import org.schulcloud.mobile.data.model.Homework;
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.data.model.requestBodies.CallbackRequest;
import org.schulcloud.mobile.data.model.requestBodies.Credentials;
import org.schulcloud.mobile.data.model.requestBodies.DeviceRequest;
import org.schulcloud.mobile.data.model.requestBodies.SignedUrlRequest;
import org.schulcloud.mobile.data.model.responseBodies.DeviceResponse;
import org.schulcloud.mobile.data.model.responseBodies.FeathersResponse;
import org.schulcloud.mobile.data.model.responseBodies.FilesResponse;
import org.schulcloud.mobile.data.model.responseBodies.SignedUrlResponse;

Expand Down Expand Up @@ -88,4 +91,10 @@ Observable<ResponseBody> uploadFile(

@GET("submissions?$limit=-1&$populate=comments")
Observable<List<Submission>> getSubmissions(@Header("Authorization") String accessToken);

@GET("courses?$populate[0]=teacherIds&$populate[1]=userIds&$populate[2]=substitutionIds")
Observable<FeathersResponse<Course>> getCourses(@Header("Authorization") String accessToken);

@GET("lessons")
Observable<FeathersResponse<Topic>> getTopics(@Header("Authorization") String accessToken, @Query("courseId") String courseId);
}
Loading

0 comments on commit 1e8ca96

Please sign in to comment.