Skip to content

Commit

Permalink
Merge branch 'release/1.99'
Browse files Browse the repository at this point in the history
  • Loading branch information
eadm committed Oct 29, 2019
2 parents 85db27b + 7b93ec7 commit 38c7299
Show file tree
Hide file tree
Showing 137 changed files with 2,606 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ interface AmplitudeAnalytic {
const val SUBMISSION_MADE = "Submission made"
const val STEP_OPENED = "Step opened"

const val STEP_EDIT_OPENED = "Step edit opened"
const val STEP_EDIT_COMPLETED = "Step edit completed"

object Params {
const val TYPE = "type"
const val LANGUAGE = "language"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/stepic/droid/analytic/Analytic.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ interface Steps {
String SHOW_KEEP_ON_SCREEN = "steps_show_keep_on_screen";
String SHOW_KEEP_OFF_SCREEN = "steps_show_keep_off_screen";
String STEP_OPENED = "step_opened";
String STEP_EDIT_OPENED = "step_edit_opened";
String STEP_EDIT_COMPLETED = "step_edit_completed";

//(message = "remove it, when click_send_submission will collect enough data")
@Deprecated
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/stepic/droid/core/ScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
Expand All @@ -22,6 +23,7 @@
import org.stepik.android.model.Step;
import org.stepik.android.model.Tag;
import org.stepik.android.model.Unit;
import org.stepik.android.model.comments.DiscussionThread;
import org.stepik.android.model.user.Profile;
import org.stepik.android.view.course.routing.CourseScreenTab;
import org.stepik.android.view.routing.deeplink.BranchRoute;
Expand Down Expand Up @@ -52,14 +54,16 @@ public interface ScreenManager {

void showPdfInBrowserByGoogleDocs(Activity activity, String fullPath);

void openComments(Activity context, String discussionProxyId, long stepId, @Nullable Long discussionId, boolean needOpenForm);
void openComments(Activity context, @NonNull DiscussionThread discussionThread, @NonNull Step step, @Nullable Long discussionId, boolean needOpenForm);

void showSteps(Activity sourceActivity, @NotNull Unit unit, @NotNull Lesson lesson, @NotNull Section section);

void showSteps(Activity sourceActivity, @NotNull Unit unit, @NotNull Lesson lesson, @NotNull Section section, boolean backAnimation, boolean isAutoplayEnabled);

void openStepInWeb(Context context, Step step);

void openDiscussionInWeb(Context context, @NonNull Step step, @NonNull DiscussionThread discussionThread, long discussionId);

void openRemindPassword(AppCompatActivity context);

void showCourseDescription(Context context, long courseId);
Expand Down
27 changes: 19 additions & 8 deletions app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.provider.Settings;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.TaskStackBuilder;
import androidx.core.content.FileProvider;
Expand Down Expand Up @@ -64,6 +65,7 @@
import org.stepik.android.model.Tag;
import org.stepik.android.model.Unit;
import org.stepik.android.model.Video;
import org.stepik.android.model.comments.DiscussionThread;
import org.stepik.android.model.user.Profile;
import org.stepik.android.view.certificate.ui.activity.CertificatesActivity;
import org.stepik.android.view.comment.ui.activity.CommentsActivity;
Expand Down Expand Up @@ -560,14 +562,9 @@ public void showPdfInBrowserByGoogleDocs(Activity activity, String fullPath) {
}

@Override
public void openComments(Activity context, String discussionProxyId, long stepId, @Nullable Long discussionId, boolean needOpenForm) {
if (discussionProxyId == null) {
analytic.reportEvent(Analytic.Screens.OPEN_COMMENT_NOT_AVAILABLE);
Toast.makeText(context, R.string.comment_disabled, Toast.LENGTH_SHORT).show();
} else {
analytic.reportEvent(Analytic.Screens.OPEN_COMMENT);
context.startActivity(CommentsActivity.Companion.createIntent(context, stepId, discussionProxyId, discussionId, needOpenForm));
}
public void openComments(Activity context, @NonNull DiscussionThread discussionThread, @NonNull Step step, @Nullable Long discussionId, boolean needOpenForm) {
analytic.reportEvent(Analytic.Screens.OPEN_COMMENT);
context.startActivity(CommentsActivity.Companion.createIntent(context, step, discussionThread, discussionId, needOpenForm));
}

@Override
Expand All @@ -590,6 +587,20 @@ public void openStepInWeb(Context context, Step step) {
context.startActivity(intent);
}

@Override
public void openDiscussionInWeb(Context context, @NonNull Step step, @NonNull DiscussionThread discussionThread, long discussionId) {
String url =
config.getBaseUrl() +
"/lesson/" + step.getLesson() +
"/step/" + step.getPosition() +
"/?from_mobile_app=true" +
"&discussion=" + discussionId +
"&thread=" + discussionThread.getThread()
;
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
context.startActivity(intent);
}

@Override
public void openSyllabusInWeb(Context context, long courseId) {
openCourseTabInWeb(context, courseId, CourseScreenTab.SYLLABUS.getPath(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class CardPresenter(
view?.let {
if (submission == null || submission?.status == Submission.Status.LOCAL) {
submission = Submission(
reply = it.getQuizViewDelegate().createReply(),
status = Submission.Status.LOCAL) // cache current choices state
_reply = it.getQuizViewDelegate().createReply(),
status = Submission.Status.LOCAL) // cache current choices state
}
super.detachView(it)
}
Expand Down Expand Up @@ -111,7 +111,7 @@ class CardPresenter(
error = null

val submission = Submission(
reply = view?.getQuizViewDelegate()?.createReply(),
_reply = view?.getQuizViewDelegate()?.createReply(),
attempt = card.attempt?.id ?: 0)
disposable = api.createNewSubmissionReactive(submission)
.ignoreElement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.stepik.android.domain.course_reviews.model.CourseReview
import org.stepik.android.model.Certificate
import org.stepik.android.model.CourseReviewSummary
import org.stepik.android.model.Submission
import org.stepik.android.model.comments.DiscussionThread
import org.stepik.android.model.user.User

@Component(modules = [StorageModule::class])
Expand Down Expand Up @@ -44,4 +45,5 @@ interface StorageComponent {
val courseReviewSummaryDao: IDao<CourseReviewSummary>
val submissionDao: IDao<Submission>
val certificateDao: IDao<Certificate>
val discussionThreadDao: IDao<DiscussionThread>
}
12 changes: 9 additions & 3 deletions app/src/main/java/org/stepic/droid/di/storage/StorageModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.stepic.droid.storage.operations.DatabaseOperationsImpl
import org.stepik.android.cache.certificates.dao.CertificateDaoImpl
import org.stepik.android.cache.comment_banner.dao.CommentBannerDao
import org.stepik.android.cache.comment_banner.dao.CommentBannerDaoImpl
import org.stepik.android.cache.discussion_thread.dao.DiscussionThreadDaoImpl
import org.stepik.android.cache.personal_deadlines.dao.DeadlinesBannerDao
import org.stepik.android.cache.personal_deadlines.dao.DeadlinesBannerDaoImpl
import org.stepik.android.cache.personal_deadlines.dao.PersonalDeadlinesDao
Expand Down Expand Up @@ -75,6 +76,7 @@ import org.stepik.android.model.Step
import org.stepik.android.model.Submission
import org.stepik.android.model.Unit
import org.stepik.android.model.ViewAssignment
import org.stepik.android.model.comments.DiscussionThread
import org.stepik.android.model.user.User

@Module
Expand Down Expand Up @@ -214,16 +216,20 @@ abstract class StorageModule {
@Binds
internal abstract fun bindCertificateDao(certificateDaoImpl: CertificateDaoImpl): IDao<Certificate>

@StorageSingleton
@Binds
internal abstract fun bindDiscussionThreadDao(discussionThreadDaoImpl: DiscussionThreadDaoImpl): IDao<DiscussionThread>

@Module
companion object {

@StorageSingleton
@Provides
@JvmStatic
internal fun provideStorageGson(): Gson =
GsonBuilder()
.enableComplexMapKeySerialization()
.create()
GsonBuilder()
.enableComplexMapKeySerialization()
.create()

@StorageSingleton
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ enum class CollectionDescriptionColors(
@ColorRes
val textColorRes: Int
): Parcelable {
BLUE(R.drawable.gradient_background_blue, R.drawable.gradient_background_blue_squared, R.color.text_color_gradient_blue),
FIRE(R.drawable.gradient_background_fire, R.drawable.gradient_background_fire_squared, R.color.text_color_gradient_fire);
BLUE(R.drawable.bg_placeholder_blue, R.drawable.gradient_background_blue_squared, R.color.text_color_gradient_blue),
FIRE(R.drawable.bg_placeholder_fire, R.drawable.gradient_background_fire_squared, R.color.text_color_gradient_fire);

override fun describeContents(): Int = 0

Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/org/stepic/droid/model/CommentAdapterItem.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.stepic.droid.persistence.content

import io.reactivex.Observable
import io.reactivex.Single
import org.stepic.droid.persistence.model.DownloadConfiguration
import org.stepic.droid.persistence.model.StepPersistentWrapper
import org.stepik.android.model.Step

interface StepContentResolver {
fun getDownloadableContentFromStep(step: Step, configuration: DownloadConfiguration): Set<String>
fun resolvePersistentContent(step: Step): Observable<StepPersistentWrapper>
fun resolvePersistentContent(step: Step): Single<StepPersistentWrapper>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.stepic.droid.persistence.content

import io.reactivex.Observable
import io.reactivex.Single
import org.stepic.droid.persistence.content.processors.StepContentProcessor
import org.stepic.droid.persistence.di.PersistenceScope
import org.stepic.droid.persistence.files.ExternalStorageManager
Expand All @@ -17,27 +17,27 @@ import javax.inject.Inject
class StepContentResolverImpl
@Inject
constructor(
private val processors: Set<@JvmSuppressWildcards StepContentProcessor>,
private val processors: Set<@JvmSuppressWildcards StepContentProcessor>,

private val persistentItemDao: PersistentItemDao,
private val persistentItemObserver: PersistentItemObserver,
private val externalStorageManager: ExternalStorageManager
private val persistentItemDao: PersistentItemDao,
private val persistentItemObserver: PersistentItemObserver,
private val externalStorageManager: ExternalStorageManager
): StepContentResolver {
override fun getDownloadableContentFromStep(step: Step, configuration: DownloadConfiguration): Set<String> =
processors.map { it.extractDownloadableContent(step, configuration) }.reduce { a, b -> a union b }

override fun resolvePersistentContent(step: Step): Observable<StepPersistentWrapper> =
persistentItemDao
.getItems(mapOf(
DBStructurePersistentItem.Columns.STEP to step.id.toString(),
DBStructurePersistentItem.Columns.STATUS to PersistentItem.Status.COMPLETED.name
))
.map { items ->
val linkMap = resolveLinksMap(items)
processors.fold(StepPersistentWrapper(step)) { wrapper, processor ->
processor.injectPersistentContent(wrapper, linkMap)
}
}
processors.map { it.extractDownloadableContent(step, configuration) }.reduce { a, b -> a union b }

override fun resolvePersistentContent(step: Step): Single<StepPersistentWrapper> =
persistentItemDao
.getItems(mapOf(
DBStructurePersistentItem.Columns.STEP to step.id.toString(),
DBStructurePersistentItem.Columns.STATUS to PersistentItem.Status.COMPLETED.name
))
.map { items ->
val linkMap = resolveLinksMap(items)
processors.fold(StepPersistentWrapper(step)) { wrapper, processor ->
processor.injectPersistentContent(wrapper, linkMap)
}
}

private fun resolveLinksMap(items: List<PersistentItem>): Map<String, String> {
val map = mutableMapOf<String, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ constructor(
.switchMap { _ ->
intervalUpdatesObservable
.startWith(kotlin.Unit)
.concatMap {
.concatMapSingle {
persistentItemDao.getItemsByStatus(PersistentItem.Status.IN_PROGRESS)
}
.takeWhile(List<PersistentItem>::isNotEmpty)
Expand All @@ -87,7 +87,7 @@ constructor(
}

private fun fixInTransferItems() = fsLock.withLock {
val itemsInTransfer = persistentItemDao.getItemsByStatus(PersistentItem.Status.FILE_TRANSFER).blockingFirst()
val itemsInTransfer = persistentItemDao.getItemsByStatus(PersistentItem.Status.FILE_TRANSFER).blockingGet()
itemsInTransfer.forEach { item ->
val path = externalStorageManager.resolvePathForPersistentItem(item.copy(status = PersistentItem.Status.COMPLETED))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ import javax.inject.Inject
class RemoveDownloadTaskHelperImpl
@Inject
constructor(
private val downloadTaskManager: DownloadTaskManager,
private val persistentStateManager: PersistentStateManager,
private val persistentItemDao: PersistentItemDao
private val downloadTaskManager: DownloadTaskManager,
private val persistentStateManager: PersistentStateManager,
private val persistentItemDao: PersistentItemDao
) : RemoveDownloadTaskHelper {
override fun removeTasks(structureObservable: Observable<Structure>): Completable =
structureObservable
.toList()
.doOnSuccess { // in order to get rid of blinking on delete operation
it.forEach { structure ->
persistentStateManager.invalidateStructure(structure, PersistentState.State.IN_PROGRESS)
}
}
.flatMapObservable(List<Structure>::toObservable)
.flatMapCompletable { structure ->
persistentItemDao.getItemsByStep(structure.step) // as step is smallest atom
.concatMapCompletable { downloadTaskManager.removeTasks(it) }
.doFinally {
persistentStateManager.invalidateStructure(structure, PersistentState.State.NOT_CACHED)
}
structureObservable
.toList()
.doOnSuccess { // in order to get rid of blinking on delete operation
it.forEach { structure ->
persistentStateManager.invalidateStructure(structure, PersistentState.State.IN_PROGRESS)
}
}
.flatMapObservable(List<Structure>::toObservable)
.flatMapCompletable { structure ->
persistentItemDao.getItemsByStep(structure.step) // as step is smallest atom
.flatMapCompletable { downloadTaskManager.removeTasks(it) }
.doFinally {
persistentStateManager.invalidateStructure(structure, PersistentState.State.NOT_CACHED)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import javax.inject.Inject
class RemovalDownloadsInteractor
@Inject
constructor(
private val persistentItemDao: PersistentItemDao,
private val removeDownloadTaskHelper: RemoveDownloadTaskHelper
private val persistentItemDao: PersistentItemDao,
private val removeDownloadTaskHelper: RemoveDownloadTaskHelper
) {
fun removeAllDownloads(): Completable = removeDownloadTaskHelper.removeTasks(
persistentItemDao.getItems(emptyMap())
.flatMap(List<PersistentItem>::toObservable)
.map { it.task.structure }
)
fun removeAllDownloads(): Completable =
removeDownloadTaskHelper.removeTasks(
persistentItemDao
.getItems(emptyMap())
.flatMapObservable(List<PersistentItem>::toObservable)
.map { it.task.structure }
)
}
Loading

0 comments on commit 38c7299

Please sign in to comment.