-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from StepicOrg/release/1.4
Release/1.4
- Loading branch information
Showing
29 changed files
with
437 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
# generated files | ||
bin/ | ||
gen/ | ||
captures/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/stepic/droid/receivers/DownloadClickReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.stepic.droid.receivers | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
|
||
import org.stepic.droid.base.MainApplication | ||
import org.stepic.droid.core.IScreenManager | ||
import javax.inject.Inject | ||
|
||
class DownloadClickReceiver : BroadcastReceiver() { | ||
|
||
@Inject | ||
lateinit var mScreenProvider : IScreenManager | ||
|
||
init { | ||
MainApplication.component().inject(this) | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) = mScreenProvider.showDownload() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/src/main/java/org/stepic/droid/services/CancelLoadingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.stepic.droid.services | ||
|
||
import android.app.DownloadManager | ||
import android.app.IntentService | ||
import android.app.Service | ||
import android.content.Intent | ||
import com.squareup.otto.Bus | ||
import org.stepic.droid.base.MainApplication | ||
import org.stepic.droid.model.Lesson | ||
import org.stepic.droid.model.Section | ||
import org.stepic.droid.preferences.UserPreferences | ||
import org.stepic.droid.store.ICancelSniffer | ||
import org.stepic.droid.store.IStoreStateManager | ||
import org.stepic.droid.store.operations.DatabaseFacade | ||
import org.stepic.droid.util.AppConstants | ||
import org.stepic.droid.util.RWLocks | ||
import javax.inject.Inject | ||
|
||
class CancelLoadingService : IntentService("cancel_loading") { | ||
|
||
@Inject | ||
lateinit var mSystemDownloadManager: DownloadManager | ||
@Inject | ||
lateinit var mUserPrefs: UserPreferences | ||
@Inject | ||
lateinit var mBus: Bus | ||
@Inject | ||
lateinit var mDb: DatabaseFacade | ||
@Inject | ||
lateinit var mStoreStateManager: IStoreStateManager | ||
@Inject | ||
lateinit var mCancelSniffer: ICancelSniffer | ||
|
||
|
||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { | ||
MainApplication.component().inject(this) | ||
super.onStartCommand(intent, flags, startId) | ||
return Service.START_REDELIVER_INTENT | ||
} | ||
|
||
override fun onHandleIntent(intent: Intent?) { | ||
val type = intent?.getSerializableExtra(AppConstants.KEY_LOAD_TYPE) as? LoadService.LoadTypeKey | ||
when (type) { | ||
LoadService.LoadTypeKey.Section -> { | ||
val section = intent?.getSerializableExtra(AppConstants.KEY_SECTION_BUNDLE) as? Section | ||
cancelSection(section) | ||
} | ||
LoadService.LoadTypeKey.UnitLesson -> { | ||
val lesson = intent?.getSerializableExtra(AppConstants.KEY_LESSON_BUNDLE) as? Lesson | ||
cancelUnitLesson(lesson) | ||
} | ||
LoadService.LoadTypeKey.Course -> { | ||
return | ||
} | ||
LoadService.LoadTypeKey.Step -> { | ||
return | ||
} | ||
} | ||
} | ||
|
||
private fun cancelUnitLesson(lesson: Lesson?) { | ||
lesson?.let { | ||
try { | ||
val lessonSteps = lesson.steps | ||
lessonSteps?.forEach { mCancelSniffer.addStepIdCancel(it)} | ||
|
||
RWLocks.DownloadLock.writeLock().lock() | ||
val steps = mDb.getStepsOfLesson(lesson.id) | ||
val downloads = mDb.getAllDownloadEntities() | ||
|
||
|
||
//todo: improve time of operation | ||
for (step in steps) { | ||
for (download in downloads) { | ||
if (step != null && download != null && download.stepId.equals(step.id)) { | ||
val numberOfRemoved = mSystemDownloadManager.remove(download.downloadId) | ||
if (numberOfRemoved > 0) { | ||
mCancelSniffer.removeStepIdCancel(step.id) | ||
mDb.deleteDownloadEntityByDownloadId(download.downloadId) | ||
mDb.deleteVideo(download.videoId) | ||
if (mDb.isStepCached(step)) { | ||
step.is_cached = false | ||
step.is_loading = false | ||
mDb.updateOnlyCachedLoadingStep(step) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
mStoreStateManager.updateUnitLessonAfterDeleting(lesson.id) | ||
} finally { | ||
RWLocks.DownloadLock.writeLock().unlock() | ||
} | ||
} | ||
} | ||
|
||
private fun cancelSection(section: Section?) { | ||
section?.let { | ||
|
||
} | ||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. | ||
} | ||
} |
Oops, something went wrong.