From e24cd0ce6b09f66f6e6bfb19149dbccde1dbb088 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Sat, 1 Oct 2016 14:58:11 +0200 Subject: [PATCH 01/15] Migrate EventBus to version 3. --- app/build.gradle | 2 +- .../de/xikolo/controller/BaseActivity.java | 33 ++++---- .../de/xikolo/controller/CourseActivity.java | 9 ++- .../de/xikolo/controller/LoginActivity.java | 3 +- .../de/xikolo/controller/MainActivity.java | 9 ++- .../de/xikolo/controller/ModuleActivity.java | 9 ++- .../downloads/DownloadsFragment.java | 10 ++- .../helper/EnrollmentController.java | 3 +- .../controller/main/CourseListFragment.java | 17 ++-- .../module/helper/DownloadViewController.java | 16 ++-- .../secondscreen/SecondScreenFragment.java | 15 +++- .../secondscreen/SlideViewerFragment.java | 11 ++- .../TranscriptViewerFragment.java | 9 ++- .../controller/settings/SettingsFragment.java | 21 ++--- .../de/xikolo/data/entities/Download.java | 12 +-- .../de/xikolo/data/net/DownloadHelper.java | 3 +- .../xikolo/managers/SecondScreenManager.java | 9 ++- .../de/xikolo/managers/WebSocketManager.java | 26 +++--- .../java/de/xikolo/model/DownloadModel.java | 71 +++++++++------- app/src/main/java/de/xikolo/model/Result.java | 3 +- .../main/java/de/xikolo/model/UserModel.java | 3 +- .../model/jobs/CreateAccessTokenJob.java | 3 +- .../receiver/DownloadCompletedReceiver.java | 3 +- .../model/receiver/NetworkChangeReceiver.java | 5 +- .../view/SettingsDividerItemDecoration.java | 80 ------------------- 25 files changed, 190 insertions(+), 195 deletions(-) delete mode 100644 app/src/main/java/de/xikolo/view/SettingsDividerItemDecoration.java diff --git a/app/build.gradle b/app/build.gradle index 8c806ad70..b32a963c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -153,7 +153,7 @@ dependencies { exclude group: 'glide-parent' } compile 'com.birbit:android-priority-jobqueue:1.3.4' - compile 'de.greenrobot:eventbus:2.4.0' + compile 'org.greenrobot:eventbus:3.0.0' compile 'org.java-websocket:Java-WebSocket:1.3.0' compile 'com.github.barteksc:android-pdf-viewer:1.4.0' diff --git a/app/src/main/java/de/xikolo/controller/BaseActivity.java b/app/src/main/java/de/xikolo/controller/BaseActivity.java index 64f74445c..319d54845 100644 --- a/app/src/main/java/de/xikolo/controller/BaseActivity.java +++ b/app/src/main/java/de/xikolo/controller/BaseActivity.java @@ -21,7 +21,10 @@ import com.google.android.libraries.cast.companionlibrary.widgets.IntroductoryOverlay; import com.path.android.jobqueue.JobManager; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.data.preferences.NotificationPreferences; @@ -151,18 +154,6 @@ protected void enableOfflineModeToolbar(boolean enable) { this.offlineModeToolbar = enable; } - public void onEventMainThread(NetworkStateEvent event) { - if (toolbar != null && offlineModeToolbar) { - if (event.isOnline()) { - toolbar.setSubtitle(""); - setColorScheme(R.color.apptheme_main, R.color.apptheme_main_dark); - } else { - toolbar.setSubtitle(getString(R.string.offline_mode)); - setColorScheme(R.color.offline_mode_actionbar, R.color.offline_mode_statusbar); - } - } - } - protected void setColorScheme(int color, int darkColor) { if (toolbar != null) { toolbar.setBackgroundColor(ContextCompat.getColor(this, color)); @@ -179,11 +170,25 @@ protected void setColorScheme(int color, int darkColor) { } } + @SuppressWarnings("unused") + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) + public void onNetworkEvent(NetworkStateEvent event) { + if (toolbar != null && offlineModeToolbar) { + if (event.isOnline()) { + toolbar.setSubtitle(""); + setColorScheme(R.color.apptheme_main, R.color.apptheme_main_dark); + } else { + toolbar.setSubtitle(getString(R.string.offline_mode)); + setColorScheme(R.color.offline_mode_actionbar, R.color.offline_mode_statusbar); + } + } + } + @Override protected void onStart() { super.onStart(); - EventBus.getDefault().registerSticky(this); + EventBus.getDefault().register(this); if (UserModel.isLoggedIn(this) && FeatureToggle.secondScreen()) { globalApplication.getWebSocketManager().initConnection(UserModel.getToken(this)); diff --git a/app/src/main/java/de/xikolo/controller/CourseActivity.java b/app/src/main/java/de/xikolo/controller/CourseActivity.java index 69096160c..e49238ad5 100644 --- a/app/src/main/java/de/xikolo/controller/CourseActivity.java +++ b/app/src/main/java/de/xikolo/controller/CourseActivity.java @@ -15,6 +15,9 @@ import android.view.MenuInflater; import android.view.MenuItem; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import java.util.List; @@ -215,8 +218,10 @@ public boolean onCreateOptionsMenu(Menu menu) { } @Override - public void onEventMainThread(NetworkStateEvent event) { - super.onEventMainThread(event); + @SuppressWarnings("unused") + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) + public void onNetworkEvent(NetworkStateEvent event) { + super.onNetworkEvent(event); if (tabLayout != null) { if (event.isOnline()) { diff --git a/app/src/main/java/de/xikolo/controller/LoginActivity.java b/app/src/main/java/de/xikolo/controller/LoginActivity.java index 506b29ca7..9269add14 100644 --- a/app/src/main/java/de/xikolo/controller/LoginActivity.java +++ b/app/src/main/java/de/xikolo/controller/LoginActivity.java @@ -13,7 +13,8 @@ import android.widget.EditText; import android.widget.TextView; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; + import de.xikolo.R; import de.xikolo.controller.dialogs.ProgressDialog; import de.xikolo.data.entities.User; diff --git a/app/src/main/java/de/xikolo/controller/MainActivity.java b/app/src/main/java/de/xikolo/controller/MainActivity.java index 9b626ba93..aa78056d2 100644 --- a/app/src/main/java/de/xikolo/controller/MainActivity.java +++ b/app/src/main/java/de/xikolo/controller/MainActivity.java @@ -9,6 +9,9 @@ import android.util.Log; import android.view.Menu; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import de.xikolo.BuildConfig; import de.xikolo.R; import de.xikolo.controller.dialogs.SecondScreenDialog; @@ -242,12 +245,14 @@ public void selectDrawerSection(int pos) { } @SuppressWarnings("unused") - public void onEventMainThread(LoginEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLoginEvent(LoginEvent event) { updateDrawer(); } @SuppressWarnings("unused") - public void onEventMainThread(LogoutEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLogoutEvent(LogoutEvent event) { updateDrawer(); } diff --git a/app/src/main/java/de/xikolo/controller/ModuleActivity.java b/app/src/main/java/de/xikolo/controller/ModuleActivity.java index b7986ae78..df1b324b8 100644 --- a/app/src/main/java/de/xikolo/controller/ModuleActivity.java +++ b/app/src/main/java/de/xikolo/controller/ModuleActivity.java @@ -17,6 +17,9 @@ import android.view.ViewGroup; import android.widget.TextView; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import java.util.List; @@ -143,8 +146,10 @@ protected void onCreate(Bundle savedInstanceState) { } @Override - public void onEventMainThread(NetworkStateEvent event) { - super.onEventMainThread(event); + @SuppressWarnings("unused") + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) + public void onNetworkEvent(NetworkStateEvent event) { + super.onNetworkEvent(event); if (tabLayout != null) { if (event.isOnline()) { diff --git a/app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java b/app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java index 7e4c78473..3153db006 100644 --- a/app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java +++ b/app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java @@ -9,11 +9,13 @@ import android.view.View; import android.view.ViewGroup; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + import java.io.File; import java.util.ArrayList; import java.util.List; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.dialogs.ConfirmDeleteDialog; @@ -83,14 +85,16 @@ public void onStart() { } @SuppressWarnings("unused") - public void onEvent(PermissionGrantedEvent permissionGrantedEvent) { + @Subscribe + public void onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEvent) { if (permissionGrantedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { fetchItems(); } } @SuppressWarnings("unused") - public void onEvent(PermissionDeniedEvent permissionDeniedEvent) { + @Subscribe + public void onPermissionDeniedEvent(PermissionDeniedEvent permissionDeniedEvent) { if (permissionDeniedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { fetchItems(); } diff --git a/app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java b/app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java index a9038cff2..a3d3c3c76 100644 --- a/app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java +++ b/app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java @@ -2,7 +2,8 @@ import android.support.v4.app.FragmentActivity; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; + import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.dialogs.ProgressDialog; diff --git a/app/src/main/java/de/xikolo/controller/main/CourseListFragment.java b/app/src/main/java/de/xikolo/controller/main/CourseListFragment.java index 27908e83a..260ec7c5f 100644 --- a/app/src/main/java/de/xikolo/controller/main/CourseListFragment.java +++ b/app/src/main/java/de/xikolo/controller/main/CourseListFragment.java @@ -11,10 +11,13 @@ import android.view.View; import android.view.ViewGroup; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import java.util.List; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.CourseActivity; @@ -349,7 +352,8 @@ public void onDetailButtonClicked(Course course) { } @SuppressWarnings("unused") - public void onEventMainThread(UnenrollEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onUnenrollEvent(UnenrollEvent event) { if (courses != null && courses.contains(event.getCourse())) { if (isMyCoursesFilter()) { courses.remove(event.getCourse()); @@ -361,7 +365,8 @@ public void onEventMainThread(UnenrollEvent event) { } @SuppressWarnings("unused") - public void onEventMainThread(EnrollEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEnrollEvent(EnrollEvent event) { if (isMyCoursesFilter()) { if (courses != null && !courses.contains(event.getCourse())) { courses.add(event.getCourse()); @@ -375,7 +380,8 @@ public void onEventMainThread(EnrollEvent event) { } @SuppressWarnings("unused") - public void onEventMainThread(LoginEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLoginEvent(LoginEvent event) { courses = null; if (courseListAdapter != null) { courseListAdapter.clear(); @@ -384,7 +390,8 @@ public void onEventMainThread(LoginEvent event) { } @SuppressWarnings("unused") - public void onEventMainThread(LogoutEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLogoutEvent(LogoutEvent event) { courses = null; if (courseListAdapter != null) { courseListAdapter.clear(); diff --git a/app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java b/app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java index 1a9546753..8072ac042 100644 --- a/app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java +++ b/app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java @@ -13,9 +13,12 @@ import android.widget.ProgressBar; import android.widget.TextView; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.io.File; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.dialogs.ConfirmDeleteDialog; @@ -307,7 +310,8 @@ private void showEndState() { } @SuppressWarnings("unused") - public void onEventMainThread(DownloadCompletedEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDownloadCompletedEvent(DownloadCompletedEvent event) { if (event.getDownload().localUri.contains(item.id) && DownloadModel.DownloadFileType.getDownloadFileTypeFromUri(event.getDownload().localUri) == type) { showEndState(); @@ -315,20 +319,22 @@ public void onEventMainThread(DownloadCompletedEvent event) { } @SuppressWarnings("unused") - public void onEventMainThread(DownloadStartedEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDownloadStartedEvent(DownloadStartedEvent event) { if (event.getUrl().equals(uri) && !progressBarUpdaterRunning) { showRunningState(); } } @SuppressWarnings("unused") - public void onEventMainThread(DownloadDeletedEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDownloadDeletedEvent(DownloadDeletedEvent event) { if (event.getItem().id.equals(item.id) && progressBarUpdaterRunning) { showStartState(); } } - public void openFileAsPdf() { + private void openFileAsPdf() { buttonOpenDownload.setText(GlobalApplication.getInstance().getResources().getText(R.string.open)); buttonOpenDownload.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java b/app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java index ea37ac767..eedd9b9e3 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java +++ b/app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java @@ -18,10 +18,13 @@ import android.widget.LinearLayout; import android.widget.TextView; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import java.util.List; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.helper.ImageController; @@ -133,7 +136,9 @@ public void onClick(View v) { } } - public void onEventMainThread(SecondScreenManager.SecondScreenNewVideoEvent event) { + @SuppressWarnings("unused") + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) + public void onSecondScreenNewVideoEvent(SecondScreenManager.SecondScreenNewVideoEvent event) { if (item == null || !item.equals(event.getItem())) { subtitleList = null; } @@ -357,7 +362,9 @@ private View inflateSeconScreenAction(@StringRes int title, @StringRes int descr return layout; } - public void onEventMainThread(SecondScreenManager.SecondScreenUpdateVideoEvent event) { + @SuppressWarnings("unused") + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSecondScreenUpdateVideoEvent(SecondScreenManager.SecondScreenUpdateVideoEvent event) { item = event.getItem(); if (event.getWebSocketMessage().payload().containsKey("current_time")) { @@ -383,7 +390,7 @@ public void onEventMainThread(SecondScreenManager.SecondScreenUpdateVideoEvent e public void onStart() { super.onStart(); - EventBus.getDefault().registerSticky(this); + EventBus.getDefault().register(this); } @Override diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java b/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java index dddd11508..5816306d6 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java +++ b/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java @@ -17,9 +17,12 @@ import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener; import com.github.barteksc.pdfviewer.listener.OnPageChangeListener; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.io.File; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.dialogs.DownloadSlidesDialog; @@ -192,7 +195,8 @@ public void onSaveInstanceState(Bundle outState) { } @SuppressWarnings("unused") - public void onEventMainThread(SecondScreenManager.SecondScreenUpdateVideoEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSecondScreenUpdateVideoEvent(SecondScreenManager.SecondScreenUpdateVideoEvent event) { if (event.getItem().equals(item)) { if (event.getWebSocketMessage().payload().containsKey("slide_number")) { try { @@ -212,7 +216,8 @@ public void onEventMainThread(SecondScreenManager.SecondScreenUpdateVideoEvent e } @SuppressWarnings("unused") - public void onEventMainThread(DownloadCompletedEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onDownloadCompletedEvent(DownloadCompletedEvent event) { if (event.getDownload().localUri.contains(item.id) && DownloadModel.DownloadFileType.getDownloadFileTypeFromUri(event.getDownload().localUri) == DownloadModel.DownloadFileType.SLIDES) { if (progressDialog != null && progressDialog.getDialog().isShowing()) { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java b/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java index d19012272..ea3fddd35 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java +++ b/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java @@ -17,10 +17,13 @@ import android.view.View; import android.view.ViewGroup; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import java.util.List; -import de.greenrobot.event.EventBus; import de.xikolo.R; import de.xikolo.controller.dialogs.ChooseLanguageDialog; import de.xikolo.controller.secondscreen.adapter.TranscriptViewerAdapter; @@ -169,7 +172,9 @@ private void performScroll() { } } - public void onEventMainThread(SecondScreenManager.SecondScreenUpdateVideoEvent event) { + @SuppressWarnings("unused") + @Subscribe(threadMode = ThreadMode.MAIN) + public void onSecondScreenUpdateVideoEvent(SecondScreenManager.SecondScreenUpdateVideoEvent event) { if (event.getItem().equals(item)) { if (event.getWebSocketMessage().payload().containsKey("current_time")) { String time = event.getWebSocketMessage().payload().get("current_time"); diff --git a/app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java b/app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java index fc09546f9..9102ec47e 100644 --- a/app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java +++ b/app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java @@ -8,12 +8,13 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceScreen; -import android.support.v7.widget.RecyclerView; -import android.view.View; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import java.util.Calendar; -import de.greenrobot.event.EventBus; import de.xikolo.BuildConfig; import de.xikolo.GlobalApplication; import de.xikolo.R; @@ -25,7 +26,6 @@ import de.xikolo.model.events.LogoutEvent; import de.xikolo.util.BuildFlavor; import de.xikolo.util.Config; -import de.xikolo.view.SettingsDividerItemDecoration; public class SettingsFragment extends PreferenceFragment { @@ -164,20 +164,15 @@ public boolean onPreferenceClick(Preference preference) { } } - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - ((RecyclerView) view.findViewById(R.id.list)).addItemDecoration( - new SettingsDividerItemDecoration(getActivity()) - ); - } - @SuppressWarnings("unused") - public void onEventMainThread(LoginEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLoginEvent(LoginEvent event) { buildLogoutView(loginOut); } @SuppressWarnings("unused") - public void onEventMainThread(LogoutEvent event) { + @Subscribe(threadMode = ThreadMode.MAIN) + public void onLogoutEvent(LogoutEvent event) { buildLoginView(loginOut); } diff --git a/app/src/main/java/de/xikolo/data/entities/Download.java b/app/src/main/java/de/xikolo/data/entities/Download.java index 4c78a54a6..951e5ea04 100644 --- a/app/src/main/java/de/xikolo/data/entities/Download.java +++ b/app/src/main/java/de/xikolo/data/entities/Download.java @@ -8,8 +8,6 @@ public class Download { public String description; - public String localFilename; - public String localUri; public String uri; @@ -30,22 +28,20 @@ public class Download { public Download() {} - public Download(long id, String title, String description, String localFilename, String localUri, String uri, int status, int reason) { + public Download(long id, String title, String description, String localUri, String uri, int status, int reason) { this.id = id; this.title = title; this.description = description; - this.localFilename = localFilename; this.localUri = localUri; this.uri = uri; this.status = status; this.reason = reason; } - public Download(long id, String title, String description, String localFilename, String localUri, String uri, int status, int reason, long totalSizeBytes, long bytesDownloadedSoFar, long lastModifiedTimestamp, String mediaproviderUri, String mediaType) { + public Download(long id, String title, String description, String localUri, String uri, int status, int reason, long totalSizeBytes, long bytesDownloadedSoFar, long lastModifiedTimestamp, String mediaproviderUri, String mediaType) { this.id = id; this.title = title; this.description = description; - this.localFilename = localFilename; this.localUri = localUri; this.uri = uri; this.status = status; @@ -64,7 +60,7 @@ public boolean equals(Object o) { Download download = (Download) o; - if (localFilename != null ? !localFilename.equals(download.localFilename) : download.localFilename != null) + if (localUri != null ? !localUri.equals(download.localUri) : download.localUri != null) return false; return true; @@ -72,7 +68,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return localFilename != null ? localFilename.hashCode() : 0; + return localUri != null ? localUri.hashCode() : 0; } } diff --git a/app/src/main/java/de/xikolo/data/net/DownloadHelper.java b/app/src/main/java/de/xikolo/data/net/DownloadHelper.java index 92217d991..b8b93a171 100644 --- a/app/src/main/java/de/xikolo/data/net/DownloadHelper.java +++ b/app/src/main/java/de/xikolo/data/net/DownloadHelper.java @@ -41,7 +41,6 @@ public static Download buildDownloadObject(Cursor c) { long id = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID)); String title = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE)); String description = c.getString(c.getColumnIndex(DownloadManager.COLUMN_DESCRIPTION)); - String localFilename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME)); String localUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); String uri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI)); int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS)); @@ -52,7 +51,7 @@ public static Download buildDownloadObject(Cursor c) { String mediaproviderUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIAPROVIDER_URI)); String mediaType = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE)); - return new Download(id, title, description, localFilename, localUri, uri, status, reason, + return new Download(id, title, description, localUri, uri, status, reason, totalSizeBytes, bytesDownloadedSoFar, lastModifiedTimestamp, mediaproviderUri, mediaType); } diff --git a/app/src/main/java/de/xikolo/managers/SecondScreenManager.java b/app/src/main/java/de/xikolo/managers/SecondScreenManager.java index c0bb58741..1801a81be 100644 --- a/app/src/main/java/de/xikolo/managers/SecondScreenManager.java +++ b/app/src/main/java/de/xikolo/managers/SecondScreenManager.java @@ -10,7 +10,10 @@ import android.support.v4.app.NotificationCompat; import android.support.v4.content.ContextCompat; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.controller.SecondScreenActivity; @@ -56,7 +59,9 @@ public SecondScreenManager() { isRequesting = false; } - public void onEventBackgroundThread(WebSocketManager.WebSocketMessageEvent event) { + @SuppressWarnings("unused") + @Subscribe(threadMode = ThreadMode.ASYNC) + public void onWebSocketMessageEvent(WebSocketManager.WebSocketMessageEvent event) { final WebSocketMessage message = event.getWebSocketMessage(); if (!message.platform().equals("web") || !message.action().startsWith("video_")) { diff --git a/app/src/main/java/de/xikolo/managers/WebSocketManager.java b/app/src/main/java/de/xikolo/managers/WebSocketManager.java index 997ec1f05..c1ba30503 100644 --- a/app/src/main/java/de/xikolo/managers/WebSocketManager.java +++ b/app/src/main/java/de/xikolo/managers/WebSocketManager.java @@ -6,6 +6,9 @@ import com.google.gson.JsonSyntaxException; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; import org.java_websocket.WebSocket; import org.java_websocket.client.DefaultSSLWebSocketClientFactory; import org.java_websocket.client.WebSocketClient; @@ -19,7 +22,6 @@ import javax.net.ssl.SSLContext; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.data.entities.WebSocketMessage; import de.xikolo.data.parser.GsonHelper; @@ -129,31 +131,37 @@ private boolean isConnecting() { return webSocketClient != null && webSocketClient.getReadyState() == WebSocket.READYSTATE.CONNECTING; } - public void onEvent(NetworkStateEvent event) { + @SuppressWarnings("unused") + @Subscribe(threadMode = ThreadMode.BACKGROUND) + public void onNetworkEvent(NetworkStateEvent event) { if (event.isOnline() && UserModel.isLoggedIn(GlobalApplication.getInstance())) { initConnection(UserModel.getToken(GlobalApplication.getInstance())); } } - public void onEvent(LoginEvent event) { + @SuppressWarnings("unused") + @Subscribe(threadMode = ThreadMode.BACKGROUND) + public void onLoginEvent(LoginEvent event) { if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { initConnection(UserModel.getToken(GlobalApplication.getInstance())); } } - public void onEvent(LogoutEvent event) { + @SuppressWarnings("unused") + @Subscribe(threadMode = ThreadMode.BACKGROUND) + public void onLogoutEvent(LogoutEvent event) { closeConnection(); } - public static class WebSocketConnectedEvent extends Event {} + static class WebSocketConnectedEvent extends Event {} - public static class WebSocketClosedEvent extends Event {} + static class WebSocketClosedEvent extends Event {} - public static class WebSocketMessageEvent extends Event { + static class WebSocketMessageEvent extends Event { private WebSocketMessage webSocketMessage; - public WebSocketMessageEvent(String message) { + WebSocketMessageEvent(String message) { super(); this.webSocketMessage = GsonHelper.create().fromJson(message, WebSocketMessage.class); } @@ -163,7 +171,7 @@ public WebSocketMessageEvent(WebSocketMessage message) { this.webSocketMessage = message; } - public WebSocketMessage getWebSocketMessage() { + WebSocketMessage getWebSocketMessage() { return this.webSocketMessage; } } diff --git a/app/src/main/java/de/xikolo/model/DownloadModel.java b/app/src/main/java/de/xikolo/model/DownloadModel.java index bf35d8e4b..f974ae146 100644 --- a/app/src/main/java/de/xikolo/model/DownloadModel.java +++ b/app/src/main/java/de/xikolo/model/DownloadModel.java @@ -2,17 +2,20 @@ import android.app.Activity; import android.app.DownloadManager; +import android.net.Uri; import android.os.Environment; import android.util.Log; import com.path.android.jobqueue.JobManager; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; + import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Set; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.R; import de.xikolo.data.entities.Course; @@ -100,14 +103,14 @@ public long startDownload(String uri, DownloadFileType type, Course course, Modu if (ExternalStorageUtil.isExternalStorageWritable()) { if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { String file = this.escapeFilename(item.title) + type.getFileSuffix(); - String filename = buildDownloadFilename(type, course, module, item); + Uri downloadUri = buildDownloadUri(type, course, module, item); - if (downloadExists(filename)) { + if (downloadExists(downloadUri)) { ToastUtil.show(R.string.toast_file_already_downloaded); } else { LanalyticsUtil.trackDownloadedFile(item.id, course.id, module.id, type); - File dlFile = new File(filename); + File dlFile = new File(downloadUri.getPath()); createFolderIfNotExists(new File(dlFile.getAbsolutePath().replace(file, ""))); @@ -128,23 +131,22 @@ public long startDownload(String uri, DownloadFileType type, Course course, Modu public boolean deleteDownload(DownloadFileType type, Course course, Module module, Item item) { if (ExternalStorageUtil.isExternalStorageWritable()) { if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { - String filename = buildDownloadFilename(type, course, module, item); + Uri downloadUri = buildDownloadUri(type, course, module, item); if (Config.DEBUG) { - Log.d(TAG, "Delete download " + filename); + Log.d(TAG, "Delete download " + downloadUri.toString()); } - if (!downloadExists(filename)) { + if (!downloadExists(downloadUri)) { return false; } else { - File dlFile = new File(filename); + EventBus.getDefault().post(new DownloadDeletedEvent(item)); + File dlFile = new File(downloadUri.getPath()); return dlFile.delete(); } } else { pendingAction = PendingAction.DELETE; pendingAction.savePayload(null, type, course, module, item); - - EventBus.getDefault().post(new DownloadDeletedEvent(item)); return false; } } else { @@ -157,22 +159,27 @@ public boolean deleteDownload(DownloadFileType type, Course course, Module modul public boolean cancelDownload(DownloadFileType type, Course course, Module module, Item item) { if (ExternalStorageUtil.isExternalStorageWritable()) { if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { - String filename = buildDownloadFilename(type, course, module, item); + Uri downloadUri = buildDownloadUri(type, course, module, item); Download dl = new Download(); - dl.localFilename = filename; + dl.localUri = downloadUri.toString(); if (Config.DEBUG) { - Log.d(TAG, "Cancel download " + filename); + Log.d(TAG, "Cancel download " + downloadUri.toString()); } + int id = 0; Set dlSet = DownloadHelper.getAllDownloads(); for (Download download : dlSet) { if (download.equals(dl)) { - DownloadHelper.remove(download.id); + id = DownloadHelper.remove(download.id); } } + if (id > 0) { + EventBus.getDefault().post(new DownloadDeletedEvent(item)); + return true; + } - return deleteDownload(type, course, module, item); + return false; } else { pendingAction = PendingAction.CANCEL; pendingAction.savePayload(null, type, course, module, item); @@ -185,7 +192,9 @@ public boolean cancelDownload(DownloadFileType type, Course course, Module modul } } - public void onEvent(PermissionGrantedEvent permissionGrantedEvent) { + @SuppressWarnings("unused") + @Subscribe + public void onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEvent) { if (permissionGrantedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { if (pendingAction != null) { switch (pendingAction) { @@ -209,19 +218,21 @@ public void onEvent(PermissionGrantedEvent permissionGrantedEvent) { } } - public void onEvent(PermissionDeniedEvent permissionDeniedEvent) { + @SuppressWarnings("unused") + @Subscribe + public void onPermissionDeniedEvent(PermissionDeniedEvent permissionDeniedEvent) { if (permissionDeniedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { pendingAction = null; } } public Download getDownload(DownloadFileType type, Course course, Module module, Item item) { - String filename = buildDownloadFilename(type, course, module, item); + Uri downloadUri = buildDownloadUri(type, course, module, item); Download dl = new Download(); - dl.localFilename = filename; + dl.localUri = downloadUri.toString(); if (Config.DEBUG) { - Log.d(TAG, "Get download " + filename); + Log.d(TAG, "Get download " + downloadUri.toString()); } Set dlSet = DownloadHelper.getAllDownloads(); @@ -235,9 +246,9 @@ public Download getDownload(DownloadFileType type, Course course, Module module, } public boolean downloadRunning(DownloadFileType type, Course course, Module module, Item item) { - String dlFilename = buildDownloadFilename(type, course, module, item); + Uri downloadUri = buildDownloadUri(type, course, module, item); Download dl = new Download(); - dl.localFilename = dlFilename; + dl.localUri = downloadUri.toString(); int flags = DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING; Set dlSet = DownloadHelper.getAllDownloadsForStatus(flags); @@ -246,17 +257,17 @@ public boolean downloadRunning(DownloadFileType type, Course course, Module modu } public boolean downloadExists(DownloadFileType type, Course course, Module module, Item item) { - File file = new File(buildDownloadFilename(type, course, module, item)); + File file = new File(buildDownloadUri(type, course, module, item).getPath()); return file.isFile() && file.exists(); } - private boolean downloadExists(String filename) { - File file = new File(filename); + private boolean downloadExists(Uri downloadUri) { + File file = new File(downloadUri.getPath()); return file.isFile() && file.exists(); } public File getDownloadFile(DownloadFileType type, Course course, Module module, Item item) { - File file = new File(buildDownloadFilename(type, course, module, item)); + File file = new File(buildDownloadUri(type, course, module, item).getPath()); if (file.isFile() && file.exists()) { return file; } @@ -264,24 +275,24 @@ public File getDownloadFile(DownloadFileType type, Course course, Module module, } public long getDownloadFileSize(DownloadFileType type, Course course, Module module, Item item) { - File file = new File(buildDownloadFilename(type, course, module, item)); + File file = new File(buildDownloadUri(type, course, module, item).getPath()); if (file.isFile() && file.exists()) { return file.length(); } return 0; } - private String buildDownloadFilename(DownloadFileType type, Course course, Module module, Item item) { + private Uri buildDownloadUri(DownloadFileType type, Course course, Module module, Item item) { File publicAppFolder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + GlobalApplication.getInstance().getString(R.string.app_name)); String file = this.escapeFilename(item.title) + type.getFileSuffix(); - return publicAppFolder.getAbsolutePath() + File.separator + return Uri.fromFile(new File(publicAppFolder.getAbsolutePath() + File.separator + escapeFilename(course.name) + "_" + course.id + File.separator + escapeFilename(module.name) + "_" + module.id + File.separator + escapeFilename(item.title) + "_" + item.id + File.separator - + file; + + file)); } private String escapeFilename(String filename) { diff --git a/app/src/main/java/de/xikolo/model/Result.java b/app/src/main/java/de/xikolo/model/Result.java index 843e461cf..b81249393 100644 --- a/app/src/main/java/de/xikolo/model/Result.java +++ b/app/src/main/java/de/xikolo/model/Result.java @@ -3,7 +3,8 @@ import android.os.Handler; import android.os.Looper; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; + import de.xikolo.model.events.NetworkStateEvent; public abstract class Result { diff --git a/app/src/main/java/de/xikolo/model/UserModel.java b/app/src/main/java/de/xikolo/model/UserModel.java index 725204b22..d97b216a8 100644 --- a/app/src/main/java/de/xikolo/model/UserModel.java +++ b/app/src/main/java/de/xikolo/model/UserModel.java @@ -4,7 +4,8 @@ import com.path.android.jobqueue.JobManager; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; + import de.xikolo.GlobalApplication; import de.xikolo.data.entities.User; import de.xikolo.data.preferences.UserPreferences; diff --git a/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java b/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java index aa7cc246a..2f73628a4 100644 --- a/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java @@ -7,11 +7,12 @@ import com.path.android.jobqueue.Params; import com.path.android.jobqueue.RetryConstraint; +import org.greenrobot.eventbus.EventBus; + import java.lang.reflect.Type; import java.net.URLEncoder; import java.util.concurrent.atomic.AtomicInteger; -import de.greenrobot.event.EventBus; import de.xikolo.GlobalApplication; import de.xikolo.data.entities.AccessToken; import de.xikolo.data.net.JsonRequest; diff --git a/app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java b/app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java index 83b539bbf..335061800 100644 --- a/app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java +++ b/app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java @@ -11,9 +11,10 @@ import android.support.v4.app.TaskStackBuilder; import android.support.v4.content.ContextCompat; +import org.greenrobot.eventbus.EventBus; + import java.util.List; -import de.greenrobot.event.EventBus; import de.xikolo.R; import de.xikolo.controller.DownloadsActivity; import de.xikolo.data.entities.Download; diff --git a/app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java b/app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java index c8a7ba208..9591801e3 100644 --- a/app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java +++ b/app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java @@ -4,7 +4,8 @@ import android.content.Context; import android.content.Intent; -import de.greenrobot.event.EventBus; +import org.greenrobot.eventbus.EventBus; + import de.xikolo.model.events.NetworkStateEvent; import de.xikolo.util.NetworkUtil; @@ -14,7 +15,7 @@ public class NetworkChangeReceiver extends BroadcastReceiver { public void onReceive(final Context context, final Intent intent) { boolean isOnline = NetworkUtil.isOnline(context); - EventBus.getDefault().post(new NetworkStateEvent(isOnline)); + EventBus.getDefault().postSticky(new NetworkStateEvent(isOnline)); } } diff --git a/app/src/main/java/de/xikolo/view/SettingsDividerItemDecoration.java b/app/src/main/java/de/xikolo/view/SettingsDividerItemDecoration.java deleted file mode 100644 index 4956df2eb..000000000 --- a/app/src/main/java/de/xikolo/view/SettingsDividerItemDecoration.java +++ /dev/null @@ -1,80 +0,0 @@ -package de.xikolo.view; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.view.View; - -public class SettingsDividerItemDecoration extends RecyclerView.ItemDecoration { - - final int dividerHeight; - final Paint paint = new Paint(); - final Drawable divider; - - public SettingsDividerItemDecoration(Context context) { - paint.setStyle(Paint.Style.FILL_AND_STROKE); - paint.setColor(Color.argb(102, 204, 204, 204)); - - final int[] attrs = {android.R.attr.listDivider}; - TypedArray ta = context.obtainStyledAttributes(attrs); - divider = ta.getDrawable(0); - - if (divider == null) { - dividerHeight = 2; - } else { - dividerHeight = divider.getIntrinsicHeight(); - } - - ta.recycle(); - } - - @Override - public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { - LinearLayoutManager lm = (LinearLayoutManager) parent.getLayoutManager(); - - final int first = lm.findFirstVisibleItemPosition(); - final int last = lm.findLastVisibleItemPosition(); - - final int left = parent.getPaddingLeft(); - final int right = parent.getWidth() - parent.getPaddingRight(); - - RecyclerView.Adapter adapter = parent.getAdapter(); - - for (int i = first; i <= last; i++) { - if (adapter.getItemCount() - 1 <= i) { - continue; - } - - final int viewType = adapter.getItemViewType(i); - final int viewTypeNext = adapter.getItemViewType(i + 1); - - if (viewType == 0 || viewTypeNext == 0) { - continue; // skipping on and before categories - } - - final View view = lm.findViewByPosition(i); - - final int top = view.getBottom() + view.getPaddingBottom(); - final int bottom = top + dividerHeight; - - if (divider == null) { - c.drawRect(left, top, right, bottom, paint); - } else { - divider.setBounds(left, top, right, bottom); - divider.draw(c); - } - } - } - - @Override - public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { - outRect.set(0, 0, 0, dividerHeight); - } - -} From 8e42ae617a5b4fafad3f23a68a5a5a917d2683e0 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Tue, 4 Oct 2016 16:37:33 +0200 Subject: [PATCH 02/15] Allow app to be installed on external storage. --- app/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5ebbc0096..b78a89969 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + package="de.xikolo" + android:installLocation="auto"> From 58a3e30c9025a5585086e0e915b0b7867310b814 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Fri, 7 Oct 2016 15:25:13 +0200 Subject: [PATCH 03/15] Remove second screen promotion dialog. --- .../de/xikolo/controller/MainActivity.java | 13 ------ .../dialogs/SecondScreenDialog.java | 44 ------------------- 2 files changed, 57 deletions(-) delete mode 100644 app/src/main/java/de/xikolo/controller/dialogs/SecondScreenDialog.java diff --git a/app/src/main/java/de/xikolo/controller/MainActivity.java b/app/src/main/java/de/xikolo/controller/MainActivity.java index aa78056d2..d2aa0b981 100644 --- a/app/src/main/java/de/xikolo/controller/MainActivity.java +++ b/app/src/main/java/de/xikolo/controller/MainActivity.java @@ -14,20 +14,17 @@ import de.xikolo.BuildConfig; import de.xikolo.R; -import de.xikolo.controller.dialogs.SecondScreenDialog; import de.xikolo.controller.main.ContentFragment; import de.xikolo.controller.main.ContentWebViewFragment; import de.xikolo.controller.main.CourseListFragment; import de.xikolo.controller.main.ProfileFragment; import de.xikolo.controller.navigation.NavigationFragment; import de.xikolo.controller.navigation.adapter.NavigationAdapter; -import de.xikolo.data.preferences.AppPreferences; import de.xikolo.model.UserModel; import de.xikolo.model.events.LoginEvent; import de.xikolo.model.events.LogoutEvent; import de.xikolo.util.Config; import de.xikolo.util.DeepLinkingUtil; -import de.xikolo.util.FeatureToggle; import de.xikolo.util.LanalyticsUtil; public class MainActivity extends BaseActivity @@ -66,16 +63,6 @@ protected void onCreate(Bundle savedInstanceState) { } handleIntent(getIntent()); - - if (FeatureToggle.secondScreen()) { - // show second screen promotion dialog - AppPreferences appPreferences = globalApplication.getPreferencesFactory().getAppPreferences(); - if (!appPreferences.showedSecondScreenDialog() && UserModel.isLoggedIn(this)) { - SecondScreenDialog dialog = new SecondScreenDialog(); - dialog.show(getSupportFragmentManager(), SecondScreenDialog.TAG); - appPreferences.setShowedSecondScreenDialog(true); - } - } } @Override diff --git a/app/src/main/java/de/xikolo/controller/dialogs/SecondScreenDialog.java b/app/src/main/java/de/xikolo/controller/dialogs/SecondScreenDialog.java deleted file mode 100644 index 97854019b..000000000 --- a/app/src/main/java/de/xikolo/controller/dialogs/SecondScreenDialog.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.xikolo.controller.dialogs; - -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.AlertDialog; - -import de.xikolo.R; -import de.xikolo.controller.SecondScreenActivity; - -public class SecondScreenDialog extends DialogFragment { - - public static final String TAG = SecondScreenDialog.class.getSimpleName(); - - @Override - @NonNull - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_Dialog); - builder.setTitle(R.string.dialog_second_screen_title) - .setMessage(R.string.dialog_second_screen_message) - .setPositiveButton(R.string.dialog_second_screen_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(getActivity(), SecondScreenActivity.class)); - } - }) - .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - SecondScreenDialog.this.getDialog().cancel(); - } - }) - .setCancelable(true); - - AlertDialog dialog = builder.create(); - dialog.setCanceledOnTouchOutside(true); - - return dialog; - } - -} From 984318d2f8d166a2a582ae33ffe82d6d50f62b09 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Fri, 7 Oct 2016 16:10:44 +0200 Subject: [PATCH 04/15] Refactor network stack to okhttp. --- .../java/de/xikolo/data/net/ApiRequest.java | 32 +++++ .../java/de/xikolo/data/net/HttpRequest.java | 119 ------------------ .../java/de/xikolo/data/net/JsonRequest.java | 48 ------- .../de/xikolo/data/net/NetworkRequest.java | 79 ++++++++++++ .../java/de/xikolo/data/parser/ApiParser.java | 43 +++++++ .../de/xikolo/data/parser/GsonHelper.java | 14 --- .../de/xikolo/managers/WebSocketManager.java | 4 +- .../model/jobs/CreateAccessTokenJob.java | 29 +++-- .../model/jobs/CreateEnrollmentJob.java | 24 ++-- .../model/jobs/DeleteEnrollmentJob.java | 15 +-- .../model/jobs/RetrieveContentLengthJob.java | 23 ++-- .../xikolo/model/jobs/RetrieveCourseJob.java | 25 ++-- .../xikolo/model/jobs/RetrieveCoursesJob.java | 21 ++-- .../model/jobs/RetrieveItemDetailJob.java | 18 ++- .../xikolo/model/jobs/RetrieveItemsJob.java | 20 ++- .../jobs/RetrieveModuleWithItemsJob.java | 35 ++---- .../xikolo/model/jobs/RetrieveModulesJob.java | 19 ++- .../jobs/RetrieveModulesWithItemsJob.java | 37 +++--- .../de/xikolo/model/jobs/RetrieveUserJob.java | 20 ++- .../model/jobs/RetrieveVideoSubtitlesJob.java | 20 ++- .../model/jobs/UpdateProgressionJob.java | 12 +- 21 files changed, 299 insertions(+), 358 deletions(-) create mode 100644 app/src/main/java/de/xikolo/data/net/ApiRequest.java delete mode 100644 app/src/main/java/de/xikolo/data/net/HttpRequest.java delete mode 100644 app/src/main/java/de/xikolo/data/net/JsonRequest.java create mode 100644 app/src/main/java/de/xikolo/data/net/NetworkRequest.java create mode 100644 app/src/main/java/de/xikolo/data/parser/ApiParser.java delete mode 100644 app/src/main/java/de/xikolo/data/parser/GsonHelper.java diff --git a/app/src/main/java/de/xikolo/data/net/ApiRequest.java b/app/src/main/java/de/xikolo/data/net/ApiRequest.java new file mode 100644 index 000000000..d3b48241c --- /dev/null +++ b/app/src/main/java/de/xikolo/data/net/ApiRequest.java @@ -0,0 +1,32 @@ +package de.xikolo.data.net; + +import android.content.Context; + +import de.xikolo.GlobalApplication; +import de.xikolo.model.UserModel; +import de.xikolo.util.Config; + +public class ApiRequest extends NetworkRequest { + + public ApiRequest(String url) { + super(url); + addDefaultHeader(); + authorize(); + } + + private void addDefaultHeader() { + builder.addHeader(Config.HEADER_ACCEPT, Config.HEADER_ACCEPT_VALUE) + .addHeader(Config.HEADER_USER_PLATFORM, Config.HEADER_USER_PLATFORM_VALUE); + } + + private boolean authorize() { + Context context = GlobalApplication.getInstance(); + if (UserModel.isLoggedIn(context)) { + builder.addHeader(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserModel.getToken(context)); + return true; + } else { + return false; + } + } + +} diff --git a/app/src/main/java/de/xikolo/data/net/HttpRequest.java b/app/src/main/java/de/xikolo/data/net/HttpRequest.java deleted file mode 100644 index 67a0da730..000000000 --- a/app/src/main/java/de/xikolo/data/net/HttpRequest.java +++ /dev/null @@ -1,119 +0,0 @@ -package de.xikolo.data.net; - -import android.util.Log; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; - -import javax.net.ssl.HttpsURLConnection; - -import de.xikolo.util.Config; - -public class HttpRequest { - - public static final String TAG = HttpRequest.class.getSimpleName(); - - protected String mUrl; - protected String mToken; - protected String mMethod; - protected boolean mCache; - - protected HttpsURLConnection urlConnection; - - public HttpRequest(String url) { - super(); - this.mUrl = url; - this.mToken = null; - this.mMethod = Config.HTTP_GET; - this.mCache = true; - } - - public void setToken(String token) { - this.mToken = token; - } - - public void setMethod(String method) { - this.mMethod = method; - } - - public void setCache(boolean cache) { - this.mCache = cache; - } - - protected void closeConnection() { - if (urlConnection != null) - urlConnection.disconnect(); - } - - public HttpsURLConnection createConnection() { - try { - URL url = new URL(mUrl); - urlConnection = (HttpsURLConnection) url.openConnection(); - urlConnection.setRequestMethod(mMethod); - urlConnection.addRequestProperty(Config.HEADER_ACCEPT, Config.HEADER_ACCEPT_VALUE); - urlConnection.addRequestProperty(Config.HEADER_USER_PLATFORM, Config.HEADER_USER_PLATFORM_VALUE); - - if (!mCache) { - urlConnection.addRequestProperty(Config.HEADER_CACHE_CONTROL, Config.HEADER_CACHE_CONTROL_VALUE); - } - if (mToken != null) { - urlConnection.addRequestProperty(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + mToken); - } - - final int statusCode = urlConnection.getResponseCode(); - - if (statusCode != HttpURLConnection.HTTP_OK) { - if (Config.DEBUG) Log.w(TAG, "Error " + statusCode + " for URL " + mUrl); - return null; - } - - return urlConnection; - } catch (IOException e) { - if (Config.DEBUG) Log.w(TAG, "Error for URL " + mUrl, e); - } - return null; - } - - public long getContentLength() { - try { - setMethod(Config.HTTP_HEAD); - URLConnection conn = createConnection(); - conn.connect(); - long length = conn.getContentLength(); - if (length < 0) { - return 0; - } else { - return length; - } - } catch (Exception e) { - if (Config.DEBUG) Log.w(TAG, "Error for URL " + mUrl, e); - } - return 0; - } - - public Object getResponse() { - try { - InputStreamReader in = new InputStreamReader(new BufferedInputStream(createConnection().getInputStream())); - BufferedReader buff = new BufferedReader(in); - StringBuffer input = new StringBuffer(); - String line; - try { - while ((line = buff.readLine()) != null) - input.append(line); - } catch (IOException e) { - if (Config.DEBUG) Log.e(TAG, "Error reading input stream for ", e); - } - closeConnection(); - return input; - } catch (Exception e) { - if (Config.DEBUG) Log.w(TAG, "Error for URL " + mUrl, e); - } - return null; - } - -} diff --git a/app/src/main/java/de/xikolo/data/net/JsonRequest.java b/app/src/main/java/de/xikolo/data/net/JsonRequest.java deleted file mode 100644 index 70176b96f..000000000 --- a/app/src/main/java/de/xikolo/data/net/JsonRequest.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.xikolo.data.net; - -import android.util.Log; - -import com.google.gson.Gson; - -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.Type; - -import javax.net.ssl.HttpsURLConnection; - -import de.xikolo.data.parser.GsonHelper; -import de.xikolo.util.Config; - -public class JsonRequest extends HttpRequest { - - public static final String TAG = JsonRequest.class.getSimpleName(); - - private Type mType; - - public JsonRequest(String url, Type type) { - super(url); - this.mType = type; - } - - @Override - public Object getResponse() { - try { - HttpsURLConnection conn = createConnection(); - InputStream in = new BufferedInputStream(conn.getInputStream()); - - Gson gson = GsonHelper.create(); - Reader reader = new InputStreamReader(in); - - Object o = gson.fromJson(reader, mType); - closeConnection(); - - return o; - } catch (Exception e) { - if (Config.DEBUG) Log.w(TAG, "Error for URL " + mUrl, e); - } - return null; - } - -} diff --git a/app/src/main/java/de/xikolo/data/net/NetworkRequest.java b/app/src/main/java/de/xikolo/data/net/NetworkRequest.java new file mode 100644 index 000000000..fe086680f --- /dev/null +++ b/app/src/main/java/de/xikolo/data/net/NetworkRequest.java @@ -0,0 +1,79 @@ +package de.xikolo.data.net; + +import java.io.IOException; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class NetworkRequest { + + protected Request.Builder builder; + + protected static OkHttpClient httpClient; + + private Response response; + + protected static OkHttpClient getDefaultHttpClient() { + synchronized (NetworkRequest.class) { + if (httpClient == null) { + httpClient = new OkHttpClient(); + } + } + return httpClient; + } + + public NetworkRequest(String url) { + builder = new Request.Builder() + .url(url); + } + + public NetworkRequest get() { + builder.get(); + return this; + } + + public NetworkRequest post() { + return post(null); + } + + public NetworkRequest post(RequestBody body) { + builder.post(body); + return this; + } + + public NetworkRequest put() { + return put(null); + } + + public NetworkRequest put(RequestBody body) { + builder.put(body); + return this; + } + + public NetworkRequest delete() { + builder.delete(); + return this; + } + + public NetworkRequest head() { + builder.head(); + return this; + } + + private Request build() { + return builder.build(); + } + + public Response execute() throws IOException { + return response = getDefaultHttpClient().newCall(build()).execute(); + } + + public void close() { + if (response != null) { + response.close(); + } + } + +} diff --git a/app/src/main/java/de/xikolo/data/parser/ApiParser.java b/app/src/main/java/de/xikolo/data/parser/ApiParser.java new file mode 100644 index 000000000..0717a6424 --- /dev/null +++ b/app/src/main/java/de/xikolo/data/parser/ApiParser.java @@ -0,0 +1,43 @@ +package de.xikolo.data.parser; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.Reader; +import java.lang.reflect.Type; + +import okhttp3.Response; + +public class ApiParser { + + public static Gson create() { + return new GsonBuilder() + .registerTypeAdapterFactory(AutoValueTypeAdapterFactory.create()) + .create(); + } + + public static T parse(Reader reader, Type type) { + return create().fromJson(reader, type); + } + + public static T parse(Reader reader, Class clazz) { + return create().fromJson(reader, clazz); + } + + public static T parse(Response response, Type type) { + return create().fromJson(response.body().charStream(), type); + } + + public static T parse(Response response, Class clazz) { + return create().fromJson(response.body().charStream(), clazz); + } + + public static T parse(String json, Type type) { + return create().fromJson(json, type); + } + + public static T parse(String json, Class clazz) { + return create().fromJson(json, clazz); + } + +} diff --git a/app/src/main/java/de/xikolo/data/parser/GsonHelper.java b/app/src/main/java/de/xikolo/data/parser/GsonHelper.java deleted file mode 100644 index 0fde0810b..000000000 --- a/app/src/main/java/de/xikolo/data/parser/GsonHelper.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.xikolo.data.parser; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public class GsonHelper { - - public static Gson create() { - return new GsonBuilder() - .registerTypeAdapterFactory(AutoValueTypeAdapterFactory.create()) - .create(); - } - -} diff --git a/app/src/main/java/de/xikolo/managers/WebSocketManager.java b/app/src/main/java/de/xikolo/managers/WebSocketManager.java index c1ba30503..72d894200 100644 --- a/app/src/main/java/de/xikolo/managers/WebSocketManager.java +++ b/app/src/main/java/de/xikolo/managers/WebSocketManager.java @@ -24,7 +24,7 @@ import de.xikolo.GlobalApplication; import de.xikolo.data.entities.WebSocketMessage; -import de.xikolo.data.parser.GsonHelper; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.UserModel; import de.xikolo.model.events.Event; import de.xikolo.model.events.LoginEvent; @@ -163,7 +163,7 @@ static class WebSocketMessageEvent extends Event { WebSocketMessageEvent(String message) { super(); - this.webSocketMessage = GsonHelper.create().fromJson(message, WebSocketMessage.class); + this.webSocketMessage = ApiParser.parse(message, WebSocketMessage.class); } public WebSocketMessageEvent(WebSocketMessage message) { diff --git a/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java b/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java index 2f73628a4..dc51d4a85 100644 --- a/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java @@ -2,25 +2,26 @@ import android.util.Log; -import com.google.gson.reflect.TypeToken; import com.path.android.jobqueue.Job; import com.path.android.jobqueue.Params; import com.path.android.jobqueue.RetryConstraint; import org.greenrobot.eventbus.EventBus; -import java.lang.reflect.Type; -import java.net.URLEncoder; import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; import de.xikolo.data.entities.AccessToken; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.data.preferences.UserPreferences; import de.xikolo.model.Result; import de.xikolo.model.events.LoginEvent; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.FormBody; +import okhttp3.RequestBody; +import okhttp3.Response; public class CreateAccessTokenJob extends Job { @@ -55,17 +56,21 @@ public void onRun() throws Throwable { if (!NetworkUtil.isOnline(GlobalApplication.getInstance())) { result.error(Result.ErrorCode.NO_NETWORK); } else { - Type type = new TypeToken(){}.getType(); + String url = Config.API + Config.AUTHENTICATE; - String url = Config.API + Config.AUTHENTICATE + "?email=" + email + "&password=" + URLEncoder.encode(password, "UTF-8"); + RequestBody body = new FormBody.Builder() + .add("email", email) + .add("password", password) + .build(); - JsonRequest request = new JsonRequest(url, type); - request.setMethod(Config.HTTP_POST); - request.setCache(false); + Response response = new ApiRequest(url) + .post(body) + .execute(); + + if (response.isSuccessful()) { + AccessToken token = ApiParser.parse(response, AccessToken.class); + response.close(); - Object o = request.getResponse(); - if (o != null) { - AccessToken token = (AccessToken) o; if (Config.DEBUG) Log.i(TAG, "AccessToken created"); UserPreferences userPreferences = GlobalApplication.getInstance() diff --git a/app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java b/app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java index cce3190a3..4adbb9754 100644 --- a/app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java @@ -11,11 +11,14 @@ import de.xikolo.GlobalApplication; import de.xikolo.data.database.CourseDataAccess; import de.xikolo.data.entities.Course; -import de.xikolo.data.net.HttpRequest; +import de.xikolo.data.net.ApiRequest; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.FormBody; +import okhttp3.RequestBody; +import okhttp3.Response; public class CreateEnrollmentJob extends Job { @@ -48,16 +51,21 @@ public void onRun() throws Throwable { } else if (!NetworkUtil.isOnline(GlobalApplication.getInstance())) { result.error(Result.ErrorCode.NO_NETWORK); } else { - String url = Config.API + Config.USER + Config.ENROLLMENTS + "?course_id=" + course.id; + String url = Config.API + Config.USER + Config.ENROLLMENTS; - HttpRequest request = new HttpRequest(url); - request.setMethod(Config.HTTP_POST); - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); - request.setCache(false); + RequestBody body = new FormBody.Builder() + .add("course_id", course.id) + .build(); + + Response response = new ApiRequest(url) + .post(body) + .execute(); + + if (response.isSuccessful()) { + response.close(); - Object o = request.getResponse(); - if (o != null) { if (Config.DEBUG) Log.i(TAG, "Enrollment created"); + course.is_enrolled = true; CourseDataAccess courseDataAccess = GlobalApplication.getInstance() .getDataAccessFactory().getCourseDataAccess(); diff --git a/app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java b/app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java index 9b422338e..4186db62e 100644 --- a/app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java @@ -13,11 +13,12 @@ import de.xikolo.data.database.ModuleDataAccess; import de.xikolo.data.entities.Course; import de.xikolo.data.entities.Module; -import de.xikolo.data.net.HttpRequest; +import de.xikolo.data.net.ApiRequest; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class DeleteEnrollmentJob extends Job { @@ -52,13 +53,13 @@ public void onRun() throws Throwable { } else { String url = Config.API + Config.USER + Config.ENROLLMENTS + course.id; - HttpRequest request = new HttpRequest(url); - request.setMethod(Config.HTTP_DELETE); - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); - request.setCache(false); + Response response = new ApiRequest(url) + .delete() + .execute(); + + if (response.isSuccessful()) { + response.close(); - Object o = request.getResponse(); - if (o != null) { if (Config.DEBUG) Log.i(TAG, "Enrollment deleted"); course.is_enrolled = false; diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java index 5aec57bdd..ac03636d2 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java @@ -9,10 +9,11 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.net.HttpRequest; +import de.xikolo.data.net.ApiRequest; import de.xikolo.model.Result; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveContentLengthJob extends Job { @@ -40,14 +41,20 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!NetworkUtil.isOnline(GlobalApplication.getInstance())) { - result.error(Result.ErrorCode.NO_NETWORK); + if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { + Response response = new ApiRequest(url) + .head() + .execute(); + if (response.isSuccessful()) { + Long length = Long.parseLong(response.header("Content-Length", "0")); + response.close(); + + result.success(length, Result.DataSource.NETWORK); + } else { + result.error(Result.ErrorCode.NO_RESULT); + } } else { - HttpRequest request = new HttpRequest(url); - request.setCache(false); - - Long length = request.getContentLength(); - result.success(length, Result.DataSource.NETWORK); + result.error(Result.ErrorCode.NO_NETWORK); } } diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java index eedad6bc8..991d1b112 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java @@ -2,22 +2,21 @@ import android.util.Log; -import com.google.gson.reflect.TypeToken; import com.path.android.jobqueue.Job; import com.path.android.jobqueue.Params; import com.path.android.jobqueue.RetryConstraint; -import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; import de.xikolo.data.database.CourseDataAccess; import de.xikolo.data.entities.Course; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; -import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveCourseJob extends Job { @@ -52,22 +51,12 @@ public void onRun() throws Throwable { result.success(courseDataAccess.getCourse(courseId), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken(){}.getType(); - String url = Config.API + Config.COURSES + courseId; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - if (UserModel.isLoggedIn(GlobalApplication.getInstance())) { - String token = UserModel.getToken(GlobalApplication.getInstance()); - request.setToken(token); - } - - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - Course course = (Course) o; + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Course course = ApiParser.parse(response, Course.class); + response.close(); if (Config.DEBUG) Log.i(TAG, "Course received (" + course.id + ")"); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java index 160045a94..cdbe4aa87 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java @@ -14,11 +14,13 @@ import de.xikolo.GlobalApplication; import de.xikolo.data.database.CourseDataAccess; import de.xikolo.data.entities.Course; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveCoursesJob extends Job { @@ -55,20 +57,13 @@ public void onRun() throws Throwable { result.success(courseDataAccess.getAllCourses(), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken>(){}.getType(); - String url = Config.API + Config.COURSES + "?include_progress=" + includeProgress; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - String token = UserModel.getToken(GlobalApplication.getInstance()); - request.setToken(token); - - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - List courses = (List) o; + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Type type = new TypeToken>(){}.getType(); + List courses = ApiParser.parse(response, type); + response.close(); if (Config.DEBUG) Log.i(TAG, "Courses received (" + courses.size() + ")"); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java index c15d24528..c91a8db24 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java @@ -15,11 +15,13 @@ import de.xikolo.data.database.VideoDataAccess; import de.xikolo.data.entities.Item; import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveItemDetailJob extends Job { @@ -80,19 +82,15 @@ public void onRun() throws Throwable { } if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = Item.getTypeToken(itemType); - String url = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + moduleId + "/" + Config.ITEMS + itemId; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Type type = Item.getTypeToken(itemType); + Item item = ApiParser.parse(response, type); + response.close(); - Object o = request.getResponse(); - if (o != null) { - Item item = (Item) o; if (Config.DEBUG) Log.i(TAG, "ItemDetail received"); if (itemType.equals(Item.TYPE_VIDEO)) { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java index acb03377d..86956d179 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java @@ -14,11 +14,13 @@ import de.xikolo.GlobalApplication; import de.xikolo.data.database.ItemDataAccess; import de.xikolo.data.entities.Item; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveItemsJob extends Job { @@ -56,21 +58,15 @@ public void onRun() throws Throwable { result.success(itemDataAccess.getAllItemsForModule(moduleId), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken>() { - }.getType(); - String url = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + moduleId + "/" + Config.ITEMS; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Type type = new TypeToken>() {}.getType(); + List items = ApiParser.parse(response, type); + response.close(); - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - List items = (List) o; if (Config.DEBUG) Log.i(TAG, "Items received (" + items.size() + ")"); for (Item item : items) { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java index 051329b2e..fd5e15953 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java @@ -17,11 +17,13 @@ import de.xikolo.data.database.ModuleDataAccess; import de.xikolo.data.entities.Item; import de.xikolo.data.entities.Module; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveModuleWithItemsJob extends Job { @@ -68,38 +70,27 @@ public void onRun() throws Throwable { } if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken(){}.getType(); - String url = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + "/" + moduleId; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Module module = ApiParser.parse(response, Module.class); + response.close(); - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - Module module = (Module) o; if (Config.DEBUG) Log.i(TAG, "Module received (" + module.id + ")"); moduleDataAccess.addOrUpdateModule(courseId, module, false); - Type typeItemList = new TypeToken>() {}.getType(); - - String urlItemList = Config.API + Config.COURSES + courseId + "/" + String itemListUrl = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + moduleId + "/" + Config.ITEMS; - JsonRequest requestItemList = new JsonRequest(urlItemList, typeItemList); - requestItemList.setCache(false); - - requestItemList.setToken(UserModel.getToken(GlobalApplication.getInstance())); + response = new ApiRequest(itemListUrl).execute(); + if (response.isSuccessful()) { + Type type = new TypeToken>() {}.getType(); + List items = ApiParser.parse(response, type); + response.close(); - Object oItemList = requestItemList.getResponse(); - if (oItemList != null) { - @SuppressWarnings("unchecked") - List items = (List) oItemList; if (Config.DEBUG) Log.i(TAG, "Items received (" + items.size() + ")"); for (Item item : items) { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java index 918352e3e..6cf067149 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java @@ -16,11 +16,13 @@ import de.xikolo.data.database.ModuleDataAccess; import de.xikolo.data.entities.Course; import de.xikolo.data.entities.Module; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveModulesJob extends Job { @@ -68,20 +70,15 @@ public void onRun() throws Throwable { result.success(localModules, Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken>(){}.getType(); - String url = Config.API + Config.COURSES + course.id + "/" + Config.MODULES + "?include_progress=" + includeProgress; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Type type = new TypeToken>(){}.getType(); + List modules = ApiParser.parse(response, type); + response.close(); - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - List modules = (List) o; if (Config.DEBUG) Log.i(TAG, "Modules received (" + modules.size() + ")"); for (Module module : modules) { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java index 00d6059d6..7036ae795 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java @@ -19,11 +19,13 @@ import de.xikolo.data.entities.Course; import de.xikolo.data.entities.Item; import de.xikolo.data.entities.Module; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveModulesWithItemsJob extends Job { @@ -73,20 +75,15 @@ public void onRun() throws Throwable { result.success(localModules, Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken>(){}.getType(); - String url = Config.API + Config.COURSES + course.id + "/" + Config.MODULES + "?include_progress=" + includeProgress; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Type type = new TypeToken>(){}.getType(); + List modules = ApiParser.parse(response, type); + response.close(); - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - List modules = (List) o; if (Config.DEBUG) Log.i(TAG, "Modules received (" + modules.size() + ")"); for (Module module : modules) { @@ -94,21 +91,15 @@ public void onRun() throws Throwable { } for (Module module : modules) { - Type typeItemList = new TypeToken>() { - }.getType(); - - String urlItemList = Config.API + Config.COURSES + course.id + "/" + String itemListUrl = Config.API + Config.COURSES + course.id + "/" + Config.MODULES + module.id + "/" + Config.ITEMS; - JsonRequest requestItemList = new JsonRequest(urlItemList, typeItemList); - requestItemList.setCache(false); - - requestItemList.setToken(UserModel.getToken(GlobalApplication.getInstance())); + response = new ApiRequest(itemListUrl).execute(); + if (response.isSuccessful()) { + Type itemListType = new TypeToken>() {}.getType(); + List items = ApiParser.parse(response, itemListType); + response.close(); - Object oItemList = requestItemList.getResponse(); - if (oItemList != null) { - @SuppressWarnings("unchecked") - List items = (List) oItemList; if (Config.DEBUG) Log.i(TAG, "Items received (" + items.size() + ")"); for (Item item : items) { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java index f153684f9..87270e73b 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java @@ -2,22 +2,22 @@ import android.util.Log; -import com.google.gson.reflect.TypeToken; import com.path.android.jobqueue.Job; import com.path.android.jobqueue.Params; import com.path.android.jobqueue.RetryConstraint; -import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; import de.xikolo.data.entities.User; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.data.preferences.UserPreferences; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveUserJob extends Job { @@ -52,19 +52,15 @@ public void onRun() throws Throwable { result.success(userPreferences.getUser(), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - Type type = new TypeToken(){}.getType(); - String url = Config.API + Config.USER; - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + User user = ApiParser.parse(response, User.class); + response.close(); - Object o = request.getResponse(); - if (o != null) { - User user = (User) o; if (Config.DEBUG) Log.i(TAG, "User received: " + user.first_name); + userPreferences.saveUser(user); result.success(user, Result.DataSource.NETWORK); } else { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java b/app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java index c538455f4..1cd1e4082 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java @@ -14,11 +14,13 @@ import de.xikolo.GlobalApplication; import de.xikolo.controller.exceptions.WrongParameterException; import de.xikolo.data.entities.Subtitle; -import de.xikolo.data.net.JsonRequest; +import de.xikolo.data.net.ApiRequest; +import de.xikolo.data.parser.ApiParser; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; import de.xikolo.util.NetworkUtil; +import okhttp3.Response; public class RetrieveVideoSubtitlesJob extends Job { @@ -61,21 +63,15 @@ public void onRun() throws Throwable { result.error(Result.ErrorCode.NO_AUTH); } else { if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - String url = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + moduleId + "/" + Config.ITEMS + videoId + "/" + Config.SUBTITLES; - Type type = new TypeToken>(){}.getType(); - - JsonRequest request = new JsonRequest(url, type); - request.setCache(false); - - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + Type type = new TypeToken>(){}.getType(); + List subtitleList = ApiParser.parse(response, type); + response.close(); - Object o = request.getResponse(); - if (o != null) { - @SuppressWarnings("unchecked") - List subtitleList = (List) o; if (Config.DEBUG) Log.i(TAG, "Subtitles received"); result.success(subtitleList, Result.DataSource.NETWORK); diff --git a/app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java b/app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java index c7193e0d5..6dbe4e8b2 100644 --- a/app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java +++ b/app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java @@ -12,10 +12,11 @@ import de.xikolo.data.database.ItemDataAccess; import de.xikolo.data.entities.Item; import de.xikolo.data.entities.Module; -import de.xikolo.data.net.HttpRequest; +import de.xikolo.data.net.ApiRequest; import de.xikolo.model.Result; import de.xikolo.model.UserModel; import de.xikolo.util.Config; +import okhttp3.Response; public class UpdateProgressionJob extends Job { @@ -58,13 +59,10 @@ public void onRun() throws Throwable { } else { String url = Config.API + Config.USER + Config.PROGRESSIONS + item.id; - HttpRequest request = new HttpRequest(url); - request.setMethod(Config.HTTP_PUT); - request.setToken(UserModel.getToken(GlobalApplication.getInstance())); - request.setCache(false); + Response response = new ApiRequest(url).execute(); + if (response.isSuccessful()) { + response.close(); - Object o = request.getResponse(); - if (o != null) { if (Config.DEBUG) Log.i(TAG, "Progression updated"); if (result != null) { result.success(null, Result.DataSource.NETWORK); From 9ce0c2237c1f1a12fb013730f68de35c40a64fb6 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Thu, 13 Oct 2016 17:23:46 +0200 Subject: [PATCH 05/15] Refactor data storage layer. --- app/build.gradle | 16 +- app/proguard-rules.pro | 2 +- app/src/main/AndroidManifest.xml | 86 ++++----- .../java/de/xikolo/GlobalApplication.java | 90 ++++----- .../BaseActivity.java | 33 ++-- .../BaseFragment.java | 2 +- .../CourseActivity.java | 34 ++-- .../CourseDetailsActivity.java | 10 +- .../DownloadsActivity.java | 4 +- .../LoginActivity.java | 30 +-- .../MainActivity.java | 38 ++-- .../ModuleActivity.java | 36 ++-- .../SecondScreenActivity.java | 4 +- .../SettingsActivity.java | 4 +- .../VideoActivity.java | 32 ++-- .../WebViewFragment.java | 4 +- .../course/CourseLearningsFragment.java | 36 ++-- .../course/ProgressFragment.java | 30 +-- .../course/adapter/ItemListAdapter.java | 12 +- .../course/adapter/ModuleListAdapter.java | 18 +- .../course/adapter/ProgressListAdapter.java | 4 +- .../dialogs/ChooseLanguageDialog.java | 6 +- .../dialogs/ConfirmDeleteDialog.java | 4 +- .../dialogs/ContributorsDialog.java | 2 +- .../dialogs/DownloadSlidesDialog.java | 2 +- .../dialogs/LicensesDialog.java | 2 +- .../dialogs/MobileDownloadDialog.java | 2 +- .../dialogs/ModuleDownloadDialog.java | 2 +- .../dialogs/PermissionsDialog.java | 6 +- .../dialogs/ProgressDialog.java | 2 +- .../dialogs/UnenrollDialog.java | 2 +- .../downloads/DownloadsFragment.java | 47 ++--- .../downloads/adapter/DownloadsAdapter.java | 6 +- .../exceptions/WrongParameterException.java | 2 +- .../helper/CacheController.java | 10 +- .../helper/EnrollmentController.java | 20 +- .../helper/ImageController.java | 2 +- .../helper/ModuleDownloadController.java | 51 ++--- .../helper/NotificationController.java | 4 +- .../helper/RefeshLayoutController.java | 2 +- .../helper/VideoController.java | 53 +++--- .../helper/WebViewController.java | 20 +- .../main/ContentFragment.java | 4 +- .../main/ContentWebViewFragment.java | 4 +- .../main/CourseListFragment.java | 62 +++--- .../main/ProfileFragment.java | 46 ++--- .../main/adapter/CourseListAdapter.java | 34 ++-- .../module/ItemWebViewFragment.java | 12 +- .../module/PagerFragment.java | 12 +- .../module/VideoFragment.java | 52 ++--- .../module/helper/DownloadViewController.java | 67 +++---- .../navigation/NavigationFragment.java | 12 +- .../navigation/adapter/NavigationAdapter.java | 32 ++-- .../navigation/adapter/NavigationItem.java | 2 +- .../secondscreen/PinboardActivity.java | 14 +- .../secondscreen/QuizActivity.java | 14 +- .../secondscreen/SecondScreenFragment.java | 35 ++-- .../secondscreen/SlideViewerActivity.java | 12 +- .../secondscreen/SlideViewerFragment.java | 32 ++-- .../TranscriptViewerActivity.java | 14 +- .../TranscriptViewerFragment.java | 14 +- .../adapter/TranscriptViewerAdapter.java | 6 +- .../settings/SettingsFragment.java | 22 +-- .../data/database/CourseDataAccess.java | 177 ------------------ .../de/xikolo/data/database/DataAccess.java | 21 --- .../data/database/DataAccessFactory.java | 59 ------ .../xikolo/data/database/DatabaseHelper.java | 88 --------- .../xikolo/data/database/ItemDataAccess.java | 164 ---------------- .../data/database/ModuleDataAccess.java | 170 ----------------- .../database/OverallProgressDataAccess.java | 149 --------------- .../xikolo/data/database/VideoDataAccess.java | 155 --------------- .../data/preferences/AppPreferences.java | 95 ---------- .../xikolo/data/preferences/Preferences.java | 13 -- .../data/preferences/PreferencesFactory.java | 40 ---- .../data/preferences/UserPreferences.java | 72 ------- .../events/DownloadCompletedEvent.java | 4 +- .../events/DownloadDeletedEvent.java | 4 +- .../events/DownloadStartedEvent.java | 2 +- .../{model => }/events/EnrollEvent.java | 4 +- .../de/xikolo/{model => }/events/Event.java | 2 +- .../xikolo/{model => }/events/LoginEvent.java | 2 +- .../{model => }/events/LogoutEvent.java | 2 +- .../{model => }/events/NetworkStateEvent.java | 2 +- .../events/PermissionDeniedEvent.java | 2 +- .../events/PermissionGrantedEvent.java | 2 +- .../{model => }/events/UnenrollEvent.java | 4 +- .../java/de/xikolo/managers/BaseManager.java | 15 ++ .../CourseManager.java} | 34 ++-- .../DownloadManager.java} | 59 +++--- .../ItemManager.java} | 44 ++--- .../ModuleManager.java} | 28 +-- .../PermissionManager.java} | 10 +- .../de/xikolo/{model => managers}/Result.java | 4 +- .../xikolo/managers/SecondScreenManager.java | 36 ++-- .../java/de/xikolo/managers/UserManager.java | 59 ++++++ .../de/xikolo/managers/WebSocketManager.java | 23 ++- .../jobs/CreateAccessTokenJob.java | 24 +-- .../jobs/CreateEnrollmentJob.java | 24 +-- .../jobs/DeleteEnrollmentJob.java | 35 ++-- .../{model => managers}/jobs/Priority.java | 2 +- .../jobs/RetrieveContentLengthJob.java | 10 +- .../jobs/RetrieveCourseJob.java | 24 +-- .../jobs/RetrieveCourseListJob.java} | 34 ++-- .../jobs/RetrieveItemDetailJob.java | 51 ++--- .../jobs/RetrieveItemListJob.java} | 36 ++-- .../jobs/RetrieveLocalVideoJob.java | 26 +-- .../jobs/RetrieveModuleListJob.java} | 47 ++--- .../RetrieveModuleListWithItemListJob.java} | 61 +++--- .../jobs/RetrieveModuleWithItemListJob.java} | 48 ++--- .../jobs/RetrieveUserJob.java | 28 +-- .../jobs/RetrieveVideoSubtitlesJob.java | 20 +- .../jobs/UpdateLocalVideoJob.java | 20 +- .../jobs/UpdateProgressionJob.java | 27 ++- .../main/java/de/xikolo/model/BaseModel.java | 15 -- .../main/java/de/xikolo/model/UserModel.java | 60 ------ .../entities => models}/AccessToken.java | 2 +- .../AssignmentItemDetail.java | 2 +- .../{data/entities => models}/Course.java | 15 +- .../{data/entities => models}/Download.java | 2 +- .../{data/entities => models}/Enrollment.java | 2 +- .../{data/entities => models}/Item.java | 22 ++- .../{data/entities => models}/ItemDetail.java | 2 +- .../entities => models}/LtiItemDetail.java | 2 +- .../{data/entities => models}/Module.java | 19 +- .../PeerAssessmentItemDetail.java | 2 +- .../Progress.java} | 35 ++-- .../entities => models}/Progression.java | 2 +- .../{data/entities => models}/Subtitle.java | 2 +- .../entities => models}/TextItemDetail.java | 2 +- .../{data/entities => models}/User.java | 2 +- .../entities => models}/VideoItemDetail.java | 11 +- .../entities => models}/WebSocketMessage.java | 2 +- .../{data/net => network}/ApiRequest.java | 10 +- .../{data/net => network}/DownloadHelper.java | 11 +- .../{data/net => network}/NetworkRequest.java | 2 +- .../{data => network}/parser/ApiParser.java | 2 +- .../parser/AutoValueTypeAdapterFactory.java | 2 +- .../DownloadCompletedReceiver.java | 26 +-- .../NetworkChangeReceiver.java | 6 +- .../NotificationDeletedReceiver.java | 14 +- .../xikolo/storages/databases/DataType.java | 7 + .../storages/databases/DatabaseHelper.java | 121 ++++++++++++ .../storages/databases/DatabaseModel.java | 7 + .../databases/adapters/CourseDataAdapter.java | 124 ++++++++++++ .../databases/adapters/DataAdapter.java | 124 ++++++++++++ .../databases/adapters/ItemDataAdapter.java | 63 +++++++ .../databases/adapters/ModuleDataAdapter.java | 112 +++++++++++ .../adapters/ProgressDataAdapter.java | 57 ++++++ .../databases/adapters/VideoDataAdapter.java | 61 ++++++ .../databases/tables}/CourseTable.java | 8 +- .../databases/tables}/ItemTable.java | 11 +- .../databases/tables}/ModuleTable.java | 8 +- .../databases/tables/ProgressTable.java} | 8 +- .../databases/tables}/Table.java | 13 +- .../databases/tables}/VideoTable.java | 19 +- .../preferences/ApplicationPreferences.java | 74 ++++++++ .../storages/preferences/KeyValueStorage.java | 23 +++ .../preferences/NotificationStorage.java} | 30 ++- .../storages/preferences/StorageHelper.java | 28 +++ .../storages/preferences/StorageType.java | 7 + .../storages/preferences/UserStorage.java | 64 +++++++ .../{util => utils}/AndroidDimenUtil.java | 2 +- .../xikolo/{util => utils}/BuildFlavor.java | 2 +- .../de/xikolo/{util => utils}/BuildType.java | 2 +- .../de/xikolo/{util => utils}/CastUtil.java | 6 +- .../de/xikolo/{util => utils}/ClientUtil.java | 2 +- .../de/xikolo/{util => utils}/Config.java | 2 +- .../de/xikolo/{util => utils}/DateUtil.java | 2 +- .../{util => utils}/DeepLinkingUtil.java | 2 +- .../xikolo/{util => utils}/DisplayUtil.java | 2 +- .../{util => utils}/ExternalStorageUtil.java | 2 +- .../xikolo/{util => utils}/FeatureToggle.java | 2 +- .../de/xikolo/{util => utils}/FileUtil.java | 2 +- .../{util => utils}/GlideConfiguration.java | 2 +- .../HeaderAndSectionsList.java | 2 +- .../de/xikolo/{util => utils}/ItemTitle.java | 4 +- .../{util => utils}/LanalyticsUtil.java | 21 ++- .../xikolo/{util => utils}/LanguageUtil.java | 2 +- .../xikolo/{util => utils}/NetworkUtil.java | 2 +- .../{util => utils}/PlayServicesUtil.java | 2 +- .../xikolo/{util => utils}/PlaybackSpeed.java | 2 +- .../{util => utils}/SslCertificateUtil.java | 2 +- .../de/xikolo/{util => utils}/TimeUtil.java | 2 +- .../de/xikolo/{util => utils}/ToastUtil.java | 2 +- .../{view => views}/AutofitRecyclerView.java | 2 +- .../{view => views}/CustomFontTextView.java | 4 +- .../{view => views}/CustomSizeImageView.java | 2 +- .../{view => views}/CustomSizeVideoView.java | 2 +- .../DividerItemDecoration.java | 2 +- .../de/xikolo/{view => views}/IconButton.java | 2 +- .../{view => views}/MaxWidthFrameLayout.java | 2 +- .../{view => views}/NestedScrollWebView.java | 2 +- .../ScrimInsetsFrameLayout.java | 2 +- .../{view => views}/SpaceItemDecoration.java | 2 +- .../TranscriptFabBehavior.java | 3 +- .../res/layout-sw600dp-land/item_progress.xml | 6 +- .../layout-sw600dp/container_info_message.xml | 6 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/activity_video.xml | 4 +- .../main/res/layout/container_custom_tab.xml | 2 +- .../main/res/layout/container_download.xml | 4 +- .../res/layout/container_info_message.xml | 6 +- app/src/main/res/layout/container_video.xml | 10 +- .../main/res/layout/fragment_course_list.xml | 2 +- app/src/main/res/layout/fragment_profile.xml | 4 +- .../res/layout/fragment_second_screen.xml | 6 +- app/src/main/res/layout/fragment_video.xml | 4 +- app/src/main/res/layout/fragment_webview.xml | 2 +- app/src/main/res/layout/icon_button.xml | 2 +- app/src/main/res/layout/item_course_list.xml | 4 +- app/src/main/res/layout/item_download.xml | 2 +- app/src/main/res/layout/item_module.xml | 6 +- app/src/main/res/layout/item_module_item.xml | 2 +- app/src/main/res/layout/item_navi_main.xml | 2 +- app/src/main/res/layout/item_navi_profile.xml | 2 +- app/src/main/res/layout/item_navi_sub.xml | 2 +- app/src/main/res/layout/item_progress.xml | 6 +- .../main/res/layout/item_second_screen.xml | 2 +- app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- 220 files changed, 2227 insertions(+), 2539 deletions(-) rename app/src/main/java/de/xikolo/{controller => controllers}/BaseActivity.java (89%) rename app/src/main/java/de/xikolo/{controller => controllers}/BaseFragment.java (96%) rename app/src/main/java/de/xikolo/{controller => controllers}/CourseActivity.java (94%) rename app/src/main/java/de/xikolo/{controller => controllers}/CourseDetailsActivity.java (91%) rename app/src/main/java/de/xikolo/{controller => controllers}/DownloadsActivity.java (91%) rename app/src/main/java/de/xikolo/{controller => controllers}/LoginActivity.java (89%) rename app/src/main/java/de/xikolo/{controller => controllers}/MainActivity.java (88%) rename app/src/main/java/de/xikolo/{controller => controllers}/ModuleActivity.java (93%) rename app/src/main/java/de/xikolo/{controller => controllers}/SecondScreenActivity.java (91%) rename app/src/main/java/de/xikolo/{controller => controllers}/SettingsActivity.java (92%) rename app/src/main/java/de/xikolo/{controller => controllers}/VideoActivity.java (94%) rename app/src/main/java/de/xikolo/{controller => controllers}/WebViewFragment.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/course/CourseLearningsFragment.java (90%) rename app/src/main/java/de/xikolo/{controller => controllers}/course/ProgressFragment.java (90%) rename app/src/main/java/de/xikolo/{controller => controllers}/course/adapter/ItemListAdapter.java (94%) rename app/src/main/java/de/xikolo/{controller => controllers}/course/adapter/ModuleListAdapter.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/course/adapter/ProgressListAdapter.java (98%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/ChooseLanguageDialog.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/ConfirmDeleteDialog.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/ContributorsDialog.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/DownloadSlidesDialog.java (98%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/LicensesDialog.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/MobileDownloadDialog.java (98%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/ModuleDownloadDialog.java (99%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/PermissionsDialog.java (89%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/ProgressDialog.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/dialogs/UnenrollDialog.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/downloads/DownloadsFragment.java (76%) rename app/src/main/java/de/xikolo/{controller => controllers}/downloads/adapter/DownloadsAdapter.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/exceptions/WrongParameterException.java (85%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/CacheController.java (93%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/EnrollmentController.java (70%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/ImageController.java (99%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/ModuleDownloadController.java (73%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/NotificationController.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/RefeshLayoutController.java (91%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/VideoController.java (93%) rename app/src/main/java/de/xikolo/{controller => controllers}/helper/WebViewController.java (92%) rename app/src/main/java/de/xikolo/{controller => controllers}/main/ContentFragment.java (93%) rename app/src/main/java/de/xikolo/{controller => controllers}/main/ContentWebViewFragment.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/main/CourseListFragment.java (90%) rename app/src/main/java/de/xikolo/{controller => controllers}/main/ProfileFragment.java (84%) rename app/src/main/java/de/xikolo/{controller => controllers}/main/adapter/CourseListAdapter.java (91%) rename app/src/main/java/de/xikolo/{controller => controllers}/module/ItemWebViewFragment.java (93%) rename app/src/main/java/de/xikolo/{controller => controllers}/module/PagerFragment.java (83%) rename app/src/main/java/de/xikolo/{controller => controllers}/module/VideoFragment.java (87%) rename app/src/main/java/de/xikolo/{controller => controllers}/module/helper/DownloadViewController.java (85%) rename app/src/main/java/de/xikolo/{controller => controllers}/navigation/NavigationFragment.java (97%) rename app/src/main/java/de/xikolo/{controller => controllers}/navigation/adapter/NavigationAdapter.java (92%) rename app/src/main/java/de/xikolo/{controller => controllers}/navigation/adapter/NavigationItem.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/PinboardActivity.java (89%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/QuizActivity.java (89%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/SecondScreenFragment.java (94%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/SlideViewerActivity.java (89%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/SlideViewerFragment.java (87%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/TranscriptViewerActivity.java (88%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/TranscriptViewerFragment.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/secondscreen/adapter/TranscriptViewerAdapter.java (95%) rename app/src/main/java/de/xikolo/{controller => controllers}/settings/SettingsFragment.java (92%) delete mode 100644 app/src/main/java/de/xikolo/data/database/CourseDataAccess.java delete mode 100644 app/src/main/java/de/xikolo/data/database/DataAccess.java delete mode 100644 app/src/main/java/de/xikolo/data/database/DataAccessFactory.java delete mode 100644 app/src/main/java/de/xikolo/data/database/DatabaseHelper.java delete mode 100644 app/src/main/java/de/xikolo/data/database/ItemDataAccess.java delete mode 100644 app/src/main/java/de/xikolo/data/database/ModuleDataAccess.java delete mode 100644 app/src/main/java/de/xikolo/data/database/OverallProgressDataAccess.java delete mode 100644 app/src/main/java/de/xikolo/data/database/VideoDataAccess.java delete mode 100644 app/src/main/java/de/xikolo/data/preferences/AppPreferences.java delete mode 100644 app/src/main/java/de/xikolo/data/preferences/Preferences.java delete mode 100644 app/src/main/java/de/xikolo/data/preferences/PreferencesFactory.java delete mode 100644 app/src/main/java/de/xikolo/data/preferences/UserPreferences.java rename app/src/main/java/de/xikolo/{model => }/events/DownloadCompletedEvent.java (82%) rename app/src/main/java/de/xikolo/{model => }/events/DownloadDeletedEvent.java (81%) rename app/src/main/java/de/xikolo/{model => }/events/DownloadStartedEvent.java (90%) rename app/src/main/java/de/xikolo/{model => }/events/EnrollEvent.java (80%) rename app/src/main/java/de/xikolo/{model => }/events/Event.java (89%) rename app/src/main/java/de/xikolo/{model => }/events/LoginEvent.java (79%) rename app/src/main/java/de/xikolo/{model => }/events/LogoutEvent.java (80%) rename app/src/main/java/de/xikolo/{model => }/events/NetworkStateEvent.java (90%) rename app/src/main/java/de/xikolo/{model => }/events/PermissionDeniedEvent.java (90%) rename app/src/main/java/de/xikolo/{model => }/events/PermissionGrantedEvent.java (90%) rename app/src/main/java/de/xikolo/{model => }/events/UnenrollEvent.java (81%) create mode 100644 app/src/main/java/de/xikolo/managers/BaseManager.java rename app/src/main/java/de/xikolo/{model/CourseModel.java => managers/CourseManager.java} (77%) rename app/src/main/java/de/xikolo/{model/DownloadModel.java => managers/DownloadManager.java} (89%) rename app/src/main/java/de/xikolo/{model/ItemModel.java => managers/ItemManager.java} (54%) rename app/src/main/java/de/xikolo/{model/ModuleModel.java => managers/ModuleManager.java} (64%) rename app/src/main/java/de/xikolo/{model/PermissionsModel.java => managers/PermissionManager.java} (90%) rename app/src/main/java/de/xikolo/{model => managers}/Result.java (96%) create mode 100644 app/src/main/java/de/xikolo/managers/UserManager.java rename app/src/main/java/de/xikolo/{model => managers}/jobs/CreateAccessTokenJob.java (81%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/CreateEnrollmentJob.java (79%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/DeleteEnrollmentJob.java (69%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/Priority.java (79%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/RetrieveContentLengthJob.java (91%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/RetrieveCourseJob.java (76%) rename app/src/main/java/de/xikolo/{model/jobs/RetrieveCoursesJob.java => managers/jobs/RetrieveCourseListJob.java} (70%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/RetrieveItemDetailJob.java (70%) rename app/src/main/java/de/xikolo/{model/jobs/RetrieveItemsJob.java => managers/jobs/RetrieveItemListJob.java} (69%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/RetrieveLocalVideoJob.java (68%) rename app/src/main/java/de/xikolo/{model/jobs/RetrieveModulesJob.java => managers/jobs/RetrieveModuleListJob.java} (70%) rename app/src/main/java/de/xikolo/{model/jobs/RetrieveModulesWithItemsJob.java => managers/jobs/RetrieveModuleListWithItemListJob.java} (68%) rename app/src/main/java/de/xikolo/{model/jobs/RetrieveModuleWithItemsJob.java => managers/jobs/RetrieveModuleWithItemListJob.java} (69%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/RetrieveUserJob.java (74%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/RetrieveVideoSubtitlesJob.java (87%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/UpdateLocalVideoJob.java (73%) rename app/src/main/java/de/xikolo/{model => managers}/jobs/UpdateProgressionJob.java (75%) delete mode 100644 app/src/main/java/de/xikolo/model/BaseModel.java delete mode 100644 app/src/main/java/de/xikolo/model/UserModel.java rename app/src/main/java/de/xikolo/{data/entities => models}/AccessToken.java (80%) rename app/src/main/java/de/xikolo/{data/entities => models}/AssignmentItemDetail.java (98%) rename app/src/main/java/de/xikolo/{data/entities => models}/Course.java (91%) rename app/src/main/java/de/xikolo/{data/entities => models}/Download.java (98%) rename app/src/main/java/de/xikolo/{data/entities => models}/Enrollment.java (96%) rename app/src/main/java/de/xikolo/{data/entities => models}/Item.java (93%) rename app/src/main/java/de/xikolo/{data/entities => models}/ItemDetail.java (80%) rename app/src/main/java/de/xikolo/{data/entities => models}/LtiItemDetail.java (97%) rename app/src/main/java/de/xikolo/{data/entities => models}/Module.java (86%) rename app/src/main/java/de/xikolo/{data/entities => models}/PeerAssessmentItemDetail.java (94%) rename app/src/main/java/de/xikolo/{data/entities/OverallProgress.java => models/Progress.java} (80%) rename app/src/main/java/de/xikolo/{data/entities => models}/Progression.java (88%) rename app/src/main/java/de/xikolo/{data/entities => models}/Subtitle.java (98%) rename app/src/main/java/de/xikolo/{data/entities => models}/TextItemDetail.java (98%) rename app/src/main/java/de/xikolo/{data/entities => models}/User.java (91%) rename app/src/main/java/de/xikolo/{data/entities => models}/VideoItemDetail.java (94%) rename app/src/main/java/de/xikolo/{data/entities => models}/WebSocketMessage.java (96%) rename app/src/main/java/de/xikolo/{data/net => network}/ApiRequest.java (77%) rename app/src/main/java/de/xikolo/{data/net => network}/DownloadHelper.java (93%) rename app/src/main/java/de/xikolo/{data/net => network}/NetworkRequest.java (98%) rename app/src/main/java/de/xikolo/{data => network}/parser/ApiParser.java (96%) rename app/src/main/java/de/xikolo/{data => network}/parser/AutoValueTypeAdapterFactory.java (90%) rename app/src/main/java/de/xikolo/{model/receiver => receivers}/DownloadCompletedReceiver.java (86%) rename app/src/main/java/de/xikolo/{model/receiver => receivers}/NetworkChangeReceiver.java (78%) rename app/src/main/java/de/xikolo/{model/receiver => receivers}/NotificationDeletedReceiver.java (62%) create mode 100644 app/src/main/java/de/xikolo/storages/databases/DataType.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/DatabaseHelper.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/DatabaseModel.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/adapters/CourseDataAdapter.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/adapters/DataAdapter.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/adapters/ItemDataAdapter.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/adapters/ModuleDataAdapter.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/adapters/ProgressDataAdapter.java create mode 100644 app/src/main/java/de/xikolo/storages/databases/adapters/VideoDataAdapter.java rename app/src/main/java/de/xikolo/{data/database => storages/databases/tables}/CourseTable.java (90%) rename app/src/main/java/de/xikolo/{data/database => storages/databases/tables}/ItemTable.java (79%) rename app/src/main/java/de/xikolo/{data/database => storages/databases/tables}/ModuleTable.java (88%) rename app/src/main/java/de/xikolo/{data/database/OverallProgressTable.java => storages/databases/tables/ProgressTable.java} (92%) rename app/src/main/java/de/xikolo/{data/database => storages/databases/tables}/Table.java (77%) rename app/src/main/java/de/xikolo/{data/database => storages/databases/tables}/VideoTable.java (80%) create mode 100644 app/src/main/java/de/xikolo/storages/preferences/ApplicationPreferences.java create mode 100644 app/src/main/java/de/xikolo/storages/preferences/KeyValueStorage.java rename app/src/main/java/de/xikolo/{data/preferences/NotificationPreferences.java => storages/preferences/NotificationStorage.java} (53%) create mode 100644 app/src/main/java/de/xikolo/storages/preferences/StorageHelper.java create mode 100644 app/src/main/java/de/xikolo/storages/preferences/StorageType.java create mode 100644 app/src/main/java/de/xikolo/storages/preferences/UserStorage.java rename app/src/main/java/de/xikolo/{util => utils}/AndroidDimenUtil.java (97%) rename app/src/main/java/de/xikolo/{util => utils}/BuildFlavor.java (80%) rename app/src/main/java/de/xikolo/{util => utils}/BuildType.java (64%) rename app/src/main/java/de/xikolo/{util => utils}/CastUtil.java (90%) rename app/src/main/java/de/xikolo/{util => utils}/ClientUtil.java (98%) rename app/src/main/java/de/xikolo/{util => utils}/Config.java (99%) rename app/src/main/java/de/xikolo/{util => utils}/DateUtil.java (99%) rename app/src/main/java/de/xikolo/{util => utils}/DeepLinkingUtil.java (98%) rename app/src/main/java/de/xikolo/{util => utils}/DisplayUtil.java (97%) rename app/src/main/java/de/xikolo/{util => utils}/ExternalStorageUtil.java (96%) rename app/src/main/java/de/xikolo/{util => utils}/FeatureToggle.java (92%) rename app/src/main/java/de/xikolo/{util => utils}/FileUtil.java (98%) rename app/src/main/java/de/xikolo/{util => utils}/GlideConfiguration.java (97%) rename app/src/main/java/de/xikolo/{util => utils}/HeaderAndSectionsList.java (98%) rename app/src/main/java/de/xikolo/{util => utils}/ItemTitle.java (90%) rename app/src/main/java/de/xikolo/{util => utils}/LanalyticsUtil.java (96%) rename app/src/main/java/de/xikolo/{util => utils}/LanguageUtil.java (95%) rename app/src/main/java/de/xikolo/{util => utils}/NetworkUtil.java (98%) rename app/src/main/java/de/xikolo/{util => utils}/PlayServicesUtil.java (97%) rename app/src/main/java/de/xikolo/{util => utils}/PlaybackSpeed.java (97%) rename app/src/main/java/de/xikolo/{util => utils}/SslCertificateUtil.java (98%) rename app/src/main/java/de/xikolo/{util => utils}/TimeUtil.java (99%) rename app/src/main/java/de/xikolo/{util => utils}/ToastUtil.java (97%) rename app/src/main/java/de/xikolo/{view => views}/AutofitRecyclerView.java (99%) rename app/src/main/java/de/xikolo/{view => views}/CustomFontTextView.java (96%) rename app/src/main/java/de/xikolo/{view => views}/CustomSizeImageView.java (97%) rename app/src/main/java/de/xikolo/{view => views}/CustomSizeVideoView.java (97%) rename app/src/main/java/de/xikolo/{view => views}/DividerItemDecoration.java (99%) rename app/src/main/java/de/xikolo/{view => views}/IconButton.java (98%) rename app/src/main/java/de/xikolo/{view => views}/MaxWidthFrameLayout.java (97%) rename app/src/main/java/de/xikolo/{view => views}/NestedScrollWebView.java (99%) rename app/src/main/java/de/xikolo/{view => views}/ScrimInsetsFrameLayout.java (99%) rename app/src/main/java/de/xikolo/{view => views}/SpaceItemDecoration.java (98%) rename app/src/main/java/de/xikolo/{view => views}/TranscriptFabBehavior.java (96%) diff --git a/app/build.gradle b/app/build.gradle index b32a963c4..1a584e3d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,37 +20,37 @@ android { productFlavors { openHPI { applicationId "de.xikolo.openhpi" - buildConfigField "de.xikolo.util.BuildFlavor", "X_FLAVOR", "de.xikolo.util.BuildFlavor.OPEN_HPI" + buildConfigField "de.xikolo.utils.BuildFlavor", "X_FLAVOR", "de.xikolo.utils.BuildFlavor.OPEN_HPI" appName = "openHPI" appHost = "open.hpi.de" } openHPI_CN { applicationId "de.xikolo.openhpi.cn" - buildConfigField "de.xikolo.util.BuildFlavor", "X_FLAVOR", "de.xikolo.util.BuildFlavor.OPEN_HPI_CN" + buildConfigField "de.xikolo.utils.BuildFlavor", "X_FLAVOR", "de.xikolo.utils.BuildFlavor.OPEN_HPI_CN" appName = "openHPI CN" appHost = "openhpi.cn" } openSAP { applicationId "de.xikolo.opensap" - buildConfigField "de.xikolo.util.BuildFlavor", "X_FLAVOR", "de.xikolo.util.BuildFlavor.OPEN_SAP" + buildConfigField "de.xikolo.utils.BuildFlavor", "X_FLAVOR", "de.xikolo.utils.BuildFlavor.OPEN_SAP" appName = "openSAP" appHost = "open.sap.com" } moocHouse { applicationId "de.xikolo.moochouse" - buildConfigField "de.xikolo.util.BuildFlavor", "X_FLAVOR", "de.xikolo.util.BuildFlavor.MOOC_HOUSE" + buildConfigField "de.xikolo.utils.BuildFlavor", "X_FLAVOR", "de.xikolo.utils.BuildFlavor.MOOC_HOUSE" appName = "mooc.house" appHost = "mooc.house" } moocHouse_CN { applicationId "de.xikolo.moochouse.cn" - buildConfigField "de.xikolo.util.BuildFlavor", "X_FLAVOR", "de.xikolo.util.BuildFlavor.MOOC_HOUSE_CN" + buildConfigField "de.xikolo.utils.BuildFlavor", "X_FLAVOR", "de.xikolo.utils.BuildFlavor.MOOC_HOUSE_CN" appName = "cnmooc.house" appHost = "cnmooc.house" } openUNE { applicationId "de.xikolo.openune" - buildConfigField "de.xikolo.util.BuildFlavor", "X_FLAVOR", "de.xikolo.util.BuildFlavor.OPEN_UNE" + buildConfigField "de.xikolo.utils.BuildFlavor", "X_FLAVOR", "de.xikolo.utils.BuildFlavor.OPEN_UNE" appName = "openUNE" appHost = "openune.cn" } @@ -102,7 +102,7 @@ android { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - buildConfigField "de.xikolo.util.BuildType", "X_TYPE", "de.xikolo.util.BuildType.RELEASE" + buildConfigField "de.xikolo.utils.BuildType", "X_TYPE", "de.xikolo.utils.BuildType.RELEASE" debuggable false zipAlignEnabled true @@ -117,7 +117,7 @@ android { } debug { minifyEnabled false - buildConfigField "de.xikolo.util.BuildType", "X_TYPE", "de.xikolo.util.BuildType.DEBUG" + buildConfigField "de.xikolo.utils.BuildType", "X_TYPE", "de.xikolo.utils.BuildType.DEBUG" shrinkResources false debuggable true diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 55d343280..294e06991 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -31,7 +31,7 @@ -keep class com.google.gson.stream.** { *; } # Application classes that will be serialized/deserialized over Gson --keep class de.xikolo.data.entities.** { *; } +-keep class de.xikolo.entities.** { *; } ##---------------Begin: proguard configuration for Samsung SDK ---------- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b78a89969..f25823d77 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,11 +29,11 @@ android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> - @@ -41,7 +41,7 @@ @@ -49,7 +49,7 @@ @@ -58,7 +58,7 @@ @@ -88,12 +88,12 @@ + android:parentActivityName=".controllers.MainActivity"> + android:value=".controllers.MainActivity" /> @@ -123,105 +123,105 @@ + android:parentActivityName=".controllers.MainActivity"> + android:value=".controllers.MainActivity" /> + android:parentActivityName=".controllers.MainActivity"> + android:value=".controllers.MainActivity" /> + android:parentActivityName=".controllers.MainActivity"> + android:value=".controllers.MainActivity" /> + android:parentActivityName=".controllers.CourseActivity"> + android:value=".controllers.CourseActivity" /> + android:value=".controllers.ModuleActivity" /> + android:parentActivityName=".controllers.MainActivity"> + android:value=".controllers.MainActivity" /> + android:parentActivityName=".controllers.MainActivity"> + android:value=".controllers.MainActivity" /> + android:parentActivityName=".controllers.SecondScreenActivity"> + android:value=".controllers.SecondScreenActivity" /> + android:parentActivityName=".controllers.SecondScreenActivity"> + android:value=".controllers.SecondScreenActivity" /> + android:parentActivityName=".controllers.SecondScreenActivity"> + android:value=".controllers.SecondScreenActivity" /> + android:parentActivityName=".controllers.SecondScreenActivity"> + android:value=".controllers.SecondScreenActivity" /> + android:value=".controllers.CourseDetailsActivity" /> diff --git a/app/src/main/java/de/xikolo/GlobalApplication.java b/app/src/main/java/de/xikolo/GlobalApplication.java index 232ee5672..54a6b7afc 100644 --- a/app/src/main/java/de/xikolo/GlobalApplication.java +++ b/app/src/main/java/de/xikolo/GlobalApplication.java @@ -1,7 +1,6 @@ package de.xikolo; import android.app.Application; -import android.net.http.HttpResponseCache; import android.os.Build; import android.support.v7.preference.PreferenceManager; import android.util.Log; @@ -15,19 +14,19 @@ import com.path.android.jobqueue.config.Configuration; import com.path.android.jobqueue.log.CustomLogger; -import java.io.File; -import java.io.IOException; - -import de.xikolo.data.database.DataAccessFactory; -import de.xikolo.data.database.DatabaseHelper; -import de.xikolo.data.preferences.PreferencesFactory; import de.xikolo.lanalytics.Lanalytics; import de.xikolo.managers.SecondScreenManager; import de.xikolo.managers.WebSocketManager; -import de.xikolo.util.ClientUtil; -import de.xikolo.util.Config; -import de.xikolo.util.FeatureToggle; -import de.xikolo.util.SslCertificateUtil; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.adapters.DataAdapter; +import de.xikolo.storages.preferences.KeyValueStorage; +import de.xikolo.storages.preferences.StorageHelper; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.ClientUtil; +import de.xikolo.utils.Config; +import de.xikolo.utils.FeatureToggle; +import de.xikolo.utils.SslCertificateUtil; public class GlobalApplication extends Application { @@ -37,13 +36,9 @@ public class GlobalApplication extends Application { private JobManager jobManager; - private HttpResponseCache httpResponseCache; - private DatabaseHelper databaseHelper; - private DataAccessFactory dataAccessFactory; - - private PreferencesFactory preferencesFactory; + private StorageHelper storageHelper; private Lanalytics lanalytics; @@ -63,40 +58,48 @@ public JobManager getJobManager() { return jobManager; } - public DataAccessFactory getDataAccessFactory() { + public Lanalytics getLanalytics() { synchronized (GlobalApplication.class) { - if (dataAccessFactory == null) { - dataAccessFactory = new DataAccessFactory(databaseHelper); + if (lanalytics == null) { + lanalytics = Lanalytics.getInstance(this, Config.API_V2 + Config.LANALYTICS); } } - return dataAccessFactory; + return lanalytics; } - public PreferencesFactory getPreferencesFactory() { + public WebSocketManager getWebSocketManager() { synchronized (GlobalApplication.class) { - if (preferencesFactory == null) { - preferencesFactory = new PreferencesFactory(this); + if (webSocketManager == null) { + webSocketManager = new WebSocketManager(Config.WEBSOCKET); } } - return preferencesFactory; + return webSocketManager; } - public Lanalytics getLanalytics() { + public static DataAdapter getDataAdapter(DataType type) { + return getInstance().getDatabaseHelper().getDataAdapter(type); + } + + public DatabaseHelper getDatabaseHelper() { synchronized (GlobalApplication.class) { - if (lanalytics == null) { - lanalytics = Lanalytics.getInstance(this, Config.API_V2 + Config.LANALYTICS); + if (databaseHelper == null) { + databaseHelper = new DatabaseHelper(this); } } - return lanalytics; + return databaseHelper; } - public WebSocketManager getWebSocketManager() { + public static KeyValueStorage getStorage(StorageType type) { + return getInstance().getStorageHelper().getStorage(type); + } + + public StorageHelper getStorageHelper() { synchronized (GlobalApplication.class) { - if (webSocketManager == null) { - webSocketManager = new WebSocketManager(Config.WEBSOCKET); + if (storageHelper == null) { + storageHelper = new StorageHelper(this); } } - return webSocketManager; + return storageHelper; } public String getClientId() { @@ -108,8 +111,6 @@ public void onCreate() { super.onCreate(); configureDefaultSettings(); - configureDatabase(); - configureHttpResponseCache(); configureWebView(); configureJobManager(); configureVideoCastManager(); @@ -126,21 +127,6 @@ private void configureDefaultSettings() { PreferenceManager.setDefaultValues(this, R.xml.settings, false); } - private void configureDatabase() { - databaseHelper = new DatabaseHelper(this); - } - - private void configureHttpResponseCache() { - // Create HTTP Response Cache - try { - File httpCacheDir = new File(this.getCacheDir(), "http"); - long httpCacheSize = 20 * 1024 * 1024; // 20 MiB - httpResponseCache = HttpResponseCache.install(httpCacheDir, httpCacheSize); - } catch (IOException e) { - Log.i(TAG, "HTTP Response Cache installation failed:" + e); - } - } - @SuppressWarnings("deprecation") private void configureWebView() { // Enable WebView Cookies @@ -189,12 +175,6 @@ public void e(String text, Object... args) { jobManager = new JobManager(this, configuration); } - public void flushHttpResponseCache() { - if (httpResponseCache != null) { - httpResponseCache.flush(); - } - } - @SuppressWarnings("deprecation") public void startCookieSyncManager() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { diff --git a/app/src/main/java/de/xikolo/controller/BaseActivity.java b/app/src/main/java/de/xikolo/controllers/BaseActivity.java similarity index 89% rename from app/src/main/java/de/xikolo/controller/BaseActivity.java rename to app/src/main/java/de/xikolo/controllers/BaseActivity.java index 319d54845..4e031ebdd 100644 --- a/app/src/main/java/de/xikolo/controller/BaseActivity.java +++ b/app/src/main/java/de/xikolo/controllers/BaseActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.Intent; import android.content.pm.PackageManager; @@ -27,15 +27,15 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.data.preferences.NotificationPreferences; -import de.xikolo.data.preferences.PreferencesFactory; -import de.xikolo.model.UserModel; -import de.xikolo.model.events.NetworkStateEvent; -import de.xikolo.model.events.PermissionDeniedEvent; -import de.xikolo.model.events.PermissionGrantedEvent; -import de.xikolo.model.receiver.NotificationDeletedReceiver; -import de.xikolo.util.FeatureToggle; -import de.xikolo.util.PlayServicesUtil; +import de.xikolo.events.NetworkStateEvent; +import de.xikolo.events.PermissionDeniedEvent; +import de.xikolo.events.PermissionGrantedEvent; +import de.xikolo.managers.UserManager; +import de.xikolo.storages.preferences.NotificationStorage; +import de.xikolo.receivers.NotificationDeletedReceiver; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.FeatureToggle; +import de.xikolo.utils.PlayServicesUtil; public abstract class BaseActivity extends AppCompatActivity { @@ -190,8 +190,8 @@ protected void onStart() { EventBus.getDefault().register(this); - if (UserModel.isLoggedIn(this) && FeatureToggle.secondScreen()) { - globalApplication.getWebSocketManager().initConnection(UserModel.getToken(this)); + if (UserManager.isLoggedIn() && FeatureToggle.secondScreen()) { + globalApplication.getWebSocketManager().initConnection(UserManager.getToken()); } } @@ -217,8 +217,6 @@ protected void onPause() { protected void onStop() { super.onStop(); - globalApplication.flushHttpResponseCache(); - EventBus.getDefault().unregister(this); } @@ -259,14 +257,13 @@ protected void onNewIntent(Intent intent) { } private void handleIntent(Intent intent) { - PreferencesFactory preferencesFactory = new PreferencesFactory(this); - NotificationPreferences notificationPreferences = preferencesFactory.getNotificationPreferences(); + NotificationStorage notificationStorage = (NotificationStorage) GlobalApplication.getStorage(StorageType.NOTIFICATION); String title = intent.getStringExtra(NotificationDeletedReceiver.KEY_TITLE); if (title != null) { - notificationPreferences.deleteDownloadNotification(title); + notificationStorage.deleteDownloadNotification(title); } else if (intent.getStringExtra(NotificationDeletedReceiver.KEY_ALL) != null) { - notificationPreferences.deleteAllDownloadNotifications(); + notificationStorage.deleteAllDownloadNotifications(); } } diff --git a/app/src/main/java/de/xikolo/controller/BaseFragment.java b/app/src/main/java/de/xikolo/controllers/BaseFragment.java similarity index 96% rename from app/src/main/java/de/xikolo/controller/BaseFragment.java rename to app/src/main/java/de/xikolo/controllers/BaseFragment.java index 16e3a198c..1e5fbe0ad 100644 --- a/app/src/main/java/de/xikolo/controller/BaseFragment.java +++ b/app/src/main/java/de/xikolo/controllers/BaseFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.os.Bundle; import android.support.v4.app.Fragment; diff --git a/app/src/main/java/de/xikolo/controller/CourseActivity.java b/app/src/main/java/de/xikolo/controllers/CourseActivity.java similarity index 94% rename from app/src/main/java/de/xikolo/controller/CourseActivity.java rename to app/src/main/java/de/xikolo/controllers/CourseActivity.java index e49238ad5..56a7aa37c 100644 --- a/app/src/main/java/de/xikolo/controller/CourseActivity.java +++ b/app/src/main/java/de/xikolo/controllers/CourseActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.Intent; import android.net.Uri; @@ -23,21 +23,21 @@ import de.xikolo.BuildConfig; import de.xikolo.R; -import de.xikolo.controller.course.CourseLearningsFragment; -import de.xikolo.controller.course.ProgressFragment; -import de.xikolo.controller.dialogs.ProgressDialog; -import de.xikolo.controller.dialogs.UnenrollDialog; -import de.xikolo.controller.helper.CacheController; -import de.xikolo.controller.helper.EnrollmentController; -import de.xikolo.data.entities.Course; -import de.xikolo.model.CourseModel; -import de.xikolo.model.Result; -import de.xikolo.model.events.NetworkStateEvent; -import de.xikolo.util.BuildFlavor; -import de.xikolo.util.Config; -import de.xikolo.util.DeepLinkingUtil; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.ToastUtil; +import de.xikolo.controllers.course.CourseLearningsFragment; +import de.xikolo.controllers.course.ProgressFragment; +import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.controllers.dialogs.UnenrollDialog; +import de.xikolo.controllers.helper.CacheController; +import de.xikolo.controllers.helper.EnrollmentController; +import de.xikolo.events.NetworkStateEvent; +import de.xikolo.managers.CourseManager; +import de.xikolo.managers.Result; +import de.xikolo.models.Course; +import de.xikolo.utils.BuildFlavor; +import de.xikolo.utils.Config; +import de.xikolo.utils.DeepLinkingUtil; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.ToastUtil; public class CourseActivity extends BaseActivity implements UnenrollDialog.UnenrollDialogListener { @@ -204,7 +204,7 @@ protected void onError(ErrorCode errorCode) { } }; - CourseModel courseModel = new CourseModel(jobManager); + CourseManager courseModel = new CourseManager(jobManager); courseModel.getCourses(result, false); progressDialog.show(getSupportFragmentManager(), ProgressDialog.TAG); } diff --git a/app/src/main/java/de/xikolo/controller/CourseDetailsActivity.java b/app/src/main/java/de/xikolo/controllers/CourseDetailsActivity.java similarity index 91% rename from app/src/main/java/de/xikolo/controller/CourseDetailsActivity.java rename to app/src/main/java/de/xikolo/controllers/CourseDetailsActivity.java index f4af928ba..22a8827de 100644 --- a/app/src/main/java/de/xikolo/controller/CourseDetailsActivity.java +++ b/app/src/main/java/de/xikolo/controllers/CourseDetailsActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -9,10 +9,10 @@ import android.view.MenuItem; import de.xikolo.R; -import de.xikolo.controller.dialogs.UnenrollDialog; -import de.xikolo.controller.helper.EnrollmentController; -import de.xikolo.data.entities.Course; -import de.xikolo.util.Config; +import de.xikolo.controllers.dialogs.UnenrollDialog; +import de.xikolo.controllers.helper.EnrollmentController; +import de.xikolo.models.Course; +import de.xikolo.utils.Config; public class CourseDetailsActivity extends BaseActivity implements UnenrollDialog.UnenrollDialogListener { diff --git a/app/src/main/java/de/xikolo/controller/DownloadsActivity.java b/app/src/main/java/de/xikolo/controllers/DownloadsActivity.java similarity index 91% rename from app/src/main/java/de/xikolo/controller/DownloadsActivity.java rename to app/src/main/java/de/xikolo/controllers/DownloadsActivity.java index 2fbd9e65c..c00088d85 100644 --- a/app/src/main/java/de/xikolo/controller/DownloadsActivity.java +++ b/app/src/main/java/de/xikolo/controllers/DownloadsActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.os.Bundle; @@ -6,7 +6,7 @@ import android.support.v4.app.FragmentTransaction; import de.xikolo.R; -import de.xikolo.controller.downloads.DownloadsFragment; +import de.xikolo.controllers.downloads.DownloadsFragment; public class DownloadsActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/LoginActivity.java b/app/src/main/java/de/xikolo/controllers/LoginActivity.java similarity index 89% rename from app/src/main/java/de/xikolo/controller/LoginActivity.java rename to app/src/main/java/de/xikolo/controllers/LoginActivity.java index 9269add14..0a35153ce 100644 --- a/app/src/main/java/de/xikolo/controller/LoginActivity.java +++ b/app/src/main/java/de/xikolo/controllers/LoginActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.Context; import android.content.Intent; @@ -16,20 +16,20 @@ import org.greenrobot.eventbus.EventBus; import de.xikolo.R; -import de.xikolo.controller.dialogs.ProgressDialog; -import de.xikolo.data.entities.User; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.model.events.LoginEvent; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; +import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.managers.UserManager; +import de.xikolo.models.User; +import de.xikolo.managers.Result; +import de.xikolo.events.LoginEvent; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; public class LoginActivity extends BaseActivity { public static final String TAG = LoginActivity.class.getSimpleName(); - private UserModel userModel; + private UserManager userManager; private Result loginResult; private Result userResult; @@ -54,11 +54,11 @@ protected void onCreate(Bundle savedInstanceState) { progressDialog = ProgressDialog.getInstance(); - userModel = new UserModel(jobManager); + userManager = new UserManager(jobManager); loginResult = new Result() { @Override protected void onSuccess(Void result, DataSource dataSource) { - userModel.getUser(userResult); + userManager.getUser(userResult); } @Override @@ -69,7 +69,7 @@ protected void onError(ErrorCode errorCode) { } else { ToastUtil.show(R.string.toast_log_in_failed); } - userModel.logout(); + userManager.logout(); } }; userResult = new Result() { @@ -88,7 +88,7 @@ protected void onError(ErrorCode errorCode) { } else { ToastUtil.show(R.string.toast_log_in_failed); } - userModel.logout(); + userManager.logout(); } }; @@ -101,7 +101,7 @@ public void onClick(View view) { String password = editTextPassword.getText().toString(); if (isEmailValid(email)) { if (!password.equals("")) { - userModel.login(loginResult, email, password); + userManager.login(loginResult, email, password); progressDialog.show(getSupportFragmentManager(), ProgressDialog.TAG); } else { editTextPassword.setError(getString(R.string.error_password)); diff --git a/app/src/main/java/de/xikolo/controller/MainActivity.java b/app/src/main/java/de/xikolo/controllers/MainActivity.java similarity index 88% rename from app/src/main/java/de/xikolo/controller/MainActivity.java rename to app/src/main/java/de/xikolo/controllers/MainActivity.java index d2aa0b981..dc920f9c6 100644 --- a/app/src/main/java/de/xikolo/controller/MainActivity.java +++ b/app/src/main/java/de/xikolo/controllers/MainActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.Intent; import android.net.Uri; @@ -14,18 +14,18 @@ import de.xikolo.BuildConfig; import de.xikolo.R; -import de.xikolo.controller.main.ContentFragment; -import de.xikolo.controller.main.ContentWebViewFragment; -import de.xikolo.controller.main.CourseListFragment; -import de.xikolo.controller.main.ProfileFragment; -import de.xikolo.controller.navigation.NavigationFragment; -import de.xikolo.controller.navigation.adapter.NavigationAdapter; -import de.xikolo.model.UserModel; -import de.xikolo.model.events.LoginEvent; -import de.xikolo.model.events.LogoutEvent; -import de.xikolo.util.Config; -import de.xikolo.util.DeepLinkingUtil; -import de.xikolo.util.LanalyticsUtil; +import de.xikolo.controllers.main.ContentFragment; +import de.xikolo.controllers.main.ContentWebViewFragment; +import de.xikolo.controllers.main.CourseListFragment; +import de.xikolo.controllers.main.ProfileFragment; +import de.xikolo.controllers.navigation.NavigationFragment; +import de.xikolo.controllers.navigation.adapter.NavigationAdapter; +import de.xikolo.managers.UserManager; +import de.xikolo.events.LoginEvent; +import de.xikolo.events.LogoutEvent; +import de.xikolo.utils.Config; +import de.xikolo.utils.DeepLinkingUtil; +import de.xikolo.utils.LanalyticsUtil; public class MainActivity extends BaseActivity implements NavigationFragment.NavigationDrawerCallbacks, ContentFragment.OnFragmentInteractionListener { @@ -114,11 +114,11 @@ public void onNavigationDrawerItemSelected(int position) { Intent intent = null; ContentFragment newFragment = null; if (position == NavigationAdapter.NAV_PROFILE.getPosition()) { - if (UserModel.isLoggedIn(this)) { + if (UserManager.isLoggedIn()) { newFragment = ProfileFragment.newInstance(); tag = "profile"; - LanalyticsUtil.trackVisitedProfile(UserModel.getSavedUser(this).id); + LanalyticsUtil.trackVisitedProfile(UserManager.getSavedUser().id); } else { intent = new Intent(MainActivity.this, LoginActivity.class); } @@ -141,12 +141,12 @@ public void onNavigationDrawerItemSelected(int position) { if (position == NavigationAdapter.NAV_DOWNLOADS.getPosition()) { intent = new Intent(MainActivity.this, DownloadsActivity.class); - LanalyticsUtil.trackVisitedDownloads(UserModel.getSavedUser(this).id); + LanalyticsUtil.trackVisitedDownloads(UserManager.getSavedUser().id); } if (position == NavigationAdapter.NAV_SETTINGS.getPosition()) { intent = new Intent(MainActivity.this, SettingsActivity.class); - LanalyticsUtil.trackVisitedPreferences(UserModel.getSavedUser(this).id); + LanalyticsUtil.trackVisitedPreferences(UserManager.getSavedUser().id); } if (tag != null) { ContentFragment oldFragment = (ContentFragment) fragmentManager.findFragmentByTag(tag); @@ -174,10 +174,10 @@ private void setTitle(String title) { @Override public void onBackPressed() { if (!navigationFragment.isDrawerOpen()) { - if (UserModel.isLoggedIn(this) + if (UserManager.isLoggedIn() && navigationFragment.getItem() == NavigationAdapter.NAV_MY_COURSES.getPosition()) { finish(); - } else if (!UserModel.isLoggedIn(this) + } else if (!UserManager.isLoggedIn() && navigationFragment.getItem() == NavigationAdapter.NAV_ALL_COURSES.getPosition()) { finish(); } else if (getSupportFragmentManager().getBackStackEntryCount() > 1) { diff --git a/app/src/main/java/de/xikolo/controller/ModuleActivity.java b/app/src/main/java/de/xikolo/controllers/ModuleActivity.java similarity index 93% rename from app/src/main/java/de/xikolo/controller/ModuleActivity.java rename to app/src/main/java/de/xikolo/controllers/ModuleActivity.java index df1b324b8..422d7d1ac 100644 --- a/app/src/main/java/de/xikolo/controller/ModuleActivity.java +++ b/app/src/main/java/de/xikolo/controllers/ModuleActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.Context; import android.content.Intent; @@ -25,19 +25,19 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.exceptions.WrongParameterException; -import de.xikolo.controller.helper.CacheController; -import de.xikolo.controller.helper.ModuleDownloadController; -import de.xikolo.controller.module.ItemWebViewFragment; -import de.xikolo.controller.module.VideoFragment; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.model.ItemModel; -import de.xikolo.model.Result; -import de.xikolo.model.events.NetworkStateEvent; -import de.xikolo.util.DateUtil; -import de.xikolo.util.LanalyticsUtil; +import de.xikolo.controllers.exceptions.WrongParameterException; +import de.xikolo.controllers.helper.CacheController; +import de.xikolo.controllers.helper.ModuleDownloadController; +import de.xikolo.controllers.module.ItemWebViewFragment; +import de.xikolo.controllers.module.VideoFragment; +import de.xikolo.managers.ItemManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.managers.Result; +import de.xikolo.events.NetworkStateEvent; +import de.xikolo.utils.DateUtil; +import de.xikolo.utils.LanalyticsUtil; public class ModuleActivity extends BaseActivity { @@ -51,7 +51,7 @@ public class ModuleActivity extends BaseActivity { private Module module; private Item item; - private ItemModel itemModel; + private ItemManager itemManager; private Result progressionResult; private ViewPager viewpager; @@ -103,7 +103,7 @@ protected void onCreate(Bundle savedInstanceState) { " and Module " + module.name + " (" + module.id + ")"); } - itemModel = new ItemModel(jobManager); + itemManager = new ItemManager(jobManager); progressionResult = new Result() { }; @@ -114,7 +114,7 @@ protected void onCreate(Bundle savedInstanceState) { index = module.items.indexOf(item); } module.items.get(index).progress.visited = true; - itemModel.updateProgression(progressionResult, module, module.items.get(index)); + itemManager.updateProgression(progressionResult, module.items.get(index)); if (index == 0) { LanalyticsUtil.trackVisitedItem(module.items.get(0).id, course.id, module.id); @@ -313,7 +313,7 @@ public void onTabSelected(TabLayout.Tab tab) { unseenIndicator.setVisibility(View.GONE); Item item = items.get(tabLayout.getSelectedTabPosition()); item.progress.visited = true; - itemModel.updateProgression(progressionResult, module, item); + itemManager.updateProgression(progressionResult, item); LanalyticsUtil.trackVisitedItem(item.id, course.id, module.id); } diff --git a/app/src/main/java/de/xikolo/controller/SecondScreenActivity.java b/app/src/main/java/de/xikolo/controllers/SecondScreenActivity.java similarity index 91% rename from app/src/main/java/de/xikolo/controller/SecondScreenActivity.java rename to app/src/main/java/de/xikolo/controllers/SecondScreenActivity.java index a6681d868..c71b655c4 100644 --- a/app/src/main/java/de/xikolo/controller/SecondScreenActivity.java +++ b/app/src/main/java/de/xikolo/controllers/SecondScreenActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.os.Bundle; @@ -6,7 +6,7 @@ import android.support.v4.app.FragmentTransaction; import de.xikolo.R; -import de.xikolo.controller.secondscreen.SecondScreenFragment; +import de.xikolo.controllers.secondscreen.SecondScreenFragment; public class SecondScreenActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/SettingsActivity.java b/app/src/main/java/de/xikolo/controllers/SettingsActivity.java similarity index 92% rename from app/src/main/java/de/xikolo/controller/SettingsActivity.java rename to app/src/main/java/de/xikolo/controllers/SettingsActivity.java index f95e97b1a..b13a122cb 100644 --- a/app/src/main/java/de/xikolo/controller/SettingsActivity.java +++ b/app/src/main/java/de/xikolo/controllers/SettingsActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.app.FragmentManager; import android.app.FragmentTransaction; @@ -6,7 +6,7 @@ import android.view.Menu; import de.xikolo.R; -import de.xikolo.controller.settings.SettingsFragment; +import de.xikolo.controllers.settings.SettingsFragment; public class SettingsActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/VideoActivity.java b/app/src/main/java/de/xikolo/controllers/VideoActivity.java similarity index 94% rename from app/src/main/java/de/xikolo/controller/VideoActivity.java rename to app/src/main/java/de/xikolo/controllers/VideoActivity.java index b8c54d96f..83336fa1e 100644 --- a/app/src/main/java/de/xikolo/controller/VideoActivity.java +++ b/app/src/main/java/de/xikolo/controllers/VideoActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.res.Configuration; import android.graphics.Point; @@ -20,17 +20,17 @@ import com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl; import de.xikolo.R; -import de.xikolo.controller.exceptions.WrongParameterException; -import de.xikolo.controller.helper.VideoController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.model.ItemModel; -import de.xikolo.model.Result; -import de.xikolo.util.CastUtil; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.AndroidDimenUtil; +import de.xikolo.controllers.exceptions.WrongParameterException; +import de.xikolo.controllers.helper.VideoController; +import de.xikolo.managers.ItemManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.managers.Result; +import de.xikolo.utils.CastUtil; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.AndroidDimenUtil; public class VideoActivity extends BaseActivity { @@ -46,7 +46,7 @@ public class VideoActivity extends BaseActivity { private Module module; private Item item; - private ItemModel itemModel; + private ItemManager itemManager; private View videoMetadataView; @@ -65,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) { View videoContainer = findViewById(R.id.videoContainer); - itemModel = new ItemModel(jobManager); + itemManager = new ItemManager(jobManager); videoMetadataView = findViewById(R.id.videoMetadata); TextView videoTitleText = (TextView) findViewById(R.id.textTitle); @@ -91,7 +91,7 @@ public void onControllerHide() { module = getIntent().getExtras().getParcelable(ARG_MODULE); item = getIntent().getExtras().getParcelable(ARG_ITEM); - itemModel.getLocalVideoProgress(new Result() { + itemManager.getLocalVideoProgress(new Result() { @Override protected void onSuccess(VideoItemDetail result, DataSource dataSource) { item.detail = result; @@ -309,7 +309,7 @@ protected void onPause() { videoController.pause(); VideoItemDetail itemDetail = videoController.getVideoItemDetail(); if (itemDetail != null) { - itemModel.updateLocalVideoProgress(new Result() { + itemManager.updateLocalVideoProgress(new Result() { }, itemDetail); } } diff --git a/app/src/main/java/de/xikolo/controller/WebViewFragment.java b/app/src/main/java/de/xikolo/controllers/WebViewFragment.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/WebViewFragment.java rename to app/src/main/java/de/xikolo/controllers/WebViewFragment.java index 38209e480..98c2c6b0c 100644 --- a/app/src/main/java/de/xikolo/controller/WebViewFragment.java +++ b/app/src/main/java/de/xikolo/controllers/WebViewFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller; +package de.xikolo.controllers; import android.content.MutableContextWrapper; import android.os.Bundle; @@ -11,7 +11,7 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.helper.WebViewController; +import de.xikolo.controllers.helper.WebViewController; public class WebViewFragment extends BaseFragment { diff --git a/app/src/main/java/de/xikolo/controller/course/CourseLearningsFragment.java b/app/src/main/java/de/xikolo/controllers/course/CourseLearningsFragment.java similarity index 90% rename from app/src/main/java/de/xikolo/controller/course/CourseLearningsFragment.java rename to app/src/main/java/de/xikolo/controllers/course/CourseLearningsFragment.java index b39ef487f..337ad252b 100644 --- a/app/src/main/java/de/xikolo/controller/course/CourseLearningsFragment.java +++ b/app/src/main/java/de/xikolo/controllers/course/CourseLearningsFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.course; +package de.xikolo.controllers.course; import android.app.Activity; import android.content.Intent; @@ -17,20 +17,20 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.controller.BaseFragment; -import de.xikolo.controller.ModuleActivity; -import de.xikolo.controller.course.adapter.ItemListAdapter; -import de.xikolo.controller.course.adapter.ModuleListAdapter; -import de.xikolo.controller.helper.NotificationController; -import de.xikolo.controller.helper.RefeshLayoutController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.model.ModuleModel; -import de.xikolo.model.Result; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; -import de.xikolo.view.SpaceItemDecoration; +import de.xikolo.controllers.BaseFragment; +import de.xikolo.controllers.ModuleActivity; +import de.xikolo.controllers.course.adapter.ItemListAdapter; +import de.xikolo.controllers.course.adapter.ModuleListAdapter; +import de.xikolo.controllers.helper.NotificationController; +import de.xikolo.controllers.helper.RefeshLayoutController; +import de.xikolo.managers.ModuleManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.managers.Result; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; +import de.xikolo.views.SpaceItemDecoration; public class CourseLearningsFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, ModuleListAdapter.OnModuleButtonClickListener, ItemListAdapter.OnItemButtonClickListener { @@ -44,7 +44,7 @@ public class CourseLearningsFragment extends BaseFragment implements SwipeRefres private SwipeRefreshLayout refreshLayout; - private ModuleModel moduleModel; + private ModuleManager moduleManager; private ModuleListAdapter adapter; private NotificationController notificationController; @@ -83,7 +83,7 @@ public void onCreate(Bundle savedInstanceState) { } setHasOptionsMenu(true); - moduleModel = new ModuleModel(jobManager); + moduleManager = new ModuleManager(jobManager); } @Override @@ -188,7 +188,7 @@ protected void onError(ErrorCode errorCode) { refreshLayout.setRefreshing(true); } - moduleModel.getModulesWithItems(result, course, includeProgress); + moduleManager.getModulesWithItems(result, course, includeProgress); } @Override diff --git a/app/src/main/java/de/xikolo/controller/course/ProgressFragment.java b/app/src/main/java/de/xikolo/controllers/course/ProgressFragment.java similarity index 90% rename from app/src/main/java/de/xikolo/controller/course/ProgressFragment.java rename to app/src/main/java/de/xikolo/controllers/course/ProgressFragment.java index cfe2cc2df..3ed17ca0a 100644 --- a/app/src/main/java/de/xikolo/controller/course/ProgressFragment.java +++ b/app/src/main/java/de/xikolo/controllers/course/ProgressFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.course; +package de.xikolo.controllers.course; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; @@ -15,17 +15,17 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.controller.BaseFragment; -import de.xikolo.controller.course.adapter.ProgressListAdapter; -import de.xikolo.controller.helper.NotificationController; -import de.xikolo.controller.helper.RefeshLayoutController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Module; -import de.xikolo.model.ModuleModel; -import de.xikolo.model.Result; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; -import de.xikolo.view.SpaceItemDecoration; +import de.xikolo.controllers.BaseFragment; +import de.xikolo.controllers.course.adapter.ProgressListAdapter; +import de.xikolo.controllers.helper.NotificationController; +import de.xikolo.controllers.helper.RefeshLayoutController; +import de.xikolo.models.Course; +import de.xikolo.models.Module; +import de.xikolo.managers.ModuleManager; +import de.xikolo.managers.Result; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; +import de.xikolo.views.SpaceItemDecoration; public class ProgressFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener { @@ -37,7 +37,7 @@ public class ProgressFragment extends BaseFragment implements SwipeRefreshLayout private Course course; private List modules; - private ModuleModel moduleModel; + private ModuleManager moduleManager; private ProgressListAdapter adapter; @@ -76,7 +76,7 @@ public void onCreate(Bundle savedInstanceState) { } setHasOptionsMenu(true); - moduleModel = new ModuleModel(jobManager); + moduleManager = new ModuleManager(jobManager); } @Override @@ -178,7 +178,7 @@ protected void onError(ErrorCode errorCode) { refreshLayout.setRefreshing(true); } - moduleModel.getModules(result, course, true); + moduleManager.getModules(result, course, true); } @Override diff --git a/app/src/main/java/de/xikolo/controller/course/adapter/ItemListAdapter.java b/app/src/main/java/de/xikolo/controllers/course/adapter/ItemListAdapter.java similarity index 94% rename from app/src/main/java/de/xikolo/controller/course/adapter/ItemListAdapter.java rename to app/src/main/java/de/xikolo/controllers/course/adapter/ItemListAdapter.java index bda0d0ad6..40383b1af 100644 --- a/app/src/main/java/de/xikolo/controller/course/adapter/ItemListAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/course/adapter/ItemListAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.course.adapter; +package de.xikolo.controllers.course.adapter; import android.content.Context; import android.support.v4.content.ContextCompat; @@ -13,11 +13,11 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.util.DateUtil; -import de.xikolo.util.ItemTitle; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.utils.DateUtil; +import de.xikolo.utils.ItemTitle; public class ItemListAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/de/xikolo/controller/course/adapter/ModuleListAdapter.java b/app/src/main/java/de/xikolo/controllers/course/adapter/ModuleListAdapter.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/course/adapter/ModuleListAdapter.java rename to app/src/main/java/de/xikolo/controllers/course/adapter/ModuleListAdapter.java index a9a077240..9bf884d00 100644 --- a/app/src/main/java/de/xikolo/controller/course/adapter/ModuleListAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/course/adapter/ModuleListAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.course.adapter; +package de.xikolo.controllers.course.adapter; import android.support.v4.app.FragmentActivity; import android.support.v4.content.ContextCompat; @@ -19,14 +19,14 @@ import java.util.Locale; import de.xikolo.R; -import de.xikolo.controller.helper.ModuleDownloadController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.util.DateUtil; -import de.xikolo.util.DisplayUtil; -import de.xikolo.view.AutofitRecyclerView; -import de.xikolo.view.SpaceItemDecoration; +import de.xikolo.controllers.helper.ModuleDownloadController; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.utils.DateUtil; +import de.xikolo.utils.DisplayUtil; +import de.xikolo.views.AutofitRecyclerView; +import de.xikolo.views.SpaceItemDecoration; public class ModuleListAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/de/xikolo/controller/course/adapter/ProgressListAdapter.java b/app/src/main/java/de/xikolo/controllers/course/adapter/ProgressListAdapter.java similarity index 98% rename from app/src/main/java/de/xikolo/controller/course/adapter/ProgressListAdapter.java rename to app/src/main/java/de/xikolo/controllers/course/adapter/ProgressListAdapter.java index 226f23796..2c652e060 100644 --- a/app/src/main/java/de/xikolo/controller/course/adapter/ProgressListAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/course/adapter/ProgressListAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.course.adapter; +package de.xikolo.controllers.course.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; @@ -12,7 +12,7 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.data.entities.Module; +import de.xikolo.models.Module; public class ProgressListAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/de/xikolo/controller/dialogs/ChooseLanguageDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/ChooseLanguageDialog.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/dialogs/ChooseLanguageDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/ChooseLanguageDialog.java index 23eeb7149..3c6104d7c 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/ChooseLanguageDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/ChooseLanguageDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.content.DialogInterface; @@ -11,8 +11,8 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.data.entities.Subtitle; -import de.xikolo.util.LanguageUtil; +import de.xikolo.models.Subtitle; +import de.xikolo.utils.LanguageUtil; public class ChooseLanguageDialog extends DialogFragment { diff --git a/app/src/main/java/de/xikolo/controller/dialogs/ConfirmDeleteDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/ConfirmDeleteDialog.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/dialogs/ConfirmDeleteDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/ConfirmDeleteDialog.java index 830fb08a9..83ca06837 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/ConfirmDeleteDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/ConfirmDeleteDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.content.DialogInterface; @@ -8,7 +8,7 @@ import android.support.v7.app.AlertDialog; import de.xikolo.R; -import de.xikolo.util.DisplayUtil; +import de.xikolo.utils.DisplayUtil; public class ConfirmDeleteDialog extends DialogFragment { diff --git a/app/src/main/java/de/xikolo/controller/dialogs/ContributorsDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/ContributorsDialog.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/dialogs/ContributorsDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/ContributorsDialog.java index 82e0425ea..65c62d311 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/ContributorsDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/ContributorsDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.app.DialogFragment; diff --git a/app/src/main/java/de/xikolo/controller/dialogs/DownloadSlidesDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/DownloadSlidesDialog.java similarity index 98% rename from app/src/main/java/de/xikolo/controller/dialogs/DownloadSlidesDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/DownloadSlidesDialog.java index 6f87afec9..29c7a3035 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/DownloadSlidesDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/DownloadSlidesDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.content.DialogInterface; diff --git a/app/src/main/java/de/xikolo/controller/dialogs/LicensesDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/LicensesDialog.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/dialogs/LicensesDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/LicensesDialog.java index c106f3a51..bcdfc970d 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/LicensesDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/LicensesDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.app.DialogFragment; diff --git a/app/src/main/java/de/xikolo/controller/dialogs/MobileDownloadDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/MobileDownloadDialog.java similarity index 98% rename from app/src/main/java/de/xikolo/controller/dialogs/MobileDownloadDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/MobileDownloadDialog.java index 80ca13aee..0fe4b72ff 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/MobileDownloadDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/MobileDownloadDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.content.DialogInterface; diff --git a/app/src/main/java/de/xikolo/controller/dialogs/ModuleDownloadDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/ModuleDownloadDialog.java similarity index 99% rename from app/src/main/java/de/xikolo/controller/dialogs/ModuleDownloadDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/ModuleDownloadDialog.java index 940e6b8ad..3107dd1a2 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/ModuleDownloadDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/ModuleDownloadDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.content.DialogInterface; diff --git a/app/src/main/java/de/xikolo/controller/dialogs/PermissionsDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/PermissionsDialog.java similarity index 89% rename from app/src/main/java/de/xikolo/controller/dialogs/PermissionsDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/PermissionsDialog.java index cf8711d5d..9fbc9b572 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/PermissionsDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/PermissionsDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.app.DialogFragment; @@ -7,7 +7,7 @@ import android.support.v7.app.AlertDialog; import de.xikolo.R; -import de.xikolo.model.PermissionsModel; +import de.xikolo.managers.PermissionManager; public class PermissionsDialog extends DialogFragment { @@ -21,7 +21,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { .setPositiveButton(R.string.title_section_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - PermissionsModel.startAppInfo(getActivity()); + PermissionManager.startAppInfo(getActivity()); } }) .setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() { diff --git a/app/src/main/java/de/xikolo/controller/dialogs/ProgressDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/ProgressDialog.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/dialogs/ProgressDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/ProgressDialog.java index b78745373..cc1cd0c22 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/ProgressDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/ProgressDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.os.Bundle; diff --git a/app/src/main/java/de/xikolo/controller/dialogs/UnenrollDialog.java b/app/src/main/java/de/xikolo/controllers/dialogs/UnenrollDialog.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/dialogs/UnenrollDialog.java rename to app/src/main/java/de/xikolo/controllers/dialogs/UnenrollDialog.java index bc601b379..376a7a573 100644 --- a/app/src/main/java/de/xikolo/controller/dialogs/UnenrollDialog.java +++ b/app/src/main/java/de/xikolo/controllers/dialogs/UnenrollDialog.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.dialogs; +package de.xikolo.controllers.dialogs; import android.app.Dialog; import android.content.DialogInterface; diff --git a/app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java b/app/src/main/java/de/xikolo/controllers/downloads/DownloadsFragment.java similarity index 76% rename from app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java rename to app/src/main/java/de/xikolo/controllers/downloads/DownloadsFragment.java index 3153db006..40df1e289 100644 --- a/app/src/main/java/de/xikolo/controller/downloads/DownloadsFragment.java +++ b/app/src/main/java/de/xikolo/controllers/downloads/DownloadsFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.downloads; +package de.xikolo.controllers.downloads; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -18,16 +18,17 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.dialogs.ConfirmDeleteDialog; -import de.xikolo.controller.downloads.adapter.DownloadsAdapter; -import de.xikolo.controller.helper.NotificationController; -import de.xikolo.data.preferences.AppPreferences; -import de.xikolo.model.DownloadModel; -import de.xikolo.model.PermissionsModel; -import de.xikolo.model.events.PermissionDeniedEvent; -import de.xikolo.model.events.PermissionGrantedEvent; -import de.xikolo.util.FileUtil; -import de.xikolo.util.ToastUtil; +import de.xikolo.controllers.dialogs.ConfirmDeleteDialog; +import de.xikolo.controllers.downloads.adapter.DownloadsAdapter; +import de.xikolo.controllers.helper.NotificationController; +import de.xikolo.managers.DownloadManager; +import de.xikolo.managers.PermissionManager; +import de.xikolo.storages.preferences.ApplicationPreferences; +import de.xikolo.events.PermissionDeniedEvent; +import de.xikolo.events.PermissionGrantedEvent; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.FileUtil; +import de.xikolo.utils.ToastUtil; public class DownloadsFragment extends Fragment implements DownloadsAdapter.OnDeleteButtonClickedListener { @@ -35,9 +36,9 @@ public class DownloadsFragment extends Fragment implements DownloadsAdapter.OnDe private DownloadsAdapter adapter; - private DownloadModel downloadModel; + private DownloadManager downloadManager; - private PermissionsModel permissionsModel; + private PermissionManager permissionManager; private NotificationController notificationController; @@ -53,8 +54,8 @@ public static DownloadsFragment newInstance() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - downloadModel = new DownloadModel(GlobalApplication.getInstance().getJobManager(), getActivity()); - permissionsModel = new PermissionsModel(GlobalApplication.getInstance().getJobManager(), getActivity()); + downloadManager = new DownloadManager(GlobalApplication.getInstance().getJobManager(), getActivity()); + permissionManager = new PermissionManager(GlobalApplication.getInstance().getJobManager(), getActivity()); adapter = new DownloadsAdapter(this); EventBus.getDefault().register(this); @@ -87,7 +88,7 @@ public void onStart() { @SuppressWarnings("unused") @Subscribe public void onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEvent) { - if (permissionGrantedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { + if (permissionGrantedEvent.getRequestCode() == PermissionManager.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { fetchItems(); } } @@ -95,26 +96,26 @@ public void onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEve @SuppressWarnings("unused") @Subscribe public void onPermissionDeniedEvent(PermissionDeniedEvent permissionDeniedEvent) { - if (permissionDeniedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { + if (permissionDeniedEvent.getRequestCode() == PermissionManager.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { fetchItems(); } } private void fetchItems() { - if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionManager.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { notificationController.setInvisible(); adapter.clear(); List list = new ArrayList<>(); - DownloadsAdapter.FolderItem total = new DownloadsAdapter.FolderItem(downloadModel.getAppFolder().substring(downloadModel.getAppFolder().lastIndexOf(File.separator) + 1), - downloadModel.getAppFolder()); + DownloadsAdapter.FolderItem total = new DownloadsAdapter.FolderItem(downloadManager.getAppFolder().substring(downloadManager.getAppFolder().lastIndexOf(File.separator) + 1), + downloadManager.getAppFolder()); list.add(total); adapter.addItem(getString(R.string.overall), list); - List folders = downloadModel.getFoldersWithDownloads(); + List folders = downloadManager.getFoldersWithDownloads(); if (folders.size() > 0) { list = new ArrayList<>(); for (String folder : folders) { @@ -130,7 +131,7 @@ private void fetchItems() { notificationController.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - PermissionsModel.startAppInfo(getActivity()); + PermissionManager.startAppInfo(getActivity()); } }); notificationController.setNotificationVisible(true); @@ -139,7 +140,7 @@ public void onClick(View v) { @Override public void onDeleteButtonClicked(final DownloadsAdapter.FolderItem item) { - final AppPreferences appPreferences = GlobalApplication.getInstance().getPreferencesFactory().getAppPreferences(); + final ApplicationPreferences appPreferences = (ApplicationPreferences) GlobalApplication.getStorage(StorageType.APP); if (appPreferences.confirmBeforeDeleting()) { ConfirmDeleteDialog dialog = ConfirmDeleteDialog.getInstance(true); diff --git a/app/src/main/java/de/xikolo/controller/downloads/adapter/DownloadsAdapter.java b/app/src/main/java/de/xikolo/controllers/downloads/adapter/DownloadsAdapter.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/downloads/adapter/DownloadsAdapter.java rename to app/src/main/java/de/xikolo/controllers/downloads/adapter/DownloadsAdapter.java index 4a8d1430b..015acad83 100644 --- a/app/src/main/java/de/xikolo/controller/downloads/adapter/DownloadsAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/downloads/adapter/DownloadsAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.downloads.adapter; +package de.xikolo.controllers.downloads.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; @@ -12,8 +12,8 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.util.FileUtil; -import de.xikolo.util.HeaderAndSectionsList; +import de.xikolo.utils.FileUtil; +import de.xikolo.utils.HeaderAndSectionsList; public class DownloadsAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/de/xikolo/controller/exceptions/WrongParameterException.java b/app/src/main/java/de/xikolo/controllers/exceptions/WrongParameterException.java similarity index 85% rename from app/src/main/java/de/xikolo/controller/exceptions/WrongParameterException.java rename to app/src/main/java/de/xikolo/controllers/exceptions/WrongParameterException.java index 366e719c9..ffbe4bff2 100644 --- a/app/src/main/java/de/xikolo/controller/exceptions/WrongParameterException.java +++ b/app/src/main/java/de/xikolo/controllers/exceptions/WrongParameterException.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.exceptions; +package de.xikolo.controllers.exceptions; public class WrongParameterException extends RuntimeException { diff --git a/app/src/main/java/de/xikolo/controller/helper/CacheController.java b/app/src/main/java/de/xikolo/controllers/helper/CacheController.java similarity index 93% rename from app/src/main/java/de/xikolo/controller/helper/CacheController.java rename to app/src/main/java/de/xikolo/controllers/helper/CacheController.java index 15a3722f4..1afd50174 100644 --- a/app/src/main/java/de/xikolo/controller/helper/CacheController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/CacheController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.content.Context; import android.os.Bundle; @@ -13,10 +13,10 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.ModuleActivity; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; +import de.xikolo.controllers.ModuleActivity; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; public class CacheController { diff --git a/app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java b/app/src/main/java/de/xikolo/controllers/helper/EnrollmentController.java similarity index 70% rename from app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java rename to app/src/main/java/de/xikolo/controllers/helper/EnrollmentController.java index a3d3c3c76..3a25d35f4 100644 --- a/app/src/main/java/de/xikolo/controller/helper/EnrollmentController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/EnrollmentController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.support.v4.app.FragmentActivity; @@ -6,18 +6,18 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.dialogs.ProgressDialog; -import de.xikolo.data.entities.Course; -import de.xikolo.model.CourseModel; -import de.xikolo.model.Result; -import de.xikolo.model.events.UnenrollEvent; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; +import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.managers.CourseManager; +import de.xikolo.models.Course; +import de.xikolo.managers.Result; +import de.xikolo.events.UnenrollEvent; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; public class EnrollmentController { public static void unenroll(final FragmentActivity activity, Course course) { - CourseModel model = new CourseModel(GlobalApplication.getInstance().getJobManager()); + CourseManager courseManager = new CourseManager(GlobalApplication.getInstance().getJobManager()); final ProgressDialog progressDialog = ProgressDialog.getInstance(); Result result = new Result() { @Override @@ -38,7 +38,7 @@ protected void onError(ErrorCode errorCode) { } }; progressDialog.show(activity.getSupportFragmentManager(), ProgressDialog.TAG); - model.deleteEnrollment(result, course); + courseManager.deleteEnrollment(result, course); } } diff --git a/app/src/main/java/de/xikolo/controller/helper/ImageController.java b/app/src/main/java/de/xikolo/controllers/helper/ImageController.java similarity index 99% rename from app/src/main/java/de/xikolo/controller/helper/ImageController.java rename to app/src/main/java/de/xikolo/controllers/helper/ImageController.java index 79d945fbb..547051289 100644 --- a/app/src/main/java/de/xikolo/controller/helper/ImageController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/ImageController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.graphics.Bitmap; import android.support.v4.graphics.drawable.RoundedBitmapDrawable; diff --git a/app/src/main/java/de/xikolo/controller/helper/ModuleDownloadController.java b/app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java similarity index 73% rename from app/src/main/java/de/xikolo/controller/helper/ModuleDownloadController.java rename to app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java index 72886542d..6d96182ce 100644 --- a/app/src/main/java/de/xikolo/controller/helper/ModuleDownloadController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java @@ -1,22 +1,23 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import de.xikolo.GlobalApplication; -import de.xikolo.controller.dialogs.MobileDownloadDialog; -import de.xikolo.controller.dialogs.ModuleDownloadDialog; -import de.xikolo.controller.dialogs.ProgressDialog; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.preferences.AppPreferences; -import de.xikolo.model.DownloadModel; -import de.xikolo.model.ItemModel; -import de.xikolo.model.Result; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.NetworkUtil; +import de.xikolo.controllers.dialogs.MobileDownloadDialog; +import de.xikolo.controllers.dialogs.ModuleDownloadDialog; +import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.managers.DownloadManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.storages.preferences.ApplicationPreferences; +import de.xikolo.managers.ItemManager; +import de.xikolo.managers.Result; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.NetworkUtil; public class ModuleDownloadController { @@ -30,12 +31,12 @@ public class ModuleDownloadController { private GlobalApplication application; - private DownloadModel downloadModel; + private DownloadManager downloadManager; public ModuleDownloadController(FragmentActivity activity) { this.application = GlobalApplication.getInstance(); this.activity = activity; - this.downloadModel = new DownloadModel(application.getJobManager(), activity); + this.downloadManager = new DownloadManager(application.getJobManager(), activity); } public void initModuleDownloads(final Course course, final Module module) { @@ -47,7 +48,7 @@ public void onDialogPositiveClick(DialogFragment dialog, boolean hdVideo, boolea ModuleDownloadController.this.sdVideo = sdVideo; ModuleDownloadController.this.slides = slides; - final AppPreferences appPreferences = GlobalApplication.getInstance().getPreferencesFactory().getAppPreferences(); + final ApplicationPreferences appPreferences = (ApplicationPreferences) GlobalApplication.getStorage(StorageType.APP); if (hdVideo || sdVideo || slides) { if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { @@ -75,7 +76,7 @@ public void onDialogPositiveClick(DialogFragment dialog) { } private void startModuleDownloads(final Course course, final Module module) { - ItemModel itemModel = new ItemModel(application.getJobManager()); + ItemManager itemModel = new ItemManager(application.getJobManager()); LanalyticsUtil.trackDownloadedSection(module.id, course.id, hdVideo, sdVideo, slides); @@ -94,15 +95,15 @@ protected void onSuccess(Item result, DataSource dataSource) { if (dataSource == DataSource.NETWORK) { dialog.dismiss(); if (sdVideo) { - startDownload(video.detail.stream.sd_url, DownloadModel.DownloadFileType.VIDEO_SD, + startDownload(video.detail.stream.sd_url, DownloadManager.DownloadFileType.VIDEO_SD, course, module, result); } if (hdVideo) { - startDownload(video.detail.stream.hd_url, DownloadModel.DownloadFileType.VIDEO_HD, + startDownload(video.detail.stream.hd_url, DownloadManager.DownloadFileType.VIDEO_HD, course, module, result); } if (slides) { - startDownload(video.detail.slides_url, DownloadModel.DownloadFileType.SLIDES, + startDownload(video.detail.slides_url, DownloadManager.DownloadFileType.SLIDES, course, module, result); } } @@ -118,11 +119,11 @@ protected void onSuccess(Item result, DataSource dataSource) { } - private void startDownload(String uri, DownloadModel.DownloadFileType downloadFileType, Course course, Module module, Item item) { + private void startDownload(String uri, DownloadManager.DownloadFileType downloadFileType, Course course, Module module, Item item) { if (uri != null - && !downloadModel.downloadExists(downloadFileType, course, module, item) - && !downloadModel.downloadRunning(downloadFileType, course, module, item)) { - downloadModel.startDownload(uri, downloadFileType, course, module, item); + && !downloadManager.downloadExists(downloadFileType, course, module, item) + && !downloadManager.downloadRunning(downloadFileType, course, module, item)) { + downloadManager.startDownload(uri, downloadFileType, course, module, item); } } diff --git a/app/src/main/java/de/xikolo/controller/helper/NotificationController.java b/app/src/main/java/de/xikolo/controllers/helper/NotificationController.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/helper/NotificationController.java rename to app/src/main/java/de/xikolo/controllers/helper/NotificationController.java index 9f0b21bde..91cf8ddc8 100644 --- a/app/src/main/java/de/xikolo/controller/helper/NotificationController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/NotificationController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.view.View; import android.widget.FrameLayout; @@ -7,7 +7,7 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.view.CustomFontTextView; +import de.xikolo.views.CustomFontTextView; @SuppressWarnings("unused") public class NotificationController { diff --git a/app/src/main/java/de/xikolo/controller/helper/RefeshLayoutController.java b/app/src/main/java/de/xikolo/controllers/helper/RefeshLayoutController.java similarity index 91% rename from app/src/main/java/de/xikolo/controller/helper/RefeshLayoutController.java rename to app/src/main/java/de/xikolo/controllers/helper/RefeshLayoutController.java index ed9af90d7..e46ba0465 100644 --- a/app/src/main/java/de/xikolo/controller/helper/RefeshLayoutController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/RefeshLayoutController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.support.v4.widget.SwipeRefreshLayout; diff --git a/app/src/main/java/de/xikolo/controller/helper/VideoController.java b/app/src/main/java/de/xikolo/controllers/helper/VideoController.java similarity index 93% rename from app/src/main/java/de/xikolo/controller/helper/VideoController.java rename to app/src/main/java/de/xikolo/controllers/helper/VideoController.java index 563f84b98..f6e0ff28e 100644 --- a/app/src/main/java/de/xikolo/controller/helper/VideoController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/VideoController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.annotation.TargetApi; import android.app.Activity; @@ -20,19 +20,20 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.preferences.AppPreferences; -import de.xikolo.model.DownloadModel; -import de.xikolo.util.Config; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.PlaybackSpeed; -import de.xikolo.util.ToastUtil; -import de.xikolo.view.CustomFontTextView; -import de.xikolo.view.CustomSizeVideoView; +import de.xikolo.managers.DownloadManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.storages.preferences.ApplicationPreferences; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.Config; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.PlaybackSpeed; +import de.xikolo.utils.ToastUtil; +import de.xikolo.views.CustomFontTextView; +import de.xikolo.views.CustomSizeVideoView; public class VideoController { @@ -45,7 +46,7 @@ public class VideoController { private static final int PLAYBACK_PARAMS_SDK_LEVEL = 23; - private DownloadModel downloadModel; + private DownloadManager downloadModel; private Activity activity; @@ -127,7 +128,7 @@ public boolean onTouch(View v, MotionEvent event) { } }); - downloadModel = new DownloadModel(GlobalApplication.getInstance().getJobManager(), activity); + downloadModel = new DownloadManager(GlobalApplication.getInstance().getJobManager(), activity); setupView(); } @@ -531,20 +532,20 @@ public void setupVideo(Course course, Module module, Item video videoItemDetails = video; int connectivityStatus = NetworkUtil.getConnectivityStatus(activity); - AppPreferences preferences = GlobalApplication.getInstance().getPreferencesFactory().getAppPreferences(); + ApplicationPreferences appPreferences = (ApplicationPreferences) GlobalApplication.getStorage(StorageType.APP); - if (videoDownloadPresent(DownloadModel.DownloadFileType.VIDEO_HD, course, module, video)) { // hd video download available + if (videoDownloadPresent(DownloadManager.DownloadFileType.VIDEO_HD, course, module, video)) { // hd video download available videoMode = VideoMode.HD; - } else if (videoDownloadPresent(DownloadModel.DownloadFileType.VIDEO_SD, course, module, video)) { // sd video download available + } else if (videoDownloadPresent(DownloadManager.DownloadFileType.VIDEO_SD, course, module, video)) { // sd video download available videoMode = VideoMode.SD; - } else if (connectivityStatus == NetworkUtil.TYPE_WIFI || !preferences.isVideoQualityLimitedOnMobile()) { + } else if (connectivityStatus == NetworkUtil.TYPE_WIFI || !appPreferences.isVideoQualityLimitedOnMobile()) { videoMode = VideoMode.HD; } else { videoMode = VideoMode.SD; } if (Build.VERSION.SDK_INT >= PLAYBACK_PARAMS_SDK_LEVEL) { - currentPlaybackSpeed = preferences.getVideoPlaybackSpeed(); + currentPlaybackSpeed = appPreferences.getVideoPlaybackSpeed(); } updateVideo(course, module, videoItemDetails); @@ -552,16 +553,16 @@ public void setupVideo(Course course, Module module, Item video private void updateVideo(Course course, Module module, Item video) { String stream; - DownloadModel.DownloadFileType fileType; + DownloadManager.DownloadFileType fileType; viewVideoWarning.setVisibility(View.GONE); if (videoMode == VideoMode.HD) { stream = video.detail.stream.hd_url; - fileType = DownloadModel.DownloadFileType.VIDEO_HD; + fileType = DownloadManager.DownloadFileType.VIDEO_HD; } else { stream = video.detail.stream.sd_url; - fileType = DownloadModel.DownloadFileType.VIDEO_SD; + fileType = DownloadManager.DownloadFileType.VIDEO_SD; } viewOfflineHint.setVisibility(View.GONE); @@ -581,12 +582,12 @@ private void updateVideo(Course course, Module module, Item vid updateHdSwitchColor(); } - private boolean videoDownloadPresent(DownloadModel.DownloadFileType fileType, Course course, Module module, Item video) { + private boolean videoDownloadPresent(DownloadManager.DownloadFileType fileType, Course course, Module module, Item video) { return !downloadModel.downloadRunning(fileType, course, module, video) && downloadModel.downloadExists(fileType, course, module, video); } - private void setLocalVideoURI(DownloadModel.DownloadFileType fileType, Course course, Module module, Item video) { + private void setLocalVideoURI(DownloadManager.DownloadFileType fileType, Course course, Module module, Item video) { setVideoURI("file://" + downloadModel.getDownloadFile(fileType, course, module, video).getAbsolutePath()); viewOfflineHint.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/de/xikolo/controller/helper/WebViewController.java b/app/src/main/java/de/xikolo/controllers/helper/WebViewController.java similarity index 92% rename from app/src/main/java/de/xikolo/controller/helper/WebViewController.java rename to app/src/main/java/de/xikolo/controllers/helper/WebViewController.java index a05cc328f..aa20ea8ad 100644 --- a/app/src/main/java/de/xikolo/controller/helper/WebViewController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/WebViewController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.helper; +package de.xikolo.controllers.helper; import android.annotation.TargetApi; import android.content.Context; @@ -25,11 +25,11 @@ import java.util.Map; import de.xikolo.R; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; +import de.xikolo.managers.UserManager; +import de.xikolo.utils.Config; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; public class WebViewController implements SwipeRefreshLayout.OnRefreshListener { @@ -114,9 +114,9 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { request(url, true); } else { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - if (url.contains(Config.HOST) && UserModel.isLoggedIn(context)) { + if (url.contains(Config.HOST) && UserManager.isLoggedIn()) { Bundle headers = new Bundle(); - headers.putString(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserModel.getToken(context)); + headers.putString(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserManager.getToken()); i.putExtra(Browser.EXTRA_HEADERS, headers); } context.startActivity(i); @@ -153,8 +153,8 @@ public void request(String url, boolean userRequest) { if (url.contains(Config.HOST)) { Map header = new HashMap<>(); header.put(Config.HEADER_USER_PLATFORM, Config.HEADER_USER_PLATFORM_VALUE); - if (UserModel.isLoggedIn(context)) { - header.put(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserModel.getToken(context)); + if (UserManager.isLoggedIn()) { + header.put(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserManager.getToken()); } // lanalytics context data cookie diff --git a/app/src/main/java/de/xikolo/controller/main/ContentFragment.java b/app/src/main/java/de/xikolo/controllers/main/ContentFragment.java similarity index 93% rename from app/src/main/java/de/xikolo/controller/main/ContentFragment.java rename to app/src/main/java/de/xikolo/controllers/main/ContentFragment.java index 1c5558070..5dc354b64 100644 --- a/app/src/main/java/de/xikolo/controller/main/ContentFragment.java +++ b/app/src/main/java/de/xikolo/controllers/main/ContentFragment.java @@ -1,8 +1,8 @@ -package de.xikolo.controller.main; +package de.xikolo.controllers.main; import android.content.Context; -import de.xikolo.controller.BaseFragment; +import de.xikolo.controllers.BaseFragment; public abstract class ContentFragment extends BaseFragment { diff --git a/app/src/main/java/de/xikolo/controller/main/ContentWebViewFragment.java b/app/src/main/java/de/xikolo/controllers/main/ContentWebViewFragment.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/main/ContentWebViewFragment.java rename to app/src/main/java/de/xikolo/controllers/main/ContentWebViewFragment.java index d98d4cd08..11e7e57e2 100644 --- a/app/src/main/java/de/xikolo/controller/main/ContentWebViewFragment.java +++ b/app/src/main/java/de/xikolo/controllers/main/ContentWebViewFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.main; +package de.xikolo.controllers.main; import android.content.MutableContextWrapper; import android.os.Bundle; @@ -12,7 +12,7 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.helper.WebViewController; +import de.xikolo.controllers.helper.WebViewController; public class ContentWebViewFragment extends ContentFragment { diff --git a/app/src/main/java/de/xikolo/controller/main/CourseListFragment.java b/app/src/main/java/de/xikolo/controllers/main/CourseListFragment.java similarity index 90% rename from app/src/main/java/de/xikolo/controller/main/CourseListFragment.java rename to app/src/main/java/de/xikolo/controllers/main/CourseListFragment.java index 260ec7c5f..79f77edc5 100644 --- a/app/src/main/java/de/xikolo/controller/main/CourseListFragment.java +++ b/app/src/main/java/de/xikolo/controllers/main/CourseListFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.main; +package de.xikolo.controllers.main; import android.content.Intent; import android.os.Bundle; @@ -20,26 +20,26 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.CourseActivity; -import de.xikolo.controller.CourseDetailsActivity; -import de.xikolo.controller.dialogs.ProgressDialog; -import de.xikolo.controller.helper.NotificationController; -import de.xikolo.controller.helper.RefeshLayoutController; -import de.xikolo.controller.main.adapter.CourseListAdapter; -import de.xikolo.controller.navigation.adapter.NavigationAdapter; -import de.xikolo.data.entities.Course; -import de.xikolo.model.CourseModel; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.model.events.EnrollEvent; -import de.xikolo.model.events.LoginEvent; -import de.xikolo.model.events.LogoutEvent; -import de.xikolo.model.events.UnenrollEvent; -import de.xikolo.util.DateUtil; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; -import de.xikolo.view.AutofitRecyclerView; -import de.xikolo.view.SpaceItemDecoration; +import de.xikolo.controllers.CourseActivity; +import de.xikolo.controllers.CourseDetailsActivity; +import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.controllers.helper.NotificationController; +import de.xikolo.controllers.helper.RefeshLayoutController; +import de.xikolo.controllers.main.adapter.CourseListAdapter; +import de.xikolo.controllers.navigation.adapter.NavigationAdapter; +import de.xikolo.managers.CourseManager; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Course; +import de.xikolo.managers.Result; +import de.xikolo.events.EnrollEvent; +import de.xikolo.events.LoginEvent; +import de.xikolo.events.LogoutEvent; +import de.xikolo.events.UnenrollEvent; +import de.xikolo.utils.DateUtil; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; +import de.xikolo.views.AutofitRecyclerView; +import de.xikolo.views.SpaceItemDecoration; public class CourseListFragment extends ContentFragment implements SwipeRefreshLayout.OnRefreshListener, CourseListAdapter.OnCourseButtonClickListener { @@ -63,7 +63,7 @@ public class CourseListFragment extends ContentFragment implements SwipeRefreshL private List courses; - private CourseModel courseModel; + private CourseManager courseManager; public CourseListFragment() { // Required empty public constructor @@ -89,7 +89,7 @@ public void onCreate(Bundle savedInstanceState) { } setHasOptionsMenu(true); - courseModel = new CourseModel(jobManager); + courseManager = new CourseManager(jobManager); EventBus.getDefault().register(this); } @@ -141,7 +141,7 @@ protected void onError(ErrorCode errorCode) { } }; - if (isMyCoursesFilter() && !UserModel.isLoggedIn(getActivity())) { + if (isMyCoursesFilter() && !UserManager.isLoggedIn()) { courses = null; notificationController.setTitle(R.string.notification_please_login); @@ -161,9 +161,9 @@ public void onClick(View v) { refreshLayout.setRefreshing(true); } if (isMyCoursesFilter()) { - courseModel.getCourses(result, includeProgress, CourseModel.CourseFilter.MY); + courseManager.getCourses(result, includeProgress, CourseManager.CourseFilter.MY); } else { - courseModel.getCourses(result, includeProgress); + courseManager.getCourses(result, includeProgress); } } } @@ -185,9 +185,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, RefeshLayoutController.setup(refreshLayout, this); if (isAllCoursesFilter()) { - courseListAdapter = new CourseListAdapter(this, CourseModel.CourseFilter.ALL); + courseListAdapter = new CourseListAdapter(this, CourseManager.CourseFilter.ALL); } else if (isMyCoursesFilter()) { - courseListAdapter = new CourseListAdapter(this, CourseModel.CourseFilter.MY); + courseListAdapter = new CourseListAdapter(this, CourseManager.CourseFilter.MY); } recyclerView = (AutofitRecyclerView) layout.findViewById(R.id.recyclerView); @@ -247,7 +247,7 @@ public void onStart() { private void updateView() { if (isAdded()) { - if (isMyCoursesFilter() && !UserModel.isLoggedIn(getActivity())) { + if (isMyCoursesFilter() && !UserManager.isLoggedIn()) { courses = null; notificationController.setTitle(R.string.notification_please_login); @@ -317,7 +317,7 @@ protected void onError(ErrorCode errorCode) { } }; dialog.show(getChildFragmentManager(), ProgressDialog.TAG); - courseModel.addEnrollment(result, course); + courseManager.addEnrollment(result, course); } private boolean isMyCoursesFilter() { @@ -330,7 +330,7 @@ private boolean isAllCoursesFilter() { @Override public void onEnterButtonClicked(Course course) { - if (UserModel.isLoggedIn(getActivity())) { + if (UserManager.isLoggedIn()) { Intent intent = new Intent(getActivity(), CourseActivity.class); Bundle b = new Bundle(); b.putParcelable(CourseActivity.ARG_COURSE, course); diff --git a/app/src/main/java/de/xikolo/controller/main/ProfileFragment.java b/app/src/main/java/de/xikolo/controllers/main/ProfileFragment.java similarity index 84% rename from app/src/main/java/de/xikolo/controller/main/ProfileFragment.java rename to app/src/main/java/de/xikolo/controllers/main/ProfileFragment.java index eaeb30e14..5d2c7fe6b 100644 --- a/app/src/main/java/de/xikolo/controller/main/ProfileFragment.java +++ b/app/src/main/java/de/xikolo/controllers/main/ProfileFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.main; +package de.xikolo.controllers.main; import android.content.res.Configuration; import android.graphics.Point; @@ -14,17 +14,17 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.controller.helper.ImageController; -import de.xikolo.controller.helper.NotificationController; -import de.xikolo.controller.navigation.adapter.NavigationAdapter; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.User; -import de.xikolo.model.CourseModel; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; -import de.xikolo.view.CustomSizeImageView; +import de.xikolo.controllers.helper.ImageController; +import de.xikolo.controllers.helper.NotificationController; +import de.xikolo.controllers.navigation.adapter.NavigationAdapter; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Course; +import de.xikolo.models.User; +import de.xikolo.managers.CourseManager; +import de.xikolo.managers.Result; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; +import de.xikolo.views.CustomSizeImageView; public class ProfileFragment extends ContentFragment { @@ -32,8 +32,8 @@ public class ProfileFragment extends ContentFragment { private static final String ARG_COURSES = "arg_courses"; - private UserModel userModel; - private CourseModel courseModel; + private UserManager userManager; + private CourseManager courseManager; private Result> coursesResult; private Result userResult; @@ -71,7 +71,7 @@ public void onCreate(Bundle savedInstanceState) { courses = savedInstanceState.getParcelableArrayList(ARG_COURSES); } - courseModel = new CourseModel(jobManager); + courseManager = new CourseManager(jobManager); coursesResult = new Result>() { @Override protected void onSuccess(List result, DataSource dataSource) { @@ -86,7 +86,7 @@ protected void onError(ErrorCode errorCode) { } }; - userModel = new UserModel(jobManager); + userManager = new UserManager(jobManager); userResult = new Result() { @Override protected void onSuccess(User result, DataSource dataSource) { @@ -127,11 +127,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, public void onStart() { super.onStart(); - if (UserModel.isLoggedIn(getActivity())) { + if (UserManager.isLoggedIn()) { showHeader(); if (courses == null) { - userModel.getUser(userResult); - courseModel.getCourses(coursesResult, false); + userManager.getUser(userResult); + courseManager.getCourses(coursesResult, false); } else { showCoursesProgress(courses); } @@ -143,7 +143,7 @@ public void onStart() { private void updateLayout() { notificationController.setProgressVisible(false); showHeader(); - showUser(UserModel.getSavedUser(getActivity())); + showUser(UserManager.getSavedUser()); setProfilePicMargin(); } @@ -178,7 +178,7 @@ private void showUser(User user) { textEmail.setText(user.email); - textEnrollCounts.setText(String.valueOf(courseModel.getEnrollmentsCount())); + textEnrollCounts.setText(String.valueOf(courseManager.getEnrollmentsCount())); } private void setProfilePicMargin() { @@ -188,13 +188,13 @@ private void setProfilePicMargin() { } private void showHeader() { - User user = UserModel.getSavedUser(getActivity()); + User user = UserManager.getSavedUser(); activityCallback.onFragmentAttached(NavigationAdapter.NAV_PROFILE.getPosition(), user.first_name + " " + user.last_name); } private void showCoursesProgress(List courses) { this.courses = courses; - textEnrollCounts.setText(String.valueOf(courseModel.getEnrollmentsCount())); + textEnrollCounts.setText(String.valueOf(courseManager.getEnrollmentsCount())); if (activityCallback != null) { activityCallback.updateDrawer(); } diff --git a/app/src/main/java/de/xikolo/controller/main/adapter/CourseListAdapter.java b/app/src/main/java/de/xikolo/controllers/main/adapter/CourseListAdapter.java similarity index 91% rename from app/src/main/java/de/xikolo/controller/main/adapter/CourseListAdapter.java rename to app/src/main/java/de/xikolo/controllers/main/adapter/CourseListAdapter.java index 4930da00c..82b12fb43 100644 --- a/app/src/main/java/de/xikolo/controller/main/adapter/CourseListAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/main/adapter/CourseListAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.main.adapter; +package de.xikolo.controllers.main.adapter; import android.content.Context; import android.support.v4.content.ContextCompat; @@ -17,13 +17,13 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.helper.ImageController; -import de.xikolo.data.entities.Course; -import de.xikolo.model.CourseModel; -import de.xikolo.util.DateUtil; -import de.xikolo.util.DisplayUtil; -import de.xikolo.util.HeaderAndSectionsList; -import de.xikolo.util.LanguageUtil; +import de.xikolo.controllers.helper.ImageController; +import de.xikolo.managers.CourseManager; +import de.xikolo.models.Course; +import de.xikolo.utils.DateUtil; +import de.xikolo.utils.DisplayUtil; +import de.xikolo.utils.HeaderAndSectionsList; +import de.xikolo.utils.LanguageUtil; public class CourseListAdapter extends RecyclerView.Adapter { @@ -32,13 +32,13 @@ public class CourseListAdapter extends RecyclerView.Adapter> headerAndSectionsList; private OnCourseButtonClickListener callback; - public CourseListAdapter(OnCourseButtonClickListener callback, CourseModel.CourseFilter courseFilter) { + public CourseListAdapter(OnCourseButtonClickListener callback, CourseManager.CourseFilter courseFilter) { this.headerAndSectionsList = new HeaderAndSectionsList<>(); this.callback = callback; this.courseFilter = courseFilter; @@ -56,24 +56,24 @@ public void updateCourses(List courses) { headerAndSectionsList.clear(); List subList; if (courses.size() > 0) { - if (courseFilter == CourseModel.CourseFilter.ALL) { - subList = CourseModel.getCurrentAndFutureCourses(courses); + if (courseFilter == CourseManager.CourseFilter.ALL) { + subList = CourseManager.getCurrentAndFutureCourses(courses); if (subList.size() > 0) { headerAndSectionsList.add(context.getString(R.string.header_current_courses), subList); } - subList = CourseModel.getPastCourses(courses); + subList = CourseManager.getPastCourses(courses); if (subList.size() > 0) { headerAndSectionsList.add(context.getString(R.string.header_self_paced_courses), subList); } - } else if (courseFilter == CourseModel.CourseFilter.MY) { - subList = CourseModel.getCurrentAndPastCourses(courses); + } else if (courseFilter == CourseManager.CourseFilter.MY) { + subList = CourseManager.getCurrentAndPastCourses(courses); if (subList.size() > 0) { headerAndSectionsList.add(context.getString(R.string.header_my_current_courses), subList); } - subList = CourseModel.getFutureCourses(courses); + subList = CourseManager.getFutureCourses(courses); if (subList.size() > 0) { headerAndSectionsList.add(context.getString(R.string.header_my_future_courses), subList); @@ -150,7 +150,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { viewHolder.textTeacher.setText(course.lecturer); viewHolder.textLanguage.setText(LanguageUtil.languageForCode(context, course.language)); - if (courseFilter == CourseModel.CourseFilter.ALL) { + if (courseFilter == CourseManager.CourseFilter.ALL) { viewHolder.textDescription.setText(course.description); viewHolder.textDescription.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/xikolo/controller/module/ItemWebViewFragment.java b/app/src/main/java/de/xikolo/controllers/module/ItemWebViewFragment.java similarity index 93% rename from app/src/main/java/de/xikolo/controller/module/ItemWebViewFragment.java rename to app/src/main/java/de/xikolo/controllers/module/ItemWebViewFragment.java index 76efb70e3..76f9504a9 100644 --- a/app/src/main/java/de/xikolo/controller/module/ItemWebViewFragment.java +++ b/app/src/main/java/de/xikolo/controllers/module/ItemWebViewFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.module; +package de.xikolo.controllers.module; import android.content.MutableContextWrapper; import android.os.Bundle; @@ -11,11 +11,11 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.helper.WebViewController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.util.Config; +import de.xikolo.controllers.helper.WebViewController; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.utils.Config; public class ItemWebViewFragment extends PagerFragment { diff --git a/app/src/main/java/de/xikolo/controller/module/PagerFragment.java b/app/src/main/java/de/xikolo/controllers/module/PagerFragment.java similarity index 83% rename from app/src/main/java/de/xikolo/controller/module/PagerFragment.java rename to app/src/main/java/de/xikolo/controllers/module/PagerFragment.java index b16ddc06c..78f1721ec 100644 --- a/app/src/main/java/de/xikolo/controller/module/PagerFragment.java +++ b/app/src/main/java/de/xikolo/controllers/module/PagerFragment.java @@ -1,12 +1,12 @@ -package de.xikolo.controller.module; +package de.xikolo.controllers.module; import android.os.Bundle; -import de.xikolo.controller.BaseFragment; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.ItemDetail; -import de.xikolo.data.entities.Module; +import de.xikolo.controllers.BaseFragment; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.ItemDetail; +import de.xikolo.models.Module; public abstract class PagerFragment extends BaseFragment { diff --git a/app/src/main/java/de/xikolo/controller/module/VideoFragment.java b/app/src/main/java/de/xikolo/controllers/module/VideoFragment.java similarity index 87% rename from app/src/main/java/de/xikolo/controller/module/VideoFragment.java rename to app/src/main/java/de/xikolo/controllers/module/VideoFragment.java index 5f747c271..ab2b7cd1e 100644 --- a/app/src/main/java/de/xikolo/controller/module/VideoFragment.java +++ b/app/src/main/java/de/xikolo/controllers/module/VideoFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.module; +package de.xikolo.controllers.module; import android.content.Intent; import android.content.res.Configuration; @@ -12,23 +12,23 @@ import android.widget.TextView; import de.xikolo.R; -import de.xikolo.controller.VideoActivity; -import de.xikolo.controller.helper.CacheController; -import de.xikolo.controller.helper.ImageController; -import de.xikolo.controller.helper.NotificationController; -import de.xikolo.controller.module.helper.DownloadViewController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.model.DownloadModel; -import de.xikolo.model.ItemModel; -import de.xikolo.model.Result; -import de.xikolo.util.CastUtil; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.NetworkUtil; -import de.xikolo.util.ToastUtil; -import de.xikolo.view.CustomSizeImageView; +import de.xikolo.controllers.VideoActivity; +import de.xikolo.controllers.helper.CacheController; +import de.xikolo.controllers.helper.ImageController; +import de.xikolo.controllers.helper.NotificationController; +import de.xikolo.controllers.module.helper.DownloadViewController; +import de.xikolo.managers.ItemManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.managers.DownloadManager; +import de.xikolo.managers.Result; +import de.xikolo.utils.CastUtil; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.utils.ToastUtil; +import de.xikolo.views.CustomSizeImageView; public class VideoFragment extends PagerFragment { @@ -43,7 +43,7 @@ public class VideoFragment extends PagerFragment { private NotificationController notificationController; - private ItemModel itemModel; + private ItemManager itemManager; public VideoFragment() { @@ -57,7 +57,7 @@ public static PagerFragment newInstance(Course course, Module module, Item item) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - itemModel = new ItemModel(jobManager); + itemManager = new ItemManager(jobManager); } @Override @@ -163,7 +163,7 @@ protected void onWarning(WarnCode warnCode) { viewContainer.setVisibility(View.GONE); notificationController.setProgressVisible(true); - itemModel.getItemDetail(result, course, module, item, Item.TYPE_VIDEO); + itemManager.getItemDetail(result, course, module, item, Item.TYPE_VIDEO); } private void setupView() { @@ -188,13 +188,13 @@ private void setupView() { textTitle.setText(item.detail.title); linearLayoutDownloads.removeAllViews(); - DownloadViewController hdVideo = new DownloadViewController(getActivity(), DownloadModel.DownloadFileType.VIDEO_HD, course, module, item); + DownloadViewController hdVideo = new DownloadViewController(getActivity(), DownloadManager.DownloadFileType.VIDEO_HD, course, module, item); linearLayoutDownloads.addView(hdVideo.getLayout()); - DownloadViewController sdVideo = new DownloadViewController(getActivity(), DownloadModel.DownloadFileType.VIDEO_SD, course, module, item); + DownloadViewController sdVideo = new DownloadViewController(getActivity(), DownloadManager.DownloadFileType.VIDEO_SD, course, module, item); linearLayoutDownloads.addView(sdVideo.getLayout()); - DownloadViewController slides = new DownloadViewController(getActivity(), DownloadModel.DownloadFileType.SLIDES, course, module, item); + DownloadViewController slides = new DownloadViewController(getActivity(), DownloadManager.DownloadFileType.SLIDES, course, module, item); linearLayoutDownloads.addView(slides.getLayout()); -// DownloadViewController transcript = new DownloadViewController(getActivity(), DownloadModel.DownloadFileType.TRANSCRIPT, course, module, item); +// DownloadViewController transcript = new DownloadViewController(getActivity(), DownloadManager.DownloadFileType.TRANSCRIPT, course, module, item); // linearLayoutDownloads.addView(transcript.getLayout()); if (item.detail.minutes != null && item.detail.seconds != null) { @@ -207,7 +207,7 @@ private void setupView() { @Override public void onClick(View v) { if (videoCastManager.isConnected()) { - itemModel.getLocalVideoProgress(new Result() { + itemManager.getLocalVideoProgress(new Result() { @Override protected void onSuccess(VideoItemDetail result, DataSource dataSource) { LanalyticsUtil.trackVideoPlay(item.id, course.id, module.id, result.progress, 1.0f, diff --git a/app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java b/app/src/main/java/de/xikolo/controllers/module/helper/DownloadViewController.java similarity index 85% rename from app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java rename to app/src/main/java/de/xikolo/controllers/module/helper/DownloadViewController.java index 8072ac042..48eae0078 100644 --- a/app/src/main/java/de/xikolo/controller/module/helper/DownloadViewController.java +++ b/app/src/main/java/de/xikolo/controllers/module/helper/DownloadViewController.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.module.helper; +package de.xikolo.controllers.module.helper; import android.content.ActivityNotFoundException; import android.content.Intent; @@ -21,35 +21,36 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.dialogs.ConfirmDeleteDialog; -import de.xikolo.controller.dialogs.MobileDownloadDialog; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Download; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.preferences.AppPreferences; -import de.xikolo.model.DownloadModel; -import de.xikolo.model.Result; -import de.xikolo.model.events.DownloadCompletedEvent; -import de.xikolo.model.events.DownloadDeletedEvent; -import de.xikolo.model.events.DownloadStartedEvent; -import de.xikolo.util.FileUtil; -import de.xikolo.util.NetworkUtil; -import de.xikolo.view.IconButton; +import de.xikolo.controllers.dialogs.ConfirmDeleteDialog; +import de.xikolo.controllers.dialogs.MobileDownloadDialog; +import de.xikolo.managers.DownloadManager; +import de.xikolo.models.Course; +import de.xikolo.models.Download; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.storages.preferences.ApplicationPreferences; +import de.xikolo.managers.Result; +import de.xikolo.events.DownloadCompletedEvent; +import de.xikolo.events.DownloadDeletedEvent; +import de.xikolo.events.DownloadStartedEvent; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.FileUtil; +import de.xikolo.utils.NetworkUtil; +import de.xikolo.views.IconButton; public class DownloadViewController { public static final String TAG = DownloadViewController.class.getSimpleName(); private static final int MILLISECONDS = 250; - private DownloadModel.DownloadFileType type; + private DownloadManager.DownloadFileType type; private Course course; private Module module; private Item item; - private DownloadModel downloadModel; + private DownloadManager downloadManager; private View layout; private TextView textFileName; @@ -69,13 +70,13 @@ public class DownloadViewController { private boolean progressBarUpdaterRunning = false; @SuppressWarnings("SetTextI18n") - public DownloadViewController(final FragmentActivity activity, final DownloadModel.DownloadFileType type, final Course course, final Module module, final Item item) { + public DownloadViewController(final FragmentActivity activity, final DownloadManager.DownloadFileType type, final Course course, final Module module, final Item item) { this.type = type; this.course = course; this.module = module; this.item = item; - this.downloadModel = new DownloadModel(GlobalApplication.getInstance().getJobManager(), activity); + this.downloadManager = new DownloadManager(GlobalApplication.getInstance().getJobManager(), activity); LayoutInflater inflater = LayoutInflater.from(GlobalApplication.getInstance()); layout = inflater.inflate(R.layout.container_download, null); @@ -83,7 +84,7 @@ public DownloadViewController(final FragmentActivity activity, final DownloadMod textFileSize = (TextView) layout.findViewById(R.id.textFileSize); textFileName = (TextView) layout.findViewById(R.id.textFileName); - final AppPreferences appPreferences = GlobalApplication.getInstance().getPreferencesFactory().getAppPreferences(); + final ApplicationPreferences appPreferences = (ApplicationPreferences) GlobalApplication.getStorage(StorageType.APP);; viewDownloadStart = layout.findViewById(R.id.downloadStartContainer); buttonDownloadStart = (IconButton) layout.findViewById(R.id.buttonDownloadStart); @@ -117,7 +118,7 @@ public void onDialogPositiveClick(DialogFragment dialog) { buttonDownloadCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - downloadModel.cancelDownload( + downloadManager.cancelDownload( DownloadViewController.this.type, DownloadViewController.this.course, DownloadViewController.this.module, @@ -190,7 +191,7 @@ public void onDialogPositiveAndAlwaysClick(DialogFragment dialog) { progressBarUpdater = new Runnable() { @Override public void run() { - final Download dl = downloadModel.getDownload(type, course, module, item); + final Download dl = downloadManager.getDownload(type, course, module, item); if (dl != null) { new Handler(Looper.getMainLooper()).post(new Runnable() { @@ -209,14 +210,14 @@ public void run() { if (progressBarUpdaterRunning) { progressBarDownload.postDelayed(this, MILLISECONDS); } else { - textFileSize.setText(FileUtil.getFormattedFileSize(downloadModel.getDownloadFileSize(type, course, module, item))); + textFileSize.setText(FileUtil.getFormattedFileSize(downloadManager.getDownloadFileSize(type, course, module, item))); } } }; - if (downloadModel.downloadRunning(type, course, module, item)) { + if (downloadManager.downloadRunning(type, course, module, item)) { showRunningState(); - } else if (downloadModel.downloadExists(type, course, module, item)) { + } else if (downloadManager.downloadExists(type, course, module, item)) { showEndState(); } else { showStartState(); @@ -225,7 +226,7 @@ public void run() { } private void deleteFile() { - if (downloadModel.cancelDownload( + if (downloadManager.cancelDownload( DownloadViewController.this.type, DownloadViewController.this.course, DownloadViewController.this.module, @@ -235,7 +236,7 @@ private void deleteFile() { } private void startDownload() { - long status = downloadModel.startDownload(uri, + long status = downloadManager.startDownload(uri, DownloadViewController.this.type, DownloadViewController.this.course, DownloadViewController.this.module, @@ -261,7 +262,7 @@ private void showStartState() { } if (uri != null) { - downloadModel.getRemoteDownloadFileSize(new Result() { + downloadManager.getRemoteDownloadFileSize(new Result() { @Override protected void onSuccess(Long result, DataSource dataSource) { if (result > 0) { @@ -304,7 +305,7 @@ private void showEndState() { viewDownloadEnd.setVisibility(View.VISIBLE); } - textFileSize.setText(FileUtil.getFormattedFileSize(downloadModel.getDownloadFileSize(type, course, module, item))); + textFileSize.setText(FileUtil.getFormattedFileSize(downloadManager.getDownloadFileSize(type, course, module, item))); progressBarUpdaterRunning = false; } @@ -313,7 +314,7 @@ private void showEndState() { @Subscribe(threadMode = ThreadMode.MAIN) public void onDownloadCompletedEvent(DownloadCompletedEvent event) { if (event.getDownload().localUri.contains(item.id) - && DownloadModel.DownloadFileType.getDownloadFileTypeFromUri(event.getDownload().localUri) == type) { + && DownloadManager.DownloadFileType.getDownloadFileTypeFromUri(event.getDownload().localUri) == type) { showEndState(); } } @@ -339,7 +340,7 @@ private void openFileAsPdf() { buttonOpenDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - File pdf = downloadModel.getDownloadFile(type, course, module, item); + File pdf = downloadManager.getDownloadFile(type, course, module, item); Intent target = new Intent(Intent.ACTION_VIEW); target.setDataAndType(Uri.fromFile(pdf), "application/pdf"); target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); diff --git a/app/src/main/java/de/xikolo/controller/navigation/NavigationFragment.java b/app/src/main/java/de/xikolo/controllers/navigation/NavigationFragment.java similarity index 97% rename from app/src/main/java/de/xikolo/controller/navigation/NavigationFragment.java rename to app/src/main/java/de/xikolo/controllers/navigation/NavigationFragment.java index 17043dfbd..23638a812 100644 --- a/app/src/main/java/de/xikolo/controller/navigation/NavigationFragment.java +++ b/app/src/main/java/de/xikolo/controllers/navigation/NavigationFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.navigation; +package de.xikolo.controllers.navigation; import android.content.Context; import android.content.SharedPreferences; @@ -21,10 +21,10 @@ import android.view.ViewGroup; import de.xikolo.R; -import de.xikolo.controller.BaseFragment; -import de.xikolo.controller.navigation.adapter.NavigationAdapter; -import de.xikolo.model.UserModel; -import de.xikolo.view.DividerItemDecoration; +import de.xikolo.controllers.BaseFragment; +import de.xikolo.controllers.navigation.adapter.NavigationAdapter; +import de.xikolo.managers.UserManager; +import de.xikolo.views.DividerItemDecoration; /** * Fragment used for managing interactions for and presentation of a navigation drawer. @@ -84,7 +84,7 @@ public void onCreate(Bundle savedInstanceState) { } if (!fromSavedInstanceState) { - if (UserModel.isLoggedIn(getActivity())) { + if (UserManager.isLoggedIn()) { selectItem(NavigationAdapter.NAV_MY_COURSES.getPosition()); } else { selectItem(NavigationAdapter.NAV_ALL_COURSES.getPosition()); diff --git a/app/src/main/java/de/xikolo/controller/navigation/adapter/NavigationAdapter.java b/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java similarity index 92% rename from app/src/main/java/de/xikolo/controller/navigation/adapter/NavigationAdapter.java rename to app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java index b35d38a5a..26c503139 100644 --- a/app/src/main/java/de/xikolo/controller/navigation/adapter/NavigationAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.navigation.adapter; +package de.xikolo.controllers.navigation.adapter; import android.content.Context; import android.support.v4.content.ContextCompat; @@ -14,14 +14,14 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.helper.ImageController; -import de.xikolo.data.entities.User; -import de.xikolo.model.CourseModel; -import de.xikolo.model.UserModel; -import de.xikolo.util.AndroidDimenUtil; -import de.xikolo.util.Config; -import de.xikolo.util.FeatureToggle; -import de.xikolo.view.CustomFontTextView; +import de.xikolo.controllers.helper.ImageController; +import de.xikolo.managers.CourseManager; +import de.xikolo.managers.UserManager; +import de.xikolo.models.User; +import de.xikolo.utils.AndroidDimenUtil; +import de.xikolo.utils.Config; +import de.xikolo.utils.FeatureToggle; +import de.xikolo.views.CustomFontTextView; public class NavigationAdapter extends RecyclerView.Adapter { @@ -92,14 +92,14 @@ public class NavigationAdapter extends RecyclerView.Adapter 0) { @@ -191,12 +191,12 @@ public void onBindViewHolder(BaseNavigationViewHolder viewHolder, int position) } if (position == getCheckedItemPosition()) { - if (position != NAV_PROFILE.getPosition() || !UserModel.isLoggedIn(context)) { + if (position != NAV_PROFILE.getPosition() || !UserManager.isLoggedIn()) { viewHolder.textIcon.setTextColor(ContextCompat.getColor(context, R.color.apptheme_main)); viewHolder.textTitle.setTextColor(ContextCompat.getColor(context, R.color.apptheme_main)); } } else { - if (position != NAV_PROFILE.getPosition() || !UserModel.isLoggedIn(context)) { + if (position != NAV_PROFILE.getPosition() || !UserManager.isLoggedIn()) { viewHolder.textIcon.setTextColor(ContextCompat.getColor(context, R.color.white)); viewHolder.textTitle.setTextColor(ContextCompat.getColor(context, R.color.white)); } diff --git a/app/src/main/java/de/xikolo/controller/navigation/adapter/NavigationItem.java b/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationItem.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/navigation/adapter/NavigationItem.java rename to app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationItem.java index b2850d0d3..4703cb6f3 100644 --- a/app/src/main/java/de/xikolo/controller/navigation/adapter/NavigationItem.java +++ b/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationItem.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.navigation.adapter; +package de.xikolo.controllers.navigation.adapter; import android.content.Context; import android.support.annotation.StringRes; diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/PinboardActivity.java b/app/src/main/java/de/xikolo/controllers/secondscreen/PinboardActivity.java similarity index 89% rename from app/src/main/java/de/xikolo/controller/secondscreen/PinboardActivity.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/PinboardActivity.java index 469cf12bb..63370f795 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/PinboardActivity.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/PinboardActivity.java @@ -1,16 +1,16 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import de.xikolo.R; -import de.xikolo.controller.BaseActivity; -import de.xikolo.controller.WebViewFragment; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.util.LanalyticsUtil; +import de.xikolo.controllers.BaseActivity; +import de.xikolo.controllers.WebViewFragment; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.utils.LanalyticsUtil; public class PinboardActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/QuizActivity.java b/app/src/main/java/de/xikolo/controllers/secondscreen/QuizActivity.java similarity index 89% rename from app/src/main/java/de/xikolo/controller/secondscreen/QuizActivity.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/QuizActivity.java index c4ecb46b9..4f6a4a32a 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/QuizActivity.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/QuizActivity.java @@ -1,16 +1,16 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import de.xikolo.R; -import de.xikolo.controller.BaseActivity; -import de.xikolo.controller.WebViewFragment; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.util.LanalyticsUtil; +import de.xikolo.controllers.BaseActivity; +import de.xikolo.controllers.WebViewFragment; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.utils.LanalyticsUtil; public class QuizActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java b/app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java similarity index 94% rename from app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java index eedd9b9e3..af7e2767a 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/SecondScreenFragment.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.annotation.TargetApi; import android.app.NotificationManager; @@ -27,20 +27,21 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.helper.ImageController; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.Subtitle; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.entities.WebSocketMessage; -import de.xikolo.data.preferences.AppPreferences; +import de.xikolo.controllers.helper.ImageController; +import de.xikolo.managers.ItemManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.Subtitle; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.models.WebSocketMessage; +import de.xikolo.storages.preferences.ApplicationPreferences; import de.xikolo.managers.SecondScreenManager; -import de.xikolo.model.ItemModel; -import de.xikolo.model.Result; -import de.xikolo.util.Config; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.TimeUtil; +import de.xikolo.managers.Result; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.utils.Config; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.TimeUtil; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class SecondScreenFragment extends Fragment { @@ -70,7 +71,7 @@ public class SecondScreenFragment extends Fragment { private Item item; private List subtitleList; - private AppPreferences appPreferences; + private ApplicationPreferences appPreferences; public SecondScreenFragment() { // Required empty public constructor @@ -99,7 +100,7 @@ public void onCreate(Bundle savedInstanceState) { } } - appPreferences = GlobalApplication.getInstance().getPreferencesFactory().getAppPreferences(); + appPreferences = (ApplicationPreferences) GlobalApplication.getStorage(StorageType.APP); } @Override @@ -187,7 +188,7 @@ private void initSeconScreenActions(WebSocketMessage message) { final View viewQuiz = addQuizAction(); final View viewPinboard = addPinboardAction(); - ItemModel itemModel = new ItemModel(GlobalApplication.getInstance().getJobManager()); + ItemManager itemModel = new ItemManager(GlobalApplication.getInstance().getJobManager()); // pdf if (!"".equals(item.detail.slides_url)) { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerActivity.java b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerActivity.java similarity index 89% rename from app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerActivity.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerActivity.java index 290d4baa9..91ba8c9a9 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerActivity.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.os.Bundle; import android.support.v4.app.FragmentManager; @@ -6,11 +6,11 @@ import android.view.WindowManager; import de.xikolo.R; -import de.xikolo.controller.BaseActivity; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.util.LanalyticsUtil; +import de.xikolo.controllers.BaseActivity; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.utils.LanalyticsUtil; public class SlideViewerActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java similarity index 87% rename from app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java index 5816306d6..29bdb1929 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/SlideViewerFragment.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.annotation.TargetApi; import android.os.Build; @@ -25,15 +25,15 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.dialogs.DownloadSlidesDialog; -import de.xikolo.controller.dialogs.ProgressDialog; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; +import de.xikolo.controllers.dialogs.DownloadSlidesDialog; +import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.managers.DownloadManager; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; import de.xikolo.managers.SecondScreenManager; -import de.xikolo.model.DownloadModel; -import de.xikolo.model.events.DownloadCompletedEvent; +import de.xikolo.events.DownloadCompletedEvent; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class SlideViewerFragment extends Fragment implements OnLoadCompleteListener, OnPageChangeListener { @@ -42,7 +42,7 @@ public class SlideViewerFragment extends Fragment implements OnLoadCompleteListe private PDFView pdfView; - private DownloadModel downloadModel; + private DownloadManager downloadModel; private ProgressDialog progressDialog; @@ -91,7 +91,7 @@ public void onCreate(Bundle savedInstanceState) { currentPage = 0; } - downloadModel = new DownloadModel(GlobalApplication.getInstance().getJobManager(), getActivity()); + downloadModel = new DownloadManager(GlobalApplication.getInstance().getJobManager(), getActivity()); } @Override @@ -122,14 +122,14 @@ public void onClick(View v) { } }); - if (downloadModel.downloadExists(DownloadModel.DownloadFileType.SLIDES, course, module, item)) { + if (downloadModel.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { initSlidesViewer(); } else { DownloadSlidesDialog dialog = DownloadSlidesDialog.getInstance(); dialog.setListener(new DownloadSlidesDialog.DownloadSlidesDialogListener() { @Override public void onDialogPositiveClick() { - downloadModel.startDownload(item.detail.slides_url, DownloadModel.DownloadFileType.SLIDES, course, module, item); + downloadModel.startDownload(item.detail.slides_url, DownloadManager.DownloadFileType.SLIDES, course, module, item); progressDialog = ProgressDialog.getInstance(); progressDialog.show(getFragmentManager(), ProgressDialog.TAG); } @@ -144,8 +144,8 @@ public void onDialogNegativeClick() { } private void initSlidesViewer() { - if (downloadModel != null && downloadModel.downloadExists(DownloadModel.DownloadFileType.SLIDES, course, module, item)) { - File file = downloadModel.getDownloadFile(DownloadModel.DownloadFileType.SLIDES, course, module, item); + if (downloadModel != null && downloadModel.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { + File file = downloadModel.getDownloadFile(DownloadManager.DownloadFileType.SLIDES, course, module, item); pdfView.fromFile(file) .swipeVertical(true) .enableAnnotationRendering(true) @@ -219,7 +219,7 @@ public void onSecondScreenUpdateVideoEvent(SecondScreenManager.SecondScreenUpdat @Subscribe(threadMode = ThreadMode.MAIN) public void onDownloadCompletedEvent(DownloadCompletedEvent event) { if (event.getDownload().localUri.contains(item.id) - && DownloadModel.DownloadFileType.getDownloadFileTypeFromUri(event.getDownload().localUri) == DownloadModel.DownloadFileType.SLIDES) { + && DownloadManager.DownloadFileType.getDownloadFileTypeFromUri(event.getDownload().localUri) == DownloadManager.DownloadFileType.SLIDES) { if (progressDialog != null && progressDialog.getDialog().isShowing()) { progressDialog.getDialog().cancel(); } diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerActivity.java b/app/src/main/java/de/xikolo/controllers/secondscreen/TranscriptViewerActivity.java similarity index 88% rename from app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerActivity.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/TranscriptViewerActivity.java index 69fb781f6..894dd8a2f 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerActivity.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/TranscriptViewerActivity.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.os.Bundle; import android.support.v4.app.FragmentManager; @@ -8,12 +8,12 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.controller.BaseActivity; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.Subtitle; -import de.xikolo.util.LanalyticsUtil; +import de.xikolo.controllers.BaseActivity; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.Subtitle; +import de.xikolo.utils.LanalyticsUtil; public class TranscriptViewerActivity extends BaseActivity { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java b/app/src/main/java/de/xikolo/controllers/secondscreen/TranscriptViewerFragment.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/TranscriptViewerFragment.java index ea3fddd35..b31173a9d 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/TranscriptViewerFragment.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/TranscriptViewerFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.secondscreen; +package de.xikolo.controllers.secondscreen; import android.annotation.TargetApi; import android.os.Build; @@ -25,13 +25,13 @@ import java.util.List; import de.xikolo.R; -import de.xikolo.controller.dialogs.ChooseLanguageDialog; -import de.xikolo.controller.secondscreen.adapter.TranscriptViewerAdapter; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Subtitle; +import de.xikolo.controllers.dialogs.ChooseLanguageDialog; +import de.xikolo.controllers.secondscreen.adapter.TranscriptViewerAdapter; +import de.xikolo.models.Item; +import de.xikolo.models.Subtitle; import de.xikolo.managers.SecondScreenManager; -import de.xikolo.util.AndroidDimenUtil; -import de.xikolo.util.TimeUtil; +import de.xikolo.utils.AndroidDimenUtil; +import de.xikolo.utils.TimeUtil; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class TranscriptViewerFragment extends Fragment implements ChooseLanguageDialog.ChooseLanguageDialogListener { diff --git a/app/src/main/java/de/xikolo/controller/secondscreen/adapter/TranscriptViewerAdapter.java b/app/src/main/java/de/xikolo/controllers/secondscreen/adapter/TranscriptViewerAdapter.java similarity index 95% rename from app/src/main/java/de/xikolo/controller/secondscreen/adapter/TranscriptViewerAdapter.java rename to app/src/main/java/de/xikolo/controllers/secondscreen/adapter/TranscriptViewerAdapter.java index 5f3fab2aa..9f9af3e3d 100644 --- a/app/src/main/java/de/xikolo/controller/secondscreen/adapter/TranscriptViewerAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/adapter/TranscriptViewerAdapter.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.secondscreen.adapter; +package de.xikolo.controllers.secondscreen.adapter; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; @@ -9,8 +9,8 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.data.entities.Subtitle; -import de.xikolo.util.TimeUtil; +import de.xikolo.models.Subtitle; +import de.xikolo.utils.TimeUtil; public class TranscriptViewerAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java b/app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java similarity index 92% rename from app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java rename to app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java index 9102ec47e..e349f90a6 100644 --- a/app/src/main/java/de/xikolo/controller/settings/SettingsFragment.java +++ b/app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java @@ -1,4 +1,4 @@ -package de.xikolo.controller.settings; +package de.xikolo.controllers.settings; import android.content.Intent; import android.net.Uri; @@ -18,14 +18,14 @@ import de.xikolo.BuildConfig; import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.LoginActivity; -import de.xikolo.controller.dialogs.ContributorsDialog; -import de.xikolo.controller.dialogs.LicensesDialog; -import de.xikolo.model.UserModel; -import de.xikolo.model.events.LoginEvent; -import de.xikolo.model.events.LogoutEvent; -import de.xikolo.util.BuildFlavor; -import de.xikolo.util.Config; +import de.xikolo.controllers.LoginActivity; +import de.xikolo.controllers.dialogs.ContributorsDialog; +import de.xikolo.controllers.dialogs.LicensesDialog; +import de.xikolo.managers.UserManager; +import de.xikolo.events.LoginEvent; +import de.xikolo.events.LogoutEvent; +import de.xikolo.utils.BuildFlavor; +import de.xikolo.utils.Config; public class SettingsFragment extends PreferenceFragment { @@ -129,7 +129,7 @@ public boolean onPreferenceClick(Preference preference) { }); loginOut = findPreference(getString(R.string.preference_login_out)); - if (UserModel.isLoggedIn(getActivity())) { + if (UserManager.isLoggedIn()) { buildLogoutView(loginOut); } else { buildLoginView(loginOut); @@ -156,7 +156,7 @@ private void buildLogoutView(Preference pref) { pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - UserModel userModel = new UserModel(GlobalApplication.getInstance().getJobManager()); + UserManager userModel = new UserManager(GlobalApplication.getInstance().getJobManager()); userModel.logout(); return true; } diff --git a/app/src/main/java/de/xikolo/data/database/CourseDataAccess.java b/app/src/main/java/de/xikolo/data/database/CourseDataAccess.java deleted file mode 100644 index 6244a0e1b..000000000 --- a/app/src/main/java/de/xikolo/data/database/CourseDataAccess.java +++ /dev/null @@ -1,177 +0,0 @@ -package de.xikolo.data.database; - -import android.content.ContentValues; -import android.database.Cursor; - -import java.util.ArrayList; -import java.util.List; - -import de.xikolo.data.entities.Course; - -public class CourseDataAccess extends DataAccess { - - private OverallProgressDataAccess progressDataAccess; - - public CourseDataAccess(DatabaseHelper databaseHelper) { - super(databaseHelper); - - this.progressDataAccess = new OverallProgressDataAccess(databaseHelper); - } - - public void addCourse(Course course, boolean includeProgress) { - openDatabase().insert(CourseTable.TABLE_NAME, null, buildContentValues(course)); - - if (includeProgress) { - progressDataAccess.addOrUpdateProgress(course.id, course.progress); - } - - closeDatabase(); - } - - public void addOrUpdateCourse(Course course, boolean includeProgress) { - if (updateCourse(course, includeProgress) < 1) { - addCourse(course, includeProgress); - } - } - - public Course getCourse(String id) { - Cursor cursor = openDatabase().query( - CourseTable.TABLE_NAME, - new String[]{ - CourseTable.COLUMN_ID, - CourseTable.COLUMN_NAME, - CourseTable.COLUMN_DESCRIPTION, - CourseTable.COLUMN_COURSE_CODE, - CourseTable.COLUMN_LECTURER, - CourseTable.COLUMN_LANGUAGE, - CourseTable.COLUMN_URL, - CourseTable.COLUMN_VISUAL_URL, - CourseTable.COLUMN_AVAILABLE_FROM, - CourseTable.COLUMN_AVAILABLE_TO, - CourseTable.COLUMN_LOCKED, - CourseTable.COLUMN_IS_ENROLLED, - }, - CourseTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}, null, null, null, null); - - Course course = null; - if (cursor.moveToFirst()) { - course = buildCourse(cursor); - course.progress = progressDataAccess.getProgress(id); - } - cursor.close(); - closeDatabase(); - - return course; - } - - public List getAllCourses() { - List courseList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + CourseTable.TABLE_NAME; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - Course course = buildCourse(cursor); - course.progress = progressDataAccess.getProgress(course.id); - courseList.add(course); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return courseList; - } - - private Course buildCourse(Cursor cursor) { - Course course = new Course(); - - course.id = cursor.getString(0); - course.name = cursor.getString(1); - course.description = cursor.getString(2); - course.course_code = cursor.getString(3); - course.lecturer = cursor.getString(4); - course.language = cursor.getString(5); - course.url = cursor.getString(6); - course.visual_url = cursor.getString(7); - course.available_from = cursor.getString(8); - course.available_to = cursor.getString(9); - course.locked = cursor.getInt(10) != 0; - course.is_enrolled = cursor.getInt(11) != 0; - - return course; - } - - private ContentValues buildContentValues(Course course) { - ContentValues values = new ContentValues(); - values.put(CourseTable.COLUMN_ID, course.id); - values.put(CourseTable.COLUMN_NAME, course.name); - values.put(CourseTable.COLUMN_DESCRIPTION, course.description); - values.put(CourseTable.COLUMN_COURSE_CODE, course.course_code); - values.put(CourseTable.COLUMN_LECTURER, course.lecturer); - values.put(CourseTable.COLUMN_LANGUAGE, course.language); - values.put(CourseTable.COLUMN_URL, course.url); - values.put(CourseTable.COLUMN_VISUAL_URL, course.visual_url); - values.put(CourseTable.COLUMN_AVAILABLE_FROM, course.available_from); - values.put(CourseTable.COLUMN_AVAILABLE_TO, course.available_to); - values.put(CourseTable.COLUMN_LOCKED, course.locked); - values.put(CourseTable.COLUMN_IS_ENROLLED, course.is_enrolled); - - return values; - } - - public int getCoursesCount() { - String countQuery = "SELECT * FROM " + CourseTable.TABLE_NAME; - Cursor cursor = openDatabase().rawQuery(countQuery, null); - - int count = cursor.getCount(); - - cursor.close(); - closeDatabase(); - - return count; - } - - public int getEnrollmentsCount() { - String countQuery = "SELECT * FROM " + CourseTable.TABLE_NAME + " WHERE " + CourseTable.COLUMN_IS_ENROLLED + " != 0 "; - Cursor cursor = openDatabase().rawQuery(countQuery, null); - - int count = cursor.getCount(); - - cursor.close(); - closeDatabase(); - - return count; - } - - public int updateCourse(Course course, boolean includeProgress) { - int affected = openDatabase().update( - CourseTable.TABLE_NAME, - buildContentValues(course), - CourseTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(course.id)}); - - if (includeProgress) { - progressDataAccess.addOrUpdateProgress(course.id, course.progress); - } - - closeDatabase(); - - return affected; - } - - public void deleteCourse(Course course) { - openDatabase().delete( - CourseTable.TABLE_NAME, - CourseTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(course.id)}); - - progressDataAccess.deleteProgress(course.id); - - closeDatabase(); - } - -} diff --git a/app/src/main/java/de/xikolo/data/database/DataAccess.java b/app/src/main/java/de/xikolo/data/database/DataAccess.java deleted file mode 100644 index 2da508eef..000000000 --- a/app/src/main/java/de/xikolo/data/database/DataAccess.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.xikolo.data.database; - -import android.database.sqlite.SQLiteDatabase; - -abstract class DataAccess { - - protected DatabaseHelper databaseHelper; - - public DataAccess(DatabaseHelper databaseHelper) { - this.databaseHelper = databaseHelper; - } - - protected SQLiteDatabase openDatabase() { - return databaseHelper.openDatabase(); - } - - protected void closeDatabase() { - databaseHelper.close(); - } - -} diff --git a/app/src/main/java/de/xikolo/data/database/DataAccessFactory.java b/app/src/main/java/de/xikolo/data/database/DataAccessFactory.java deleted file mode 100644 index 5659be875..000000000 --- a/app/src/main/java/de/xikolo/data/database/DataAccessFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.xikolo.data.database; - -public class DataAccessFactory { - - private CourseDataAccess courseDataAccess; - - private ModuleDataAccess moduleDataAccess; - - private ItemDataAccess itemDataAccess; - - private OverallProgressDataAccess overallProgressDataAccess; - - private VideoDataAccess videoDataAccess; - - private DatabaseHelper databaseHelper; - - public DataAccessFactory(DatabaseHelper databaseHelper) { - this.databaseHelper = databaseHelper; - } - - public CourseDataAccess getCourseDataAccess() { - if (courseDataAccess == null) { - courseDataAccess = new CourseDataAccess(databaseHelper); - } - return courseDataAccess; - } - - public ModuleDataAccess getModuleDataAccess() { - if (moduleDataAccess == null) { - moduleDataAccess = new ModuleDataAccess(databaseHelper); - } - return moduleDataAccess; - } - - public ItemDataAccess getItemDataAccess() { - if (itemDataAccess == null) { - itemDataAccess = new ItemDataAccess(databaseHelper); - } - return itemDataAccess; - } - - public OverallProgressDataAccess getOverallProgressDataAccess() { - if (overallProgressDataAccess == null) { - overallProgressDataAccess = new OverallProgressDataAccess(databaseHelper); - } - return overallProgressDataAccess; - } - - public VideoDataAccess getVideoDataAccess() { - if (videoDataAccess == null) { - videoDataAccess = new VideoDataAccess(databaseHelper); - } - return videoDataAccess; - } - - public DatabaseHelper getDatabaseHelper() { - return databaseHelper; - } -} diff --git a/app/src/main/java/de/xikolo/data/database/DatabaseHelper.java b/app/src/main/java/de/xikolo/data/database/DatabaseHelper.java deleted file mode 100644 index 37129d763..000000000 --- a/app/src/main/java/de/xikolo/data/database/DatabaseHelper.java +++ /dev/null @@ -1,88 +0,0 @@ -package de.xikolo.data.database; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.util.Log; - -import java.util.ArrayList; -import java.util.List; - -public class DatabaseHelper extends SQLiteOpenHelper { - - private static final String TAG = DatabaseHelper.class.getSimpleName(); - - private static final int DATABASE_VERSION = 3; - - private static final String DATABASE_NAME = "xikolo"; - - private SQLiteDatabase db; - - private List mTables; - - private int mOpenCounter; - - public DatabaseHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - - mTables = new ArrayList<>(); - mTables.add(new OverallProgressTable()); - mTables.add(new CourseTable()); - mTables.add(new ModuleTable()); - mTables.add(new ItemTable()); - mTables.add(new VideoTable()); - - mOpenCounter = 0; - } - - @Override - public void onCreate(SQLiteDatabase db) { - for (Table table : mTables) { - table.onCreate(db); - } - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion); - - for (Table table : mTables) { - table.onUpgrade(db, oldVersion, newVersion); - } - } - - @Override - public void onOpen(SQLiteDatabase db) { - super.onOpen(db); - - if (!db.isReadOnly()) { - // Enable foreign key constraints - db.execSQL("PRAGMA foreign_keys = ON;"); - } - } - - public synchronized SQLiteDatabase openDatabase() { - mOpenCounter++; - if(mOpenCounter == 1) { - db = getWritableDatabase(); - } - return this.db; - } - - @Override - public synchronized void close() { - if (mOpenCounter > 0) { - mOpenCounter--; - } - if(mOpenCounter == 0) { - super.close(); - } - } - - public void deleteDatabase() { - for (Table table : mTables) { - table.deleteTable(openDatabase()); - } - } - -} diff --git a/app/src/main/java/de/xikolo/data/database/ItemDataAccess.java b/app/src/main/java/de/xikolo/data/database/ItemDataAccess.java deleted file mode 100644 index 8ae1360c8..000000000 --- a/app/src/main/java/de/xikolo/data/database/ItemDataAccess.java +++ /dev/null @@ -1,164 +0,0 @@ -package de.xikolo.data.database; - -import android.content.ContentValues; -import android.database.Cursor; - -import java.util.ArrayList; -import java.util.List; - -import de.xikolo.data.entities.Item; - -public class ItemDataAccess extends DataAccess { - - public ItemDataAccess(DatabaseHelper databaseHelper) { - super(databaseHelper); - } - - public void addItem(String moduleId, Item item) { - openDatabase().insert(ItemTable.TABLE_NAME, null, buildContentValues(moduleId, item)); - - closeDatabase(); - } - - public void addOrUpdateItem(String moduleId, Item item) { - if (updateItem(moduleId, item) < 1) { - addItem(moduleId, item); - } - } - - public Item getItem(String id) { - Cursor cursor = openDatabase().query( - ItemTable.TABLE_NAME, - new String[]{ - ItemTable.COLUMN_ID, - ItemTable.COLUMN_POSITION, - ItemTable.COLUMN_TITLE, - ItemTable.COLUMN_TYPE, - ItemTable.COLUMN_AVAILABLE_FROM, - ItemTable.COLUMN_AVAILABLE_TO, - ItemTable.COLUMN_EXERCISE_TYPE, - ItemTable.COLUMN_LOCKED, - ItemTable.COLUMN_VISITED, - ItemTable.COLUMN_COMPLETED, - }, - ItemTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}, null, null, null, null); - - Item item = null; - if (cursor.moveToFirst()) { - item = buildItem(cursor); - } - cursor.close(); - closeDatabase(); - - return item; - } - - public List getAllItems() { - List itemList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + ItemTable.TABLE_NAME; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - Item item = buildItem(cursor); - itemList.add(item); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return itemList; - } - - public List getAllItemsForModule(String moduleId) { - List itemList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + ItemTable.TABLE_NAME + " WHERE " + ItemTable.COLUMN_MODULE_ID + " = \'" + moduleId + "\'"; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - Item item = buildItem(cursor); - itemList.add(item); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return itemList; - } - - private Item buildItem(Cursor cursor) { - Item item = new Item(); - - item.id = cursor.getString(0); - item.position = cursor.getInt(1); - item.title = cursor.getString(2); - item.type = cursor.getString(3); - item.available_from = cursor.getString(4); - item.available_to = cursor.getString(5); - item.exercise_type = cursor.getString(6); - item.locked = cursor.getInt(7) != 0; - item.progress.visited = cursor.getInt(8) != 0; - item.progress.completed = cursor.getInt(9) != 0; - - return item; - } - - private ContentValues buildContentValues(String moduleId, Item item) { - ContentValues values = new ContentValues(); - values.put(ItemTable.COLUMN_ID, item.id); - values.put(ItemTable.COLUMN_POSITION, item.position); - values.put(ItemTable.COLUMN_TITLE, item.title); - values.put(ItemTable.COLUMN_TYPE, item.type); - values.put(ItemTable.COLUMN_AVAILABLE_FROM, item.available_from); - values.put(ItemTable.COLUMN_AVAILABLE_TO, item.available_to); - values.put(ItemTable.COLUMN_EXERCISE_TYPE, item.exercise_type); - values.put(ItemTable.COLUMN_LOCKED, item.locked); - values.put(ItemTable.COLUMN_VISITED, item.progress.visited); - values.put(ItemTable.COLUMN_COMPLETED, item.progress.completed); - values.put(ItemTable.COLUMN_MODULE_ID, moduleId); - - return values; - } - - public int getItemsCount() { - String countQuery = "SELECT * FROM " + ItemTable.TABLE_NAME; - Cursor cursor = openDatabase().rawQuery(countQuery, null); - - int count = cursor.getCount(); - - cursor.close(); - closeDatabase(); - - return count; - } - - public int updateItem(String moduleId, Item item) { - int affected = openDatabase().update( - ItemTable.TABLE_NAME, - buildContentValues(moduleId, item), - ItemTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(item.id)}); - - closeDatabase(); - - return affected; - } - - public void deleteItem(Item item) { - openDatabase().delete( - ItemTable.TABLE_NAME, - ItemTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(item.id)}); - - closeDatabase(); - } - -} diff --git a/app/src/main/java/de/xikolo/data/database/ModuleDataAccess.java b/app/src/main/java/de/xikolo/data/database/ModuleDataAccess.java deleted file mode 100644 index 692bfa223..000000000 --- a/app/src/main/java/de/xikolo/data/database/ModuleDataAccess.java +++ /dev/null @@ -1,170 +0,0 @@ -package de.xikolo.data.database; - -import android.content.ContentValues; -import android.database.Cursor; - -import java.util.ArrayList; -import java.util.List; - -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Module; - -public class ModuleDataAccess extends DataAccess { - - private OverallProgressDataAccess progressDataAccess; - - public ModuleDataAccess(DatabaseHelper databaseHelper) { - super(databaseHelper); - - this.progressDataAccess = new OverallProgressDataAccess(databaseHelper); - } - - public void addModule(String courseId, Module module, boolean includeProgress) { - openDatabase().insert(ModuleTable.TABLE_NAME, null, buildContentValues(courseId, module)); - - if (includeProgress) { - progressDataAccess.addOrUpdateProgress(module.id, module.progress); - } - - closeDatabase(); - } - - public void addOrUpdateModule(String courseId, Module module, boolean includeProgress) { - if (updateModule(courseId, module, includeProgress) < 1) { - addModule(courseId, module, includeProgress); - } - } - - public Module getModule(String id) { - Cursor cursor = openDatabase().query( - ModuleTable.TABLE_NAME, - new String[]{ - ModuleTable.COLUMN_ID, - ModuleTable.COLUMN_POSITION, - ModuleTable.COLUMN_NAME, - ModuleTable.COLUMN_AVAILABLE_FROM, - ModuleTable.COLUMN_AVAILABLE_TO, - ModuleTable.COLUMN_LOCKED, - }, - ModuleTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}, null, null, null, null); - - Module module = null; - if (cursor.moveToFirst()) { - module = buildModule(cursor); - module.progress = progressDataAccess.getProgress(module.id); - } - cursor.close(); - closeDatabase(); - - return module; - } - - public List getAllModules() { - List moduleList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + ModuleTable.TABLE_NAME; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - Module module = buildModule(cursor); - module.progress = progressDataAccess.getProgress(module.id); - moduleList.add(module); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return moduleList; - } - - public List getAllModulesForCourse(Course course) { - List moduleList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + ModuleTable.TABLE_NAME + " WHERE " + ModuleTable.COLUMN_COURSE_ID + " = \'" + course.id + "\'"; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - Module module = buildModule(cursor); - module.progress = progressDataAccess.getProgress(module.id); - moduleList.add(module); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return moduleList; - } - - private Module buildModule(Cursor cursor) { - Module module = new Module(); - - module.id = cursor.getString(0); - module.position = cursor.getInt(1); - module.name = cursor.getString(2); - module.available_from = cursor.getString(3); - module.available_to = cursor.getString(4); - module.locked = cursor.getInt(5) != 0; - - return module; - } - - private ContentValues buildContentValues(String courseId, Module module) { - ContentValues values = new ContentValues(); - values.put(ModuleTable.COLUMN_ID, module.id); - values.put(ModuleTable.COLUMN_POSITION, module.position); - values.put(ModuleTable.COLUMN_NAME, module.name); - values.put(ModuleTable.COLUMN_AVAILABLE_FROM, module.available_from); - values.put(ModuleTable.COLUMN_AVAILABLE_TO, module.available_to); - values.put(ModuleTable.COLUMN_LOCKED, module.locked); - values.put(ModuleTable.COLUMN_COURSE_ID, courseId); - - return values; - } - - public int getModulesCount() { - String countQuery = "SELECT * FROM " + ModuleTable.TABLE_NAME; - Cursor cursor = openDatabase().rawQuery(countQuery, null); - - int count = cursor.getCount(); - - cursor.close(); - closeDatabase(); - - return count; - } - - public int updateModule(String courseId, Module module, boolean includeProgress) { - int affected = openDatabase().update( - ModuleTable.TABLE_NAME, - buildContentValues(courseId, module), - ModuleTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(module.id)}); - - if (includeProgress) { - progressDataAccess.addOrUpdateProgress(module.id, module.progress); - } - - closeDatabase(); - - return affected; - } - - public void deleteModule(Module module) { - openDatabase().delete( - ModuleTable.TABLE_NAME, - ModuleTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(module.id)}); - - progressDataAccess.deleteProgress(module.id); - - closeDatabase(); - } - -} diff --git a/app/src/main/java/de/xikolo/data/database/OverallProgressDataAccess.java b/app/src/main/java/de/xikolo/data/database/OverallProgressDataAccess.java deleted file mode 100644 index eec91ae71..000000000 --- a/app/src/main/java/de/xikolo/data/database/OverallProgressDataAccess.java +++ /dev/null @@ -1,149 +0,0 @@ -package de.xikolo.data.database; - -import android.content.ContentValues; -import android.database.Cursor; - -import java.util.ArrayList; -import java.util.List; - -import de.xikolo.data.entities.OverallProgress; - -class OverallProgressDataAccess extends DataAccess { - - public OverallProgressDataAccess(DatabaseHelper databaseHelper) { - super(databaseHelper); - } - - public void addProgress(String id, OverallProgress progress) { - openDatabase().insert(OverallProgressTable.TABLE_NAME, null, buildContentValues(id, progress)); - - closeDatabase(); - } - - public void addOrUpdateProgress(String id, OverallProgress progress) { - if (updateProgress(id, progress) < 1) { - addProgress(id, progress); - } - } - - public OverallProgress getProgress(String id) { - Cursor cursor = openDatabase().query( - OverallProgressTable.TABLE_NAME, - new String[]{ - OverallProgressTable.COLUMN_ID, - OverallProgressTable.COLUMN_ITEM_COUNT_AVAILABLE, - OverallProgressTable.COLUMN_ITEM_COUNT_VISITED, - OverallProgressTable.COLUMN_ITEM_COUNT_COMPLETED, - OverallProgressTable.COLUMN_SELF_TESTS_COUNT_AVAILABLE, - OverallProgressTable.COLUMN_SELF_TESTS_COUNT_TAKEN, - OverallProgressTable.COLUMN_SELF_TESTS_POINTS_POSSIBLE, - OverallProgressTable.COLUMN_SELF_TESTS_POINTS_SCORED, - OverallProgressTable.COLUMN_ASSIGNMENTS_COUNT_AVAILABLE, - OverallProgressTable.COLUMN_ASSIGNMENTS_COUNT_TAKEN, - OverallProgressTable.COLUMN_ASSIGNMENTS_POINTS_POSSIBLE, - OverallProgressTable.COLUMN_ASSIGNMENTS_POINTS_SCORED, - }, - OverallProgressTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}, null, null, null, null); - - OverallProgress progress = null; - if (cursor.moveToFirst()) { - progress = buildProgress(cursor); - } - cursor.close(); - closeDatabase(); - - return progress; - } - - public List getAllProgress() { - List progressList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + OverallProgressTable.TABLE_NAME; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - OverallProgress progress = buildProgress(cursor); - progressList.add(progress); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return progressList; - } - - private OverallProgress buildProgress(Cursor cursor) { - OverallProgress progress = new OverallProgress(); - - cursor.getString(0); - progress.items.count_available = cursor.getInt(1); - progress.items.count_visited = cursor.getInt(2); - progress.items.count_completed = cursor.getInt(3); - progress.self_tests.count_available = cursor.getFloat(4); - progress.self_tests.count_taken = cursor.getFloat(5); - progress.self_tests.points_possible = cursor.getFloat(6); - progress.self_tests.points_scored = cursor.getFloat(7); - progress.assignments.count_available = cursor.getFloat(8); - progress.assignments.count_taken = cursor.getFloat(9); - progress.assignments.points_possible = cursor.getFloat(10); - progress.assignments.points_scored = cursor.getFloat(11); - - return progress; - } - - private ContentValues buildContentValues(String id, OverallProgress progress) { - ContentValues values = new ContentValues(); - values.put(OverallProgressTable.COLUMN_ID, id); - values.put(OverallProgressTable.COLUMN_ITEM_COUNT_AVAILABLE, progress.items.count_available); - values.put(OverallProgressTable.COLUMN_ITEM_COUNT_VISITED, progress.items.count_visited); - values.put(OverallProgressTable.COLUMN_ITEM_COUNT_COMPLETED, progress.items.count_completed); - values.put(OverallProgressTable.COLUMN_SELF_TESTS_COUNT_AVAILABLE, progress.self_tests.count_available); - values.put(OverallProgressTable.COLUMN_SELF_TESTS_COUNT_TAKEN, progress.self_tests.count_taken); - values.put(OverallProgressTable.COLUMN_SELF_TESTS_POINTS_POSSIBLE, progress.self_tests.points_possible); - values.put(OverallProgressTable.COLUMN_SELF_TESTS_POINTS_SCORED, progress.self_tests.points_scored); - values.put(OverallProgressTable.COLUMN_ASSIGNMENTS_COUNT_AVAILABLE, progress.assignments.count_available); - values.put(OverallProgressTable.COLUMN_ASSIGNMENTS_COUNT_TAKEN, progress.assignments.count_taken); - values.put(OverallProgressTable.COLUMN_ASSIGNMENTS_POINTS_POSSIBLE, progress.assignments.points_possible); - values.put(OverallProgressTable.COLUMN_ASSIGNMENTS_POINTS_SCORED, progress.assignments.points_scored); - - return values; - } - - public int getProgressCount() { - String countQuery = "SELECT * FROM " + OverallProgressTable.TABLE_NAME; - Cursor cursor = openDatabase().rawQuery(countQuery, null); - - int count = cursor.getCount(); - - cursor.close(); - closeDatabase(); - - return count; - } - - public int updateProgress(String id, OverallProgress progress) { - int affected = openDatabase().update( - OverallProgressTable.TABLE_NAME, - buildContentValues(id, progress), - OverallProgressTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}); - - closeDatabase(); - - return affected; - } - - public void deleteProgress(String id) { - openDatabase().delete( - OverallProgressTable.TABLE_NAME, - OverallProgressTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}); - - closeDatabase(); - } - -} diff --git a/app/src/main/java/de/xikolo/data/database/VideoDataAccess.java b/app/src/main/java/de/xikolo/data/database/VideoDataAccess.java deleted file mode 100644 index c0fcb4653..000000000 --- a/app/src/main/java/de/xikolo/data/database/VideoDataAccess.java +++ /dev/null @@ -1,155 +0,0 @@ -package de.xikolo.data.database; - -import android.content.ContentValues; -import android.database.Cursor; - -import java.util.ArrayList; -import java.util.List; - -import de.xikolo.data.entities.VideoItemDetail; - -public class VideoDataAccess extends DataAccess { - - public VideoDataAccess(DatabaseHelper databaseHelper) { - super(databaseHelper); - } - - public void addVideo(VideoItemDetail video) { - openDatabase().insert(VideoTable.TABLE_NAME, null, buildContentValues(video)); - - closeDatabase(); - } - - public void addOrUpdateVideo(VideoItemDetail video) { - if (updateVideo(video) < 1) { - addVideo(video); - } - } - - public VideoItemDetail getVideo(String id) { - Cursor cursor = openDatabase().query( - VideoTable.TABLE_NAME, - new String[]{ - VideoTable.COLUMN_ID, - VideoTable.COLUMN_TITLE, - VideoTable.COLUMN_MINUTES, - VideoTable.COLUMN_SECONDS, - VideoTable.COLUMN_PROGRESS, - VideoTable.COLUMN_URL, - VideoTable.COLUMN_DOWNLOAD_URL, - VideoTable.COLUMN_SLIDES_URL, - VideoTable.COLUMN_TRANSCRIPT_URL, - VideoTable.COLUMN_HD_URL, - VideoTable.COLUMN_SD_URL, - VideoTable.COLUMN_VIMEO_ID, - VideoTable.COLUMN_POSTER_IMAGE_URL, - }, - VideoTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(id)}, null, null, null, null); - - VideoItemDetail video = null; - if (cursor.moveToFirst()) { - video = buildVideo(cursor); - } - - cursor.close(); - closeDatabase(); - - return video; - } - - public List getAllVideos() { - List videoList = new ArrayList<>(); - - String selectQuery = "SELECT * FROM " + VideoTable.TABLE_NAME; - - Cursor cursor = openDatabase().rawQuery(selectQuery, null); - - if (cursor.moveToFirst()) { - do { - VideoItemDetail video = buildVideo(cursor); - videoList.add(video); - } while (cursor.moveToNext()); - } - - cursor.close(); - closeDatabase(); - - return videoList; - } - - private VideoItemDetail buildVideo(Cursor cursor) { - VideoItemDetail video = new VideoItemDetail(); - - video.id = cursor.getString(0); - video.title = cursor.getString(1); - video.minutes = cursor.getString(2); - video.seconds = cursor.getString(3); - video.progress = cursor.getInt(4); - video.url = cursor.getString(5); - video.download_url = cursor.getString(6); - video.slides_url = cursor.getString(7); - video.transcript_url = cursor.getString(8); - video.stream.hd_url = cursor.getString(9); - video.stream.sd_url = cursor.getString(10); - video.stream.vimeo_id = cursor.getString(11); - video.stream.poster = cursor.getString(12); - - return video; - } - - private ContentValues buildContentValues(VideoItemDetail video) { - ContentValues values = new ContentValues(); - values.put(VideoTable.COLUMN_ID, video.id); - values.put(VideoTable.COLUMN_TITLE, video.title); - values.put(VideoTable.COLUMN_MINUTES, video.minutes); - values.put(VideoTable.COLUMN_SECONDS, video.seconds); - if(video.progress > 0) { - values.put(VideoTable.COLUMN_PROGRESS, video.progress); - } - values.put(VideoTable.COLUMN_URL, video.url); - values.put(VideoTable.COLUMN_DOWNLOAD_URL, video.download_url); - values.put(VideoTable.COLUMN_SLIDES_URL, video.slides_url); - values.put(VideoTable.COLUMN_TRANSCRIPT_URL, video.transcript_url); - values.put(VideoTable.COLUMN_HD_URL, video.stream.hd_url); - values.put(VideoTable.COLUMN_SD_URL, video.stream.sd_url); - values.put(VideoTable.COLUMN_VIMEO_ID, video.stream.vimeo_id); - values.put(VideoTable.COLUMN_POSTER_IMAGE_URL, video.stream.poster); - - return values; - } - - public int getVideosCount() { - String countQuery = "SELECT * FROM " + VideoTable.TABLE_NAME; - Cursor cursor = openDatabase().rawQuery(countQuery, null); - - int count = cursor.getCount(); - - cursor.close(); - closeDatabase(); - - return count; - } - - public int updateVideo(VideoItemDetail video) { - int affected = openDatabase().update( - VideoTable.TABLE_NAME, - buildContentValues(video), - VideoTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(video.id)}); - - closeDatabase(); - - return affected; - } - - public void deleteVideo(VideoItemDetail video) { - openDatabase().delete( - VideoTable.TABLE_NAME, - VideoTable.COLUMN_ID + " =? ", - new String[]{String.valueOf(video.id)}); - - closeDatabase(); - } - -} diff --git a/app/src/main/java/de/xikolo/data/preferences/AppPreferences.java b/app/src/main/java/de/xikolo/data/preferences/AppPreferences.java deleted file mode 100644 index 6e146742b..000000000 --- a/app/src/main/java/de/xikolo/data/preferences/AppPreferences.java +++ /dev/null @@ -1,95 +0,0 @@ -package de.xikolo.data.preferences; - -import android.content.Context; -import android.content.SharedPreferences; -import android.support.v7.preference.PreferenceManager; - -import de.xikolo.R; -import de.xikolo.util.PlaybackSpeed; - -public class AppPreferences extends Preferences { - - public AppPreferences(Context context) { - super(context); - } - - private boolean getBoolean(String key) { - return getBoolean(key, true); - } - - private boolean getBoolean(String key, boolean defValue) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext); - return preferences.getBoolean(key, defValue); - } - - private void putBoolean(boolean value, String key) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean(key, value); - editor.apply(); - } - - public boolean isVideoQualityLimitedOnMobile() { - return getBoolean(mContext.getString(R.string.preference_video_quality)); - } - - public void setIsVideoQualityLimitedOnMobile(boolean value) { - putBoolean(value, mContext.getString(R.string.preference_video_quality)); - } - - public boolean isDownloadNetworkLimitedOnMobile() { - return getBoolean(mContext.getString(R.string.preference_download_network)); - } - - public void setIsDownloadNetworkLimitedOnMobile(boolean value) { - putBoolean(value, mContext.getString(R.string.preference_download_network)); - } - - public boolean confirmBeforeDeleting() { - return getBoolean(mContext.getString(R.string.preference_confirm_delete)); - } - - public void setConfirmBeforeDeleting(boolean value) { - putBoolean(value, mContext.getString(R.string.preference_confirm_delete)); - } - - public boolean isUsingExternalStorage() { - return getBoolean(mContext.getString(R.string.preference_storage)); - } - - public void setIsUsingExternalStorage(boolean value) { - putBoolean(value, mContext.getString(R.string.preference_storage)); - } - - public PlaybackSpeed getVideoPlaybackSpeed() { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext); - String speed = preferences.getString(mContext.getString(R.string.preference_video_playback_speed), - mContext.getString(R.string.settings_default_value_video_playback_speed)); - return PlaybackSpeed.get(speed); - } - - public void setVideoPlaybackSpeed(PlaybackSpeed speed) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext); - SharedPreferences.Editor editor = preferences.edit(); - editor.putString(mContext.getString(R.string.preference_video_playback_speed), - speed.toString()); - editor.apply(); - } - - public boolean usedSecondScreen() { - return getBoolean(mContext.getString(R.string.preference_used_second_screen), false); - } - - public void setUsedSecondScreen(boolean used) { - putBoolean(used, mContext.getString(R.string.preference_used_second_screen)); - } - - public boolean showedSecondScreenDialog() { - return getBoolean(mContext.getString(R.string.preference_dialog_second_screen), false); - } - - public void setShowedSecondScreenDialog(boolean showed) { - putBoolean(showed, mContext.getString(R.string.preference_dialog_second_screen)); - } - -} diff --git a/app/src/main/java/de/xikolo/data/preferences/Preferences.java b/app/src/main/java/de/xikolo/data/preferences/Preferences.java deleted file mode 100644 index c8e70d742..000000000 --- a/app/src/main/java/de/xikolo/data/preferences/Preferences.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.xikolo.data.preferences; - -import android.content.Context; - -public class Preferences { - - protected Context mContext; - - public Preferences(Context context) { - this.mContext = context; - } - -} diff --git a/app/src/main/java/de/xikolo/data/preferences/PreferencesFactory.java b/app/src/main/java/de/xikolo/data/preferences/PreferencesFactory.java deleted file mode 100644 index 6880b6d73..000000000 --- a/app/src/main/java/de/xikolo/data/preferences/PreferencesFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.xikolo.data.preferences; - -import android.content.Context; - -public class PreferencesFactory { - - private AppPreferences appPreferences; - - private UserPreferences userPreferences; - - private NotificationPreferences notificationPreferences; - - private Context context; - - public PreferencesFactory(Context context) { - this.context = context; - } - - public AppPreferences getAppPreferences() { - if (appPreferences == null) { - appPreferences = new AppPreferences(context); - } - return appPreferences; - } - - public UserPreferences getUserPreferences() { - if (userPreferences == null) { - userPreferences = new UserPreferences(context); - } - return userPreferences; - } - - public NotificationPreferences getNotificationPreferences() { - if (notificationPreferences == null) { - notificationPreferences = new NotificationPreferences(context); - } - return notificationPreferences; - } - -} diff --git a/app/src/main/java/de/xikolo/data/preferences/UserPreferences.java b/app/src/main/java/de/xikolo/data/preferences/UserPreferences.java deleted file mode 100644 index eb1e07974..000000000 --- a/app/src/main/java/de/xikolo/data/preferences/UserPreferences.java +++ /dev/null @@ -1,72 +0,0 @@ -package de.xikolo.data.preferences; - -import android.content.Context; -import android.content.SharedPreferences; - -import de.xikolo.data.entities.AccessToken; -import de.xikolo.data.entities.User; - -public class UserPreferences extends Preferences { - - public static final String PREF_USER = UserPreferences.class.getName(); - - public static String ACCESS_TOKEN_DEFAULT = null; - - private static String USER_ID = "id"; - private static String USER_FIRST_NAME = "first_name"; - private static String USER_LAST_NAME = "last_name"; - private static String USER_EMAIL = "email"; - private static String USER_ACCESS_TOKEN = "token"; - private static String USER_VISUAL_URL = "visual_url"; - - public UserPreferences(Context context) { - super(context); - } - - public User getUser() { - User user = new User(); - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_USER, Context.MODE_PRIVATE); - user.id = sharedPref.getString(USER_ID, null); - user.first_name = sharedPref.getString(USER_FIRST_NAME, null); - user.last_name = sharedPref.getString(USER_LAST_NAME, null); - user.email = sharedPref.getString(USER_EMAIL, null); - user.user_visual = sharedPref.getString(USER_VISUAL_URL, null); - return user; - } - - public void saveUser(User user) { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_USER, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.putString(USER_ID, user.id); - editor.putString(USER_FIRST_NAME, user.first_name); - editor.putString(USER_LAST_NAME, user.last_name); - editor.putString(USER_EMAIL, user.email); - editor.putString(USER_VISUAL_URL, user.user_visual); - editor.commit(); - } - - public void deleteUser() { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_USER, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.clear(); - editor.commit(); - } - - public AccessToken getAccessToken() { - AccessToken token = new AccessToken(); - token.token = ACCESS_TOKEN_DEFAULT; - if (mContext != null) { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_USER, Context.MODE_PRIVATE); - token.token = sharedPref.getString(USER_ACCESS_TOKEN, ACCESS_TOKEN_DEFAULT); - } - return token; - } - - public void saveAccessToken(AccessToken token) { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_USER, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.putString(USER_ACCESS_TOKEN, token.token); - editor.commit(); - } - -} diff --git a/app/src/main/java/de/xikolo/model/events/DownloadCompletedEvent.java b/app/src/main/java/de/xikolo/events/DownloadCompletedEvent.java similarity index 82% rename from app/src/main/java/de/xikolo/model/events/DownloadCompletedEvent.java rename to app/src/main/java/de/xikolo/events/DownloadCompletedEvent.java index 8131813c5..e1f012d7f 100644 --- a/app/src/main/java/de/xikolo/model/events/DownloadCompletedEvent.java +++ b/app/src/main/java/de/xikolo/events/DownloadCompletedEvent.java @@ -1,6 +1,6 @@ -package de.xikolo.model.events; +package de.xikolo.events; -import de.xikolo.data.entities.Download; +import de.xikolo.models.Download; public class DownloadCompletedEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/DownloadDeletedEvent.java b/app/src/main/java/de/xikolo/events/DownloadDeletedEvent.java similarity index 81% rename from app/src/main/java/de/xikolo/model/events/DownloadDeletedEvent.java rename to app/src/main/java/de/xikolo/events/DownloadDeletedEvent.java index a6c455ef7..bf090eaa4 100644 --- a/app/src/main/java/de/xikolo/model/events/DownloadDeletedEvent.java +++ b/app/src/main/java/de/xikolo/events/DownloadDeletedEvent.java @@ -1,6 +1,6 @@ -package de.xikolo.model.events; +package de.xikolo.events; -import de.xikolo.data.entities.Item; +import de.xikolo.models.Item; public class DownloadDeletedEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/DownloadStartedEvent.java b/app/src/main/java/de/xikolo/events/DownloadStartedEvent.java similarity index 90% rename from app/src/main/java/de/xikolo/model/events/DownloadStartedEvent.java rename to app/src/main/java/de/xikolo/events/DownloadStartedEvent.java index 1cb99aeb1..a762f05d2 100644 --- a/app/src/main/java/de/xikolo/model/events/DownloadStartedEvent.java +++ b/app/src/main/java/de/xikolo/events/DownloadStartedEvent.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public class DownloadStartedEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/EnrollEvent.java b/app/src/main/java/de/xikolo/events/EnrollEvent.java similarity index 80% rename from app/src/main/java/de/xikolo/model/events/EnrollEvent.java rename to app/src/main/java/de/xikolo/events/EnrollEvent.java index 053b25f85..2745c8328 100644 --- a/app/src/main/java/de/xikolo/model/events/EnrollEvent.java +++ b/app/src/main/java/de/xikolo/events/EnrollEvent.java @@ -1,6 +1,6 @@ -package de.xikolo.model.events; +package de.xikolo.events; -import de.xikolo.data.entities.Course; +import de.xikolo.models.Course; public class EnrollEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/Event.java b/app/src/main/java/de/xikolo/events/Event.java similarity index 89% rename from app/src/main/java/de/xikolo/model/events/Event.java rename to app/src/main/java/de/xikolo/events/Event.java index 30fb8de66..d23b7f850 100644 --- a/app/src/main/java/de/xikolo/model/events/Event.java +++ b/app/src/main/java/de/xikolo/events/Event.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public abstract class Event { diff --git a/app/src/main/java/de/xikolo/model/events/LoginEvent.java b/app/src/main/java/de/xikolo/events/LoginEvent.java similarity index 79% rename from app/src/main/java/de/xikolo/model/events/LoginEvent.java rename to app/src/main/java/de/xikolo/events/LoginEvent.java index bfdcd1ea4..ff6a905a5 100644 --- a/app/src/main/java/de/xikolo/model/events/LoginEvent.java +++ b/app/src/main/java/de/xikolo/events/LoginEvent.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public class LoginEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/LogoutEvent.java b/app/src/main/java/de/xikolo/events/LogoutEvent.java similarity index 80% rename from app/src/main/java/de/xikolo/model/events/LogoutEvent.java rename to app/src/main/java/de/xikolo/events/LogoutEvent.java index a0a0df674..a558ec275 100644 --- a/app/src/main/java/de/xikolo/model/events/LogoutEvent.java +++ b/app/src/main/java/de/xikolo/events/LogoutEvent.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public class LogoutEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/NetworkStateEvent.java b/app/src/main/java/de/xikolo/events/NetworkStateEvent.java similarity index 90% rename from app/src/main/java/de/xikolo/model/events/NetworkStateEvent.java rename to app/src/main/java/de/xikolo/events/NetworkStateEvent.java index 7fe2e38d0..99d4cbc5c 100644 --- a/app/src/main/java/de/xikolo/model/events/NetworkStateEvent.java +++ b/app/src/main/java/de/xikolo/events/NetworkStateEvent.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public class NetworkStateEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/PermissionDeniedEvent.java b/app/src/main/java/de/xikolo/events/PermissionDeniedEvent.java similarity index 90% rename from app/src/main/java/de/xikolo/model/events/PermissionDeniedEvent.java rename to app/src/main/java/de/xikolo/events/PermissionDeniedEvent.java index 8baf09e13..eb42b7aef 100644 --- a/app/src/main/java/de/xikolo/model/events/PermissionDeniedEvent.java +++ b/app/src/main/java/de/xikolo/events/PermissionDeniedEvent.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public class PermissionDeniedEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/PermissionGrantedEvent.java b/app/src/main/java/de/xikolo/events/PermissionGrantedEvent.java similarity index 90% rename from app/src/main/java/de/xikolo/model/events/PermissionGrantedEvent.java rename to app/src/main/java/de/xikolo/events/PermissionGrantedEvent.java index 6e3612dda..abe4b9371 100644 --- a/app/src/main/java/de/xikolo/model/events/PermissionGrantedEvent.java +++ b/app/src/main/java/de/xikolo/events/PermissionGrantedEvent.java @@ -1,4 +1,4 @@ -package de.xikolo.model.events; +package de.xikolo.events; public class PermissionGrantedEvent extends Event { diff --git a/app/src/main/java/de/xikolo/model/events/UnenrollEvent.java b/app/src/main/java/de/xikolo/events/UnenrollEvent.java similarity index 81% rename from app/src/main/java/de/xikolo/model/events/UnenrollEvent.java rename to app/src/main/java/de/xikolo/events/UnenrollEvent.java index 581f62b0f..a62bee2e7 100644 --- a/app/src/main/java/de/xikolo/model/events/UnenrollEvent.java +++ b/app/src/main/java/de/xikolo/events/UnenrollEvent.java @@ -1,6 +1,6 @@ -package de.xikolo.model.events; +package de.xikolo.events; -import de.xikolo.data.entities.Course; +import de.xikolo.models.Course; public class UnenrollEvent extends Event { diff --git a/app/src/main/java/de/xikolo/managers/BaseManager.java b/app/src/main/java/de/xikolo/managers/BaseManager.java new file mode 100644 index 000000000..77675af8b --- /dev/null +++ b/app/src/main/java/de/xikolo/managers/BaseManager.java @@ -0,0 +1,15 @@ +package de.xikolo.managers; + +import com.path.android.jobqueue.JobManager; + +public abstract class BaseManager { + + protected JobManager jobManager; + + public BaseManager(JobManager jobManager) { + super(); + + this.jobManager = jobManager; + } + +} diff --git a/app/src/main/java/de/xikolo/model/CourseModel.java b/app/src/main/java/de/xikolo/managers/CourseManager.java similarity index 77% rename from app/src/main/java/de/xikolo/model/CourseModel.java rename to app/src/main/java/de/xikolo/managers/CourseManager.java index 60b916d8f..07d4e6921 100644 --- a/app/src/main/java/de/xikolo/model/CourseModel.java +++ b/app/src/main/java/de/xikolo/managers/CourseManager.java @@ -1,4 +1,4 @@ -package de.xikolo.model; +package de.xikolo.managers; import com.path.android.jobqueue.JobManager; @@ -8,32 +8,34 @@ import java.util.List; import de.xikolo.GlobalApplication; -import de.xikolo.data.entities.Course; -import de.xikolo.model.jobs.CreateEnrollmentJob; -import de.xikolo.model.jobs.DeleteEnrollmentJob; -import de.xikolo.model.jobs.RetrieveCourseJob; -import de.xikolo.model.jobs.RetrieveCoursesJob; -import de.xikolo.util.DateUtil; +import de.xikolo.models.Course; +import de.xikolo.managers.jobs.CreateEnrollmentJob; +import de.xikolo.managers.jobs.DeleteEnrollmentJob; +import de.xikolo.managers.jobs.RetrieveCourseJob; +import de.xikolo.managers.jobs.RetrieveCourseListJob; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.utils.DateUtil; -public class CourseModel extends BaseModel { +public class CourseManager extends BaseManager { public enum CourseFilter { ALL, MY } - public static final String TAG = CourseModel.class.getSimpleName(); + public static final String TAG = CourseManager.class.getSimpleName(); - public CourseModel(JobManager jobManager) { + public CourseManager(JobManager jobManager) { super(jobManager); } public int getEnrollmentsCount() { - return GlobalApplication.getInstance() - .getDataAccessFactory().getCourseDataAccess().getEnrollmentsCount(); + CourseDataAdapter courseDataAdapter = (CourseDataAdapter) GlobalApplication.getDataAdapter(DataType.COURSE); + return courseDataAdapter.getEnrollmentsCount(); } public void getCourse(Result result, String courseId) { - mJobManager.addJobInBackground(new RetrieveCourseJob(result, courseId)); + jobManager.addJobInBackground(new RetrieveCourseJob(result, courseId)); } public void getCourses(Result> result, boolean includeProgress) { @@ -58,15 +60,15 @@ public List onFilter(List result, Result.DataSource dataSource) } }); - mJobManager.addJobInBackground(new RetrieveCoursesJob(result, includeProgress)); + jobManager.addJobInBackground(new RetrieveCourseListJob(result, includeProgress)); } public void addEnrollment(Result result, Course course) { - mJobManager.addJobInBackground(new CreateEnrollmentJob(result, course)); + jobManager.addJobInBackground(new CreateEnrollmentJob(result, course)); } public void deleteEnrollment(Result result, Course course) { - mJobManager.addJobInBackground(new DeleteEnrollmentJob(result, course)); + jobManager.addJobInBackground(new DeleteEnrollmentJob(result, course)); } public static void sortCoursesAscending(List courses) { diff --git a/app/src/main/java/de/xikolo/model/DownloadModel.java b/app/src/main/java/de/xikolo/managers/DownloadManager.java similarity index 89% rename from app/src/main/java/de/xikolo/model/DownloadModel.java rename to app/src/main/java/de/xikolo/managers/DownloadManager.java index f974ae146..364319ffe 100644 --- a/app/src/main/java/de/xikolo/model/DownloadModel.java +++ b/app/src/main/java/de/xikolo/managers/DownloadManager.java @@ -1,7 +1,6 @@ -package de.xikolo.model; +package de.xikolo.managers; import android.app.Activity; -import android.app.DownloadManager; import android.net.Uri; import android.os.Environment; import android.util.Log; @@ -18,28 +17,28 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Download; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.net.DownloadHelper; -import de.xikolo.model.events.DownloadDeletedEvent; -import de.xikolo.model.events.DownloadStartedEvent; -import de.xikolo.model.events.PermissionDeniedEvent; -import de.xikolo.model.events.PermissionGrantedEvent; -import de.xikolo.model.jobs.RetrieveContentLengthJob; -import de.xikolo.util.Config; -import de.xikolo.util.ExternalStorageUtil; -import de.xikolo.util.LanalyticsUtil; -import de.xikolo.util.ToastUtil; - -public class DownloadModel extends BaseModel { - - public static final String TAG = DownloadModel.class.getSimpleName(); +import de.xikolo.models.Course; +import de.xikolo.models.Download; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.network.DownloadHelper; +import de.xikolo.events.DownloadDeletedEvent; +import de.xikolo.events.DownloadStartedEvent; +import de.xikolo.events.PermissionDeniedEvent; +import de.xikolo.events.PermissionGrantedEvent; +import de.xikolo.managers.jobs.RetrieveContentLengthJob; +import de.xikolo.utils.Config; +import de.xikolo.utils.ExternalStorageUtil; +import de.xikolo.utils.LanalyticsUtil; +import de.xikolo.utils.ToastUtil; + +public class DownloadManager extends BaseManager { + + public static final String TAG = DownloadManager.class.getSimpleName(); private Activity activity; - private PermissionsModel permissionsModel; + private PermissionManager permissionsModel; public enum PendingAction { START, DELETE, CANCEL; @@ -81,11 +80,11 @@ public Item getItem() { private PendingAction pendingAction; - public DownloadModel(JobManager jobManager, Activity activity) { + public DownloadManager(JobManager jobManager, Activity activity) { super(jobManager); this.activity = activity; - this.permissionsModel = new PermissionsModel(jobManager, activity); + this.permissionsModel = new PermissionManager(jobManager, activity); this.pendingAction = null; @@ -93,7 +92,7 @@ public DownloadModel(JobManager jobManager, Activity activity) { } public void getRemoteDownloadFileSize(Result result, String url) { - mJobManager.addJobInBackground(new RetrieveContentLengthJob(result, url)); + jobManager.addJobInBackground(new RetrieveContentLengthJob(result, url)); } public long startDownload(String uri, DownloadFileType type, Course course, Module module, Item item) { @@ -101,7 +100,7 @@ public long startDownload(String uri, DownloadFileType type, Course course, Modu Log.d(TAG, "Start download for " + uri); } if (ExternalStorageUtil.isExternalStorageWritable()) { - if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionsModel.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { String file = this.escapeFilename(item.title) + type.getFileSuffix(); Uri downloadUri = buildDownloadUri(type, course, module, item); @@ -130,7 +129,7 @@ public long startDownload(String uri, DownloadFileType type, Course course, Modu public boolean deleteDownload(DownloadFileType type, Course course, Module module, Item item) { if (ExternalStorageUtil.isExternalStorageWritable()) { - if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionsModel.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { Uri downloadUri = buildDownloadUri(type, course, module, item); if (Config.DEBUG) { @@ -158,7 +157,7 @@ public boolean deleteDownload(DownloadFileType type, Course course, Module modul public boolean cancelDownload(DownloadFileType type, Course course, Module module, Item item) { if (ExternalStorageUtil.isExternalStorageWritable()) { - if (permissionsModel.requestPermission(PermissionsModel.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionsModel.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { Uri downloadUri = buildDownloadUri(type, course, module, item); Download dl = new Download(); dl.localUri = downloadUri.toString(); @@ -195,7 +194,7 @@ public boolean cancelDownload(DownloadFileType type, Course course, Module modul @SuppressWarnings("unused") @Subscribe public void onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEvent) { - if (permissionGrantedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { + if (permissionGrantedEvent.getRequestCode() == PermissionManager.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { if (pendingAction != null) { switch (pendingAction) { case START: @@ -221,7 +220,7 @@ public void onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEve @SuppressWarnings("unused") @Subscribe public void onPermissionDeniedEvent(PermissionDeniedEvent permissionDeniedEvent) { - if (permissionDeniedEvent.getRequestCode() == PermissionsModel.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { + if (permissionDeniedEvent.getRequestCode() == PermissionManager.REQUEST_CODE_WRITE_EXTERNAL_STORAGE) { pendingAction = null; } } @@ -250,7 +249,7 @@ public boolean downloadRunning(DownloadFileType type, Course course, Module modu Download dl = new Download(); dl.localUri = downloadUri.toString(); - int flags = DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING; + int flags = android.app.DownloadManager.STATUS_PAUSED | android.app.DownloadManager.STATUS_PENDING | android.app.DownloadManager.STATUS_RUNNING; Set dlSet = DownloadHelper.getAllDownloadsForStatus(flags); return dlSet.contains(dl); diff --git a/app/src/main/java/de/xikolo/model/ItemModel.java b/app/src/main/java/de/xikolo/managers/ItemManager.java similarity index 54% rename from app/src/main/java/de/xikolo/model/ItemModel.java rename to app/src/main/java/de/xikolo/managers/ItemManager.java index 28da02437..60e6bfe75 100644 --- a/app/src/main/java/de/xikolo/model/ItemModel.java +++ b/app/src/main/java/de/xikolo/managers/ItemManager.java @@ -1,4 +1,4 @@ -package de.xikolo.model; +package de.xikolo.managers; import com.path.android.jobqueue.JobManager; @@ -6,23 +6,23 @@ import java.util.Comparator; import java.util.List; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.Subtitle; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.model.jobs.RetrieveItemDetailJob; -import de.xikolo.model.jobs.RetrieveItemsJob; -import de.xikolo.model.jobs.RetrieveLocalVideoJob; -import de.xikolo.model.jobs.RetrieveVideoSubtitlesJob; -import de.xikolo.model.jobs.UpdateProgressionJob; -import de.xikolo.model.jobs.UpdateLocalVideoJob; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.Subtitle; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.managers.jobs.RetrieveItemDetailJob; +import de.xikolo.managers.jobs.RetrieveItemListJob; +import de.xikolo.managers.jobs.RetrieveLocalVideoJob; +import de.xikolo.managers.jobs.RetrieveVideoSubtitlesJob; +import de.xikolo.managers.jobs.UpdateProgressionJob; +import de.xikolo.managers.jobs.UpdateLocalVideoJob; -public class ItemModel extends BaseModel { +public class ItemManager extends BaseManager { - public static final String TAG = ItemModel.class.getSimpleName(); + public static final String TAG = ItemManager.class.getSimpleName(); - public ItemModel(JobManager jobManager) { + public ItemManager(JobManager jobManager) { super(jobManager); } @@ -39,7 +39,7 @@ public List onFilter(List result, Result.DataSource dataSource) { } }); - mJobManager.addJobInBackground(new RetrieveItemsJob(result, courseId, moduleId)); + jobManager.addJobInBackground(new RetrieveItemListJob(result, courseId, moduleId)); } public void getItemDetail(Result result, Course course, Module module, Item item, String itemType) { @@ -47,23 +47,23 @@ public void getItemDetail(Result result, Course course, Module module, Ite } public void getItemDetail(Result result, String courseId, String moduleId, String itemId, String itemType) { - mJobManager.addJobInBackground(new RetrieveItemDetailJob(result, courseId, moduleId, itemId, itemType)); + jobManager.addJobInBackground(new RetrieveItemDetailJob(result, courseId, moduleId, itemId, itemType)); } public void getVideoSubtitles(Result> result, String courseId, String moduleId, String videoId) { - mJobManager.addJobInBackground(new RetrieveVideoSubtitlesJob(result, courseId, moduleId, videoId)); + jobManager.addJobInBackground(new RetrieveVideoSubtitlesJob(result, courseId, moduleId, videoId)); } - public void updateProgression(Result result, Module module, Item item) { - mJobManager.addJobInBackground(new UpdateProgressionJob(result, module, item)); + public void updateProgression(Result result, Item item) { + jobManager.addJobInBackground(new UpdateProgressionJob(result, item)); } public void updateLocalVideoProgress(Result result, VideoItemDetail videoItemDetail) { - mJobManager.addJobInBackground(new UpdateLocalVideoJob(result, videoItemDetail)); + jobManager.addJobInBackground(new UpdateLocalVideoJob(result, videoItemDetail)); } public void getLocalVideoProgress(Result result, VideoItemDetail videoItemDetail) { - mJobManager.addJobInBackground(new RetrieveLocalVideoJob(result, videoItemDetail)); + jobManager.addJobInBackground(new RetrieveLocalVideoJob(result, videoItemDetail.id)); } public static void sortItems(List items) { diff --git a/app/src/main/java/de/xikolo/model/ModuleModel.java b/app/src/main/java/de/xikolo/managers/ModuleManager.java similarity index 64% rename from app/src/main/java/de/xikolo/model/ModuleModel.java rename to app/src/main/java/de/xikolo/managers/ModuleManager.java index 8beac0b05..f0ebbdcde 100644 --- a/app/src/main/java/de/xikolo/model/ModuleModel.java +++ b/app/src/main/java/de/xikolo/managers/ModuleManager.java @@ -1,4 +1,4 @@ -package de.xikolo.model; +package de.xikolo.managers; import com.path.android.jobqueue.JobManager; @@ -6,17 +6,17 @@ import java.util.Comparator; import java.util.List; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Module; -import de.xikolo.model.jobs.RetrieveModuleWithItemsJob; -import de.xikolo.model.jobs.RetrieveModulesJob; -import de.xikolo.model.jobs.RetrieveModulesWithItemsJob; +import de.xikolo.models.Course; +import de.xikolo.models.Module; +import de.xikolo.managers.jobs.RetrieveModuleWithItemListJob; +import de.xikolo.managers.jobs.RetrieveModuleListJob; +import de.xikolo.managers.jobs.RetrieveModuleListWithItemListJob; -public class ModuleModel extends BaseModel { +public class ModuleManager extends BaseManager { - public static final String TAG = ModuleModel.class.getSimpleName(); + public static final String TAG = ModuleManager.class.getSimpleName(); - public ModuleModel(JobManager jobManager) { + public ModuleManager(JobManager jobManager) { super(jobManager); } @@ -29,7 +29,7 @@ public List onFilter(List result, Result.DataSource dataSource) } }); - mJobManager.addJobInBackground(new RetrieveModulesJob(result, course, includeProgress)); + jobManager.addJobInBackground(new RetrieveModuleListJob(result, course.id, includeProgress)); } public void getModulesWithItems(Result> result, Course course, boolean includeProgress) { @@ -38,25 +38,25 @@ public void getModulesWithItems(Result> result, Course course, bool public List onFilter(List result, Result.DataSource dataSource) { sortModules(result); for (Module module : result) { - ItemModel.sortItems(module.items); + ItemManager.sortItems(module.items); } return result; } }); - mJobManager.addJobInBackground(new RetrieveModulesWithItemsJob(result, course, includeProgress)); + jobManager.addJobInBackground(new RetrieveModuleListWithItemListJob(result, course.id, includeProgress)); } public void getModuleWithItems(Result result, String courseId, String moduleId) { result.setResultFilter(result.new ResultFilter() { @Override public Module onFilter(Module result, Result.DataSource dataSource) { - ItemModel.sortItems(result.items); + ItemManager.sortItems(result.items); return result; } }); - mJobManager.addJobInBackground(new RetrieveModuleWithItemsJob(result, courseId, moduleId)); + jobManager.addJobInBackground(new RetrieveModuleWithItemListJob(result, courseId, moduleId)); } public static void sortModules(List modules) { diff --git a/app/src/main/java/de/xikolo/model/PermissionsModel.java b/app/src/main/java/de/xikolo/managers/PermissionManager.java similarity index 90% rename from app/src/main/java/de/xikolo/model/PermissionsModel.java rename to app/src/main/java/de/xikolo/managers/PermissionManager.java index 051d423d6..9dfa1ee2e 100644 --- a/app/src/main/java/de/xikolo/model/PermissionsModel.java +++ b/app/src/main/java/de/xikolo/managers/PermissionManager.java @@ -1,4 +1,4 @@ -package de.xikolo.model; +package de.xikolo.managers; import android.Manifest; import android.app.Activity; @@ -13,11 +13,11 @@ import com.path.android.jobqueue.JobManager; import de.xikolo.GlobalApplication; -import de.xikolo.controller.dialogs.PermissionsDialog; +import de.xikolo.controllers.dialogs.PermissionsDialog; -public class PermissionsModel extends BaseModel { +public class PermissionManager extends BaseManager { - public static final String TAG = PermissionsModel.class.getSimpleName(); + public static final String TAG = PermissionManager.class.getSimpleName(); public static final int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 92; @@ -25,7 +25,7 @@ public class PermissionsModel extends BaseModel { private Activity mActivity; - public PermissionsModel(JobManager jobManager, Activity parentActivity) { + public PermissionManager(JobManager jobManager, Activity parentActivity) { super(jobManager); this.mActivity = parentActivity; } diff --git a/app/src/main/java/de/xikolo/model/Result.java b/app/src/main/java/de/xikolo/managers/Result.java similarity index 96% rename from app/src/main/java/de/xikolo/model/Result.java rename to app/src/main/java/de/xikolo/managers/Result.java index b81249393..5f2f1f1e4 100644 --- a/app/src/main/java/de/xikolo/model/Result.java +++ b/app/src/main/java/de/xikolo/managers/Result.java @@ -1,11 +1,11 @@ -package de.xikolo.model; +package de.xikolo.managers; import android.os.Handler; import android.os.Looper; import org.greenrobot.eventbus.EventBus; -import de.xikolo.model.events.NetworkStateEvent; +import de.xikolo.events.NetworkStateEvent; public abstract class Result { diff --git a/app/src/main/java/de/xikolo/managers/SecondScreenManager.java b/app/src/main/java/de/xikolo/managers/SecondScreenManager.java index 1801a81be..a586ec553 100644 --- a/app/src/main/java/de/xikolo/managers/SecondScreenManager.java +++ b/app/src/main/java/de/xikolo/managers/SecondScreenManager.java @@ -16,17 +16,13 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.SecondScreenActivity; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.entities.WebSocketMessage; -import de.xikolo.model.CourseModel; -import de.xikolo.model.ItemModel; -import de.xikolo.model.ModuleModel; -import de.xikolo.model.Result; -import de.xikolo.model.events.Event; +import de.xikolo.controllers.SecondScreenActivity; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.models.WebSocketMessage; +import de.xikolo.events.Event; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class SecondScreenManager { @@ -41,18 +37,18 @@ public class SecondScreenManager { private Item item; - private CourseModel courseModel; + private CourseManager courseManager; - private ModuleModel moduleModel; + private ModuleManager moduleManager; - private ItemModel itemModel; + private ItemManager itemManager; private boolean isRequesting; public SecondScreenManager() { - courseModel = new CourseModel(GlobalApplication.getInstance().getJobManager()); - moduleModel = new ModuleModel(GlobalApplication.getInstance().getJobManager()); - itemModel = new ItemModel(GlobalApplication.getInstance().getJobManager()); + courseManager = new CourseManager(GlobalApplication.getInstance().getJobManager()); + moduleManager = new ModuleManager(GlobalApplication.getInstance().getJobManager()); + itemManager = new ItemManager(GlobalApplication.getInstance().getJobManager()); EventBus.getDefault().register(this); @@ -114,7 +110,7 @@ protected void onError(ErrorCode errorCode) { protected void onSuccess(Module module, DataSource dataSource) { if (module != null && !module.equals(SecondScreenManager.this.module) && module.items != null && module.items.size() > 0) { SecondScreenManager.this.module = module; - itemModel.getItemDetail(itemResult, course.id, module.id, message.payload().get("item_id"), Item.TYPE_VIDEO); + itemManager.getItemDetail(itemResult, course.id, module.id, message.payload().get("item_id"), Item.TYPE_VIDEO); } } @@ -129,7 +125,7 @@ protected void onError(ErrorCode errorCode) { protected void onSuccess(Course course, DataSource dataSource) { if (course != null && !course.equals(SecondScreenManager.this.course)) { SecondScreenManager.this.course = course; - moduleModel.getModuleWithItems(moduleResult, course.id, message.payload().get("section_id")); + moduleManager.getModuleWithItems(moduleResult, course.id, message.payload().get("section_id")); } } @@ -145,7 +141,7 @@ protected void onError(ErrorCode errorCode) { isRequesting = true; course = null; module = null; - courseModel.getCourse(courseResult, message.payload().get("course_id")); + courseManager.getCourse(courseResult, message.payload().get("course_id")); } else if (item != null && item.id.equals(message.payload().get("item_id"))) { // post video updated event EventBus.getDefault().post(new SecondScreenUpdateVideoEvent(course, module, item, message)); diff --git a/app/src/main/java/de/xikolo/managers/UserManager.java b/app/src/main/java/de/xikolo/managers/UserManager.java new file mode 100644 index 000000000..86cab4002 --- /dev/null +++ b/app/src/main/java/de/xikolo/managers/UserManager.java @@ -0,0 +1,59 @@ +package de.xikolo.managers; + +import com.path.android.jobqueue.JobManager; + +import org.greenrobot.eventbus.EventBus; + +import de.xikolo.GlobalApplication; +import de.xikolo.events.LogoutEvent; +import de.xikolo.managers.jobs.CreateAccessTokenJob; +import de.xikolo.managers.jobs.RetrieveUserJob; +import de.xikolo.models.User; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.storages.preferences.UserStorage; + +public class UserManager extends BaseManager { + + public static final String TAG = UserManager.class.getSimpleName(); + + public UserManager(JobManager jobManager) { + super(jobManager); + } + + public static String getToken() { + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); + return userStorage.getAccessToken().token; + } + + public static User getSavedUser() { + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); + return userStorage.getUser(); + } + + public static boolean isLoggedIn() { + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); + return userStorage.getAccessToken().token != null; + } + + public void logout() { + GlobalApplication application = GlobalApplication.getInstance(); + + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); + userStorage.deleteUser(); + + application.getDatabaseHelper().deleteDatabase(); + + application.getLanalytics().deleteData(); + + EventBus.getDefault().post(new LogoutEvent()); + } + + public void login(Result result, String email, String password) { + jobManager.addJobInBackground(new CreateAccessTokenJob(result, email, password)); + } + + public void getUser(Result result) { + jobManager.addJobInBackground(new RetrieveUserJob(result)); + } + +} diff --git a/app/src/main/java/de/xikolo/managers/WebSocketManager.java b/app/src/main/java/de/xikolo/managers/WebSocketManager.java index 72d894200..3ef0f8bb3 100644 --- a/app/src/main/java/de/xikolo/managers/WebSocketManager.java +++ b/app/src/main/java/de/xikolo/managers/WebSocketManager.java @@ -23,15 +23,14 @@ import javax.net.ssl.SSLContext; import de.xikolo.GlobalApplication; -import de.xikolo.data.entities.WebSocketMessage; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.UserModel; -import de.xikolo.model.events.Event; -import de.xikolo.model.events.LoginEvent; -import de.xikolo.model.events.LogoutEvent; -import de.xikolo.model.events.NetworkStateEvent; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.models.WebSocketMessage; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.events.Event; +import de.xikolo.events.LoginEvent; +import de.xikolo.events.LogoutEvent; +import de.xikolo.events.NetworkStateEvent; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class WebSocketManager { @@ -134,8 +133,8 @@ private boolean isConnecting() { @SuppressWarnings("unused") @Subscribe(threadMode = ThreadMode.BACKGROUND) public void onNetworkEvent(NetworkStateEvent event) { - if (event.isOnline() && UserModel.isLoggedIn(GlobalApplication.getInstance())) { - initConnection(UserModel.getToken(GlobalApplication.getInstance())); + if (event.isOnline() && UserManager.isLoggedIn()) { + initConnection(UserManager.getToken()); } } @@ -143,7 +142,7 @@ public void onNetworkEvent(NetworkStateEvent event) { @Subscribe(threadMode = ThreadMode.BACKGROUND) public void onLoginEvent(LoginEvent event) { if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - initConnection(UserModel.getToken(GlobalApplication.getInstance())); + initConnection(UserManager.getToken()); } } diff --git a/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java b/app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java similarity index 81% rename from app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java rename to app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java index dc51d4a85..76e91ca0f 100644 --- a/app/src/main/java/de/xikolo/model/jobs/CreateAccessTokenJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -11,14 +11,15 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.entities.AccessToken; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.data.preferences.UserPreferences; -import de.xikolo.model.Result; -import de.xikolo.model.events.LoginEvent; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.events.LoginEvent; +import de.xikolo.managers.Result; +import de.xikolo.models.AccessToken; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.storages.preferences.UserStorage; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.FormBody; import okhttp3.RequestBody; import okhttp3.Response; @@ -73,9 +74,8 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "AccessToken created"); - UserPreferences userPreferences = GlobalApplication.getInstance() - .getPreferencesFactory().getUserPreferences(); - userPreferences.saveAccessToken(token); + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); + userStorage.saveAccessToken(token); result.success(null, Result.DataSource.NETWORK); EventBus.getDefault().post(new LoginEvent()); diff --git a/app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java b/app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java similarity index 79% rename from app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java rename to app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java index 4adbb9754..1501cbe32 100644 --- a/app/src/main/java/de/xikolo/model/jobs/CreateEnrollmentJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,13 +9,14 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.CourseDataAccess; -import de.xikolo.data.entities.Course; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.managers.UserManager; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.models.Course; +import de.xikolo.network.ApiRequest; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.FormBody; import okhttp3.RequestBody; import okhttp3.Response; @@ -46,7 +47,7 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else if (!NetworkUtil.isOnline(GlobalApplication.getInstance())) { result.error(Result.ErrorCode.NO_NETWORK); @@ -67,9 +68,8 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Enrollment created"); course.is_enrolled = true; - CourseDataAccess courseDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getCourseDataAccess(); - courseDataAccess.updateCourse(course, false); + CourseDataAdapter courseDataAccess = (CourseDataAdapter) GlobalApplication.getDataAdapter(DataType.COURSE); + courseDataAccess.update(course, false); result.success(course, Result.DataSource.NETWORK); } else { if (Config.DEBUG) Log.w(TAG, "Enrollment not created"); diff --git a/app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java b/app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java similarity index 69% rename from app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java rename to app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java index 4186db62e..089efce03 100644 --- a/app/src/main/java/de/xikolo/model/jobs/DeleteEnrollmentJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,15 +9,16 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.DataAccessFactory; -import de.xikolo.data.database.ModuleDataAccess; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Module; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.models.Course; +import de.xikolo.models.Module; +import de.xikolo.network.ApiRequest; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; public class DeleteEnrollmentJob extends Job { @@ -46,7 +47,7 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else if (!NetworkUtil.isOnline(GlobalApplication.getInstance())) { result.error(Result.ErrorCode.NO_NETWORK); @@ -63,11 +64,13 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Enrollment deleted"); course.is_enrolled = false; - DataAccessFactory dataAccessFactory = GlobalApplication.getInstance().getDataAccessFactory(); - dataAccessFactory.getCourseDataAccess().updateCourse(course, false); - ModuleDataAccess moduleDataAccess = dataAccessFactory.getModuleDataAccess(); - for (Module module : moduleDataAccess.getAllModulesForCourse(course)) { - moduleDataAccess.deleteModule(module); + + CourseDataAdapter courseDataAdapter = (CourseDataAdapter) GlobalApplication.getDataAdapter(DataType.COURSE); + courseDataAdapter.update(course, false); + + ModuleDataAdapter moduleDataAdapter = (ModuleDataAdapter) GlobalApplication.getDataAdapter(DataType.MODULE); + for (Module module : moduleDataAdapter.getAllForCourse(course.id)) { + moduleDataAdapter.delete(module.id); } result.success(course, Result.DataSource.NETWORK); diff --git a/app/src/main/java/de/xikolo/model/jobs/Priority.java b/app/src/main/java/de/xikolo/managers/jobs/Priority.java similarity index 79% rename from app/src/main/java/de/xikolo/model/jobs/Priority.java rename to app/src/main/java/de/xikolo/managers/jobs/Priority.java index 0741f46b5..6f604cee5 100644 --- a/app/src/main/java/de/xikolo/model/jobs/Priority.java +++ b/app/src/main/java/de/xikolo/managers/jobs/Priority.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; public class Priority { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java similarity index 91% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java index ac03636d2..adba44778 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveContentLengthJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,10 +9,10 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.model.Result; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.network.ApiRequest; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; public class RetrieveContentLengthJob extends Job { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java similarity index 76% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java index 991d1b112..88e891d41 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveCourseJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,13 +9,14 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.CourseDataAccess; -import de.xikolo.data.entities.Course; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.models.Course; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; public class RetrieveCourseJob extends Job { @@ -46,9 +47,8 @@ public void onAdded() { @Override public void onRun() throws Throwable { - CourseDataAccess courseDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getCourseDataAccess(); - result.success(courseDataAccess.getCourse(courseId), Result.DataSource.LOCAL); + CourseDataAdapter courseDataAdapter = (CourseDataAdapter) GlobalApplication.getDataAdapter(DataType.COURSE); + result.success(courseDataAdapter.get(courseId), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { String url = Config.API + Config.COURSES + courseId; @@ -60,7 +60,7 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Course received (" + course.id + ")"); - courseDataAccess.addOrUpdateCourse(course, false); + courseDataAdapter.addOrUpdate(course, false); result.success(course, Result.DataSource.NETWORK); } else { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java similarity index 70% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java index cdbe4aa87..161f02bed 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveCoursesJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -12,19 +12,20 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.CourseDataAccess; -import de.xikolo.data.entities.Course; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.managers.UserManager; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.models.Course; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; -public class RetrieveCoursesJob extends Job { +public class RetrieveCourseListJob extends Job { - public static final String TAG = RetrieveCoursesJob.class.getSimpleName(); + public static final String TAG = RetrieveCourseListJob.class.getSimpleName(); private static final AtomicInteger jobCounter = new AtomicInteger(0); @@ -34,7 +35,7 @@ public class RetrieveCoursesJob extends Job { private boolean includeProgress; - public RetrieveCoursesJob(Result> result, boolean includeProgress) { + public RetrieveCourseListJob(Result> result, boolean includeProgress) { super(new Params(includeProgress ? Priority.MID : Priority.MID)); this.id = jobCounter.incrementAndGet(); @@ -49,12 +50,11 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (includeProgress && !UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (includeProgress && !UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - CourseDataAccess courseDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getCourseDataAccess(); - result.success(courseDataAccess.getAllCourses(), Result.DataSource.LOCAL); + CourseDataAdapter courseDataAdapter = (CourseDataAdapter) GlobalApplication.getDataAdapter(DataType.COURSE); + result.success(courseDataAdapter.getAll(), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { String url = Config.API + Config.COURSES + "?include_progress=" + includeProgress; @@ -68,7 +68,7 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Courses received (" + courses.size() + ")"); for (Course course : courses) { - courseDataAccess.addOrUpdateCourse(course, includeProgress); + courseDataAdapter.addOrUpdate(course, includeProgress); } result.success(courses, Result.DataSource.NETWORK); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java similarity index 70% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java index c91a8db24..704373df3 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemDetailJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -6,21 +6,21 @@ import com.path.android.jobqueue.Params; import com.path.android.jobqueue.RetryConstraint; -import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.controller.exceptions.WrongParameterException; -import de.xikolo.data.database.ItemDataAccess; -import de.xikolo.data.database.VideoDataAccess; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.controllers.exceptions.WrongParameterException; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Item; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.storages.databases.adapters.VideoDataAdapter; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; public class RetrieveItemDetailJob extends Job { @@ -64,17 +64,16 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - VideoDataAccess videoDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getVideoDataAccess(); - ItemDataAccess itemDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getItemDataAccess(); + ItemDataAdapter itemDataAdapter = (ItemDataAdapter) GlobalApplication.getDataAdapter(DataType.ITEM); + VideoDataAdapter videoDataAdapter = (VideoDataAdapter) GlobalApplication.getDataAdapter(DataType.VIDEO); + if (itemType.equals(Item.TYPE_VIDEO)) { - Item item = itemDataAccess.getItem(itemId); + Item item = itemDataAdapter.get(itemId); if (item != null) { - item.detail = videoDataAccess.getVideo(itemId); + item.detail = videoDataAdapter.get(itemId); if (item.detail != null) { result.success(item, Result.DataSource.LOCAL); } @@ -87,17 +86,19 @@ public void onRun() throws Throwable { Response response = new ApiRequest(url).execute(); if (response.isSuccessful()) { - Type type = Item.getTypeToken(itemType); - Item item = ApiParser.parse(response, type); + Item item = ApiParser.parse(response, Item.getTypeToken(itemType)); response.close(); + item.courseId = courseId; + item.moduleId = moduleId; + if (Config.DEBUG) Log.i(TAG, "ItemDetail received"); if (itemType.equals(Item.TYPE_VIDEO)) { - itemDataAccess.addOrUpdateItem(moduleId, item); - videoDataAccess.addOrUpdateVideo((VideoItemDetail) item.detail); + itemDataAdapter.addOrUpdate(item); + videoDataAdapter.addOrUpdate((VideoItemDetail) item.detail); // get local video progress, if available - item.detail = videoDataAccess.getVideo(item.id); + item.detail = videoDataAdapter.get(item.id); } result.success(item, Result.DataSource.NETWORK); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java similarity index 69% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java index 86956d179..a3cb216be 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveItemsJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -12,19 +12,20 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.ItemDataAccess; -import de.xikolo.data.entities.Item; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.managers.UserManager; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.models.Item; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; -public class RetrieveItemsJob extends Job { +public class RetrieveItemListJob extends Job { - public static final String TAG = RetrieveItemsJob.class.getSimpleName(); + public static final String TAG = RetrieveItemListJob.class.getSimpleName(); private static final AtomicInteger jobCounter = new AtomicInteger(0); @@ -34,7 +35,7 @@ public class RetrieveItemsJob extends Job { private String courseId; private String moduleId; - public RetrieveItemsJob(Result> result, String courseId, String moduleId) { + public RetrieveItemListJob(Result> result, String courseId, String moduleId) { super(new Params(Priority.MID)); id = jobCounter.incrementAndGet(); @@ -50,12 +51,11 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - ItemDataAccess itemDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getItemDataAccess(); - result.success(itemDataAccess.getAllItemsForModule(moduleId), Result.DataSource.LOCAL); + ItemDataAdapter itemDataAdapter = (ItemDataAdapter) GlobalApplication.getDataAdapter(DataType.ITEM); + result.success(itemDataAdapter.getAllForModule(moduleId), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { String url = Config.API + Config.COURSES + courseId + "/" @@ -70,7 +70,9 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Items received (" + items.size() + ")"); for (Item item : items) { - itemDataAccess.addOrUpdateItem(moduleId, item); + item.courseId = courseId; + item.moduleId = moduleId; + itemDataAdapter.addOrUpdate(item); } result.success(items, Result.DataSource.NETWORK); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveLocalVideoJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java similarity index 68% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveLocalVideoJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java index cb87dd327..557dbdfea 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveLocalVideoJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,11 +9,12 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.VideoDataAccess; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.VideoDataAdapter; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.utils.Config; public class RetrieveLocalVideoJob extends Job { @@ -23,15 +24,15 @@ public class RetrieveLocalVideoJob extends Job { private final int id; + private String videoId; private Result result; - private VideoItemDetail videoItemDetail; - public RetrieveLocalVideoJob(Result result, VideoItemDetail videoItemDetail) { + public RetrieveLocalVideoJob(Result result, String videoId) { super(new Params(Priority.MID)); id = jobCounter.incrementAndGet(); this.result = result; - this.videoItemDetail = videoItemDetail; + this.videoId = videoId; } @Override @@ -41,12 +42,11 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - VideoDataAccess videoDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getVideoDataAccess(); - VideoItemDetail video = videoDataAccess.getVideo(videoItemDetail.id); + VideoDataAdapter videoDataAdapter = (VideoDataAdapter) GlobalApplication.getDataAdapter(DataType.VIDEO); + VideoItemDetail video = videoDataAdapter.get(videoId); if (video != null) { result.success(video, Result.DataSource.LOCAL); } else { diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java similarity index 70% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java index 6cf067149..1143cec2f 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -13,51 +13,51 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.ModuleDataAccess; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Module; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Module; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; -public class RetrieveModulesJob extends Job { +public class RetrieveModuleListJob extends Job { - public static final String TAG = RetrieveModulesJob.class.getSimpleName(); + public static final String TAG = RetrieveModuleListJob.class.getSimpleName(); private static final AtomicInteger jobCounter = new AtomicInteger(0); private final int id; - private Result> result; - private Course course; + private String courseId; private boolean includeProgress; + private Result> result; - public RetrieveModulesJob(Result> result, Course course, boolean includeProgress) { + public RetrieveModuleListJob(Result> result, String courseId, boolean includeProgress) { super(new Params(Priority.MID)); id = jobCounter.incrementAndGet(); this.result = result; - this.course = course; + this.courseId = courseId; this.includeProgress = includeProgress; } @Override public void onAdded() { - if (Config.DEBUG) Log.i(TAG, TAG + " added | includeProgress " + includeProgress + " | course.id " + course.id); + if (Config.DEBUG) Log.i(TAG, TAG + " added | includeProgress " + includeProgress + " | course.id " + courseId); } @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance()) || !course.is_enrolled) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - ModuleDataAccess moduleDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getModuleDataAccess(); - List localModules = moduleDataAccess.getAllModulesForCourse(course); + ModuleDataAdapter moduleDataAccess = (ModuleDataAdapter) GlobalApplication.getDataAdapter(DataType.MODULE); + List localModules = moduleDataAccess.getAllForCourse(courseId); + if (includeProgress) { List deleteList = new ArrayList<>(); for (Module module : localModules) { @@ -70,7 +70,7 @@ public void onRun() throws Throwable { result.success(localModules, Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - String url = Config.API + Config.COURSES + course.id + "/" + String url = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + "?include_progress=" + includeProgress; Response response = new ApiRequest(url).execute(); @@ -82,7 +82,8 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Modules received (" + modules.size() + ")"); for (Module module : modules) { - moduleDataAccess.addOrUpdateModule(course.id, module, includeProgress); + module.courseId = courseId; + moduleDataAccess.addOrUpdate(module, includeProgress); } result.success(modules, Result.DataSource.NETWORK); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java similarity index 68% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java index 7036ae795..b4b07458b 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveModulesWithItemsJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -13,69 +13,67 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.DataAccessFactory; -import de.xikolo.data.database.ItemDataAccess; -import de.xikolo.data.database.ModuleDataAccess; -import de.xikolo.data.entities.Course; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; -public class RetrieveModulesWithItemsJob extends Job { +public class RetrieveModuleListWithItemListJob extends Job { - public static final String TAG = RetrieveModulesWithItemsJob.class.getSimpleName(); + public static final String TAG = RetrieveModuleListWithItemListJob.class.getSimpleName(); private static final AtomicInteger jobCounter = new AtomicInteger(0); private final int id; - private Result> result; - private Course course; + private String courseId; private boolean includeProgress; + private Result> result; - public RetrieveModulesWithItemsJob(Result> result, Course course, boolean includeProgress) { + public RetrieveModuleListWithItemListJob(Result> result, String courseId, boolean includeProgress) { super(new Params(Priority.MID)); id = jobCounter.incrementAndGet(); this.result = result; - this.course = course; + this.courseId = courseId; this.includeProgress = includeProgress; } @Override public void onAdded() { - if (Config.DEBUG) Log.i(TAG, TAG + " added | includeProgress " + includeProgress + " | course.id " + course.id); + if (Config.DEBUG) Log.i(TAG, TAG + " added | includeProgress " + includeProgress + " | course.id " + courseId); } @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance()) || !course.is_enrolled) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - DataAccessFactory dataAccessFactory = GlobalApplication.getInstance().getDataAccessFactory(); - ModuleDataAccess moduleDataAccess = dataAccessFactory.getModuleDataAccess(); - ItemDataAccess itemDataAccess = dataAccessFactory.getItemDataAccess(); + ModuleDataAdapter moduleDataAdapter = (ModuleDataAdapter) GlobalApplication.getDataAdapter(DataType.MODULE); + ItemDataAdapter itemDataAdapter = (ItemDataAdapter) GlobalApplication.getDataAdapter(DataType.ITEM); - List localModules = moduleDataAccess.getAllModulesForCourse(course); + List localModules = moduleDataAdapter.getAllForCourse(courseId); List deleteList = new ArrayList<>(); for (Module module : localModules) { if (includeProgress && module.progress == null) { deleteList.add(module); } else { - module.items = itemDataAccess.getAllItemsForModule(module.id); + module.items = itemDataAdapter.getAllForModule(module.id); } } localModules.removeAll(deleteList); result.success(localModules, Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { - String url = Config.API + Config.COURSES + course.id + "/" + String url = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + "?include_progress=" + includeProgress; Response response = new ApiRequest(url).execute(); @@ -87,11 +85,12 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Modules received (" + modules.size() + ")"); for (Module module : modules) { - moduleDataAccess.addOrUpdateModule(course.id, module, includeProgress); + module.courseId = courseId; + moduleDataAdapter.addOrUpdate(module, includeProgress); } for (Module module : modules) { - String itemListUrl = Config.API + Config.COURSES + course.id + "/" + String itemListUrl = Config.API + Config.COURSES + courseId+ "/" + Config.MODULES + module.id + "/" + Config.ITEMS; response = new ApiRequest(itemListUrl).execute(); @@ -103,7 +102,9 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Items received (" + items.size() + ")"); for (Item item : items) { - itemDataAccess.addOrUpdateItem(module.id, item); + item.courseId = courseId; + item.moduleId = module.id; + itemDataAdapter.addOrUpdate(item); } module.items = items; diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java similarity index 69% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java index fd5e15953..accadce3e 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveModuleWithItemsJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -12,22 +12,22 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.DataAccessFactory; -import de.xikolo.data.database.ItemDataAccess; -import de.xikolo.data.database.ModuleDataAccess; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; -public class RetrieveModuleWithItemsJob extends Job { +public class RetrieveModuleWithItemListJob extends Job { - public static final String TAG = RetrieveModuleWithItemsJob.class.getSimpleName(); + public static final String TAG = RetrieveModuleWithItemListJob.class.getSimpleName(); private static final AtomicInteger jobCounter = new AtomicInteger(0); @@ -37,7 +37,7 @@ public class RetrieveModuleWithItemsJob extends Job { private String courseId; private String moduleId; - public RetrieveModuleWithItemsJob(Result result, String courseId, String moduleId) { + public RetrieveModuleWithItemListJob(Result result, String courseId, String moduleId) { super(new Params(Priority.MID)); id = jobCounter.incrementAndGet(); @@ -53,16 +53,15 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - DataAccessFactory dataAccessFactory = GlobalApplication.getInstance().getDataAccessFactory(); - ModuleDataAccess moduleDataAccess = dataAccessFactory.getModuleDataAccess(); - ItemDataAccess itemDataAccess = dataAccessFactory.getItemDataAccess(); + ModuleDataAdapter moduleDataAdapter = (ModuleDataAdapter) GlobalApplication.getDataAdapter(DataType.MODULE); + ItemDataAdapter itemDataAdapter = (ItemDataAdapter) GlobalApplication.getDataAdapter(DataType.ITEM); - Module localModule = moduleDataAccess.getModule(moduleId); + Module localModule = moduleDataAdapter.get(moduleId); if (localModule != null) { - localModule.items = itemDataAccess.getAllItemsForModule(moduleId); + localModule.items = itemDataAdapter.getAllForModule(moduleId); } if (localModule != null && localModule.items != null) { @@ -80,7 +79,8 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Module received (" + module.id + ")"); - moduleDataAccess.addOrUpdateModule(courseId, module, false); + module.courseId = courseId; + moduleDataAdapter.addOrUpdate(module, false); String itemListUrl = Config.API + Config.COURSES + courseId + "/" + Config.MODULES + moduleId + "/" + Config.ITEMS; @@ -94,7 +94,9 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "Items received (" + items.size() + ")"); for (Item item : items) { - itemDataAccess.addOrUpdateItem(module.id, item); + item.courseId = courseId; + item.moduleId = module.id; + itemDataAdapter.addOrUpdate(item); } module.items = items; diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java similarity index 74% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java index 87270e73b..e4956b3a3 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveUserJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,14 +9,15 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.entities.User; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.data.preferences.UserPreferences; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.managers.UserManager; +import de.xikolo.models.User; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.storages.preferences.UserStorage; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; public class RetrieveUserJob extends Job { @@ -43,13 +44,12 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - UserPreferences userPreferences = GlobalApplication.getInstance() - .getPreferencesFactory().getUserPreferences(); + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); - result.success(userPreferences.getUser(), Result.DataSource.LOCAL); + result.success(userStorage.getUser(), Result.DataSource.LOCAL); if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { String url = Config.API + Config.USER; @@ -61,7 +61,7 @@ public void onRun() throws Throwable { if (Config.DEBUG) Log.i(TAG, "User received: " + user.first_name); - userPreferences.saveUser(user); + userStorage.saveUser(user); result.success(user, Result.DataSource.NETWORK); } else { if (Config.DEBUG) Log.w(TAG, "No User received"); diff --git a/app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java similarity index 87% rename from app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java rename to app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java index 1cd1e4082..f55df7cb4 100644 --- a/app/src/main/java/de/xikolo/model/jobs/RetrieveVideoSubtitlesJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -12,14 +12,14 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.controller.exceptions.WrongParameterException; -import de.xikolo.data.entities.Subtitle; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.data.parser.ApiParser; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; -import de.xikolo.util.NetworkUtil; +import de.xikolo.controllers.exceptions.WrongParameterException; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Subtitle; +import de.xikolo.network.ApiRequest; +import de.xikolo.network.parser.ApiParser; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; +import de.xikolo.utils.NetworkUtil; import okhttp3.Response; public class RetrieveVideoSubtitlesJob extends Job { @@ -59,7 +59,7 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { if (NetworkUtil.isOnline(GlobalApplication.getInstance())) { diff --git a/app/src/main/java/de/xikolo/model/jobs/UpdateLocalVideoJob.java b/app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java similarity index 73% rename from app/src/main/java/de/xikolo/model/jobs/UpdateLocalVideoJob.java rename to app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java index f083356be..d14c8cb9c 100644 --- a/app/src/main/java/de/xikolo/model/jobs/UpdateLocalVideoJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,11 +9,12 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.VideoDataAccess; -import de.xikolo.data.entities.VideoItemDetail; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; +import de.xikolo.managers.UserManager; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.VideoDataAdapter; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.managers.Result; +import de.xikolo.utils.Config; public class UpdateLocalVideoJob extends Job { @@ -41,12 +42,11 @@ public void onAdded() { @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { - VideoDataAccess videoDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getVideoDataAccess(); - videoDataAccess.addOrUpdateVideo(videoItemDetail); + VideoDataAdapter videoDataAdapter = (VideoDataAdapter) GlobalApplication.getDataAdapter(DataType.VIDEO); + videoDataAdapter.addOrUpdate(videoItemDetail); result.success(null, Result.DataSource.LOCAL); } } diff --git a/app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java b/app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java similarity index 75% rename from app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java rename to app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java index 6dbe4e8b2..689b550e5 100644 --- a/app/src/main/java/de/xikolo/model/jobs/UpdateProgressionJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java @@ -1,4 +1,4 @@ -package de.xikolo.model.jobs; +package de.xikolo.managers.jobs; import android.util.Log; @@ -9,13 +9,13 @@ import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.data.database.ItemDataAccess; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.Module; -import de.xikolo.data.net.ApiRequest; -import de.xikolo.model.Result; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; +import de.xikolo.models.Item; +import de.xikolo.network.ApiRequest; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.utils.Config; import okhttp3.Response; public class UpdateProgressionJob extends Job { @@ -28,15 +28,13 @@ public class UpdateProgressionJob extends Job { private transient Result result; private Item item; - private Module module; - public UpdateProgressionJob(Result result, Module module, Item item) { + public UpdateProgressionJob(Result result, Item item) { super(new Params(Priority.LOW).requireNetwork().persist()); id = jobCounter.incrementAndGet(); this.result = result; this.item = item; - this.module = module; } @Override @@ -44,17 +42,16 @@ public void onAdded() { if (Config.DEBUG) Log.i(TAG, TAG + " added | item.id " + item.id); Log.d(TAG, "update progression added"); - ItemDataAccess itemDataAccess = GlobalApplication.getInstance() - .getDataAccessFactory().getItemDataAccess(); + ItemDataAdapter itemDataAccess = (ItemDataAdapter) GlobalApplication.getDataAdapter(DataType.ITEM); item.progress.visited = true; - itemDataAccess.updateItem(module.id, item); + itemDataAccess.update(item); result.success(null, Result.DataSource.LOCAL); } @Override public void onRun() throws Throwable { - if (!UserModel.isLoggedIn(GlobalApplication.getInstance())) { + if (!UserManager.isLoggedIn()) { result.error(Result.ErrorCode.NO_AUTH); } else { String url = Config.API + Config.USER + Config.PROGRESSIONS + item.id; diff --git a/app/src/main/java/de/xikolo/model/BaseModel.java b/app/src/main/java/de/xikolo/model/BaseModel.java deleted file mode 100644 index d9b746eda..000000000 --- a/app/src/main/java/de/xikolo/model/BaseModel.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.xikolo.model; - -import com.path.android.jobqueue.JobManager; - -public abstract class BaseModel { - - protected JobManager mJobManager; - - public BaseModel(JobManager jobManager) { - super(); - - mJobManager = jobManager; - } - -} diff --git a/app/src/main/java/de/xikolo/model/UserModel.java b/app/src/main/java/de/xikolo/model/UserModel.java deleted file mode 100644 index d97b216a8..000000000 --- a/app/src/main/java/de/xikolo/model/UserModel.java +++ /dev/null @@ -1,60 +0,0 @@ -package de.xikolo.model; - -import android.content.Context; - -import com.path.android.jobqueue.JobManager; - -import org.greenrobot.eventbus.EventBus; - -import de.xikolo.GlobalApplication; -import de.xikolo.data.entities.User; -import de.xikolo.data.preferences.UserPreferences; -import de.xikolo.model.events.LogoutEvent; -import de.xikolo.model.jobs.CreateAccessTokenJob; -import de.xikolo.model.jobs.RetrieveUserJob; - -public class UserModel extends BaseModel { - - public static final String TAG = UserModel.class.getSimpleName(); - - public UserModel(JobManager jobManager) { - super(jobManager); - } - - public static String getToken(Context context) { - UserPreferences prefs = GlobalApplication.getInstance() - .getPreferencesFactory().getUserPreferences(); - return prefs.getAccessToken().token; - } - - public static User getSavedUser(Context context) { - UserPreferences prefs = GlobalApplication.getInstance() - .getPreferencesFactory().getUserPreferences(); - return prefs.getUser(); - } - - public static boolean isLoggedIn(Context context) { - UserPreferences prefs = GlobalApplication.getInstance() - .getPreferencesFactory().getUserPreferences(); - return prefs.getAccessToken().token != null; - } - - public void logout() { - GlobalApplication application = GlobalApplication.getInstance(); - - application.getPreferencesFactory().getUserPreferences().deleteUser(); - application.getDataAccessFactory().getDatabaseHelper().deleteDatabase(); - application.getLanalytics().deleteData(); - - EventBus.getDefault().post(new LogoutEvent()); - } - - public void login(Result result, String email, String password) { - mJobManager.addJobInBackground(new CreateAccessTokenJob(result, email, password)); - } - - public void getUser(Result result) { - mJobManager.addJobInBackground(new RetrieveUserJob(result)); - } - -} diff --git a/app/src/main/java/de/xikolo/data/entities/AccessToken.java b/app/src/main/java/de/xikolo/models/AccessToken.java similarity index 80% rename from app/src/main/java/de/xikolo/data/entities/AccessToken.java rename to app/src/main/java/de/xikolo/models/AccessToken.java index dd662b1dc..bac333ac7 100644 --- a/app/src/main/java/de/xikolo/data/entities/AccessToken.java +++ b/app/src/main/java/de/xikolo/models/AccessToken.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import com.google.gson.annotations.SerializedName; diff --git a/app/src/main/java/de/xikolo/data/entities/AssignmentItemDetail.java b/app/src/main/java/de/xikolo/models/AssignmentItemDetail.java similarity index 98% rename from app/src/main/java/de/xikolo/data/entities/AssignmentItemDetail.java rename to app/src/main/java/de/xikolo/models/AssignmentItemDetail.java index c5aed7142..9a4c6074a 100644 --- a/app/src/main/java/de/xikolo/data/entities/AssignmentItemDetail.java +++ b/app/src/main/java/de/xikolo/models/AssignmentItemDetail.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; diff --git a/app/src/main/java/de/xikolo/data/entities/Course.java b/app/src/main/java/de/xikolo/models/Course.java similarity index 91% rename from app/src/main/java/de/xikolo/data/entities/Course.java rename to app/src/main/java/de/xikolo/models/Course.java index 5f066c185..3c55d3386 100644 --- a/app/src/main/java/de/xikolo/data/entities/Course.java +++ b/app/src/main/java/de/xikolo/models/Course.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; import android.os.Parcelable; @@ -7,7 +7,9 @@ import java.io.Serializable; -public class Course implements Parcelable, Serializable { +import de.xikolo.storages.databases.DatabaseModel; + +public class Course implements DatabaseModel, Parcelable, Serializable { @SerializedName("id") public String id; @@ -46,7 +48,12 @@ public class Course implements Parcelable, Serializable { public boolean is_enrolled; @SerializedName("progress") - public OverallProgress progress; + public Progress progress; + + @Override + public String getId() { + return id; + } @Override public int describeContents() { @@ -71,7 +78,7 @@ public void writeToParcel(Parcel parcel, int i) { } public Course() { - progress = new OverallProgress(); + progress = new Progress(); } public Course(Parcel in) { diff --git a/app/src/main/java/de/xikolo/data/entities/Download.java b/app/src/main/java/de/xikolo/models/Download.java similarity index 98% rename from app/src/main/java/de/xikolo/data/entities/Download.java rename to app/src/main/java/de/xikolo/models/Download.java index 951e5ea04..e280db392 100644 --- a/app/src/main/java/de/xikolo/data/entities/Download.java +++ b/app/src/main/java/de/xikolo/models/Download.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; public class Download { diff --git a/app/src/main/java/de/xikolo/data/entities/Enrollment.java b/app/src/main/java/de/xikolo/models/Enrollment.java similarity index 96% rename from app/src/main/java/de/xikolo/data/entities/Enrollment.java rename to app/src/main/java/de/xikolo/models/Enrollment.java index ffcb267a4..f14ddaf97 100644 --- a/app/src/main/java/de/xikolo/data/entities/Enrollment.java +++ b/app/src/main/java/de/xikolo/models/Enrollment.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; import android.os.Parcelable; diff --git a/app/src/main/java/de/xikolo/data/entities/Item.java b/app/src/main/java/de/xikolo/models/Item.java similarity index 93% rename from app/src/main/java/de/xikolo/data/entities/Item.java rename to app/src/main/java/de/xikolo/models/Item.java index 4ba482b9b..bac8b4d6e 100644 --- a/app/src/main/java/de/xikolo/data/entities/Item.java +++ b/app/src/main/java/de/xikolo/models/Item.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.content.Context; import android.os.Parcel; @@ -11,8 +11,9 @@ import java.lang.reflect.Type; import de.xikolo.R; +import de.xikolo.storages.databases.DatabaseModel; -public class Item implements Parcelable, Serializable { +public class Item implements DatabaseModel, Parcelable, Serializable { public static final String TYPE_TEXT = "text"; public static final String TYPE_VIDEO = "video"; @@ -120,12 +121,21 @@ public static Type getTypeToken(String itemType) { @SerializedName("exercise_type") public String exercise_type; + public String courseId; + + public String moduleId; + @SerializedName("object") public T detail; @SerializedName("progress") public Progress progress; + @Override + public String getId() { + return id; + } + @Override public int describeContents() { return 0; @@ -140,9 +150,11 @@ public void writeToParcel(Parcel parcel, int i) { parcel.writeString(available_from); parcel.writeString(available_to); parcel.writeByte((byte) (locked ? 1 : 0)); + parcel.writeString(exercise_type); + parcel.writeString(courseId); + parcel.writeString(moduleId); parcel.writeParcelable(detail, i); parcel.writeParcelable(progress, i); - parcel.writeString(exercise_type); } public Item(Parcel in) { @@ -153,9 +165,11 @@ public Item(Parcel in) { available_from = in.readString(); available_to = in.readString(); locked = in.readByte() != 0; + exercise_type = in.readString(); + courseId = in.readString(); + moduleId = in.readString(); detail = in.readParcelable(Item.class.getClassLoader()); progress = in.readParcelable(Item.class.getClassLoader()); - exercise_type = in.readString(); } public Item() { diff --git a/app/src/main/java/de/xikolo/data/entities/ItemDetail.java b/app/src/main/java/de/xikolo/models/ItemDetail.java similarity index 80% rename from app/src/main/java/de/xikolo/data/entities/ItemDetail.java rename to app/src/main/java/de/xikolo/models/ItemDetail.java index fda325415..192219c6e 100644 --- a/app/src/main/java/de/xikolo/data/entities/ItemDetail.java +++ b/app/src/main/java/de/xikolo/models/ItemDetail.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcelable; diff --git a/app/src/main/java/de/xikolo/data/entities/LtiItemDetail.java b/app/src/main/java/de/xikolo/models/LtiItemDetail.java similarity index 97% rename from app/src/main/java/de/xikolo/data/entities/LtiItemDetail.java rename to app/src/main/java/de/xikolo/models/LtiItemDetail.java index 6b60e4ecb..d0d945e03 100644 --- a/app/src/main/java/de/xikolo/data/entities/LtiItemDetail.java +++ b/app/src/main/java/de/xikolo/models/LtiItemDetail.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; diff --git a/app/src/main/java/de/xikolo/data/entities/Module.java b/app/src/main/java/de/xikolo/models/Module.java similarity index 86% rename from app/src/main/java/de/xikolo/data/entities/Module.java rename to app/src/main/java/de/xikolo/models/Module.java index 2570d5d93..82390a5dd 100644 --- a/app/src/main/java/de/xikolo/data/entities/Module.java +++ b/app/src/main/java/de/xikolo/models/Module.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; import android.os.Parcelable; @@ -9,7 +9,9 @@ import java.util.ArrayList; import java.util.List; -public class Module implements Parcelable, Serializable { +import de.xikolo.storages.databases.DatabaseModel; + +public class Module implements DatabaseModel, Parcelable, Serializable { @SerializedName("id") public String id; @@ -29,11 +31,18 @@ public class Module implements Parcelable, Serializable { @SerializedName("locked") public boolean locked; + public String courseId; + @SerializedName("progress") - public OverallProgress progress; + public Progress progress; public List items; + @Override + public String getId() { + return id; + } + @Override public int describeContents() { return 0; @@ -48,12 +57,13 @@ public void writeToParcel(Parcel parcel, int i) { parcel.writeString(available_to); parcel.writeByte((byte) (locked ? 1 : 0 )); parcel.writeTypedList(items); + parcel.writeString(courseId); parcel.writeParcelable(progress, i); } public Module() { items = new ArrayList<>(); - progress = new OverallProgress(); + progress = new Progress(); } public Module(Parcel in) { @@ -65,6 +75,7 @@ public Module(Parcel in) { available_to = in.readString(); locked = in.readByte() != 0; in.readTypedList(items, Item.CREATOR); + courseId = in.readString(); progress = in.readParcelable(Module.class.getClassLoader()); } diff --git a/app/src/main/java/de/xikolo/data/entities/PeerAssessmentItemDetail.java b/app/src/main/java/de/xikolo/models/PeerAssessmentItemDetail.java similarity index 94% rename from app/src/main/java/de/xikolo/data/entities/PeerAssessmentItemDetail.java rename to app/src/main/java/de/xikolo/models/PeerAssessmentItemDetail.java index 9f05ac387..310a11fcf 100644 --- a/app/src/main/java/de/xikolo/data/entities/PeerAssessmentItemDetail.java +++ b/app/src/main/java/de/xikolo/models/PeerAssessmentItemDetail.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; diff --git a/app/src/main/java/de/xikolo/data/entities/OverallProgress.java b/app/src/main/java/de/xikolo/models/Progress.java similarity index 80% rename from app/src/main/java/de/xikolo/data/entities/OverallProgress.java rename to app/src/main/java/de/xikolo/models/Progress.java index 38f85e0b9..770b4ce98 100644 --- a/app/src/main/java/de/xikolo/data/entities/OverallProgress.java +++ b/app/src/main/java/de/xikolo/models/Progress.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; import android.os.Parcelable; @@ -7,7 +7,11 @@ import java.io.Serializable; -public class OverallProgress implements Parcelable, Serializable { +import de.xikolo.storages.databases.DatabaseModel; + +public class Progress implements DatabaseModel, Parcelable, Serializable { + + public String id; @SerializedName("items") public ItemCount items; @@ -18,6 +22,11 @@ public class OverallProgress implements Parcelable, Serializable { @SerializedName("assignments") public TestCount assignments; + @Override + public String getId() { + return id; + } + @Override public int describeContents() { return 0; @@ -25,31 +34,33 @@ public int describeContents() { @Override public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(id); parcel.writeParcelable(items, i); parcel.writeParcelable(self_tests, i); parcel.writeParcelable(assignments, i); } - public OverallProgress() { + public Progress() { items = new ItemCount(); self_tests = new TestCount(); assignments = new TestCount(); } - public OverallProgress(Parcel in) { + public Progress(Parcel in) { this(); - items = in.readParcelable(OverallProgress.class.getClassLoader()); - self_tests = in.readParcelable(OverallProgress.class.getClassLoader()); - assignments = in.readParcelable(OverallProgress.class.getClassLoader()); + id = in.readString(); + items = in.readParcelable(Progress.class.getClassLoader()); + self_tests = in.readParcelable(Progress.class.getClassLoader()); + assignments = in.readParcelable(Progress.class.getClassLoader()); } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public OverallProgress createFromParcel(Parcel in) { - return new OverallProgress(in); + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public Progress createFromParcel(Parcel in) { + return new Progress(in); } - public OverallProgress[] newArray(int size) { - return new OverallProgress[size]; + public Progress[] newArray(int size) { + return new Progress[size]; } }; diff --git a/app/src/main/java/de/xikolo/data/entities/Progression.java b/app/src/main/java/de/xikolo/models/Progression.java similarity index 88% rename from app/src/main/java/de/xikolo/data/entities/Progression.java rename to app/src/main/java/de/xikolo/models/Progression.java index e42418498..0bf38439f 100644 --- a/app/src/main/java/de/xikolo/data/entities/Progression.java +++ b/app/src/main/java/de/xikolo/models/Progression.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import com.google.gson.annotations.SerializedName; diff --git a/app/src/main/java/de/xikolo/data/entities/Subtitle.java b/app/src/main/java/de/xikolo/models/Subtitle.java similarity index 98% rename from app/src/main/java/de/xikolo/data/entities/Subtitle.java rename to app/src/main/java/de/xikolo/models/Subtitle.java index 49b5d4bcf..d355db75b 100644 --- a/app/src/main/java/de/xikolo/data/entities/Subtitle.java +++ b/app/src/main/java/de/xikolo/models/Subtitle.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcelable; diff --git a/app/src/main/java/de/xikolo/data/entities/TextItemDetail.java b/app/src/main/java/de/xikolo/models/TextItemDetail.java similarity index 98% rename from app/src/main/java/de/xikolo/data/entities/TextItemDetail.java rename to app/src/main/java/de/xikolo/models/TextItemDetail.java index 6252f0e13..57af26b8d 100644 --- a/app/src/main/java/de/xikolo/data/entities/TextItemDetail.java +++ b/app/src/main/java/de/xikolo/models/TextItemDetail.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; diff --git a/app/src/main/java/de/xikolo/data/entities/User.java b/app/src/main/java/de/xikolo/models/User.java similarity index 91% rename from app/src/main/java/de/xikolo/data/entities/User.java rename to app/src/main/java/de/xikolo/models/User.java index 729043a79..cae115768 100644 --- a/app/src/main/java/de/xikolo/data/entities/User.java +++ b/app/src/main/java/de/xikolo/models/User.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import com.google.gson.annotations.SerializedName; diff --git a/app/src/main/java/de/xikolo/data/entities/VideoItemDetail.java b/app/src/main/java/de/xikolo/models/VideoItemDetail.java similarity index 94% rename from app/src/main/java/de/xikolo/data/entities/VideoItemDetail.java rename to app/src/main/java/de/xikolo/models/VideoItemDetail.java index 3ac759cff..90984939c 100644 --- a/app/src/main/java/de/xikolo/data/entities/VideoItemDetail.java +++ b/app/src/main/java/de/xikolo/models/VideoItemDetail.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcel; import android.os.Parcelable; @@ -7,7 +7,9 @@ import java.io.Serializable; -public class VideoItemDetail extends ItemDetail { +import de.xikolo.storages.databases.DatabaseModel; + +public class VideoItemDetail extends ItemDetail implements DatabaseModel { @SerializedName("id") public String id; @@ -38,6 +40,11 @@ public class VideoItemDetail extends ItemDetail { @SerializedName("pip_stream") public Stream stream; + @Override + public String getId() { + return id; + } + @Override public int describeContents() { return 0; diff --git a/app/src/main/java/de/xikolo/data/entities/WebSocketMessage.java b/app/src/main/java/de/xikolo/models/WebSocketMessage.java similarity index 96% rename from app/src/main/java/de/xikolo/data/entities/WebSocketMessage.java rename to app/src/main/java/de/xikolo/models/WebSocketMessage.java index a6370f42a..089b35b41 100644 --- a/app/src/main/java/de/xikolo/data/entities/WebSocketMessage.java +++ b/app/src/main/java/de/xikolo/models/WebSocketMessage.java @@ -1,4 +1,4 @@ -package de.xikolo.data.entities; +package de.xikolo.models; import android.os.Parcelable; diff --git a/app/src/main/java/de/xikolo/data/net/ApiRequest.java b/app/src/main/java/de/xikolo/network/ApiRequest.java similarity index 77% rename from app/src/main/java/de/xikolo/data/net/ApiRequest.java rename to app/src/main/java/de/xikolo/network/ApiRequest.java index d3b48241c..135f1cbe1 100644 --- a/app/src/main/java/de/xikolo/data/net/ApiRequest.java +++ b/app/src/main/java/de/xikolo/network/ApiRequest.java @@ -1,10 +1,10 @@ -package de.xikolo.data.net; +package de.xikolo.network; import android.content.Context; import de.xikolo.GlobalApplication; -import de.xikolo.model.UserModel; -import de.xikolo.util.Config; +import de.xikolo.managers.UserManager; +import de.xikolo.utils.Config; public class ApiRequest extends NetworkRequest { @@ -21,8 +21,8 @@ private void addDefaultHeader() { private boolean authorize() { Context context = GlobalApplication.getInstance(); - if (UserModel.isLoggedIn(context)) { - builder.addHeader(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserModel.getToken(context)); + if (UserManager.isLoggedIn()) { + builder.addHeader(Config.HEADER_AUTHORIZATION, Config.HEADER_AUTHORIZATION_PREFIX + UserManager.getToken()); return true; } else { return false; diff --git a/app/src/main/java/de/xikolo/data/net/DownloadHelper.java b/app/src/main/java/de/xikolo/network/DownloadHelper.java similarity index 93% rename from app/src/main/java/de/xikolo/data/net/DownloadHelper.java rename to app/src/main/java/de/xikolo/network/DownloadHelper.java index b8b93a171..c90f79a8f 100644 --- a/app/src/main/java/de/xikolo/data/net/DownloadHelper.java +++ b/app/src/main/java/de/xikolo/network/DownloadHelper.java @@ -1,4 +1,4 @@ -package de.xikolo.data.net; +package de.xikolo.network; import android.app.Application; import android.app.DownloadManager; @@ -9,7 +9,9 @@ import java.util.Set; import de.xikolo.GlobalApplication; -import de.xikolo.data.entities.Download; +import de.xikolo.models.Download; +import de.xikolo.storages.preferences.ApplicationPreferences; +import de.xikolo.storages.preferences.StorageType; public class DownloadHelper { @@ -17,8 +19,9 @@ public static long request(String uri, String target, String title) { DownloadManager dm = (DownloadManager) GlobalApplication.getInstance().getSystemService(Application.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(uri)); - if (GlobalApplication.getInstance().getPreferencesFactory() - .getAppPreferences().isDownloadNetworkLimitedOnMobile()) { + ApplicationPreferences appPreferences = (ApplicationPreferences) GlobalApplication.getStorage(StorageType.APP); + + if (appPreferences.isDownloadNetworkLimitedOnMobile()) { request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); } else { request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE); diff --git a/app/src/main/java/de/xikolo/data/net/NetworkRequest.java b/app/src/main/java/de/xikolo/network/NetworkRequest.java similarity index 98% rename from app/src/main/java/de/xikolo/data/net/NetworkRequest.java rename to app/src/main/java/de/xikolo/network/NetworkRequest.java index fe086680f..f75dfd2cb 100644 --- a/app/src/main/java/de/xikolo/data/net/NetworkRequest.java +++ b/app/src/main/java/de/xikolo/network/NetworkRequest.java @@ -1,4 +1,4 @@ -package de.xikolo.data.net; +package de.xikolo.network; import java.io.IOException; diff --git a/app/src/main/java/de/xikolo/data/parser/ApiParser.java b/app/src/main/java/de/xikolo/network/parser/ApiParser.java similarity index 96% rename from app/src/main/java/de/xikolo/data/parser/ApiParser.java rename to app/src/main/java/de/xikolo/network/parser/ApiParser.java index 0717a6424..ff7a3717f 100644 --- a/app/src/main/java/de/xikolo/data/parser/ApiParser.java +++ b/app/src/main/java/de/xikolo/network/parser/ApiParser.java @@ -1,4 +1,4 @@ -package de.xikolo.data.parser; +package de.xikolo.network.parser; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/app/src/main/java/de/xikolo/data/parser/AutoValueTypeAdapterFactory.java b/app/src/main/java/de/xikolo/network/parser/AutoValueTypeAdapterFactory.java similarity index 90% rename from app/src/main/java/de/xikolo/data/parser/AutoValueTypeAdapterFactory.java rename to app/src/main/java/de/xikolo/network/parser/AutoValueTypeAdapterFactory.java index 7b4bf4f83..6c8033b56 100644 --- a/app/src/main/java/de/xikolo/data/parser/AutoValueTypeAdapterFactory.java +++ b/app/src/main/java/de/xikolo/network/parser/AutoValueTypeAdapterFactory.java @@ -1,4 +1,4 @@ -package de.xikolo.data.parser; +package de.xikolo.network.parser; import com.google.gson.TypeAdapterFactory; import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory; diff --git a/app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java b/app/src/main/java/de/xikolo/receivers/DownloadCompletedReceiver.java similarity index 86% rename from app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java rename to app/src/main/java/de/xikolo/receivers/DownloadCompletedReceiver.java index 335061800..929d176cf 100644 --- a/app/src/main/java/de/xikolo/model/receiver/DownloadCompletedReceiver.java +++ b/app/src/main/java/de/xikolo/receivers/DownloadCompletedReceiver.java @@ -1,4 +1,4 @@ -package de.xikolo.model.receiver; +package de.xikolo.receivers; import android.app.DownloadManager; import android.app.PendingIntent; @@ -15,13 +15,14 @@ import java.util.List; +import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.controller.DownloadsActivity; -import de.xikolo.data.entities.Download; -import de.xikolo.data.net.DownloadHelper; -import de.xikolo.data.preferences.NotificationPreferences; -import de.xikolo.data.preferences.PreferencesFactory; -import de.xikolo.model.events.DownloadCompletedEvent; +import de.xikolo.controllers.DownloadsActivity; +import de.xikolo.events.DownloadCompletedEvent; +import de.xikolo.models.Download; +import de.xikolo.network.DownloadHelper; +import de.xikolo.storages.preferences.NotificationStorage; +import de.xikolo.storages.preferences.StorageType; public class DownloadCompletedReceiver extends BroadcastReceiver { @@ -41,20 +42,19 @@ public void onReceive(final Context context, final Intent intent) { if (dl != null) { EventBus.getDefault().post(new DownloadCompletedEvent(dl)); - PreferencesFactory preferencesFactory = new PreferencesFactory(context); - NotificationPreferences notificationPreferences = preferencesFactory.getNotificationPreferences(); + NotificationStorage notificationStorage = (NotificationStorage) GlobalApplication.getStorage(StorageType.NOTIFICATION); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { - notificationPreferences.addDownloadNotification(dl.title); + notificationStorage.addDownloadNotification(dl.title); showNotification(context, dl.title); - List downloadList = notificationPreferences.getDownloadNotifications(); + List downloadList = notificationStorage.getDownloadNotifications(); if (downloadList.size() > 1) { showSummaryNotification(context, downloadList); } } else { // Notifications with group doesn't work before Lollipop - notificationPreferences.addDownloadNotification(dl.title); - List downloadList = notificationPreferences.getDownloadNotifications(); + notificationStorage.addDownloadNotification(dl.title); + List downloadList = notificationStorage.getDownloadNotifications(); showSummaryNotification(context, downloadList); } } diff --git a/app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java b/app/src/main/java/de/xikolo/receivers/NetworkChangeReceiver.java similarity index 78% rename from app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java rename to app/src/main/java/de/xikolo/receivers/NetworkChangeReceiver.java index 9591801e3..0facd3187 100644 --- a/app/src/main/java/de/xikolo/model/receiver/NetworkChangeReceiver.java +++ b/app/src/main/java/de/xikolo/receivers/NetworkChangeReceiver.java @@ -1,4 +1,4 @@ -package de.xikolo.model.receiver; +package de.xikolo.receivers; import android.content.BroadcastReceiver; import android.content.Context; @@ -6,8 +6,8 @@ import org.greenrobot.eventbus.EventBus; -import de.xikolo.model.events.NetworkStateEvent; -import de.xikolo.util.NetworkUtil; +import de.xikolo.events.NetworkStateEvent; +import de.xikolo.utils.NetworkUtil; public class NetworkChangeReceiver extends BroadcastReceiver { diff --git a/app/src/main/java/de/xikolo/model/receiver/NotificationDeletedReceiver.java b/app/src/main/java/de/xikolo/receivers/NotificationDeletedReceiver.java similarity index 62% rename from app/src/main/java/de/xikolo/model/receiver/NotificationDeletedReceiver.java rename to app/src/main/java/de/xikolo/receivers/NotificationDeletedReceiver.java index da4dc2ba4..b9da77745 100644 --- a/app/src/main/java/de/xikolo/model/receiver/NotificationDeletedReceiver.java +++ b/app/src/main/java/de/xikolo/receivers/NotificationDeletedReceiver.java @@ -1,11 +1,12 @@ -package de.xikolo.model.receiver; +package de.xikolo.receivers; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import de.xikolo.data.preferences.NotificationPreferences; -import de.xikolo.data.preferences.PreferencesFactory; +import de.xikolo.GlobalApplication; +import de.xikolo.storages.preferences.NotificationStorage; +import de.xikolo.storages.preferences.StorageType; public class NotificationDeletedReceiver extends BroadcastReceiver { @@ -19,14 +20,13 @@ public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); if (INTENT_ACTION_NOTIFICATION_DELETED.equals(action)) { - PreferencesFactory preferencesFactory = new PreferencesFactory(context); - NotificationPreferences notificationPreferences = preferencesFactory.getNotificationPreferences(); + NotificationStorage notificationStorage = (NotificationStorage) GlobalApplication.getStorage(StorageType.NOTIFICATION); String title = intent.getStringExtra(KEY_TITLE); if (title != null) { - notificationPreferences.deleteDownloadNotification(title); + notificationStorage.deleteDownloadNotification(title); } else if (intent.getStringExtra(KEY_ALL) != null) { - notificationPreferences.deleteAllDownloadNotifications(); + notificationStorage.deleteAllDownloadNotifications(); } } } diff --git a/app/src/main/java/de/xikolo/storages/databases/DataType.java b/app/src/main/java/de/xikolo/storages/databases/DataType.java new file mode 100644 index 000000000..ea35807ec --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/DataType.java @@ -0,0 +1,7 @@ +package de.xikolo.storages.databases; + +public enum DataType { + + COURSE, MODULE, ITEM, VIDEO + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/DatabaseHelper.java b/app/src/main/java/de/xikolo/storages/databases/DatabaseHelper.java new file mode 100644 index 000000000..83ace3ab8 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/DatabaseHelper.java @@ -0,0 +1,121 @@ +package de.xikolo.storages.databases; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; + +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.storages.databases.adapters.DataAdapter; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.storages.databases.adapters.VideoDataAdapter; +import de.xikolo.storages.databases.tables.CourseTable; +import de.xikolo.storages.databases.tables.ItemTable; +import de.xikolo.storages.databases.tables.ModuleTable; +import de.xikolo.storages.databases.tables.ProgressTable; +import de.xikolo.storages.databases.tables.Table; +import de.xikolo.storages.databases.tables.VideoTable; + +public class DatabaseHelper extends SQLiteOpenHelper { + + private static final String TAG = DatabaseHelper.class.getSimpleName(); + + private static final int DATABASE_VERSION = 4; + + private static final String DATABASE_NAME = "xikolo"; + + private SQLiteDatabase db; + + private List
tables; + + private int openCounter; + + public DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + + tables = new ArrayList<>(); + tables.add(new ProgressTable()); + tables.add(new CourseTable()); + tables.add(new ModuleTable()); + tables.add(new ItemTable()); + tables.add(new VideoTable()); + + openCounter = 0; + } + + @Override + public void onCreate(SQLiteDatabase db) { + for (Table table : tables) { + table.onCreate(db); + } + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion); + + for (Table table : tables) { + table.onUpgrade(db, oldVersion, newVersion); + } + } + + @Override + public void onOpen(SQLiteDatabase db) { + super.onOpen(db); + + if (!db.isReadOnly()) { + // Enable foreign key constraints + db.execSQL("PRAGMA foreign_keys = ON;"); + } + } + + public synchronized SQLiteDatabase openDatabase() { + openCounter++; + if(openCounter == 1) { + db = getWritableDatabase(); + } + return this.db; + } + + @Override + public synchronized void close() { + if (openCounter > 0) { + openCounter--; + } + if(openCounter == 0) { + super.close(); + } + } + + public void deleteDatabase() { + for (Table table : tables) { + table.deleteTable(openDatabase()); + } + } + + public DataAdapter getDataAdapter(DataType type) { + DataAdapter dataAdapter = null; + + switch (type) { + case COURSE: + dataAdapter = new CourseDataAdapter(this, new CourseTable(), new ProgressTable()); + break; + case MODULE: + dataAdapter = new ModuleDataAdapter(this, new ModuleTable(), new ProgressTable()); + break; + case ITEM: + dataAdapter = new ItemDataAdapter(this, new ItemTable()); + break; + case VIDEO: + dataAdapter = new VideoDataAdapter(this, new VideoTable()); + break; + } + + return dataAdapter; + } + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/DatabaseModel.java b/app/src/main/java/de/xikolo/storages/databases/DatabaseModel.java new file mode 100644 index 000000000..f822cabe8 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/DatabaseModel.java @@ -0,0 +1,7 @@ +package de.xikolo.storages.databases; + +public interface DatabaseModel { + + String getId(); + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/adapters/CourseDataAdapter.java b/app/src/main/java/de/xikolo/storages/databases/adapters/CourseDataAdapter.java new file mode 100644 index 000000000..4f0601fff --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/adapters/CourseDataAdapter.java @@ -0,0 +1,124 @@ +package de.xikolo.storages.databases.adapters; + +import android.content.ContentValues; +import android.database.Cursor; + +import java.util.List; + +import de.xikolo.models.Course; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.tables.CourseTable; +import de.xikolo.storages.databases.tables.Table; + +public class CourseDataAdapter extends DataAdapter { + + private ProgressDataAdapter progressDataAccess; + + public CourseDataAdapter(DatabaseHelper databaseHelper, Table table, Table progressTable) { + super(databaseHelper, table); + + this.progressDataAccess = new ProgressDataAdapter(databaseHelper, progressTable); + } + + @Override + protected Course buildEntity(Cursor cursor) { + Course course = new Course(); + + course.id = cursor.getString(0); + course.name = cursor.getString(1); + course.description = cursor.getString(2); + course.course_code = cursor.getString(3); + course.lecturer = cursor.getString(4); + course.language = cursor.getString(5); + course.url = cursor.getString(6); + course.visual_url = cursor.getString(7); + course.available_from = cursor.getString(8); + course.available_to = cursor.getString(9); + course.locked = cursor.getInt(10) != 0; + course.is_enrolled = cursor.getInt(11) != 0; + + return course; + } + + @Override + protected ContentValues buildContentValues(Course course) { + ContentValues values = new ContentValues(); + + values.put(CourseTable.COLUMN_ID, course.id); + values.put(CourseTable.COLUMN_NAME, course.name); + values.put(CourseTable.COLUMN_DESCRIPTION, course.description); + values.put(CourseTable.COLUMN_COURSE_CODE, course.course_code); + values.put(CourseTable.COLUMN_LECTURER, course.lecturer); + values.put(CourseTable.COLUMN_LANGUAGE, course.language); + values.put(CourseTable.COLUMN_URL, course.url); + values.put(CourseTable.COLUMN_VISUAL_URL, course.visual_url); + values.put(CourseTable.COLUMN_AVAILABLE_FROM, course.available_from); + values.put(CourseTable.COLUMN_AVAILABLE_TO, course.available_to); + values.put(CourseTable.COLUMN_LOCKED, course.locked); + values.put(CourseTable.COLUMN_IS_ENROLLED, course.is_enrolled); + + return values; + } + + public void add(Course course, boolean includeProgress) { + super.add(course); + + if (includeProgress) { + progressDataAccess.addOrUpdate(course.progress); + } + } + + public void addOrUpdate(Course course, boolean includeProgress) { + if (update(course, includeProgress) < 1) { + add(course, includeProgress); + } + } + + @Override + public Course get(String id) { + Course course = super.get(id); + course.progress = progressDataAccess.get(id); + return course; + } + + @Override + public List getAll() { + List courseList = super.getAll(); + + for (Course course : courseList) { + course.progress = progressDataAccess.get(course.id); + } + + return courseList; + } + + public int getEnrollmentsCount() { + String countQuery = "SELECT * FROM " + CourseTable.TABLE_NAME + " WHERE " + CourseTable.COLUMN_IS_ENROLLED + " != 0 "; + Cursor cursor = openDatabase().rawQuery(countQuery, null); + + int count = cursor.getCount(); + + cursor.close(); + closeDatabase(); + + return count; + } + + public int update(Course course, boolean includeProgress) { + int affected = super.update(course); + + if (includeProgress) { + progressDataAccess.addOrUpdate(course.progress); + } + + return affected; + } + + @Override + public void delete(String id) { + super.delete(id); + + progressDataAccess.delete(id); + } + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/adapters/DataAdapter.java b/app/src/main/java/de/xikolo/storages/databases/adapters/DataAdapter.java new file mode 100644 index 000000000..b4f5cb2cb --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/adapters/DataAdapter.java @@ -0,0 +1,124 @@ +package de.xikolo.storages.databases.adapters; + +import android.content.ContentValues; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import java.util.ArrayList; +import java.util.List; + +import de.xikolo.storages.databases.tables.Table; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.DatabaseModel; + +@SuppressWarnings("unused") +public abstract class DataAdapter { + + protected DatabaseHelper databaseHelper; + + protected Table table; + + public DataAdapter(DatabaseHelper databaseHelper, Table table) { + this.databaseHelper = databaseHelper; + this.table = table; + } + + protected SQLiteDatabase openDatabase() { + return databaseHelper.openDatabase(); + } + + protected void closeDatabase() { + databaseHelper.close(); + } + + public void add(E entity) { + openDatabase().insert(table.getTableName(), null, buildContentValues(entity)); + closeDatabase(); + } + + public void addOrUpdate(E entity) { + if (update(entity) < 1) { + add(entity); + } + } + + public E get(String id) { + Cursor cursor = openDatabase().query( + table.getTableName(), + null, + Table.COLUMN_ID + " =? ", + new String[]{String.valueOf(id)}, null, null, null, null); + + E entity = null; + if (cursor.moveToFirst()) { + entity = buildEntity(cursor); + } + cursor.close(); + closeDatabase(); + + return entity; + } + + public List getAll() { + return getAll("SELECT * FROM " + table.getTableName()); + } + + protected List getAll(String selectQuery) { + List list = new ArrayList<>(); + + Cursor cursor = openDatabase().rawQuery(selectQuery, null); + + if (cursor.moveToFirst()) { + do { + E entity = buildEntity(cursor); + list.add(entity); + } while (cursor.moveToNext()); + } + + cursor.close(); + closeDatabase(); + + return list; + } + + protected abstract E buildEntity(Cursor cursor); + + protected abstract ContentValues buildContentValues(E entity); + + public int getCount() { + return getCount("SELECT * FROM " + table.getTableName()); + } + + public int getCount(String countQuery) { + Cursor cursor = openDatabase().rawQuery(countQuery, null); + + int count = cursor.getCount(); + + cursor.close(); + closeDatabase(); + + return count; + } + + public int update(E entity) { + int affected = openDatabase().update( + table.getTableName(), + buildContentValues(entity), + Table.COLUMN_ID + " =? ", + new String[]{String.valueOf(entity.getId())}); + + closeDatabase(); + + return affected; + } + + public void delete(String id) { + openDatabase().delete( + table.getTableName(), + Table.COLUMN_ID + " =? ", + new String[]{String.valueOf(id)}); + + closeDatabase(); + } + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/adapters/ItemDataAdapter.java b/app/src/main/java/de/xikolo/storages/databases/adapters/ItemDataAdapter.java new file mode 100644 index 000000000..6d01d0f04 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/adapters/ItemDataAdapter.java @@ -0,0 +1,63 @@ +package de.xikolo.storages.databases.adapters; + +import android.content.ContentValues; +import android.database.Cursor; + +import java.util.List; + +import de.xikolo.models.Item; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.tables.ItemTable; +import de.xikolo.storages.databases.tables.Table; + +public class ItemDataAdapter extends DataAdapter { + + public ItemDataAdapter(DatabaseHelper databaseHelper, Table table) { + super(databaseHelper, table); + } + + @Override + protected Item buildEntity(Cursor cursor) { + Item item = new Item(); + + item.id = cursor.getString(0); + item.position = cursor.getInt(1); + item.title = cursor.getString(2); + item.type = cursor.getString(3); + item.available_from = cursor.getString(4); + item.available_to = cursor.getString(5); + item.exercise_type = cursor.getString(6); + item.locked = cursor.getInt(7) != 0; + item.progress.visited = cursor.getInt(8) != 0; + item.progress.completed = cursor.getInt(9) != 0; + item.courseId = cursor.getString(10); + item.moduleId = cursor.getString(11); + + return item; + } + + @Override + protected ContentValues buildContentValues(Item item) { + ContentValues values = new ContentValues(); + + values.put(ItemTable.COLUMN_ID, item.id); + values.put(ItemTable.COLUMN_POSITION, item.position); + values.put(ItemTable.COLUMN_TITLE, item.title); + values.put(ItemTable.COLUMN_TYPE, item.type); + values.put(ItemTable.COLUMN_AVAILABLE_FROM, item.available_from); + values.put(ItemTable.COLUMN_AVAILABLE_TO, item.available_to); + values.put(ItemTable.COLUMN_EXERCISE_TYPE, item.exercise_type); + values.put(ItemTable.COLUMN_LOCKED, item.locked); + values.put(ItemTable.COLUMN_VISITED, item.progress.visited); + values.put(ItemTable.COLUMN_COMPLETED, item.progress.completed); + values.put(ItemTable.COLUMN_COURSE_ID, item.courseId); + values.put(ItemTable.COLUMN_MODULE_ID, item.moduleId); + + return values; + } + + public List getAllForModule(String moduleId) { + return super.getAll("SELECT * FROM " + ItemTable.TABLE_NAME + " WHERE " + ItemTable.COLUMN_MODULE_ID + " = \'" + moduleId + "\'"); + } + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/adapters/ModuleDataAdapter.java b/app/src/main/java/de/xikolo/storages/databases/adapters/ModuleDataAdapter.java new file mode 100644 index 000000000..8a2ac2505 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/adapters/ModuleDataAdapter.java @@ -0,0 +1,112 @@ +package de.xikolo.storages.databases.adapters; + +import android.content.ContentValues; +import android.database.Cursor; + +import java.util.List; + +import de.xikolo.models.Module; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.tables.ModuleTable; +import de.xikolo.storages.databases.tables.Table; + +public class ModuleDataAdapter extends DataAdapter { + + private ProgressDataAdapter progressDataAccess; + + public ModuleDataAdapter(DatabaseHelper databaseHelper, Table table, Table progressTable) { + super(databaseHelper, table); + + this.progressDataAccess = new ProgressDataAdapter(databaseHelper, progressTable); + } + + @Override + protected Module buildEntity(Cursor cursor) { + Module module = new Module(); + + module.id = cursor.getString(0); + module.position = cursor.getInt(1); + module.name = cursor.getString(2); + module.available_from = cursor.getString(3); + module.available_to = cursor.getString(4); + module.locked = cursor.getInt(5) != 0; + module.courseId = cursor.getString(6); + + return module; + } + + @Override + protected ContentValues buildContentValues(Module module) { + ContentValues values = new ContentValues(); + + values.put(ModuleTable.COLUMN_ID, module.id); + values.put(ModuleTable.COLUMN_POSITION, module.position); + values.put(ModuleTable.COLUMN_NAME, module.name); + values.put(ModuleTable.COLUMN_AVAILABLE_FROM, module.available_from); + values.put(ModuleTable.COLUMN_AVAILABLE_TO, module.available_to); + values.put(ModuleTable.COLUMN_LOCKED, module.locked); + values.put(ModuleTable.COLUMN_COURSE_ID, module.courseId); + + return values; + } + + public void add(Module module, boolean includeProgress) { + super.add(module); + + if (includeProgress) { + progressDataAccess.addOrUpdate(module.progress); + } + } + + public void addOrUpdate(Module module, boolean includeProgress) { + if (update(module, includeProgress) < 1) { + add(module, includeProgress); + } + } + + @Override + public Module get(String id) { + Module module = super.get(id); + module.progress = progressDataAccess.get(id); + return module; + } + + @Override + public List getAll() { + List courseList = super.getAll(); + + for (Module module : courseList) { + module.progress = progressDataAccess.get(module.id); + } + + return courseList; + } + + public List getAllForCourse(String courseId) { + List moduleList = super.getAll("SELECT * FROM " + ModuleTable.TABLE_NAME + " WHERE " + ModuleTable.COLUMN_COURSE_ID + " = \'" + courseId + "\'"); + + for (Module module : moduleList) { + module.progress = progressDataAccess.get(module.id); + } + + return moduleList; + } + + public int update(Module module, boolean includeProgress) { + int affected = super.update(module); + + if (includeProgress) { + progressDataAccess.addOrUpdate(module.progress); + } + + return affected; + } + + @Override + public void delete(String id) { + super.delete(id); + + progressDataAccess.delete(id); + } + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/adapters/ProgressDataAdapter.java b/app/src/main/java/de/xikolo/storages/databases/adapters/ProgressDataAdapter.java new file mode 100644 index 000000000..218688a61 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/adapters/ProgressDataAdapter.java @@ -0,0 +1,57 @@ +package de.xikolo.storages.databases.adapters; + +import android.content.ContentValues; +import android.database.Cursor; + +import de.xikolo.models.Progress; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.tables.ProgressTable; +import de.xikolo.storages.databases.tables.Table; + +class ProgressDataAdapter extends DataAdapter { + + public ProgressDataAdapter(DatabaseHelper databaseHelper, Table table) { + super(databaseHelper, table); + } + + @Override + protected Progress buildEntity(Cursor cursor) { + Progress progress = new Progress(); + + progress.id = cursor.getString(0); + progress.items.count_available = cursor.getInt(1); + progress.items.count_visited = cursor.getInt(2); + progress.items.count_completed = cursor.getInt(3); + progress.self_tests.count_available = cursor.getFloat(4); + progress.self_tests.count_taken = cursor.getFloat(5); + progress.self_tests.points_possible = cursor.getFloat(6); + progress.self_tests.points_scored = cursor.getFloat(7); + progress.assignments.count_available = cursor.getFloat(8); + progress.assignments.count_taken = cursor.getFloat(9); + progress.assignments.points_possible = cursor.getFloat(10); + progress.assignments.points_scored = cursor.getFloat(11); + + return progress; + } + + @Override + protected ContentValues buildContentValues(Progress progress) { + ContentValues values = new ContentValues(); + + values.put(ProgressTable.COLUMN_ID, progress.id); + values.put(ProgressTable.COLUMN_ITEM_COUNT_AVAILABLE, progress.items.count_available); + values.put(ProgressTable.COLUMN_ITEM_COUNT_VISITED, progress.items.count_visited); + values.put(ProgressTable.COLUMN_ITEM_COUNT_COMPLETED, progress.items.count_completed); + values.put(ProgressTable.COLUMN_SELF_TESTS_COUNT_AVAILABLE, progress.self_tests.count_available); + values.put(ProgressTable.COLUMN_SELF_TESTS_COUNT_TAKEN, progress.self_tests.count_taken); + values.put(ProgressTable.COLUMN_SELF_TESTS_POINTS_POSSIBLE, progress.self_tests.points_possible); + values.put(ProgressTable.COLUMN_SELF_TESTS_POINTS_SCORED, progress.self_tests.points_scored); + values.put(ProgressTable.COLUMN_ASSIGNMENTS_COUNT_AVAILABLE, progress.assignments.count_available); + values.put(ProgressTable.COLUMN_ASSIGNMENTS_COUNT_TAKEN, progress.assignments.count_taken); + values.put(ProgressTable.COLUMN_ASSIGNMENTS_POINTS_POSSIBLE, progress.assignments.points_possible); + values.put(ProgressTable.COLUMN_ASSIGNMENTS_POINTS_SCORED, progress.assignments.points_scored); + + return values; + } + +} diff --git a/app/src/main/java/de/xikolo/storages/databases/adapters/VideoDataAdapter.java b/app/src/main/java/de/xikolo/storages/databases/adapters/VideoDataAdapter.java new file mode 100644 index 000000000..35bd5515c --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/databases/adapters/VideoDataAdapter.java @@ -0,0 +1,61 @@ +package de.xikolo.storages.databases.adapters; + +import android.content.ContentValues; +import android.database.Cursor; + +import de.xikolo.models.VideoItemDetail; +import de.xikolo.storages.databases.DatabaseHelper; +import de.xikolo.storages.databases.tables.Table; +import de.xikolo.storages.databases.tables.VideoTable; + +public class VideoDataAdapter extends DataAdapter { + + public VideoDataAdapter(DatabaseHelper databaseHelper, Table table) { + super(databaseHelper, table); + } + + @Override + protected VideoItemDetail buildEntity(Cursor cursor) { + VideoItemDetail video = new VideoItemDetail(); + + video.id = cursor.getString(0); + video.title = cursor.getString(1); + video.minutes = cursor.getString(2); + video.seconds = cursor.getString(3); + video.progress = cursor.getInt(4); + video.url = cursor.getString(5); + video.download_url = cursor.getString(6); + video.slides_url = cursor.getString(7); + video.transcript_url = cursor.getString(8); + video.stream.hd_url = cursor.getString(9); + video.stream.sd_url = cursor.getString(10); + video.stream.vimeo_id = cursor.getString(11); + video.stream.poster = cursor.getString(12); + + return video; + } + + @Override + protected ContentValues buildContentValues(VideoItemDetail video) { + ContentValues values = new ContentValues(); + + values.put(VideoTable.COLUMN_ID, video.id); + values.put(VideoTable.COLUMN_TITLE, video.title); + values.put(VideoTable.COLUMN_MINUTES, video.minutes); + values.put(VideoTable.COLUMN_SECONDS, video.seconds); + if (video.progress > 0) { + values.put(VideoTable.COLUMN_PROGRESS, video.progress); + } + values.put(VideoTable.COLUMN_URL, video.url); + values.put(VideoTable.COLUMN_DOWNLOAD_URL, video.download_url); + values.put(VideoTable.COLUMN_SLIDES_URL, video.slides_url); + values.put(VideoTable.COLUMN_TRANSCRIPT_URL, video.transcript_url); + values.put(VideoTable.COLUMN_HD_URL, video.stream.hd_url); + values.put(VideoTable.COLUMN_SD_URL, video.stream.sd_url); + values.put(VideoTable.COLUMN_VIMEO_ID, video.stream.vimeo_id); + values.put(VideoTable.COLUMN_POSTER_IMAGE_URL, video.stream.poster); + + return values; + } + +} diff --git a/app/src/main/java/de/xikolo/data/database/CourseTable.java b/app/src/main/java/de/xikolo/storages/databases/tables/CourseTable.java similarity index 90% rename from app/src/main/java/de/xikolo/data/database/CourseTable.java rename to app/src/main/java/de/xikolo/storages/databases/tables/CourseTable.java index d8f84d23f..e79a862ce 100644 --- a/app/src/main/java/de/xikolo/data/database/CourseTable.java +++ b/app/src/main/java/de/xikolo/storages/databases/tables/CourseTable.java @@ -1,6 +1,6 @@ -package de.xikolo.data.database; +package de.xikolo.storages.databases.tables; -class CourseTable extends Table { +public class CourseTable extends Table { public static final String TABLE_NAME = "course"; @@ -33,12 +33,12 @@ class CourseTable extends Table { ");"; @Override - String getTableName() { + public String getTableName() { return TABLE_NAME; } @Override - String getTableCreate() { + public String getTableCreate() { return TABLE_CREATE; } diff --git a/app/src/main/java/de/xikolo/data/database/ItemTable.java b/app/src/main/java/de/xikolo/storages/databases/tables/ItemTable.java similarity index 79% rename from app/src/main/java/de/xikolo/data/database/ItemTable.java rename to app/src/main/java/de/xikolo/storages/databases/tables/ItemTable.java index 628f8502b..26925c6f0 100644 --- a/app/src/main/java/de/xikolo/data/database/ItemTable.java +++ b/app/src/main/java/de/xikolo/storages/databases/tables/ItemTable.java @@ -1,6 +1,6 @@ -package de.xikolo.data.database; +package de.xikolo.storages.databases.tables; -class ItemTable extends Table { +public class ItemTable extends Table { public static final String TABLE_NAME = "item"; @@ -15,6 +15,7 @@ class ItemTable extends Table { public static final String COLUMN_VISITED = "visited"; public static final String COLUMN_COMPLETED = "completed"; + public static final String COLUMN_COURSE_ID = "course_id"; public static final String COLUMN_MODULE_ID = "module_id"; private static final String TABLE_CREATE = @@ -29,17 +30,19 @@ class ItemTable extends Table { COLUMN_LOCKED + " integer, " + COLUMN_VISITED + " integer, " + COLUMN_COMPLETED + " integer, " + + COLUMN_COURSE_ID + " text, " + COLUMN_MODULE_ID + " text, " + + "FOREIGN KEY(" + COLUMN_COURSE_ID + ") REFERENCES " + CourseTable.TABLE_NAME + "(" + Table.COLUMN_ID + ") ON UPDATE CASCADE ON DELETE CASCADE " + "FOREIGN KEY(" + COLUMN_MODULE_ID + ") REFERENCES " + ModuleTable.TABLE_NAME + "(" + Table.COLUMN_ID + ") ON UPDATE CASCADE ON DELETE CASCADE " + ");"; @Override - String getTableName() { + public String getTableName() { return TABLE_NAME; } @Override - String getTableCreate() { + public String getTableCreate() { return TABLE_CREATE; } diff --git a/app/src/main/java/de/xikolo/data/database/ModuleTable.java b/app/src/main/java/de/xikolo/storages/databases/tables/ModuleTable.java similarity index 88% rename from app/src/main/java/de/xikolo/data/database/ModuleTable.java rename to app/src/main/java/de/xikolo/storages/databases/tables/ModuleTable.java index 5091522a2..0e63492be 100644 --- a/app/src/main/java/de/xikolo/data/database/ModuleTable.java +++ b/app/src/main/java/de/xikolo/storages/databases/tables/ModuleTable.java @@ -1,6 +1,6 @@ -package de.xikolo.data.database; +package de.xikolo.storages.databases.tables; -class ModuleTable extends Table { +public class ModuleTable extends Table { public static final String TABLE_NAME = "module"; @@ -25,12 +25,12 @@ class ModuleTable extends Table { ");"; @Override - String getTableName() { + public String getTableName() { return TABLE_NAME; } @Override - String getTableCreate() { + public String getTableCreate() { return TABLE_CREATE; } diff --git a/app/src/main/java/de/xikolo/data/database/OverallProgressTable.java b/app/src/main/java/de/xikolo/storages/databases/tables/ProgressTable.java similarity index 92% rename from app/src/main/java/de/xikolo/data/database/OverallProgressTable.java rename to app/src/main/java/de/xikolo/storages/databases/tables/ProgressTable.java index 575cdea2c..008064428 100644 --- a/app/src/main/java/de/xikolo/data/database/OverallProgressTable.java +++ b/app/src/main/java/de/xikolo/storages/databases/tables/ProgressTable.java @@ -1,6 +1,6 @@ -package de.xikolo.data.database; +package de.xikolo.storages.databases.tables; -class OverallProgressTable extends Table { +public class ProgressTable extends Table { public static final String TABLE_NAME = "overall_progress"; @@ -35,12 +35,12 @@ class OverallProgressTable extends Table { ");"; @Override - String getTableName() { + public String getTableName() { return TABLE_NAME; } @Override - String getTableCreate() { + public String getTableCreate() { return TABLE_CREATE; } diff --git a/app/src/main/java/de/xikolo/data/database/Table.java b/app/src/main/java/de/xikolo/storages/databases/tables/Table.java similarity index 77% rename from app/src/main/java/de/xikolo/data/database/Table.java rename to app/src/main/java/de/xikolo/storages/databases/tables/Table.java index 45439cb09..41548d82c 100644 --- a/app/src/main/java/de/xikolo/data/database/Table.java +++ b/app/src/main/java/de/xikolo/storages/databases/tables/Table.java @@ -1,15 +1,15 @@ -package de.xikolo.data.database; +package de.xikolo.storages.databases.tables; import android.database.sqlite.SQLiteDatabase; import android.provider.BaseColumns; -abstract class Table { +public abstract class Table { - static String COLUMN_ID = BaseColumns._ID; + public static String COLUMN_ID = BaseColumns._ID; - abstract String getTableName(); + public abstract String getTableName(); - abstract String getTableCreate(); + public abstract String getTableCreate(); public void onCreate(SQLiteDatabase db) { db.execSQL(getTableCreate()); @@ -21,9 +21,6 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { while (upgradeTo <= newVersion) { switch (upgradeTo) { - case 2: - upgradeTo(db, upgradeTo); - break; default: System.out.println("Deleting " + getTableName()); deleteTable(db); diff --git a/app/src/main/java/de/xikolo/data/database/VideoTable.java b/app/src/main/java/de/xikolo/storages/databases/tables/VideoTable.java similarity index 80% rename from app/src/main/java/de/xikolo/data/database/VideoTable.java rename to app/src/main/java/de/xikolo/storages/databases/tables/VideoTable.java index 7402f49a5..29daca94f 100644 --- a/app/src/main/java/de/xikolo/data/database/VideoTable.java +++ b/app/src/main/java/de/xikolo/storages/databases/tables/VideoTable.java @@ -1,8 +1,6 @@ -package de.xikolo.data.database; +package de.xikolo.storages.databases.tables; -import android.database.sqlite.SQLiteDatabase; - -class VideoTable extends Table { +public class VideoTable extends Table { public static final String TABLE_NAME = "video"; @@ -38,22 +36,13 @@ class VideoTable extends Table { ");"; @Override - String getTableName() { + public String getTableName() { return TABLE_NAME; } @Override - String getTableCreate() { + public String getTableCreate() { return TABLE_CREATE; } - @Override - protected void upgradeTo(SQLiteDatabase db, int version) { - switch (version) { - case 2: - db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_PROGRESS + " INTEGER DEFAULT 0"); - break; - } - } - } diff --git a/app/src/main/java/de/xikolo/storages/preferences/ApplicationPreferences.java b/app/src/main/java/de/xikolo/storages/preferences/ApplicationPreferences.java new file mode 100644 index 000000000..7a1a66455 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/preferences/ApplicationPreferences.java @@ -0,0 +1,74 @@ +package de.xikolo.storages.preferences; + +import android.content.Context; +import android.content.SharedPreferences; + +import de.xikolo.R; +import de.xikolo.utils.PlaybackSpeed; + +public class ApplicationPreferences extends KeyValueStorage { + + ApplicationPreferences(Context context) { + super(context); + } + + private boolean getBoolean(String key) { + return getBoolean(key, true); + } + + private boolean getBoolean(String key, boolean defValue) { + return preferences.getBoolean(key, defValue); + } + + private void putBoolean(boolean value, String key) { + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean(key, value); + editor.apply(); + } + + public boolean isVideoQualityLimitedOnMobile() { + return getBoolean(context.getString(R.string.preference_video_quality)); + } + + public void setIsVideoQualityLimitedOnMobile(boolean value) { + putBoolean(value, context.getString(R.string.preference_video_quality)); + } + + public boolean isDownloadNetworkLimitedOnMobile() { + return getBoolean(context.getString(R.string.preference_download_network)); + } + + public void setIsDownloadNetworkLimitedOnMobile(boolean value) { + putBoolean(value, context.getString(R.string.preference_download_network)); + } + + public boolean confirmBeforeDeleting() { + return getBoolean(context.getString(R.string.preference_confirm_delete)); + } + + public void setConfirmBeforeDeleting(boolean value) { + putBoolean(value, context.getString(R.string.preference_confirm_delete)); + } + + public PlaybackSpeed getVideoPlaybackSpeed() { + String speed = preferences.getString(context.getString(R.string.preference_video_playback_speed), + context.getString(R.string.settings_default_value_video_playback_speed)); + return PlaybackSpeed.get(speed); + } + + public void setVideoPlaybackSpeed(PlaybackSpeed speed) { + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(context.getString(R.string.preference_video_playback_speed), + speed.toString()); + editor.apply(); + } + + public boolean usedSecondScreen() { + return getBoolean(context.getString(R.string.preference_used_second_screen), false); + } + + public void setUsedSecondScreen(boolean used) { + putBoolean(used, context.getString(R.string.preference_used_second_screen)); + } + +} diff --git a/app/src/main/java/de/xikolo/storages/preferences/KeyValueStorage.java b/app/src/main/java/de/xikolo/storages/preferences/KeyValueStorage.java new file mode 100644 index 000000000..30f66550e --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/preferences/KeyValueStorage.java @@ -0,0 +1,23 @@ +package de.xikolo.storages.preferences; + +import android.content.Context; +import android.content.SharedPreferences; +import android.support.v7.preference.PreferenceManager; + +public abstract class KeyValueStorage { + + protected Context context; + + protected SharedPreferences preferences; + + KeyValueStorage(Context context, String name, int mode) { + this.context = context; + this.preferences = context.getSharedPreferences(name, mode); + } + + KeyValueStorage(Context context) { + this.context = context; + this.preferences = PreferenceManager.getDefaultSharedPreferences(context); + } + +} diff --git a/app/src/main/java/de/xikolo/data/preferences/NotificationPreferences.java b/app/src/main/java/de/xikolo/storages/preferences/NotificationStorage.java similarity index 53% rename from app/src/main/java/de/xikolo/data/preferences/NotificationPreferences.java rename to app/src/main/java/de/xikolo/storages/preferences/NotificationStorage.java index 6c05dc644..cd0d02d20 100644 --- a/app/src/main/java/de/xikolo/data/preferences/NotificationPreferences.java +++ b/app/src/main/java/de/xikolo/storages/preferences/NotificationStorage.java @@ -1,4 +1,4 @@ -package de.xikolo.data.preferences; +package de.xikolo.storages.preferences; import android.content.Context; import android.content.SharedPreferences; @@ -10,28 +10,25 @@ import java.util.ArrayList; import java.util.List; -public class NotificationPreferences extends Preferences { +public class NotificationStorage extends KeyValueStorage { - public static final String PREF_NOTIFICATIONS = NotificationPreferences.class.getName(); + private static final String PREF_NOTIFICATIONS = "pref_notifications"; - private String DOWNLOAD_NOTIFICATIONS; + private String DOWNLOAD_NOTIFICATIONS = "download_notifications"; - public NotificationPreferences(Context context) { - super(context); + NotificationStorage(Context context) { + super(context, PREF_NOTIFICATIONS, Context.MODE_PRIVATE); } public List getDownloadNotifications() { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_NOTIFICATIONS, Context.MODE_PRIVATE); Gson gson = new Gson(); - String json = sharedPref.getString(DOWNLOAD_NOTIFICATIONS, null); + String json = preferences.getString(DOWNLOAD_NOTIFICATIONS, null); Type type = new TypeToken>() {}.getType(); - List notifications = gson.fromJson(json, type); - return notifications; + return gson.fromJson(json, type); } public void saveDownloadNotifications(List notifications) { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_NOTIFICATIONS, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); + SharedPreferences.Editor editor = preferences.edit(); Gson gson = new Gson(); editor.putString(DOWNLOAD_NOTIFICATIONS, gson.toJson(notifications)); editor.commit(); @@ -45,8 +42,7 @@ public void addDownloadNotification(String notification) { } notifications.add(notification); - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_NOTIFICATIONS, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); + SharedPreferences.Editor editor = preferences.edit(); Gson gson = new Gson(); editor.putString(DOWNLOAD_NOTIFICATIONS, gson.toJson(notifications)); editor.commit(); @@ -57,8 +53,7 @@ public void deleteDownloadNotification(String notification) { if (notifications != null) { notifications.remove(notification); - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_NOTIFICATIONS, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); + SharedPreferences.Editor editor = preferences.edit(); Gson gson = new Gson(); editor.putString(DOWNLOAD_NOTIFICATIONS, gson.toJson(notifications)); editor.commit(); @@ -66,8 +61,7 @@ public void deleteDownloadNotification(String notification) { } public void deleteAllDownloadNotifications() { - SharedPreferences sharedPref = mContext.getSharedPreferences(PREF_NOTIFICATIONS, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); + SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); } diff --git a/app/src/main/java/de/xikolo/storages/preferences/StorageHelper.java b/app/src/main/java/de/xikolo/storages/preferences/StorageHelper.java new file mode 100644 index 000000000..ad087d8ce --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/preferences/StorageHelper.java @@ -0,0 +1,28 @@ +package de.xikolo.storages.preferences; + +import android.content.Context; + +public class StorageHelper { + + private Context context; + + public StorageHelper(Context context) { + this.context = context; + } + + public KeyValueStorage getStorage(StorageType type) { + KeyValueStorage storage = null; + + switch (type) { + case APP: + return new ApplicationPreferences(context); + case USER: + return new UserStorage(context); + case NOTIFICATION: + return new NotificationStorage(context); + } + + return storage; + } + +} diff --git a/app/src/main/java/de/xikolo/storages/preferences/StorageType.java b/app/src/main/java/de/xikolo/storages/preferences/StorageType.java new file mode 100644 index 000000000..7c8257ef6 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/preferences/StorageType.java @@ -0,0 +1,7 @@ +package de.xikolo.storages.preferences; + +public enum StorageType { + + APP, USER, NOTIFICATION + +} diff --git a/app/src/main/java/de/xikolo/storages/preferences/UserStorage.java b/app/src/main/java/de/xikolo/storages/preferences/UserStorage.java new file mode 100644 index 000000000..2fb228fb0 --- /dev/null +++ b/app/src/main/java/de/xikolo/storages/preferences/UserStorage.java @@ -0,0 +1,64 @@ +package de.xikolo.storages.preferences; + +import android.content.Context; +import android.content.SharedPreferences; + +import de.xikolo.models.AccessToken; +import de.xikolo.models.User; + +public class UserStorage extends KeyValueStorage { + + private static final String PREF_USER = "pref_user"; + + private static String ACCESS_TOKEN_DEFAULT = null; + + private static String USER_ID = "id"; + private static String USER_FIRST_NAME = "first_name"; + private static String USER_LAST_NAME = "last_name"; + private static String USER_EMAIL = "email"; + private static String USER_ACCESS_TOKEN = "token"; + private static String USER_VISUAL_URL = "visual_url"; + + UserStorage(Context context) { + super(context, PREF_USER, Context.MODE_PRIVATE); + } + + public User getUser() { + User user = new User(); + user.id = preferences.getString(USER_ID, null); + user.first_name = preferences.getString(USER_FIRST_NAME, null); + user.last_name = preferences.getString(USER_LAST_NAME, null); + user.email = preferences.getString(USER_EMAIL, null); + user.user_visual = preferences.getString(USER_VISUAL_URL, null); + return user; + } + + public void saveUser(User user) { + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(USER_ID, user.id); + editor.putString(USER_FIRST_NAME, user.first_name); + editor.putString(USER_LAST_NAME, user.last_name); + editor.putString(USER_EMAIL, user.email); + editor.putString(USER_VISUAL_URL, user.user_visual); + editor.commit(); + } + + public void deleteUser() { + SharedPreferences.Editor editor = preferences.edit(); + editor.clear(); + editor.commit(); + } + + public AccessToken getAccessToken() { + AccessToken token = new AccessToken(); + token.token = preferences.getString(USER_ACCESS_TOKEN, ACCESS_TOKEN_DEFAULT); + return token; + } + + public void saveAccessToken(AccessToken token) { + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(USER_ACCESS_TOKEN, token.token); + editor.commit(); + } + +} diff --git a/app/src/main/java/de/xikolo/util/AndroidDimenUtil.java b/app/src/main/java/de/xikolo/utils/AndroidDimenUtil.java similarity index 97% rename from app/src/main/java/de/xikolo/util/AndroidDimenUtil.java rename to app/src/main/java/de/xikolo/utils/AndroidDimenUtil.java index 5b539849c..616f86ddf 100644 --- a/app/src/main/java/de/xikolo/util/AndroidDimenUtil.java +++ b/app/src/main/java/de/xikolo/utils/AndroidDimenUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.res.TypedArray; import android.os.Build; diff --git a/app/src/main/java/de/xikolo/util/BuildFlavor.java b/app/src/main/java/de/xikolo/utils/BuildFlavor.java similarity index 80% rename from app/src/main/java/de/xikolo/util/BuildFlavor.java rename to app/src/main/java/de/xikolo/utils/BuildFlavor.java index 8ef210bfd..9aa84d449 100644 --- a/app/src/main/java/de/xikolo/util/BuildFlavor.java +++ b/app/src/main/java/de/xikolo/utils/BuildFlavor.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; public enum BuildFlavor { OPEN_HPI, OPEN_HPI_CN, OPEN_SAP, MOOC_HOUSE, MOOC_HOUSE_CN, OPEN_UNE diff --git a/app/src/main/java/de/xikolo/util/BuildType.java b/app/src/main/java/de/xikolo/utils/BuildType.java similarity index 64% rename from app/src/main/java/de/xikolo/util/BuildType.java rename to app/src/main/java/de/xikolo/utils/BuildType.java index e98919fb4..a90512cec 100644 --- a/app/src/main/java/de/xikolo/util/BuildType.java +++ b/app/src/main/java/de/xikolo/utils/BuildType.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; public enum BuildType { DEBUG, RELEASE diff --git a/app/src/main/java/de/xikolo/util/CastUtil.java b/app/src/main/java/de/xikolo/utils/CastUtil.java similarity index 90% rename from app/src/main/java/de/xikolo/util/CastUtil.java rename to app/src/main/java/de/xikolo/utils/CastUtil.java index 4085f2685..0c2ba5911 100644 --- a/app/src/main/java/de/xikolo/util/CastUtil.java +++ b/app/src/main/java/de/xikolo/utils/CastUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.net.Uri; @@ -6,8 +6,8 @@ import com.google.android.gms.cast.MediaMetadata; import com.google.android.gms.common.images.WebImage; -import de.xikolo.data.entities.Item; -import de.xikolo.data.entities.VideoItemDetail; +import de.xikolo.models.Item; +import de.xikolo.models.VideoItemDetail; public class CastUtil { diff --git a/app/src/main/java/de/xikolo/util/ClientUtil.java b/app/src/main/java/de/xikolo/utils/ClientUtil.java similarity index 98% rename from app/src/main/java/de/xikolo/util/ClientUtil.java rename to app/src/main/java/de/xikolo/utils/ClientUtil.java index 84e7fc07e..63f37bc17 100644 --- a/app/src/main/java/de/xikolo/util/ClientUtil.java +++ b/app/src/main/java/de/xikolo/utils/ClientUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.Context; diff --git a/app/src/main/java/de/xikolo/util/Config.java b/app/src/main/java/de/xikolo/utils/Config.java similarity index 99% rename from app/src/main/java/de/xikolo/util/Config.java rename to app/src/main/java/de/xikolo/utils/Config.java index dc7589814..88a54f9d0 100644 --- a/app/src/main/java/de/xikolo/util/Config.java +++ b/app/src/main/java/de/xikolo/utils/Config.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import com.google.android.gms.cast.CastMediaControlIntent; diff --git a/app/src/main/java/de/xikolo/util/DateUtil.java b/app/src/main/java/de/xikolo/utils/DateUtil.java similarity index 99% rename from app/src/main/java/de/xikolo/util/DateUtil.java rename to app/src/main/java/de/xikolo/utils/DateUtil.java index 2f7c4be06..6ff07a798 100644 --- a/app/src/main/java/de/xikolo/util/DateUtil.java +++ b/app/src/main/java/de/xikolo/utils/DateUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.util.Log; diff --git a/app/src/main/java/de/xikolo/util/DeepLinkingUtil.java b/app/src/main/java/de/xikolo/utils/DeepLinkingUtil.java similarity index 98% rename from app/src/main/java/de/xikolo/util/DeepLinkingUtil.java rename to app/src/main/java/de/xikolo/utils/DeepLinkingUtil.java index 9358af8a8..473957c62 100644 --- a/app/src/main/java/de/xikolo/util/DeepLinkingUtil.java +++ b/app/src/main/java/de/xikolo/utils/DeepLinkingUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.net.Uri; diff --git a/app/src/main/java/de/xikolo/util/DisplayUtil.java b/app/src/main/java/de/xikolo/utils/DisplayUtil.java similarity index 97% rename from app/src/main/java/de/xikolo/util/DisplayUtil.java rename to app/src/main/java/de/xikolo/utils/DisplayUtil.java index c66d0933a..eebcf6ba5 100644 --- a/app/src/main/java/de/xikolo/util/DisplayUtil.java +++ b/app/src/main/java/de/xikolo/utils/DisplayUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.Context; import android.util.DisplayMetrics; diff --git a/app/src/main/java/de/xikolo/util/ExternalStorageUtil.java b/app/src/main/java/de/xikolo/utils/ExternalStorageUtil.java similarity index 96% rename from app/src/main/java/de/xikolo/util/ExternalStorageUtil.java rename to app/src/main/java/de/xikolo/utils/ExternalStorageUtil.java index dfedfef9d..84f0ca7a8 100644 --- a/app/src/main/java/de/xikolo/util/ExternalStorageUtil.java +++ b/app/src/main/java/de/xikolo/utils/ExternalStorageUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.os.Environment; diff --git a/app/src/main/java/de/xikolo/util/FeatureToggle.java b/app/src/main/java/de/xikolo/utils/FeatureToggle.java similarity index 92% rename from app/src/main/java/de/xikolo/util/FeatureToggle.java rename to app/src/main/java/de/xikolo/utils/FeatureToggle.java index c712a2a7a..70d8a8e0c 100644 --- a/app/src/main/java/de/xikolo/util/FeatureToggle.java +++ b/app/src/main/java/de/xikolo/utils/FeatureToggle.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.os.Build; diff --git a/app/src/main/java/de/xikolo/util/FileUtil.java b/app/src/main/java/de/xikolo/utils/FileUtil.java similarity index 98% rename from app/src/main/java/de/xikolo/util/FileUtil.java rename to app/src/main/java/de/xikolo/utils/FileUtil.java index 4f59ef476..f2bb59a37 100644 --- a/app/src/main/java/de/xikolo/util/FileUtil.java +++ b/app/src/main/java/de/xikolo/utils/FileUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import java.io.File; import java.text.DecimalFormat; diff --git a/app/src/main/java/de/xikolo/util/GlideConfiguration.java b/app/src/main/java/de/xikolo/utils/GlideConfiguration.java similarity index 97% rename from app/src/main/java/de/xikolo/util/GlideConfiguration.java rename to app/src/main/java/de/xikolo/utils/GlideConfiguration.java index cbcad5bbe..6eb089792 100644 --- a/app/src/main/java/de/xikolo/util/GlideConfiguration.java +++ b/app/src/main/java/de/xikolo/utils/GlideConfiguration.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.Context; diff --git a/app/src/main/java/de/xikolo/util/HeaderAndSectionsList.java b/app/src/main/java/de/xikolo/utils/HeaderAndSectionsList.java similarity index 98% rename from app/src/main/java/de/xikolo/util/HeaderAndSectionsList.java rename to app/src/main/java/de/xikolo/utils/HeaderAndSectionsList.java index 7c075aad8..f6e5393ee 100644 --- a/app/src/main/java/de/xikolo/util/HeaderAndSectionsList.java +++ b/app/src/main/java/de/xikolo/utils/HeaderAndSectionsList.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/de/xikolo/util/ItemTitle.java b/app/src/main/java/de/xikolo/utils/ItemTitle.java similarity index 90% rename from app/src/main/java/de/xikolo/util/ItemTitle.java rename to app/src/main/java/de/xikolo/utils/ItemTitle.java index bde56d2bc..e57d16230 100644 --- a/app/src/main/java/de/xikolo/util/ItemTitle.java +++ b/app/src/main/java/de/xikolo/utils/ItemTitle.java @@ -1,6 +1,4 @@ -package de.xikolo.util; - -import android.util.Log; +package de.xikolo.utils; public class ItemTitle { diff --git a/app/src/main/java/de/xikolo/util/LanalyticsUtil.java b/app/src/main/java/de/xikolo/utils/LanalyticsUtil.java similarity index 96% rename from app/src/main/java/de/xikolo/util/LanalyticsUtil.java rename to app/src/main/java/de/xikolo/utils/LanalyticsUtil.java index a2f6d28fb..8893c0214 100644 --- a/app/src/main/java/de/xikolo/util/LanalyticsUtil.java +++ b/app/src/main/java/de/xikolo/utils/LanalyticsUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.res.Configuration; import android.util.Log; @@ -9,11 +9,12 @@ import de.xikolo.BuildConfig; import de.xikolo.GlobalApplication; -import de.xikolo.data.preferences.UserPreferences; +import de.xikolo.managers.UserManager; +import de.xikolo.storages.preferences.StorageType; +import de.xikolo.storages.preferences.UserStorage; import de.xikolo.lanalytics.Lanalytics; import de.xikolo.lanalytics.Tracker; -import de.xikolo.model.DownloadModel; -import de.xikolo.model.UserModel; +import de.xikolo.managers.DownloadManager; public class LanalyticsUtil { @@ -112,7 +113,7 @@ public static void trackVideoSeek(String videoId, String courseId, String sectio .build()); } - public static void trackDownloadedFile(String videoId, String courseId, String sectionId, DownloadModel.DownloadFileType type) { + public static void trackDownloadedFile(String videoId, String courseId, String sectionId, DownloadManager.DownloadFileType type) { String verb = null; switch (type) { case VIDEO_HD: verb = "DOWNLOADED_HD_VIDEO"; break; @@ -366,9 +367,9 @@ public static void trackVisitedSecondScreenPinboard(String videoId, String cours public static void track(Lanalytics.Event event) { GlobalApplication application = GlobalApplication.getInstance(); - if (UserModel.isLoggedIn(application) && isTrackingEnabled()) { + if (UserManager.isLoggedIn() && isTrackingEnabled()) { Tracker tracker = application.getLanalytics().getDefaultTracker(); - tracker.send(event, UserModel.getToken(GlobalApplication.getInstance())); + tracker.send(event, UserManager.getToken()); } else { if (Config.DEBUG) { Log.i(TAG, "Couldn't track event " + event.verb + ". No user login found or tracking is disabled for this build."); @@ -385,9 +386,9 @@ public static Lanalytics.Event.Builder newEventBuilder() { GlobalApplication application = GlobalApplication.getInstance(); Lanalytics.Event.Builder builder = new Lanalytics.Event.Builder(application); - if (UserModel.isLoggedIn(application)) { - UserPreferences userPreferences = application.getPreferencesFactory().getUserPreferences(); - builder.setUser(userPreferences.getUser().id); + if (UserManager.isLoggedIn()) { + UserStorage userStorage = (UserStorage) GlobalApplication.getStorage(StorageType.USER); + builder.setUser(userStorage.getUser().id); } builder.putContext(CONTEXT_CLIENT_ID, application.getClientId()); diff --git a/app/src/main/java/de/xikolo/util/LanguageUtil.java b/app/src/main/java/de/xikolo/utils/LanguageUtil.java similarity index 95% rename from app/src/main/java/de/xikolo/util/LanguageUtil.java rename to app/src/main/java/de/xikolo/utils/LanguageUtil.java index 7868c7ee7..d4c4549b4 100644 --- a/app/src/main/java/de/xikolo/util/LanguageUtil.java +++ b/app/src/main/java/de/xikolo/utils/LanguageUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.Context; diff --git a/app/src/main/java/de/xikolo/util/NetworkUtil.java b/app/src/main/java/de/xikolo/utils/NetworkUtil.java similarity index 98% rename from app/src/main/java/de/xikolo/util/NetworkUtil.java rename to app/src/main/java/de/xikolo/utils/NetworkUtil.java index c90c7d322..3ac326b52 100644 --- a/app/src/main/java/de/xikolo/util/NetworkUtil.java +++ b/app/src/main/java/de/xikolo/utils/NetworkUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.content.Context; import android.net.ConnectivityManager; diff --git a/app/src/main/java/de/xikolo/util/PlayServicesUtil.java b/app/src/main/java/de/xikolo/utils/PlayServicesUtil.java similarity index 97% rename from app/src/main/java/de/xikolo/util/PlayServicesUtil.java rename to app/src/main/java/de/xikolo/utils/PlayServicesUtil.java index 6ffd7fff3..6665c462c 100644 --- a/app/src/main/java/de/xikolo/util/PlayServicesUtil.java +++ b/app/src/main/java/de/xikolo/utils/PlayServicesUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.app.Activity; diff --git a/app/src/main/java/de/xikolo/util/PlaybackSpeed.java b/app/src/main/java/de/xikolo/utils/PlaybackSpeed.java similarity index 97% rename from app/src/main/java/de/xikolo/util/PlaybackSpeed.java rename to app/src/main/java/de/xikolo/utils/PlaybackSpeed.java index b64e2d32c..26eab826d 100644 --- a/app/src/main/java/de/xikolo/util/PlaybackSpeed.java +++ b/app/src/main/java/de/xikolo/utils/PlaybackSpeed.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; public enum PlaybackSpeed { diff --git a/app/src/main/java/de/xikolo/util/SslCertificateUtil.java b/app/src/main/java/de/xikolo/utils/SslCertificateUtil.java similarity index 98% rename from app/src/main/java/de/xikolo/util/SslCertificateUtil.java rename to app/src/main/java/de/xikolo/utils/SslCertificateUtil.java index 60463c701..840934f0c 100644 --- a/app/src/main/java/de/xikolo/util/SslCertificateUtil.java +++ b/app/src/main/java/de/xikolo/utils/SslCertificateUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; diff --git a/app/src/main/java/de/xikolo/util/TimeUtil.java b/app/src/main/java/de/xikolo/utils/TimeUtil.java similarity index 99% rename from app/src/main/java/de/xikolo/util/TimeUtil.java rename to app/src/main/java/de/xikolo/utils/TimeUtil.java index ab323e961..2aa456db3 100644 --- a/app/src/main/java/de/xikolo/util/TimeUtil.java +++ b/app/src/main/java/de/xikolo/utils/TimeUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import java.util.Locale; import java.util.concurrent.TimeUnit; diff --git a/app/src/main/java/de/xikolo/util/ToastUtil.java b/app/src/main/java/de/xikolo/utils/ToastUtil.java similarity index 97% rename from app/src/main/java/de/xikolo/util/ToastUtil.java rename to app/src/main/java/de/xikolo/utils/ToastUtil.java index e8c1f3f3c..074a19139 100644 --- a/app/src/main/java/de/xikolo/util/ToastUtil.java +++ b/app/src/main/java/de/xikolo/utils/ToastUtil.java @@ -1,4 +1,4 @@ -package de.xikolo.util; +package de.xikolo.utils; import android.support.annotation.StringRes; import android.widget.Toast; diff --git a/app/src/main/java/de/xikolo/view/AutofitRecyclerView.java b/app/src/main/java/de/xikolo/views/AutofitRecyclerView.java similarity index 99% rename from app/src/main/java/de/xikolo/view/AutofitRecyclerView.java rename to app/src/main/java/de/xikolo/views/AutofitRecyclerView.java index 185bec03f..d408e4130 100644 --- a/app/src/main/java/de/xikolo/view/AutofitRecyclerView.java +++ b/app/src/main/java/de/xikolo/views/AutofitRecyclerView.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/de/xikolo/view/CustomFontTextView.java b/app/src/main/java/de/xikolo/views/CustomFontTextView.java similarity index 96% rename from app/src/main/java/de/xikolo/view/CustomFontTextView.java rename to app/src/main/java/de/xikolo/views/CustomFontTextView.java index 9a352d01b..b79c105ec 100644 --- a/app/src/main/java/de/xikolo/view/CustomFontTextView.java +++ b/app/src/main/java/de/xikolo/views/CustomFontTextView.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.content.res.TypedArray; @@ -10,7 +10,7 @@ import java.util.Hashtable; import de.xikolo.R; -import de.xikolo.util.Config; +import de.xikolo.utils.Config; public class CustomFontTextView extends TextView { diff --git a/app/src/main/java/de/xikolo/view/CustomSizeImageView.java b/app/src/main/java/de/xikolo/views/CustomSizeImageView.java similarity index 97% rename from app/src/main/java/de/xikolo/view/CustomSizeImageView.java rename to app/src/main/java/de/xikolo/views/CustomSizeImageView.java index 673fb34b0..dabdda9af 100644 --- a/app/src/main/java/de/xikolo/view/CustomSizeImageView.java +++ b/app/src/main/java/de/xikolo/views/CustomSizeImageView.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.util.AttributeSet; diff --git a/app/src/main/java/de/xikolo/view/CustomSizeVideoView.java b/app/src/main/java/de/xikolo/views/CustomSizeVideoView.java similarity index 97% rename from app/src/main/java/de/xikolo/view/CustomSizeVideoView.java rename to app/src/main/java/de/xikolo/views/CustomSizeVideoView.java index d93c8d6b9..ef9d5c1c6 100644 --- a/app/src/main/java/de/xikolo/view/CustomSizeVideoView.java +++ b/app/src/main/java/de/xikolo/views/CustomSizeVideoView.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.util.AttributeSet; diff --git a/app/src/main/java/de/xikolo/view/DividerItemDecoration.java b/app/src/main/java/de/xikolo/views/DividerItemDecoration.java similarity index 99% rename from app/src/main/java/de/xikolo/view/DividerItemDecoration.java rename to app/src/main/java/de/xikolo/views/DividerItemDecoration.java index 7f9e2fd3f..c918c909e 100644 --- a/app/src/main/java/de/xikolo/view/DividerItemDecoration.java +++ b/app/src/main/java/de/xikolo/views/DividerItemDecoration.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/de/xikolo/view/IconButton.java b/app/src/main/java/de/xikolo/views/IconButton.java similarity index 98% rename from app/src/main/java/de/xikolo/view/IconButton.java rename to app/src/main/java/de/xikolo/views/IconButton.java index a313f09eb..c3de8fd6f 100644 --- a/app/src/main/java/de/xikolo/view/IconButton.java +++ b/app/src/main/java/de/xikolo/views/IconButton.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/de/xikolo/view/MaxWidthFrameLayout.java b/app/src/main/java/de/xikolo/views/MaxWidthFrameLayout.java similarity index 97% rename from app/src/main/java/de/xikolo/view/MaxWidthFrameLayout.java rename to app/src/main/java/de/xikolo/views/MaxWidthFrameLayout.java index 0da05fd92..4a700cea6 100644 --- a/app/src/main/java/de/xikolo/view/MaxWidthFrameLayout.java +++ b/app/src/main/java/de/xikolo/views/MaxWidthFrameLayout.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/de/xikolo/view/NestedScrollWebView.java b/app/src/main/java/de/xikolo/views/NestedScrollWebView.java similarity index 99% rename from app/src/main/java/de/xikolo/view/NestedScrollWebView.java rename to app/src/main/java/de/xikolo/views/NestedScrollWebView.java index 82fc076a0..4e42d8842 100644 --- a/app/src/main/java/de/xikolo/view/NestedScrollWebView.java +++ b/app/src/main/java/de/xikolo/views/NestedScrollWebView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.support.v4.view.MotionEventCompat; diff --git a/app/src/main/java/de/xikolo/view/ScrimInsetsFrameLayout.java b/app/src/main/java/de/xikolo/views/ScrimInsetsFrameLayout.java similarity index 99% rename from app/src/main/java/de/xikolo/view/ScrimInsetsFrameLayout.java rename to app/src/main/java/de/xikolo/views/ScrimInsetsFrameLayout.java index f2ce071c9..523fd2c95 100644 --- a/app/src/main/java/de/xikolo/view/ScrimInsetsFrameLayout.java +++ b/app/src/main/java/de/xikolo/views/ScrimInsetsFrameLayout.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; /* * Copyright 2014 Google Inc. diff --git a/app/src/main/java/de/xikolo/view/SpaceItemDecoration.java b/app/src/main/java/de/xikolo/views/SpaceItemDecoration.java similarity index 98% rename from app/src/main/java/de/xikolo/view/SpaceItemDecoration.java rename to app/src/main/java/de/xikolo/views/SpaceItemDecoration.java index f1732b3de..4aa4a238d 100644 --- a/app/src/main/java/de/xikolo/view/SpaceItemDecoration.java +++ b/app/src/main/java/de/xikolo/views/SpaceItemDecoration.java @@ -1,4 +1,4 @@ -package de.xikolo.view; +package de.xikolo.views; import android.graphics.Rect; import android.support.v7.widget.RecyclerView; diff --git a/app/src/main/java/de/xikolo/view/TranscriptFabBehavior.java b/app/src/main/java/de/xikolo/views/TranscriptFabBehavior.java similarity index 96% rename from app/src/main/java/de/xikolo/view/TranscriptFabBehavior.java rename to app/src/main/java/de/xikolo/views/TranscriptFabBehavior.java index 74dc23a03..dc396ff6f 100644 --- a/app/src/main/java/de/xikolo/view/TranscriptFabBehavior.java +++ b/app/src/main/java/de/xikolo/views/TranscriptFabBehavior.java @@ -1,11 +1,10 @@ -package de.xikolo.view; +package de.xikolo.views; import android.content.Context; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.v4.view.ViewCompat; import android.util.AttributeSet; -import android.util.Log; import android.view.View; public class TranscriptFabBehavior extends FloatingActionButton.Behavior { diff --git a/app/src/main/res/layout-sw600dp-land/item_progress.xml b/app/src/main/res/layout-sw600dp-land/item_progress.xml index 314aad090..9908e9dd4 100644 --- a/app/src/main/res/layout-sw600dp-land/item_progress.xml +++ b/app/src/main/res/layout-sw600dp-land/item_progress.xml @@ -73,7 +73,7 @@ android:layout_marginBottom="4dp" android:orientation="horizontal"> - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 94f27d026..605f5ed07 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -59,7 +59,7 @@ diff --git a/app/src/main/res/layout/activity_video.xml b/app/src/main/res/layout/activity_video.xml index 9980774d3..fbd7cfc3e 100644 --- a/app/src/main/res/layout/activity_video.xml +++ b/app/src/main/res/layout/activity_video.xml @@ -1,4 +1,4 @@ - - + diff --git a/app/src/main/res/layout/container_custom_tab.xml b/app/src/main/res/layout/container_custom_tab.xml index 3be83d595..bfbdb5647 100644 --- a/app/src/main/res/layout/container_custom_tab.xml +++ b/app/src/main/res/layout/container_custom_tab.xml @@ -12,7 +12,7 @@ android:layout_marginBottom="4dp" android:background="@drawable/circle_white" /> - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/container_video.xml b/app/src/main/res/layout/container_video.xml index b05a13446..58f835a1e 100644 --- a/app/src/main/res/layout/container_video.xml +++ b/app/src/main/res/layout/container_video.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create new account enrollments Total + Points Please scan the QR Code Presentation slides as PDF Transcript as PDF diff --git a/build.gradle b/build.gradle index 881b0e16f..a27dee12e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:2.2.1' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } From 2dd22130c429173246f544fee3c951bc9a9bebdc Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Fri, 14 Oct 2016 15:12:23 +0200 Subject: [PATCH 06/15] Migrate JobQueue to V2. --- app/build.gradle | 2 +- .../java/de/xikolo/GlobalApplication.java | 19 ++++++++----- .../de/xikolo/controllers/BaseActivity.java | 4 +-- .../de/xikolo/controllers/BaseFragment.java | 2 +- .../de/xikolo/controllers/CourseActivity.java | 4 +-- .../helper/ModuleDownloadController.java | 4 +-- .../controllers/helper/VideoController.java | 10 +++---- .../navigation/adapter/NavigationAdapter.java | 6 ++-- .../secondscreen/SecondScreenFragment.java | 4 +-- .../secondscreen/SlideViewerFragment.java | 12 ++++---- .../settings/SettingsFragment.java | 4 +-- .../java/de/xikolo/managers/BaseManager.java | 2 +- .../de/xikolo/managers/CourseManager.java | 4 +-- .../de/xikolo/managers/DownloadManager.java | 26 ++++++++--------- .../java/de/xikolo/managers/ItemManager.java | 14 +++++----- .../de/xikolo/managers/ModuleManager.java | 8 +++--- .../de/xikolo/managers/PermissionManager.java | 2 +- .../java/de/xikolo/managers/UserManager.java | 2 +- .../managers/jobs/CreateAccessTokenJob.java | 17 ++++------- .../managers/jobs/CreateEnrollmentJob.java | 22 ++++++--------- .../managers/jobs/DeleteEnrollmentJob.java | 28 ++++++++----------- .../jobs/RetrieveContentLengthJob.java | 20 +++++-------- .../managers/jobs/RetrieveCourseJob.java | 24 ++++++---------- .../managers/jobs/RetrieveCourseListJob.java | 24 ++++++---------- .../managers/jobs/RetrieveItemDetailJob.java | 20 ++++--------- .../managers/jobs/RetrieveItemListJob.java | 23 ++++++--------- .../managers/jobs/RetrieveLocalVideoJob.java | 22 ++++++--------- .../managers/jobs/RetrieveModuleListJob.java | 15 ++++------ .../RetrieveModuleListWithItemListJob.java | 15 ++++------ .../jobs/RetrieveModuleWithItemListJob.java | 27 ++++++++---------- .../xikolo/managers/jobs/RetrieveUserJob.java | 18 ++++-------- .../jobs/RetrieveVideoSubtitlesJob.java | 20 +++++-------- .../managers/jobs/UpdateLocalVideoJob.java | 22 ++++++--------- .../managers/jobs/UpdateProgressionJob.java | 18 ++++-------- 34 files changed, 184 insertions(+), 280 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1a584e3d0..a543cb605 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -152,7 +152,7 @@ dependencies { compile ('com.github.bumptech.glide:okhttp3-integration:1.4.0') { exclude group: 'glide-parent' } - compile 'com.birbit:android-priority-jobqueue:1.3.4' + compile 'com.birbit:android-priority-jobqueue:2.0.1' compile 'org.greenrobot:eventbus:3.0.0' compile 'org.java-websocket:Java-WebSocket:1.3.0' diff --git a/app/src/main/java/de/xikolo/GlobalApplication.java b/app/src/main/java/de/xikolo/GlobalApplication.java index 54a6b7afc..65b0abd1f 100644 --- a/app/src/main/java/de/xikolo/GlobalApplication.java +++ b/app/src/main/java/de/xikolo/GlobalApplication.java @@ -8,11 +8,11 @@ import android.webkit.CookieSyncManager; import android.webkit.WebView; +import com.birbit.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.config.Configuration; +import com.birbit.android.jobqueue.log.CustomLogger; import com.google.android.libraries.cast.companionlibrary.cast.CastConfiguration; import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; -import com.path.android.jobqueue.JobManager; -import com.path.android.jobqueue.config.Configuration; -import com.path.android.jobqueue.log.CustomLogger; import de.xikolo.lanalytics.Lanalytics; import de.xikolo.managers.SecondScreenManager; @@ -145,16 +145,21 @@ private void configureJobManager() { Configuration configuration = new Configuration.Builder(this) .customLogger(new CustomLogger() { - private static final String TAG = "JOBS"; + private final String TAG = JobManager.class.getSimpleName(); @Override public boolean isDebugEnabled() { - return false; + return Config.DEBUG; + } + + @Override + public void v(String text, Object... args) { + if (Config.DEBUG) Log.v(TAG, String.format(text, args)); } @Override public void d(String text, Object... args) { - Log.d(TAG, String.format(text, args)); + if (Config.DEBUG) Log.d(TAG, String.format(text, args)); } @Override @@ -172,7 +177,7 @@ public void e(String text, Object... args) { .loadFactor(2) // jobs per consumer .consumerKeepAlive(120) // wait 2 minute .build(); - jobManager = new JobManager(this, configuration); + jobManager = new JobManager(configuration); } @SuppressWarnings("deprecation") diff --git a/app/src/main/java/de/xikolo/controllers/BaseActivity.java b/app/src/main/java/de/xikolo/controllers/BaseActivity.java index 4e031ebdd..2f1877e13 100644 --- a/app/src/main/java/de/xikolo/controllers/BaseActivity.java +++ b/app/src/main/java/de/xikolo/controllers/BaseActivity.java @@ -16,10 +16,10 @@ import android.view.Menu; import android.view.MenuItem; +import com.birbit.android.jobqueue.JobManager; import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; import com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl; import com.google.android.libraries.cast.companionlibrary.widgets.IntroductoryOverlay; -import com.path.android.jobqueue.JobManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -31,8 +31,8 @@ import de.xikolo.events.PermissionDeniedEvent; import de.xikolo.events.PermissionGrantedEvent; import de.xikolo.managers.UserManager; -import de.xikolo.storages.preferences.NotificationStorage; import de.xikolo.receivers.NotificationDeletedReceiver; +import de.xikolo.storages.preferences.NotificationStorage; import de.xikolo.storages.preferences.StorageType; import de.xikolo.utils.FeatureToggle; import de.xikolo.utils.PlayServicesUtil; diff --git a/app/src/main/java/de/xikolo/controllers/BaseFragment.java b/app/src/main/java/de/xikolo/controllers/BaseFragment.java index 1e5fbe0ad..f31657d6f 100644 --- a/app/src/main/java/de/xikolo/controllers/BaseFragment.java +++ b/app/src/main/java/de/xikolo/controllers/BaseFragment.java @@ -3,8 +3,8 @@ import android.os.Bundle; import android.support.v4.app.Fragment; +import com.birbit.android.jobqueue.JobManager; import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; -import com.path.android.jobqueue.JobManager; import de.xikolo.GlobalApplication; diff --git a/app/src/main/java/de/xikolo/controllers/CourseActivity.java b/app/src/main/java/de/xikolo/controllers/CourseActivity.java index 56a7aa37c..af54d2fab 100644 --- a/app/src/main/java/de/xikolo/controllers/CourseActivity.java +++ b/app/src/main/java/de/xikolo/controllers/CourseActivity.java @@ -204,8 +204,8 @@ protected void onError(ErrorCode errorCode) { } }; - CourseManager courseModel = new CourseManager(jobManager); - courseModel.getCourses(result, false); + CourseManager courseManager = new CourseManager(jobManager); + courseManager.getCourses(result, false); progressDialog.show(getSupportFragmentManager(), ProgressDialog.TAG); } diff --git a/app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java b/app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java index 6d96182ce..89c9734a1 100644 --- a/app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/ModuleDownloadController.java @@ -76,7 +76,7 @@ public void onDialogPositiveClick(DialogFragment dialog) { } private void startModuleDownloads(final Course course, final Module module) { - ItemManager itemModel = new ItemManager(application.getJobManager()); + ItemManager itemManager = new ItemManager(application.getJobManager()); LanalyticsUtil.trackDownloadedSection(module.id, course.id, hdVideo, sdVideo, slides); @@ -109,7 +109,7 @@ protected void onSuccess(Item result, DataSource dataSource) { } } }; - itemModel.getItemDetail(result, course, module, item, item.type); + itemManager.getItemDetail(result, course, module, item, item.type); downloadStarted = true; } } diff --git a/app/src/main/java/de/xikolo/controllers/helper/VideoController.java b/app/src/main/java/de/xikolo/controllers/helper/VideoController.java index f6e0ff28e..191e8b268 100644 --- a/app/src/main/java/de/xikolo/controllers/helper/VideoController.java +++ b/app/src/main/java/de/xikolo/controllers/helper/VideoController.java @@ -46,7 +46,7 @@ public class VideoController { private static final int PLAYBACK_PARAMS_SDK_LEVEL = 23; - private DownloadManager downloadModel; + private DownloadManager downloadManager; private Activity activity; @@ -128,7 +128,7 @@ public boolean onTouch(View v, MotionEvent event) { } }); - downloadModel = new DownloadManager(GlobalApplication.getInstance().getJobManager(), activity); + downloadManager = new DownloadManager(GlobalApplication.getInstance().getJobManager(), activity); setupView(); } @@ -583,12 +583,12 @@ private void updateVideo(Course course, Module module, Item vid } private boolean videoDownloadPresent(DownloadManager.DownloadFileType fileType, Course course, Module module, Item video) { - return !downloadModel.downloadRunning(fileType, course, module, video) - && downloadModel.downloadExists(fileType, course, module, video); + return !downloadManager.downloadRunning(fileType, course, module, video) + && downloadManager.downloadExists(fileType, course, module, video); } private void setLocalVideoURI(DownloadManager.DownloadFileType fileType, Course course, Module module, Item video) { - setVideoURI("file://" + downloadModel.getDownloadFile(fileType, course, module, video).getAbsolutePath()); + setVideoURI("file://" + downloadManager.getDownloadFile(fileType, course, module, video).getAbsolutePath()); viewOfflineHint.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java b/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java index 26c503139..264e8260a 100644 --- a/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java +++ b/app/src/main/java/de/xikolo/controllers/navigation/adapter/NavigationAdapter.java @@ -92,14 +92,14 @@ public class NavigationAdapter extends RecyclerView.Adapter 0) { counterViewHolder.textCounter.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java b/app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java index af7e2767a..f1b3d38cc 100644 --- a/app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/SecondScreenFragment.java @@ -188,7 +188,7 @@ private void initSeconScreenActions(WebSocketMessage message) { final View viewQuiz = addQuizAction(); final View viewPinboard = addPinboardAction(); - ItemManager itemModel = new ItemManager(GlobalApplication.getInstance().getJobManager()); + ItemManager itemManager = new ItemManager(GlobalApplication.getInstance().getJobManager()); // pdf if (!"".equals(item.detail.slides_url)) { @@ -207,7 +207,7 @@ protected void onSuccess(List result, DataSource dataSource) { } }; - itemModel.getVideoSubtitles(result, message.payload().get("course_id"), message.payload().get("section_id"), item.id); + itemManager.getVideoSubtitles(result, message.payload().get("course_id"), message.payload().get("section_id"), item.id); } else { if (subtitleList.size() > 0) { viewTranscript.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java index 29bdb1929..b72ad6a18 100644 --- a/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java @@ -42,7 +42,7 @@ public class SlideViewerFragment extends Fragment implements OnLoadCompleteListe private PDFView pdfView; - private DownloadManager downloadModel; + private DownloadManager downloadManager; private ProgressDialog progressDialog; @@ -91,7 +91,7 @@ public void onCreate(Bundle savedInstanceState) { currentPage = 0; } - downloadModel = new DownloadManager(GlobalApplication.getInstance().getJobManager(), getActivity()); + downloadManager = new DownloadManager(GlobalApplication.getInstance().getJobManager(), getActivity()); } @Override @@ -122,14 +122,14 @@ public void onClick(View v) { } }); - if (downloadModel.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { + if (downloadManager.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { initSlidesViewer(); } else { DownloadSlidesDialog dialog = DownloadSlidesDialog.getInstance(); dialog.setListener(new DownloadSlidesDialog.DownloadSlidesDialogListener() { @Override public void onDialogPositiveClick() { - downloadModel.startDownload(item.detail.slides_url, DownloadManager.DownloadFileType.SLIDES, course, module, item); + downloadManager.startDownload(item.detail.slides_url, DownloadManager.DownloadFileType.SLIDES, course, module, item); progressDialog = ProgressDialog.getInstance(); progressDialog.show(getFragmentManager(), ProgressDialog.TAG); } @@ -144,8 +144,8 @@ public void onDialogNegativeClick() { } private void initSlidesViewer() { - if (downloadModel != null && downloadModel.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { - File file = downloadModel.getDownloadFile(DownloadManager.DownloadFileType.SLIDES, course, module, item); + if (downloadManager != null && downloadManager.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { + File file = downloadManager.getDownloadFile(DownloadManager.DownloadFileType.SLIDES, course, module, item); pdfView.fromFile(file) .swipeVertical(true) .enableAnnotationRendering(true) diff --git a/app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java b/app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java index e349f90a6..7e05ed22a 100644 --- a/app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java +++ b/app/src/main/java/de/xikolo/controllers/settings/SettingsFragment.java @@ -156,8 +156,8 @@ private void buildLogoutView(Preference pref) { pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - UserManager userModel = new UserManager(GlobalApplication.getInstance().getJobManager()); - userModel.logout(); + UserManager userManager = new UserManager(GlobalApplication.getInstance().getJobManager()); + userManager.logout(); return true; } }); diff --git a/app/src/main/java/de/xikolo/managers/BaseManager.java b/app/src/main/java/de/xikolo/managers/BaseManager.java index 77675af8b..117c48522 100644 --- a/app/src/main/java/de/xikolo/managers/BaseManager.java +++ b/app/src/main/java/de/xikolo/managers/BaseManager.java @@ -1,6 +1,6 @@ package de.xikolo.managers; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; public abstract class BaseManager { diff --git a/app/src/main/java/de/xikolo/managers/CourseManager.java b/app/src/main/java/de/xikolo/managers/CourseManager.java index 07d4e6921..5ffb1a093 100644 --- a/app/src/main/java/de/xikolo/managers/CourseManager.java +++ b/app/src/main/java/de/xikolo/managers/CourseManager.java @@ -1,6 +1,6 @@ package de.xikolo.managers; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; import java.util.ArrayList; import java.util.Collections; @@ -8,11 +8,11 @@ import java.util.List; import de.xikolo.GlobalApplication; -import de.xikolo.models.Course; import de.xikolo.managers.jobs.CreateEnrollmentJob; import de.xikolo.managers.jobs.DeleteEnrollmentJob; import de.xikolo.managers.jobs.RetrieveCourseJob; import de.xikolo.managers.jobs.RetrieveCourseListJob; +import de.xikolo.models.Course; import de.xikolo.storages.databases.DataType; import de.xikolo.storages.databases.adapters.CourseDataAdapter; import de.xikolo.utils.DateUtil; diff --git a/app/src/main/java/de/xikolo/managers/DownloadManager.java b/app/src/main/java/de/xikolo/managers/DownloadManager.java index 364319ffe..e33dbdb7c 100644 --- a/app/src/main/java/de/xikolo/managers/DownloadManager.java +++ b/app/src/main/java/de/xikolo/managers/DownloadManager.java @@ -5,7 +5,7 @@ import android.os.Environment; import android.util.Log; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -17,16 +17,16 @@ import de.xikolo.GlobalApplication; import de.xikolo.R; -import de.xikolo.models.Course; -import de.xikolo.models.Download; -import de.xikolo.models.Item; -import de.xikolo.models.Module; -import de.xikolo.network.DownloadHelper; import de.xikolo.events.DownloadDeletedEvent; import de.xikolo.events.DownloadStartedEvent; import de.xikolo.events.PermissionDeniedEvent; import de.xikolo.events.PermissionGrantedEvent; import de.xikolo.managers.jobs.RetrieveContentLengthJob; +import de.xikolo.models.Course; +import de.xikolo.models.Download; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.network.DownloadHelper; import de.xikolo.utils.Config; import de.xikolo.utils.ExternalStorageUtil; import de.xikolo.utils.LanalyticsUtil; @@ -36,9 +36,7 @@ public class DownloadManager extends BaseManager { public static final String TAG = DownloadManager.class.getSimpleName(); - private Activity activity; - - private PermissionManager permissionsModel; + private PermissionManager permissionManager; public enum PendingAction { START, DELETE, CANCEL; @@ -82,10 +80,8 @@ public Item getItem() { public DownloadManager(JobManager jobManager, Activity activity) { super(jobManager); - this.activity = activity; - - this.permissionsModel = new PermissionManager(jobManager, activity); + this.permissionManager = new PermissionManager(jobManager, activity); this.pendingAction = null; EventBus.getDefault().register(this); @@ -100,7 +96,7 @@ public long startDownload(String uri, DownloadFileType type, Course course, Modu Log.d(TAG, "Start download for " + uri); } if (ExternalStorageUtil.isExternalStorageWritable()) { - if (permissionsModel.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionManager.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { String file = this.escapeFilename(item.title) + type.getFileSuffix(); Uri downloadUri = buildDownloadUri(type, course, module, item); @@ -129,7 +125,7 @@ public long startDownload(String uri, DownloadFileType type, Course course, Modu public boolean deleteDownload(DownloadFileType type, Course course, Module module, Item item) { if (ExternalStorageUtil.isExternalStorageWritable()) { - if (permissionsModel.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionManager.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { Uri downloadUri = buildDownloadUri(type, course, module, item); if (Config.DEBUG) { @@ -157,7 +153,7 @@ public boolean deleteDownload(DownloadFileType type, Course course, Module modul public boolean cancelDownload(DownloadFileType type, Course course, Module module, Item item) { if (ExternalStorageUtil.isExternalStorageWritable()) { - if (permissionsModel.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { + if (permissionManager.requestPermission(PermissionManager.WRITE_EXTERNAL_STORAGE) == 1) { Uri downloadUri = buildDownloadUri(type, course, module, item); Download dl = new Download(); dl.localUri = downloadUri.toString(); diff --git a/app/src/main/java/de/xikolo/managers/ItemManager.java b/app/src/main/java/de/xikolo/managers/ItemManager.java index 60e6bfe75..b271d979e 100644 --- a/app/src/main/java/de/xikolo/managers/ItemManager.java +++ b/app/src/main/java/de/xikolo/managers/ItemManager.java @@ -1,22 +1,22 @@ package de.xikolo.managers; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; import java.util.Collections; import java.util.Comparator; import java.util.List; -import de.xikolo.models.Course; -import de.xikolo.models.Item; -import de.xikolo.models.Module; -import de.xikolo.models.Subtitle; -import de.xikolo.models.VideoItemDetail; import de.xikolo.managers.jobs.RetrieveItemDetailJob; import de.xikolo.managers.jobs.RetrieveItemListJob; import de.xikolo.managers.jobs.RetrieveLocalVideoJob; import de.xikolo.managers.jobs.RetrieveVideoSubtitlesJob; -import de.xikolo.managers.jobs.UpdateProgressionJob; import de.xikolo.managers.jobs.UpdateLocalVideoJob; +import de.xikolo.managers.jobs.UpdateProgressionJob; +import de.xikolo.models.Course; +import de.xikolo.models.Item; +import de.xikolo.models.Module; +import de.xikolo.models.Subtitle; +import de.xikolo.models.VideoItemDetail; public class ItemManager extends BaseManager { diff --git a/app/src/main/java/de/xikolo/managers/ModuleManager.java b/app/src/main/java/de/xikolo/managers/ModuleManager.java index f0ebbdcde..0fb477f34 100644 --- a/app/src/main/java/de/xikolo/managers/ModuleManager.java +++ b/app/src/main/java/de/xikolo/managers/ModuleManager.java @@ -1,16 +1,16 @@ package de.xikolo.managers; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; import java.util.Collections; import java.util.Comparator; import java.util.List; -import de.xikolo.models.Course; -import de.xikolo.models.Module; -import de.xikolo.managers.jobs.RetrieveModuleWithItemListJob; import de.xikolo.managers.jobs.RetrieveModuleListJob; import de.xikolo.managers.jobs.RetrieveModuleListWithItemListJob; +import de.xikolo.managers.jobs.RetrieveModuleWithItemListJob; +import de.xikolo.models.Course; +import de.xikolo.models.Module; public class ModuleManager extends BaseManager { diff --git a/app/src/main/java/de/xikolo/managers/PermissionManager.java b/app/src/main/java/de/xikolo/managers/PermissionManager.java index 9dfa1ee2e..8b50ab33d 100644 --- a/app/src/main/java/de/xikolo/managers/PermissionManager.java +++ b/app/src/main/java/de/xikolo/managers/PermissionManager.java @@ -10,7 +10,7 @@ import android.support.v4.content.ContextCompat; import android.util.Log; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; import de.xikolo.GlobalApplication; import de.xikolo.controllers.dialogs.PermissionsDialog; diff --git a/app/src/main/java/de/xikolo/managers/UserManager.java b/app/src/main/java/de/xikolo/managers/UserManager.java index 86cab4002..f972621ce 100644 --- a/app/src/main/java/de/xikolo/managers/UserManager.java +++ b/app/src/main/java/de/xikolo/managers/UserManager.java @@ -1,6 +1,6 @@ package de.xikolo.managers; -import com.path.android.jobqueue.JobManager; +import com.birbit.android.jobqueue.JobManager; import org.greenrobot.eventbus.EventBus; diff --git a/app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java b/app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java index 76e91ca0f..3215fffd3 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/CreateAccessTokenJob.java @@ -1,15 +1,14 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import org.greenrobot.eventbus.EventBus; -import java.util.concurrent.atomic.AtomicInteger; - import de.xikolo.GlobalApplication; import de.xikolo.events.LoginEvent; import de.xikolo.managers.Result; @@ -28,18 +27,12 @@ public class CreateAccessTokenJob extends Job { public static final String TAG = CreateAccessTokenJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private String email; private String password; - private Result result; public CreateAccessTokenJob(Result result, String email, String password) { super(new Params(Priority.HIGH)); - id = jobCounter.incrementAndGet(); this.result = result; @@ -87,7 +80,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java b/app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java index 1501cbe32..9febf5ef3 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/CreateEnrollmentJob.java @@ -1,20 +1,19 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; +import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.CourseDataAdapter; import de.xikolo.models.Course; import de.xikolo.network.ApiRequest; -import de.xikolo.managers.Result; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.FormBody; @@ -25,16 +24,11 @@ public class CreateEnrollmentJob extends Job { public static final String TAG = CreateEnrollmentJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private Course course; private Result result; public CreateEnrollmentJob(Result result, Course course) { super(new Params(Priority.HIGH)); - id = jobCounter.incrementAndGet(); this.result = result; this.course = course; @@ -80,7 +74,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java b/app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java index 089efce03..c112a58af 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/DeleteEnrollmentJob.java @@ -1,22 +1,21 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.CourseDataAdapter; -import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; import de.xikolo.models.Course; import de.xikolo.models.Module; import de.xikolo.network.ApiRequest; -import de.xikolo.managers.Result; -import de.xikolo.managers.UserManager; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -25,16 +24,11 @@ public class DeleteEnrollmentJob extends Job { public static final String TAG = DeleteEnrollmentJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result result; private Course course; + private Result result; public DeleteEnrollmentJob(Result result, Course course) { super(new Params(Priority.HIGH)); - id = jobCounter.incrementAndGet(); this.result = result; this.course = course; @@ -82,7 +76,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java index adba44778..2c5af3cdf 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveContentLengthJob.java @@ -1,16 +1,15 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; -import de.xikolo.network.ApiRequest; import de.xikolo.managers.Result; +import de.xikolo.network.ApiRequest; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -19,16 +18,11 @@ public class RetrieveContentLengthJob extends Job { public static final String TAG = RetrieveContentLengthJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result result; private String url; + private Result result; public RetrieveContentLengthJob(Result result, String url) { super(new Params(Priority.LOW)); - id = jobCounter.incrementAndGet(); this.result = result; this.url = url; @@ -59,7 +53,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java index 88e891d41..2bbd2d396 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseJob.java @@ -1,20 +1,19 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.CourseDataAdapter; +import de.xikolo.managers.Result; import de.xikolo.models.Course; import de.xikolo.network.ApiRequest; import de.xikolo.network.parser.ApiParser; -import de.xikolo.managers.Result; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -23,20 +22,13 @@ public class RetrieveCourseJob extends Job { public static final String TAG = RetrieveCourseJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private String courseId; - private Result result; public RetrieveCourseJob(Result result, String courseId) { super(new Params(Priority.MID)); - this.id = jobCounter.incrementAndGet(); this.courseId = courseId; - this.result = result; } @@ -73,7 +65,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java index 161f02bed..104f16126 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveCourseListJob.java @@ -1,24 +1,24 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import com.google.gson.reflect.TypeToken; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; import java.lang.reflect.Type; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; +import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.CourseDataAdapter; import de.xikolo.models.Course; import de.xikolo.network.ApiRequest; import de.xikolo.network.parser.ApiParser; -import de.xikolo.managers.Result; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.CourseDataAdapter; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -27,17 +27,11 @@ public class RetrieveCourseListJob extends Job { public static final String TAG = RetrieveCourseListJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result> result; - private boolean includeProgress; + private Result> result; public RetrieveCourseListJob(Result> result, boolean includeProgress) { super(new Params(includeProgress ? Priority.MID : Priority.MID)); - this.id = jobCounter.incrementAndGet(); this.result = result; this.includeProgress = includeProgress; @@ -83,7 +77,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java index 704373df3..b5485633f 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemDetailJob.java @@ -1,12 +1,11 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; import de.xikolo.controllers.exceptions.WrongParameterException; @@ -27,21 +26,14 @@ public class RetrieveItemDetailJob extends Job { public static final String TAG = RetrieveItemDetailJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result result; - private String courseId; private String moduleId; private String itemId; - private String itemType; + private Result result; public RetrieveItemDetailJob(Result result, String courseId, String moduleId, String itemId, String itemType) { super(new Params(Priority.HIGH)); - id = jobCounter.incrementAndGet(); if (courseId == null || moduleId == null || itemId == null) { throw new WrongParameterException(); @@ -117,7 +109,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java index a3cb216be..b84cbbe60 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveItemListJob.java @@ -1,24 +1,24 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import com.google.gson.reflect.TypeToken; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; import java.lang.reflect.Type; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; +import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.ItemDataAdapter; import de.xikolo.models.Item; import de.xikolo.network.ApiRequest; import de.xikolo.network.parser.ApiParser; -import de.xikolo.managers.Result; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -27,17 +27,12 @@ public class RetrieveItemListJob extends Job { public static final String TAG = RetrieveItemListJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result> result; private String courseId; private String moduleId; + private Result> result; public RetrieveItemListJob(Result> result, String courseId, String moduleId) { super(new Params(Priority.MID)); - id = jobCounter.incrementAndGet(); this.result = result; this.courseId = courseId; @@ -87,7 +82,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java index 557dbdfea..d3e75625c 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveLocalVideoJob.java @@ -1,35 +1,29 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.VideoDataAdapter; -import de.xikolo.models.VideoItemDetail; import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; +import de.xikolo.models.VideoItemDetail; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.VideoDataAdapter; import de.xikolo.utils.Config; public class RetrieveLocalVideoJob extends Job { public static final String TAG = RetrieveLocalVideoJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private String videoId; private Result result; public RetrieveLocalVideoJob(Result result, String videoId) { super(new Params(Priority.MID)); - id = jobCounter.incrementAndGet(); this.result = result; this.videoId = videoId; @@ -56,7 +50,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java index 1143cec2f..27f282b21 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListJob.java @@ -1,16 +1,16 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import com.google.gson.reflect.TypeToken; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; import de.xikolo.managers.Result; @@ -28,17 +28,12 @@ public class RetrieveModuleListJob extends Job { public static final String TAG = RetrieveModuleListJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private String courseId; private boolean includeProgress; private Result> result; public RetrieveModuleListJob(Result> result, String courseId, boolean includeProgress) { super(new Params(Priority.MID)); - id = jobCounter.incrementAndGet(); this.result = result; this.courseId = courseId; @@ -99,7 +94,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java index b4b07458b..8c25b1b08 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleListWithItemListJob.java @@ -1,16 +1,16 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import com.google.gson.reflect.TypeToken; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; import de.xikolo.managers.Result; @@ -30,17 +30,12 @@ public class RetrieveModuleListWithItemListJob extends Job { public static final String TAG = RetrieveModuleListWithItemListJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private String courseId; private boolean includeProgress; private Result> result; public RetrieveModuleListWithItemListJob(Result> result, String courseId, boolean includeProgress) { super(new Params(Priority.MID)); - id = jobCounter.incrementAndGet(); this.result = result; this.courseId = courseId; @@ -127,7 +122,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java index accadce3e..16c0d30b2 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveModuleWithItemListJob.java @@ -1,26 +1,26 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import com.google.gson.reflect.TypeToken; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; import java.lang.reflect.Type; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; -import de.xikolo.storages.databases.DataType; -import de.xikolo.storages.databases.adapters.ItemDataAdapter; -import de.xikolo.storages.databases.adapters.ModuleDataAdapter; +import de.xikolo.managers.Result; +import de.xikolo.managers.UserManager; import de.xikolo.models.Item; import de.xikolo.models.Module; import de.xikolo.network.ApiRequest; import de.xikolo.network.parser.ApiParser; -import de.xikolo.managers.Result; -import de.xikolo.managers.UserManager; +import de.xikolo.storages.databases.DataType; +import de.xikolo.storages.databases.adapters.ItemDataAdapter; +import de.xikolo.storages.databases.adapters.ModuleDataAdapter; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -29,17 +29,12 @@ public class RetrieveModuleWithItemListJob extends Job { public static final String TAG = RetrieveModuleWithItemListJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result result; private String courseId; private String moduleId; + private Result result; public RetrieveModuleWithItemListJob(Result result, String courseId, String moduleId) { super(new Params(Priority.MID)); - id = jobCounter.incrementAndGet(); this.result = result; this.courseId = courseId; @@ -118,7 +113,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java index e4956b3a3..e4ba9cf20 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveUserJob.java @@ -1,21 +1,20 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; +import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; import de.xikolo.models.User; import de.xikolo.network.ApiRequest; import de.xikolo.network.parser.ApiParser; import de.xikolo.storages.preferences.StorageType; import de.xikolo.storages.preferences.UserStorage; -import de.xikolo.managers.Result; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -24,15 +23,10 @@ public class RetrieveUserJob extends Job { public static final String TAG = RetrieveUserJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - private Result result; public RetrieveUserJob(Result result) { super(new Params(Priority.HIGH)); - id = jobCounter.incrementAndGet(); this.result = result; } @@ -74,7 +68,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java b/app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java index f55df7cb4..22d83c457 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/RetrieveVideoSubtitlesJob.java @@ -1,23 +1,23 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import com.google.gson.reflect.TypeToken; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; import java.lang.reflect.Type; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import de.xikolo.GlobalApplication; import de.xikolo.controllers.exceptions.WrongParameterException; +import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; import de.xikolo.models.Subtitle; import de.xikolo.network.ApiRequest; import de.xikolo.network.parser.ApiParser; -import de.xikolo.managers.Result; import de.xikolo.utils.Config; import de.xikolo.utils.NetworkUtil; import okhttp3.Response; @@ -26,19 +26,13 @@ public class RetrieveVideoSubtitlesJob extends Job { public static final String TAG = RetrieveVideoSubtitlesJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result> result; - private String courseId; private String moduleId; private String videoId; + private Result> result; public RetrieveVideoSubtitlesJob(Result> result, String courseId, String moduleId, String videoId) { super(new Params(Priority.HIGH)); - id = jobCounter.incrementAndGet(); if (courseId == null || moduleId == null || videoId == null) { throw new WrongParameterException(); @@ -86,7 +80,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java b/app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java index d14c8cb9c..509c19b63 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/UpdateLocalVideoJob.java @@ -1,35 +1,29 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; +import de.xikolo.managers.Result; import de.xikolo.managers.UserManager; +import de.xikolo.models.VideoItemDetail; import de.xikolo.storages.databases.DataType; import de.xikolo.storages.databases.adapters.VideoDataAdapter; -import de.xikolo.models.VideoItemDetail; -import de.xikolo.managers.Result; import de.xikolo.utils.Config; public class UpdateLocalVideoJob extends Job { public static final String TAG = UpdateLocalVideoJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private Result result; private VideoItemDetail videoItemDetail; + private Result result; public UpdateLocalVideoJob(Result result, VideoItemDetail videoItemDetail) { super(new Params(Priority.MID)); - id = jobCounter.incrementAndGet(); this.result = result; this.videoItemDetail = videoItemDetail; @@ -52,7 +46,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } diff --git a/app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java b/app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java index 689b550e5..92c0bf578 100644 --- a/app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java +++ b/app/src/main/java/de/xikolo/managers/jobs/UpdateProgressionJob.java @@ -1,12 +1,11 @@ package de.xikolo.managers.jobs; +import android.support.annotation.Nullable; import android.util.Log; -import com.path.android.jobqueue.Job; -import com.path.android.jobqueue.Params; -import com.path.android.jobqueue.RetryConstraint; - -import java.util.concurrent.atomic.AtomicInteger; +import com.birbit.android.jobqueue.Job; +import com.birbit.android.jobqueue.Params; +import com.birbit.android.jobqueue.RetryConstraint; import de.xikolo.GlobalApplication; import de.xikolo.managers.Result; @@ -22,16 +21,11 @@ public class UpdateProgressionJob extends Job { public static final String TAG = UpdateProgressionJob.class.getSimpleName(); - private static final AtomicInteger jobCounter = new AtomicInteger(0); - - private final int id; - - private transient Result result; private Item item; + private transient Result result; public UpdateProgressionJob(Result result, Item item) { super(new Params(Priority.LOW).requireNetwork().persist()); - id = jobCounter.incrementAndGet(); this.result = result; this.item = item; @@ -74,7 +68,7 @@ public void onRun() throws Throwable { } @Override - protected void onCancel() { + protected void onCancel(int cancelReason, @Nullable Throwable throwable) { result.error(Result.ErrorCode.ERROR); } From 18973d4bf16877adc47b4e12ce30b76621c1f324 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Sat, 15 Oct 2016 14:48:57 +0200 Subject: [PATCH 07/15] Disable ProGuard for now, caused too much problems. --- app/build.gradle | 4 ++-- app/proguard-rules.pro | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a543cb605..08427bff5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -99,8 +99,8 @@ android { } buildTypes { release { - minifyEnabled true - shrinkResources true + minifyEnabled false + shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "de.xikolo.utils.BuildType", "X_TYPE", "de.xikolo.utils.BuildType.RELEASE" debuggable false diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 294e06991..545d672fb 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -15,9 +15,11 @@ ##---------------Begin: proguard configuration for EventBus ---------- +-keepattributes *Annotation* -keepclassmembers class ** { - public void onEvent*(**); + @org.greenrobot.eventbus.Subscribe ; } +-keep enum org.greenrobot.eventbus.ThreadMode { *; } ##---------------Begin: proguard configuration for Gson ---------- @@ -49,3 +51,15 @@ ##---------------Begin: proguard configuration for CastCompanionLibrary ---------- -keep class android.support.v7.** { *; } + + +##---------------Begin: proguard configuration for OkHttp3 ---------- + +-keepattributes InnerClasses +-keepattributes Annotation +-keep class okhttp3.** { *; } +-keep interface okhttp3.** { *; } +-dontwarn okhttp3.** +-keep class okio.** { *; } +-keep interface okio.** { *; } +-dontwarn okio.** \ No newline at end of file From d1b16941a67391ed841f261c3c19688ffd9559ca Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Fri, 21 Oct 2016 12:15:07 +0200 Subject: [PATCH 08/15] Upgrade to Android 7.1 (API level 25). --- .travis.yml | 4 ++-- app/build.gradle | 8 ++++---- build.gradle | 2 +- lanalytics/build.gradle | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index fdb5f9d85..c10df113d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ android: components: - platform-tools - tools - - build-tools-24.0.3 - - android-24 + - build-tools-25.0.0 + - android-25 - extra-android-m2repository - extra-google-m2repository diff --git a/app/build.gradle b/app/build.gradle index 08427bff5..c1723ebfc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' android { - compileSdkVersion 24 - buildToolsVersion "24.0.3" + compileSdkVersion 25 + buildToolsVersion "25.0.0" defaultConfig { minSdkVersion 15 - targetSdkVersion 24 + targetSdkVersion 25 versionName "1.5.1" versionCode 26 } @@ -162,7 +162,7 @@ dependencies { compile 'com.google.android.libraries.cast.companionlibrary:ccl:2.8.4' compile 'com.google.android.gms:play-services-cast:9.6.1' - def supportVersion = '24.2.1' + def supportVersion = '25.0.0' compile "com.android.support:support-v4:${supportVersion}" compile "com.android.support:appcompat-v7:${supportVersion}" diff --git a/build.gradle b/build.gradle index a27dee12e..951d2d9c5 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.1' + classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } } diff --git a/lanalytics/build.gradle b/lanalytics/build.gradle index fa749ba53..0a49bd3b8 100644 --- a/lanalytics/build.gradle +++ b/lanalytics/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 24 - buildToolsVersion "24.0.3" + compileSdkVersion 25 + buildToolsVersion "25.0.0" defaultConfig { minSdkVersion 15 - targetSdkVersion 24 + targetSdkVersion 25 versionCode 1 versionName "1.0" } From 7cf246dcd8a1896c53eb535365f1f38daf65eb68 Mon Sep 17 00:00:00 2001 From: Tobias Rohloff Date: Fri, 21 Oct 2016 12:34:33 +0200 Subject: [PATCH 09/15] Update PdfReader library to v2. --- app/build.gradle | 2 +- .../secondscreen/SlideViewerFragment.java | 23 ++++++++----------- .../main/res/layout/fragment_slide_viewer.xml | 14 +---------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c1723ebfc..aa24447f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -156,7 +156,7 @@ dependencies { compile 'org.greenrobot:eventbus:3.0.0' compile 'org.java-websocket:Java-WebSocket:1.3.0' - compile 'com.github.barteksc:android-pdf-viewer:1.4.0' + compile 'com.github.barteksc:android-pdf-viewer:2.1.0' compile 'com.google.code.gson:gson:2.7' compile 'com.google.android.libraries.cast.companionlibrary:ccl:2.8.4' diff --git a/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java index b72ad6a18..3840cf837 100644 --- a/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java +++ b/app/src/main/java/de/xikolo/controllers/secondscreen/SlideViewerFragment.java @@ -13,9 +13,9 @@ import android.widget.TextView; import com.github.barteksc.pdfviewer.PDFView; -import com.github.barteksc.pdfviewer.ScrollBar; import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener; import com.github.barteksc.pdfviewer.listener.OnPageChangeListener; +import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -27,13 +27,13 @@ import de.xikolo.R; import de.xikolo.controllers.dialogs.DownloadSlidesDialog; import de.xikolo.controllers.dialogs.ProgressDialog; +import de.xikolo.events.DownloadCompletedEvent; import de.xikolo.managers.DownloadManager; +import de.xikolo.managers.SecondScreenManager; import de.xikolo.models.Course; import de.xikolo.models.Item; import de.xikolo.models.Module; import de.xikolo.models.VideoItemDetail; -import de.xikolo.managers.SecondScreenManager; -import de.xikolo.events.DownloadCompletedEvent; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class SlideViewerFragment extends Fragment implements OnLoadCompleteListener, OnPageChangeListener { @@ -88,7 +88,7 @@ public void onCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { currentPage = savedInstanceState.getInt(KEY_CURRENT_PAGE); } else { - currentPage = 0; + currentPage = -1; } downloadManager = new DownloadManager(GlobalApplication.getInstance().getJobManager(), getActivity()); @@ -108,15 +108,12 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { pdfView = (PDFView) view.findViewById(R.id.pdf_view); - ScrollBar scrollBar = (ScrollBar) view.findViewById(R.id.scroll_bar); - pdfView.setScrollBar(scrollBar); - fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fab.hide(); textCurrentPage.setVisibility(View.GONE); - if (currentPage > 0) { + if (currentPage >= 0) { pdfView.jumpTo(currentPage); } } @@ -147,17 +144,17 @@ private void initSlidesViewer() { if (downloadManager != null && downloadManager.downloadExists(DownloadManager.DownloadFileType.SLIDES, course, module, item)) { File file = downloadManager.getDownloadFile(DownloadManager.DownloadFileType.SLIDES, course, module, item); pdfView.fromFile(file) - .swipeVertical(true) .enableAnnotationRendering(true) .onLoad(this) .onPageChange(this) + .scrollHandle(new DefaultScrollHandle(getActivity())) .load(); } } @Override public void onPageChanged(int page, int pageCount) { - if (currentPage > 0 && page != currentPage) { + if (currentPage >= 0 && page != currentPage) { fab.show(); textCurrentPage.setVisibility(View.VISIBLE); } @@ -165,7 +162,7 @@ public void onPageChanged(int page, int pageCount) { @Override public void loadComplete(int nbPages) { - if (currentPage > 0) { + if (currentPage >= 0) { pdfView.jumpTo(currentPage); if (fab != null) { fab.hide(); @@ -202,9 +199,9 @@ public void onSecondScreenUpdateVideoEvent(SecondScreenManager.SecondScreenUpdat try { int page = Integer.parseInt(event.getWebSocketMessage().payload().get("slide_number")); if (pdfView != null) { - currentPage = page + 1; + currentPage = page; if (currentPage != pdfView.getCurrentPage() && fab != null && !fab.isShown()) { - textCurrentPage.setText(String.format(getString(R.string.second_screen_pdf_pager), currentPage)); + textCurrentPage.setText(String.format(getString(R.string.second_screen_pdf_pager), currentPage + 1)); pdfView.jumpTo(currentPage); } } diff --git a/app/src/main/res/layout/fragment_slide_viewer.xml b/app/src/main/res/layout/fragment_slide_viewer.xml index d70452438..ea96c3463 100644 --- a/app/src/main/res/layout/fragment_slide_viewer.xml +++ b/app/src/main/res/layout/fragment_slide_viewer.xml @@ -6,19 +6,7 @@ - - + android:layout_height="match_parent" /> Date: Fri, 21 Oct 2016 17:46:45 +0200 Subject: [PATCH 10/15] Migrate from CCL to Cast SDK v3. --- app/build.gradle | 11 +- app/src/main/AndroidManifest.xml | 22 +- .../java/de/xikolo/GlobalApplication.java | 43 ++-- .../de/xikolo/controllers/BaseActivity.java | 91 ++++---- .../de/xikolo/controllers/BaseFragment.java | 8 +- .../de/xikolo/controllers/CastActivity.java | 48 +++++ .../de/xikolo/controllers/VideoActivity.java | 63 +++--- .../controllers/module/VideoFragment.java | 6 +- .../de/xikolo/utils/CastOptionsProvider.java | 41 ++++ .../main/java/de/xikolo/utils/CastUtil.java | 67 +++++- .../main/res/layout-land/cast_activity.xml | 199 ------------------ .../res/layout/activity_blank_no_scroll.xml | 3 +- app/src/main/res/layout/ccl_intro_overlay.xml | 58 ----- .../res/layout/container_mini_controller.xml | 9 +- app/src/main/res/values/intro_overlay.xml | 68 ------ app/src/main/res/values/themes.xml | 13 ++ 16 files changed, 299 insertions(+), 451 deletions(-) create mode 100644 app/src/main/java/de/xikolo/controllers/CastActivity.java create mode 100644 app/src/main/java/de/xikolo/utils/CastOptionsProvider.java delete mode 100644 app/src/main/res/layout-land/cast_activity.xml delete mode 100644 app/src/main/res/layout/ccl_intro_overlay.xml delete mode 100644 app/src/main/res/values/intro_overlay.xml diff --git a/app/build.gradle b/app/build.gradle index aa24447f1..984a00317 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -159,8 +159,7 @@ dependencies { compile 'com.github.barteksc:android-pdf-viewer:2.1.0' compile 'com.google.code.gson:gson:2.7' - compile 'com.google.android.libraries.cast.companionlibrary:ccl:2.8.4' - compile 'com.google.android.gms:play-services-cast:9.6.1' + compile 'com.google.android.gms:play-services-cast-framework:9.6.1' def supportVersion = '25.0.0' @@ -174,10 +173,10 @@ dependencies { apt 'com.google.auto.value:auto-value:1.3' provided 'com.google.auto.value:auto-value:1.3' - apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.4-rc2' - provided 'com.ryanharter.auto.value:auto-value-parcel:0.2.4-rc2' - apt 'com.ryanharter.auto.value:auto-value-gson:0.4.2' - provided 'com.ryanharter.auto.value:auto-value-gson:0.4.2' + apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.5' + provided 'com.ryanharter.auto.value:auto-value-parcel:0.2.5' + apt 'com.ryanharter.auto.value:auto-value-gson:0.4.3' + provided 'com.ryanharter.auto.value:auto-value-gson:0.4.3' compile project(":lanalytics") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f25823d77..508cc04e8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,9 +29,14 @@ android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> - + + @@ -214,26 +219,19 @@ - - + - - - - - - diff --git a/app/src/main/java/de/xikolo/GlobalApplication.java b/app/src/main/java/de/xikolo/GlobalApplication.java index 65b0abd1f..b9fa7a6d4 100644 --- a/app/src/main/java/de/xikolo/GlobalApplication.java +++ b/app/src/main/java/de/xikolo/GlobalApplication.java @@ -11,8 +11,8 @@ import com.birbit.android.jobqueue.JobManager; import com.birbit.android.jobqueue.config.Configuration; import com.birbit.android.jobqueue.log.CustomLogger; -import com.google.android.libraries.cast.companionlibrary.cast.CastConfiguration; -import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; +import com.google.android.gms.cast.framework.CastContext; +import com.google.android.gms.cast.framework.CastStateListener; import de.xikolo.lanalytics.Lanalytics; import de.xikolo.managers.SecondScreenManager; @@ -46,6 +46,8 @@ public class GlobalApplication extends Application { private SecondScreenManager secondScreenManager; + private int castState; + public GlobalApplication() { instance = this; } @@ -106,6 +108,10 @@ public String getClientId() { return ClientUtil.id(this); } + public int getCastState() { + return castState; + } + @Override public void onCreate() { super.onCreate(); @@ -113,8 +119,7 @@ public void onCreate() { configureDefaultSettings(); configureWebView(); configureJobManager(); - configureVideoCastManager(); - + configureCastListener(); configureSecondScreenManager(); // just for debugging, never use for production @@ -149,17 +154,17 @@ private void configureJobManager() { @Override public boolean isDebugEnabled() { - return Config.DEBUG; + return false; } @Override public void v(String text, Object... args) { - if (Config.DEBUG) Log.v(TAG, String.format(text, args)); +// if (Config.DEBUG) Log.v(TAG, String.format(text, args)); } @Override public void d(String text, Object... args) { - if (Config.DEBUG) Log.d(TAG, String.format(text, args)); +// if (Config.DEBUG) Log.d(TAG, String.format(text, args)); } @Override @@ -180,6 +185,16 @@ public void e(String text, Object... args) { jobManager = new JobManager(configuration); } + private void configureCastListener() { + final CastContext castContext = CastContext.getSharedInstance(this); + castContext.addCastStateListener(new CastStateListener() { + @Override + public void onCastStateChanged(int newState) { + castState = newState; + } + }); + } + @SuppressWarnings("deprecation") public void startCookieSyncManager() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { @@ -203,20 +218,6 @@ public void syncCookieSyncManager() { } } - private void configureVideoCastManager() { - CastConfiguration options = new CastConfiguration.Builder(Config.CAST_MEDIA_RECEIVER_APPLICATION_ID) - .enableAutoReconnect() - .enableLockScreen() - .enableWifiReconnection() - .enableNotification() - .setNextPrevVisibilityPolicy(CastConfiguration.NEXT_PREV_VISIBILITY_POLICY_HIDDEN) - .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true) - .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true) - .setCastControllerImmersive(false) - .build(); - VideoCastManager.initialize(this, options); - } - public void configureSecondScreenManager() { if (FeatureToggle.secondScreen()) { synchronized (GlobalApplication.class) { diff --git a/app/src/main/java/de/xikolo/controllers/BaseActivity.java b/app/src/main/java/de/xikolo/controllers/BaseActivity.java index 2f1877e13..a2e679536 100644 --- a/app/src/main/java/de/xikolo/controllers/BaseActivity.java +++ b/app/src/main/java/de/xikolo/controllers/BaseActivity.java @@ -13,13 +13,16 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import com.birbit.android.jobqueue.JobManager; -import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; -import com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl; -import com.google.android.libraries.cast.companionlibrary.widgets.IntroductoryOverlay; +import com.google.android.gms.cast.framework.CastButtonFactory; +import com.google.android.gms.cast.framework.CastContext; +import com.google.android.gms.cast.framework.CastState; +import com.google.android.gms.cast.framework.CastStateListener; +import com.google.android.gms.cast.framework.IntroductoryOverlay; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -37,7 +40,7 @@ import de.xikolo.utils.FeatureToggle; import de.xikolo.utils.PlayServicesUtil; -public abstract class BaseActivity extends AppCompatActivity { +public abstract class BaseActivity extends AppCompatActivity implements CastStateListener { protected GlobalApplication globalApplication; @@ -49,7 +52,7 @@ public abstract class BaseActivity extends AppCompatActivity { protected AppBarLayout appBar; - protected VideoCastManager videoCastManager; + protected CastContext castContext; private DrawerLayout drawerLayout; @@ -72,17 +75,7 @@ protected void onCreate(Bundle savedInstanceState) { PlayServicesUtil.checkPlayServices(this); - videoCastManager = VideoCastManager.getInstance(); - - VideoCastConsumerImpl castConsumer = new VideoCastConsumerImpl() { - @Override - public void onCastAvailabilityChanged(boolean castPresent) { - if (castPresent) { - showOverlay(); - } - } - }; - videoCastManager.addVideoCastConsumer(castConsumer); + castContext = CastContext.getSharedInstance(this); if (overlay == null) { showOverlay(); @@ -95,25 +88,33 @@ private void showOverlay() { if (overlay != null) { overlay.remove(); } - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (mediaRouteMenuItem != null && mediaRouteMenuItem.isVisible()) { - overlay = new IntroductoryOverlay.Builder(BaseActivity.this) - .setMenuItem(mediaRouteMenuItem) - .setTitleText(R.string.intro_overlay_text) - .setSingleTime() - .setOnDismissed(new IntroductoryOverlay.OnOverlayDismissedListener() { - @Override - public void onOverlayDismissed() { - overlay = null; - } - }) - .build(); - overlay.show(); + if ((mediaRouteMenuItem != null) && mediaRouteMenuItem.isVisible()) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (mediaRouteMenuItem != null && mediaRouteMenuItem.isVisible()) { + overlay = new IntroductoryOverlay.Builder(BaseActivity.this, mediaRouteMenuItem) + .setTitleText(R.string.intro_overlay_text) + .setSingleTime() + .setOnOverlayDismissedListener(new IntroductoryOverlay.OnOverlayDismissedListener() { + @Override + public void onOverlayDismissed() { + overlay = null; + } + }) + .build(); + overlay.show(); + } } - } - }, 1000); + }, 1000); + } + } + + @Override + public void onCastStateChanged(int newState) { + if (newState != CastState.NO_DEVICES_AVAILABLE) { + showOverlay(); + } } protected void setupActionBar() { @@ -190,6 +191,8 @@ protected void onStart() { EventBus.getDefault().register(this); + castContext.addCastStateListener(this); + if (UserManager.isLoggedIn() && FeatureToggle.secondScreen()) { globalApplication.getWebSocketManager().initConnection(UserManager.getToken()); } @@ -200,8 +203,6 @@ protected void onResume() { super.onResume(); globalApplication.startCookieSyncManager(); - videoCastManager = VideoCastManager.getInstance(); - videoCastManager.incrementUiCounter(); } @Override @@ -210,7 +211,6 @@ protected void onPause() { globalApplication.syncCookieSyncManager(); globalApplication.stopCookieSyncManager(); - videoCastManager.decrementUiCounter(); } @Override @@ -218,6 +218,8 @@ protected void onStop() { super.onStop(); EventBus.getDefault().unregister(this); + + castContext.removeCastStateListener(this); } @Override @@ -244,9 +246,13 @@ protected void enableCastMediaRouterButton(boolean enable) { @Override public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.cast, menu); - mediaRouteMenuItem = videoCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item); - return super.onCreateOptionsMenu(menu); + mediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton( + getApplicationContext(), + menu, + R.id.media_route_menu_item); + return true; } @Override @@ -267,4 +273,11 @@ private void handleIntent(Intent intent) { } } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + return CastContext.getSharedInstance(this) + .onDispatchVolumeKeyEventBeforeJellyBean(event) + || super.dispatchKeyEvent(event); + } + } diff --git a/app/src/main/java/de/xikolo/controllers/BaseFragment.java b/app/src/main/java/de/xikolo/controllers/BaseFragment.java index f31657d6f..2ed92251c 100644 --- a/app/src/main/java/de/xikolo/controllers/BaseFragment.java +++ b/app/src/main/java/de/xikolo/controllers/BaseFragment.java @@ -4,7 +4,7 @@ import android.support.v4.app.Fragment; import com.birbit.android.jobqueue.JobManager; -import com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager; +import com.google.android.gms.cast.framework.CastContext; import de.xikolo.GlobalApplication; @@ -14,7 +14,7 @@ public abstract class BaseFragment extends Fragment { protected JobManager jobManager; - protected VideoCastManager videoCastManager; + protected CastContext castContext; @Override public void onCreate(Bundle savedInstanceState) { @@ -23,13 +23,13 @@ public void onCreate(Bundle savedInstanceState) { globalApplication = GlobalApplication.getInstance(); jobManager = globalApplication.getJobManager(); - videoCastManager = VideoCastManager.getInstance(); + castContext = CastContext.getSharedInstance(getActivity()); } @Override public void onResume() { super.onResume(); - videoCastManager = VideoCastManager.getInstance(); + castContext = CastContext.getSharedInstance(getActivity()); } } diff --git a/app/src/main/java/de/xikolo/controllers/CastActivity.java b/app/src/main/java/de/xikolo/controllers/CastActivity.java new file mode 100644 index 000000000..1ff714ef5 --- /dev/null +++ b/app/src/main/java/de/xikolo/controllers/CastActivity.java @@ -0,0 +1,48 @@ +package de.xikolo.controllers; + +import android.view.KeyEvent; +import android.view.Menu; +import android.view.View; + +import com.google.android.gms.cast.framework.CastButtonFactory; +import com.google.android.gms.cast.framework.CastContext; +import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity; + +import de.xikolo.R; + +public class CastActivity extends ExpandedControllerActivity { + + @Override + protected void onStart() { + super.onStart(); + + showSystemBars(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + getMenuInflater().inflate(R.menu.cast, menu); + CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item); + return true; + } + + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + return CastContext.getSharedInstance(this) + .onDispatchVolumeKeyEventBeforeJellyBean(event) + || super.dispatchKeyEvent(event); + } + + private void showSystemBars() { + View decorView = getWindow().getDecorView(); + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + + @Override + public void onWindowFocusChanged(boolean b) { + super.onWindowFocusChanged(b); + + showSystemBars(); + } +} diff --git a/app/src/main/java/de/xikolo/controllers/VideoActivity.java b/app/src/main/java/de/xikolo/controllers/VideoActivity.java index 83336fa1e..71831fb7a 100644 --- a/app/src/main/java/de/xikolo/controllers/VideoActivity.java +++ b/app/src/main/java/de/xikolo/controllers/VideoActivity.java @@ -16,21 +16,21 @@ import android.view.Window; import android.widget.TextView; -import com.google.android.gms.cast.ApplicationMetadata; -import com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl; +import com.google.android.gms.cast.framework.CastButtonFactory; +import com.google.android.gms.cast.framework.CastState; import de.xikolo.R; import de.xikolo.controllers.exceptions.WrongParameterException; import de.xikolo.controllers.helper.VideoController; import de.xikolo.managers.ItemManager; +import de.xikolo.managers.Result; import de.xikolo.models.Course; import de.xikolo.models.Item; import de.xikolo.models.Module; import de.xikolo.models.VideoItemDetail; -import de.xikolo.managers.Result; +import de.xikolo.utils.AndroidDimenUtil; import de.xikolo.utils.CastUtil; import de.xikolo.utils.LanalyticsUtil; -import de.xikolo.utils.AndroidDimenUtil; public class VideoActivity extends BaseActivity { @@ -124,38 +124,14 @@ public void onSystemUiVisibilityChange(int visibility) { mediaRouteButton = (MediaRouteButton) findViewById(R.id.video_media_route_button); if (mediaRouteButton != null) { - videoCastManager.addMediaRouterButton(mediaRouteButton); + CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton); Configuration config = getResources().getConfiguration(); - mediaRouteButton.setVisibility(videoCastManager.isAnyRouteAvailable() + + mediaRouteButton.setVisibility(CastUtil.isAvailable() && config.orientation == Configuration.ORIENTATION_LANDSCAPE ? View.VISIBLE : View.GONE); } - VideoCastConsumerImpl castConsumer = new VideoCastConsumerImpl() { - @Override - public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched) { - if (videoController != null) { - LanalyticsUtil.trackVideoPlay(item.id, course.id, module.id, item.detail.progress, 1.0f, - Configuration.ORIENTATION_LANDSCAPE, "hd", LanalyticsUtil.CONTEXT_CAST); - - videoController.pause(); - videoCastManager.startVideoCastControllerActivity(VideoActivity.this, CastUtil.buildCastMetadata(item), item.detail.progress, true); - finish(); - } - } - - @Override - public void onCastAvailabilityChanged(boolean castPresent) { - if (mediaRouteButton != null) { - Configuration config = getResources().getConfiguration(); - mediaRouteButton.setVisibility(castPresent - && config.orientation == Configuration.ORIENTATION_LANDSCAPE - ? View.VISIBLE : View.GONE); - } - } - }; - videoCastManager.addVideoCastConsumer(castConsumer); - hideSystemBars(); updateVideoView(getResources().getConfiguration().orientation); @@ -171,6 +147,29 @@ public void onCastAvailabilityChanged(boolean castPresent) { videoController.getSourceString()); } + @Override + public void onCastStateChanged(int newState) { + super.onCastStateChanged(newState); + + if (newState != CastState.NO_DEVICES_AVAILABLE) { + if (mediaRouteButton != null) { + Configuration config = getResources().getConfiguration(); + mediaRouteButton.setVisibility(config.orientation == Configuration.ORIENTATION_LANDSCAPE + ? View.VISIBLE : View.GONE); + } + } + + if (newState == CastState.CONNECTED && videoController != null) { + LanalyticsUtil.trackVideoPlay(item.id, course.id, module.id, item.detail.progress, 1.0f, + Configuration.ORIENTATION_LANDSCAPE, "hd", LanalyticsUtil.CONTEXT_CAST); + + videoController.pause(); + CastUtil.loadMedia(this, item, true, item.detail.progress); + + finish(); + } + } + private void updateVideoView(int orientation) { View layout = findViewById(R.id.container); if (Build.VERSION.SDK_INT >= 17 && layout != null) { @@ -180,7 +179,7 @@ private void updateVideoView(int orientation) { actionBar.hide(); if (mediaRouteButton != null) { - mediaRouteButton.setVisibility(videoCastManager.isAnyRouteAvailable() + mediaRouteButton.setVisibility(CastUtil.isAvailable() ? View.VISIBLE : View.GONE); } diff --git a/app/src/main/java/de/xikolo/controllers/module/VideoFragment.java b/app/src/main/java/de/xikolo/controllers/module/VideoFragment.java index ab2b7cd1e..265d53fee 100644 --- a/app/src/main/java/de/xikolo/controllers/module/VideoFragment.java +++ b/app/src/main/java/de/xikolo/controllers/module/VideoFragment.java @@ -206,7 +206,7 @@ private void setupView() { viewPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (videoCastManager.isConnected()) { + if (CastUtil.isConnected()) { itemManager.getLocalVideoProgress(new Result() { @Override protected void onSuccess(VideoItemDetail result, DataSource dataSource) { @@ -215,7 +215,7 @@ protected void onSuccess(VideoItemDetail result, DataSource dataSource) { item.detail = result; setCurrentCourse(); - videoCastManager.startVideoCastControllerActivity(getActivity(), CastUtil.buildCastMetadata(item), result.progress, true); + CastUtil.loadMedia(getActivity(), item, true, result.progress); } @Override @@ -224,7 +224,7 @@ protected void onError(ErrorCode errorCode) { Configuration.ORIENTATION_LANDSCAPE, "hd", LanalyticsUtil.CONTEXT_CAST); setCurrentCourse(); - videoCastManager.startVideoCastControllerActivity(getActivity(), CastUtil.buildCastMetadata(item), 0, true); + CastUtil.loadMedia(getActivity(), item, true, 0); } }, item.detail); } else { diff --git a/app/src/main/java/de/xikolo/utils/CastOptionsProvider.java b/app/src/main/java/de/xikolo/utils/CastOptionsProvider.java new file mode 100644 index 000000000..d347792d0 --- /dev/null +++ b/app/src/main/java/de/xikolo/utils/CastOptionsProvider.java @@ -0,0 +1,41 @@ +package de.xikolo.utils; + +import android.content.Context; + +import com.google.android.gms.cast.framework.CastOptions; +import com.google.android.gms.cast.framework.OptionsProvider; +import com.google.android.gms.cast.framework.SessionProvider; +import com.google.android.gms.cast.framework.media.CastMediaOptions; +import com.google.android.gms.cast.framework.media.NotificationOptions; + +import java.util.List; + +import de.xikolo.controllers.CastActivity; + +class CastOptionsProvider implements OptionsProvider { + + @Override + public CastOptions getCastOptions(Context appContext) { + NotificationOptions notificationOptions = new NotificationOptions.Builder() + .setTargetActivityClassName(CastActivity.class.getName()) + .build(); + + CastMediaOptions mediaOptions = new CastMediaOptions.Builder() + .setNotificationOptions(notificationOptions) + .setExpandedControllerActivityClassName(CastActivity.class.getName()) + .build(); + + CastOptions castOptions = new CastOptions.Builder() + .setReceiverApplicationId(Config.CAST_MEDIA_RECEIVER_APPLICATION_ID) + .setCastMediaOptions(mediaOptions) + .build(); + + return castOptions; + } + + @Override + public List getAdditionalSessionProviders(Context context) { + return null; + } + +} diff --git a/app/src/main/java/de/xikolo/utils/CastUtil.java b/app/src/main/java/de/xikolo/utils/CastUtil.java index 0c2ba5911..619e777f0 100644 --- a/app/src/main/java/de/xikolo/utils/CastUtil.java +++ b/app/src/main/java/de/xikolo/utils/CastUtil.java @@ -1,16 +1,36 @@ package de.xikolo.utils; +import android.app.Activity; +import android.content.Intent; import android.net.Uri; import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaMetadata; +import com.google.android.gms.cast.framework.CastContext; +import com.google.android.gms.cast.framework.CastSession; +import com.google.android.gms.cast.framework.CastState; +import com.google.android.gms.cast.framework.SessionManager; +import com.google.android.gms.cast.framework.media.RemoteMediaClient; import com.google.android.gms.common.images.WebImage; +import de.xikolo.GlobalApplication; +import de.xikolo.controllers.CastActivity; import de.xikolo.models.Item; import de.xikolo.models.VideoItemDetail; public class CastUtil { + public static boolean isConnected() { + CastContext castContext = CastContext.getSharedInstance(GlobalApplication.getInstance()); + SessionManager sessionManager = castContext.getSessionManager(); + + return sessionManager.getCurrentCastSession() != null && sessionManager.getCurrentCastSession().isConnected(); + } + + public static boolean isAvailable() { + return GlobalApplication.getInstance().getCastState() != CastState.NO_DEVICES_AVAILABLE; + } + public static MediaInfo buildCastMetadata(Item video) { MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); mediaMetadata.putString(MediaMetadata.KEY_TITLE, video.title); @@ -23,12 +43,53 @@ public static MediaInfo buildCastMetadata(Item video) { // large image, used on the Cast Player page and Lock Screen on KitKat mediaMetadata.addImage(image); - return new MediaInfo.Builder( - video.detail.stream.hd_url) - .setContentType("video/mp4") + return new MediaInfo.Builder(video.detail.stream.hd_url) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) + .setContentType("videos/mp4") .setMetadata(mediaMetadata) .build(); } + public static void loadMedia(final Activity activity, Item video, boolean autoPlay, int position) { + CastContext castContext = CastContext.getSharedInstance(GlobalApplication.getInstance()); + SessionManager sessionManager = castContext.getSessionManager(); + CastSession session = sessionManager.getCurrentCastSession(); + + if (session != null) { + final RemoteMediaClient remoteMediaClient = session.getRemoteMediaClient(); + + remoteMediaClient.addListener(new RemoteMediaClient.Listener() { + @Override + public void onStatusUpdated() { + Intent intent = new Intent(activity, CastActivity.class); + activity.startActivity(intent); + remoteMediaClient.removeListener(this); + } + + @Override + public void onMetadataUpdated() { + + } + + @Override + public void onQueueStatusUpdated() { + + } + + @Override + public void onPreloadStatusUpdated() { + + } + + @Override + public void onSendingRemoteMediaRequest() { + + } + }); + + remoteMediaClient.load(buildCastMetadata(video), autoPlay, position); + } + } + + } diff --git a/app/src/main/res/layout-land/cast_activity.xml b/app/src/main/res/layout-land/cast_activity.xml deleted file mode 100644 index 0769d1820..000000000 --- a/app/src/main/res/layout-land/cast_activity.xml +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_blank_no_scroll.xml b/app/src/main/res/layout/activity_blank_no_scroll.xml index 8ec5a8023..e2110a66f 100644 --- a/app/src/main/res/layout/activity_blank_no_scroll.xml +++ b/app/src/main/res/layout/activity_blank_no_scroll.xml @@ -10,7 +10,8 @@ diff --git a/app/src/main/res/layout/ccl_intro_overlay.xml b/app/src/main/res/layout/ccl_intro_overlay.xml deleted file mode 100644 index 4c4f506d3..000000000 --- a/app/src/main/res/layout/ccl_intro_overlay.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - -