Skip to content

Commit

Permalink
Merge pull request #41 from StepicOrg/release/1.8
Browse files Browse the repository at this point in the history
Release/1.8
  • Loading branch information
KirillMakarov committed May 21, 2016
2 parents aab49ca + 4da70a8 commit fd3c4f2
Show file tree
Hide file tree
Showing 79 changed files with 1,351 additions and 735 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "org.stepic.droid"
minSdkVersion 14
targetSdkVersion 23
versionCode 50
versionName "1.7"
versionCode 53
versionName "1.8.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
Expand Down Expand Up @@ -113,7 +113,7 @@ dependencies {

compile 'uk.co.chrisjenx:calligraphy:2.1.0'

compile 'me.zhanghai.android.materialprogressbar:library:1.1.4'
compile 'me.zhanghai.android.materialprogressbar:library:1.1.6'

// Required -- JUnit 4 framework
testCompile 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.stepic.droid.store.operations.DatabaseFacade;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.util.JsonHelper;
import org.stepic.droid.util.KotlinUtil;
import org.stepic.droid.util.ProgressHelper;
import org.stepic.droid.view.fragments.CourseListFragmentBase;
import org.stepic.droid.web.CoursesStepicResponse;
Expand Down Expand Up @@ -67,6 +68,7 @@ protected void showCourses(List<Course> cachedCourses) {
}

mCourses.clear();
cachedCourses = KotlinUtil.INSTANCE.filterIfNotUnique(cachedCourses);
if (getCourseType() == DatabaseFacade.Table.enrolled) {
for (Course course : cachedCourses) {
if (course.getEnrollment() != 0)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/stepic/droid/base/FragmentBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.stepic.droid.core.IShell;
import org.stepic.droid.preferences.SharedPreferenceHelper;
import org.stepic.droid.preferences.UserPreferences;
import org.stepic.droid.services.CancelLoadingService;
import org.stepic.droid.store.ICancelSniffer;
import org.stepic.droid.store.IDownloadManager;
import org.stepic.droid.store.operations.DatabaseFacade;
import org.stepic.droid.util.resolvers.CoursePropertyResolver;
Expand Down Expand Up @@ -86,6 +88,9 @@ public class FragmentBase extends Fragment {
@Inject
public DownloadManager mSystemDownloadManager;

@Inject
public ICancelSniffer cancelSniffer;

public FragmentBase() {
MainApplication.component(MainApplication.getAppContext()).inject(this);
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/org/stepic/droid/concurrency/DownloadPoster.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.stepic.droid.concurrency

import com.squareup.otto.Bus

import org.stepic.droid.base.MainApplication
import org.stepic.droid.events.video.DownloadReportEvent
import org.stepic.droid.model.DownloadingVideoItem

import javax.inject.Inject

class DownloadPoster(private val downloadingVideoItem: DownloadingVideoItem) : Function0<Unit> {

@Inject
lateinit var bus: Bus

init {
MainApplication.component().inject(this)
}

override fun invoke(): Unit {
bus.post(DownloadReportEvent(downloadingVideoItem))
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/org/stepic/droid/core/IScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public interface IScreenManager {

void showDownload();

void showDownload(Context context);

void showVideo(Activity sourceActivity, String source);

void showSettings(Activity sourceActivity);
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/org/stepic/droid/core/ScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,33 +137,37 @@ public void showStoreWithApp(@NotNull Activity sourceActivity) {

@Override
public void showDownload() {
Intent intent = new Intent(MainApplication.getAppContext(), MainFeedActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Context context = MainApplication.getAppContext();
showDownload(context);
}

@Override
public void showDownload(Context context) {
Intent intent = new Intent(context, MainFeedActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Bundle bundle = new Bundle();
int index = MainFeedActivity.getDownloadFragmentIndex();
bundle.putInt(MainFeedActivity.KEY_CURRENT_INDEX, index);
intent.putExtras(bundle);
MainApplication.getAppContext().startActivity(intent);
context.startActivity(intent);
}

@Override
public void showVideo(Activity sourceActivity, String videoPath) {
YandexMetrica.reportEvent("video is tried to show");
boolean isOpenExternal = mUserPreferences.isOpenInExternal();
if (isOpenExternal){
boolean isOpenExternal = mUserPreferences.isOpenInExternal();
if (isOpenExternal) {
YandexMetrica.reportEvent("video open external");
}
else{
} else {
YandexMetrica.reportEvent("video open native");
}

boolean isCompatible = VLCUtil.hasCompatibleCPU(MainApplication.getAppContext());
if (!isCompatible){
if (!isCompatible) {
YandexMetrica.reportEvent("video is not compatible");
}



if (isCompatible && !isOpenExternal) {
Intent intent = new Intent(MainApplication.getAppContext(), VideoActivity.class);
intent.putExtra(VideoActivity.Companion.getVideoPathKey(), videoPath);
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/org/stepic/droid/core/StepicCoreComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.stepic.droid.base.FragmentActivityBase;
import org.stepic.droid.base.FragmentBase;
import org.stepic.droid.concurrency.DownloadPoster;
import org.stepic.droid.concurrency.tasks.FromDbCoursesTask;
import org.stepic.droid.concurrency.tasks.FromDbSectionTask;
import org.stepic.droid.concurrency.tasks.FromDbStepTask;
Expand Down Expand Up @@ -34,12 +35,11 @@
import org.stepic.droid.view.adapters.StepFragmentAdapter;
import org.stepic.droid.view.adapters.UnitAdapter;
import org.stepic.droid.view.dialogs.AllowMobileDataDialogFragment;
import org.stepic.droid.view.dialogs.ClearCacheDialogFragment;
import org.stepic.droid.view.dialogs.ClearVideosDialog;
import org.stepic.droid.view.dialogs.LogoutAreYouSureDialog;
import org.stepic.droid.view.dialogs.NeedUpdatingDialog;
import org.stepic.droid.view.dialogs.RemindPasswordDialogFragment;
import org.stepic.droid.view.dialogs.VideoQualityDialog;
import org.stepic.droid.view.fragments.DownloadsFragment;
import org.stepic.droid.web.RetrofitRESTApi;

import javax.inject.Singleton;
Expand Down Expand Up @@ -69,8 +69,6 @@ public interface StepicCoreComponent {

void inject(StepFragmentAdapter adapter);

void inject(ClearCacheDialogFragment dialogFragment);

void inject(LogoutAreYouSureDialog dialogFragment);

void inject(VideoQualityDialog dialogFragment);
Expand Down Expand Up @@ -112,7 +110,7 @@ public interface StepicCoreComponent {

void inject(DownloadsAdapter downloadsAdapter);

void inject(DownloadsFragment.ClearVideosDialog clearVideosDialog);
void inject(ClearVideosDialog clearVideosDialog);

void inject(CoursePropertyAdapter coursePropertyAdapter);

Expand All @@ -137,4 +135,8 @@ public interface StepicCoreComponent {
void inject(NeedUpdatingDialog needUpdatingDialog);

void inject(UpdateWithApkService service);

void inject(DownloadPoster downloadPoster);

void inject(DownloadsAdapter.CancelVideoDialog cancelVideoDialog);
}
35 changes: 21 additions & 14 deletions app/src/main/java/org/stepic/droid/core/StepicDefaultModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.DownloadManager;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.squareup.otto.Bus;
Expand All @@ -27,13 +28,13 @@
import org.stepic.droid.preferences.UserPreferences;
import org.stepic.droid.social.SocialManager;
import org.stepic.droid.store.CleanManager;
import org.stepic.droid.store.ConcurrentCancelSniffer;
import org.stepic.droid.store.DatabaseHelper;
import org.stepic.droid.store.DownloadManagerImpl;
import org.stepic.droid.store.ICancelSniffer;
import org.stepic.droid.store.IDownloadManager;
import org.stepic.droid.store.IStoreStateManager;
import org.stepic.droid.store.StoreStateManager;
import org.stepic.droid.store.SynchronizedCancelSniffer;
import org.stepic.droid.store.dao.AssignmentDaoImpl;
import org.stepic.droid.store.dao.BlockDaoImpl;
import org.stepic.droid.store.dao.CourseDaoImpl;
Expand Down Expand Up @@ -213,73 +214,79 @@ public SQLiteOpenHelper provideSqlOpenHelper(Context context) {
return new DatabaseHelper(context);
}

@Singleton
@Provides
public SQLiteDatabase provideWritableDatabase(DatabaseHelper helper){
return helper.getWritableDatabase();
}

@Provides
public IDao<Section> provideSectionDao(SQLiteOpenHelper openHelper) {
public IDao<Section> provideSectionDao(SQLiteDatabase openHelper) {
return new SectionDaoImpl(openHelper);
}

@Provides
public IDao<Unit> provideUnitDao(SQLiteOpenHelper openHelper, IDao<Progress> progressDao) {
public IDao<Unit> provideUnitDao(SQLiteDatabase openHelper, IDao<Progress> progressDao) {
return new UnitDaoImpl(openHelper, progressDao);
}

@Provides
public IDao<Progress> provideProgressDao(SQLiteOpenHelper openHelper) {
public IDao<Progress> provideProgressDao(SQLiteDatabase openHelper) {
return new ProgressDaoImpl(openHelper);
}

@Provides
public IDao<Assignment> provideAssignmentDao(SQLiteOpenHelper openHelper) {
public IDao<Assignment> provideAssignmentDao(SQLiteDatabase openHelper) {
return new AssignmentDaoImpl(openHelper);
}

@Provides
public IDao<Lesson> provideLessonDao(SQLiteOpenHelper openHelper) {
public IDao<Lesson> provideLessonDao(SQLiteDatabase openHelper) {
return new LessonDaoImpl(openHelper);
}

@Provides
public IDao<ViewAssignment> provideViewAssignment(SQLiteOpenHelper openHelper) {
public IDao<ViewAssignment> provideViewAssignment(SQLiteDatabase openHelper) {
return new ViewAssignmentDaoImpl(openHelper);
}

@Provides
public IDao<DownloadEntity> provideDownloadEntity(SQLiteOpenHelper openHelper) {
public IDao<DownloadEntity> provideDownloadEntity(SQLiteDatabase openHelper) {
return new DownloadEntityDaoImpl(openHelper);
}

@Provides
public IDao<CachedVideo> provideCachedVideo(SQLiteOpenHelper openHelper) {
public IDao<CachedVideo> provideCachedVideo(SQLiteDatabase openHelper) {
return new PersistentVideoDaoImpl(openHelper);
}

@Provides
public IDao<BlockPersistentWrapper> provideBlockWrapper(SQLiteOpenHelper openHelper, IDao<CachedVideo> daoCached) {
public IDao<BlockPersistentWrapper> provideBlockWrapper(SQLiteDatabase openHelper, IDao<CachedVideo> daoCached) {
return new BlockDaoImpl(openHelper, daoCached);
}

@Provides
public IDao<Step> provideStep(SQLiteOpenHelper openHelper,
public IDao<Step> provideStep(SQLiteDatabase openHelper,
IDao<BlockPersistentWrapper> blockDao,
IDao<Assignment> assignmentDao,
IDao<Progress> progressDao) {
return new StepDaoImpl(openHelper, blockDao, assignmentDao, progressDao);
}

@Provides
public IDao<Course> provideCourse(SQLiteOpenHelper openHelper, IDao<CachedVideo> daoCached) {
public IDao<Course> provideCourse(SQLiteDatabase openHelper, IDao<CachedVideo> daoCached) {
return new CourseDaoImpl(openHelper, daoCached);
}

@Provides
public IDao<Notification> provideNotification(SQLiteOpenHelper openHelper) {
public IDao<Notification> provideNotification(SQLiteDatabase openHelper) {
return new NotificationDaoImpl(openHelper);
}

@Provides
@Singleton
public ICancelSniffer provideCancelSniffer() {
return new SynchronizedCancelSniffer();
return new ConcurrentCancelSniffer();
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.stepic.droid.events;

public class CancelAllVideosEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.stepic.droid.events;

public class DownloadingIsLoadedSuccessfullyEvent {
long downloadId;

public DownloadingIsLoadedSuccessfullyEvent(long downloadId) {
this.downloadId = downloadId;
}

public long getDownloadId() {
return downloadId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.stepic.droid.events.loading

class FinishDeletingLoadEvent
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.stepic.droid.events.loading

class StartDeletingLoadEvent
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.stepic.droid.model

data class DownloadReportItem(
val mBytesDownloaded: Int,
val mBytesTotal: Int,
val bytesDownloaded: Int,
val bytesTotal: Int,
val mColumnStatus: Int,
val mDownloadId: Int,
val mColumnReason: Int
Expand Down
Loading

0 comments on commit fd3c4f2

Please sign in to comment.