Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
MA-2375 downloaded videos not appearing in my videos
Browse files Browse the repository at this point in the history
  • Loading branch information
mdinino authored and christopher lee committed Jun 1, 2016
1 parent 6520474 commit a7dac21
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.inject.AbstractModule;

import org.edx.mobile.base.MainApplication;
Expand All @@ -11,6 +14,8 @@
import org.edx.mobile.http.IApi;
import org.edx.mobile.http.OkHttpUtil;
import org.edx.mobile.http.RestApiManager;
import org.edx.mobile.http.serialization.JsonPageDeserializer;
import org.edx.mobile.model.Page;
import org.edx.mobile.module.analytics.ISegment;
import org.edx.mobile.module.analytics.ISegmentEmptyImpl;
import org.edx.mobile.module.analytics.ISegmentImpl;
Expand All @@ -27,6 +32,7 @@
import org.edx.mobile.module.storage.Storage;
import org.edx.mobile.util.BrowserUtil;
import org.edx.mobile.util.Config;
import org.edx.mobile.util.DateUtil;
import org.edx.mobile.util.MediaConsentUtils;

import de.greenrobot.event.EventBus;
Expand Down Expand Up @@ -85,6 +91,14 @@ public void configure() {

bind(EventBus.class).toInstance(EventBus.getDefault());

bind(Gson.class).toInstance(new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.setDateFormat(DateUtil.ISO_8601_DATE_TIME_FORMAT)
.registerTypeAdapter(Page.class, new JsonPageDeserializer())
.registerTypeAdapterFactory(new ServerJsonDateAdapterFactory())
.serializeNulls()
.create());

requestStaticInjection(BrowserUtil.class, MediaConsentUtils.class,
DiscussionTextUtils.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package org.edx.mobile.core;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.jakewharton.retrofit.Ok3Client;

import org.edx.mobile.http.RetroHttpExceptionHandler;
import org.edx.mobile.http.serialization.JsonPageDeserializer;
import org.edx.mobile.model.Page;
import org.edx.mobile.util.Config;
import org.edx.mobile.util.DateUtil;

import okhttp3.OkHttpClient;
import retrofit.RestAdapter;
Expand All @@ -25,16 +20,11 @@ public class RestAdapterProvider implements Provider<RestAdapter> {
@Inject
OkHttpClient client;

@Inject
Gson gson;

@Override
public RestAdapter get() {
Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.setDateFormat(DateUtil.ISO_8601_DATE_TIME_FORMAT)
.registerTypeAdapter(Page.class, new JsonPageDeserializer())
.registerTypeAdapterFactory(new ServerJsonDateAdapterFactory())
.serializeNulls()
.create();

return new RestAdapter.Builder()
.setClient(new Ok3Client(client))
.setEndpoint(config.getApiHostURL())
Expand Down
7 changes: 5 additions & 2 deletions VideoLocker/src/main/java/org/edx/mobile/http/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.edx.mobile.module.db.impl.DatabaseFactory;
import org.edx.mobile.module.prefs.PrefManager;
import org.edx.mobile.module.registration.model.RegistrationDescription;
import org.edx.mobile.user.UserAPI;
import org.edx.mobile.util.Config;
import org.edx.mobile.util.DateUtil;
import org.edx.mobile.util.NetworkUtil;
Expand Down Expand Up @@ -61,6 +62,9 @@ public class Api implements IApi {
@Inject
private CacheManager cache;

@Inject
private UserAPI userApi;

private Context context;
protected final Logger logger = new Logger(getClass().getName());

Expand Down Expand Up @@ -355,8 +359,7 @@ public List<EnrolledCoursesResponse> getEnrolledCourses(boolean fetchFromCache)

Bundle p = new Bundle();
p.putString("format", "json");
String url = getBaseUrl() + "/api/mobile/v0.5/users/" + pref.getCurrentUserProfile().username
+ "/course_enrollments/";
String url = userApi.getUserEnrolledCoursesURL(pref.getCurrentUserProfile().username);
String json = null;

if (NetworkUtil.isConnected(context) && !fetchFromCache) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

public class CoursesAsyncLoader extends AsyncTaskLoader<AsyncTaskResult<List<EnrolledCoursesResponse>>> {
private AsyncTaskResult<List<EnrolledCoursesResponse>> mData;
private Context context;

private final Context context;
private Observer mObserver;

@Inject
Expand All @@ -38,17 +37,28 @@ public CoursesAsyncLoader(Context context) {

@Override
public AsyncTaskResult<List<EnrolledCoursesResponse>> loadInBackground() {

PrefManager pref = new PrefManager(context, PrefManager.Pref.LOGIN);
ProfileModel profile = pref.getCurrentUserProfile();
List<EnrolledCoursesResponse> enrolledCoursesResponse = null;

AsyncTaskResult<List<EnrolledCoursesResponse>> result = new AsyncTaskResult<>();

try {
List<EnrolledCoursesResponse> enrolledCoursesResponse = api.getUserEnrolledCourses(profile.username);
environment.getNotificationDelegate().syncWithServerForFailure();
environment.getNotificationDelegate().checkCourseEnrollment(enrolledCoursesResponse);
result.setResult(enrolledCoursesResponse);
if (profile != null) {
enrolledCoursesResponse = api.getUserEnrolledCourses(profile.username, false);
environment.getNotificationDelegate().syncWithServerForFailure();
if (enrolledCoursesResponse != null) {
environment.getNotificationDelegate().checkCourseEnrollment(enrolledCoursesResponse);
}
}

} catch (RetroHttpException exception) {
result.setEx(exception);
}

result.setResult(enrolledCoursesResponse);

return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.edx.mobile.module.storage;

import android.support.annotation.NonNull;

import org.edx.mobile.interfaces.SectionItemInterface;
import org.edx.mobile.model.VideoModel;
import org.edx.mobile.model.api.EnrolledCoursesResponse;
Expand Down Expand Up @@ -94,14 +96,14 @@ void getAverageDownloadProgressInSection(String enrollmentId,
* videos and no videos downloaded in the course
* @return
*/
ArrayList<EnrolledCoursesResponse> getDownloadedCoursesWithVideoCountAndSize();
@NonNull ArrayList<EnrolledCoursesResponse> getDownloadedCoursesWithVideoCountAndSize();

/**
* Returns list of all recently downloaded videos list
* The list contains local videos with only course header sorted based on Downloaded Date.
* @return
*/
ArrayList<SectionItemInterface> getRecentDownloadedVideosList();
@NonNull ArrayList<SectionItemInterface> getRecentDownloadedVideosList();

/**
* This DownloadEntry model is fetched and returned from the db
Expand Down
Loading

0 comments on commit a7dac21

Please sign in to comment.