Skip to content

Commit

Permalink
Merge branch 'release/1.81'
Browse files Browse the repository at this point in the history
  • Loading branch information
eadm committed Apr 5, 2019
2 parents 73596b7 + 0889d75 commit dbd00a3
Show file tree
Hide file tree
Showing 113 changed files with 2,505 additions and 116 deletions.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@

</activity>

<activity
android:name="org.stepik.android.view.profile_edit.ui.activity.ProfileEditActivity" />

<activity
android:name="org.stepik.android.view.profile_edit.ui.activity.ProfileEditPasswordActivity" />

<activity
android:name="org.stepik.android.view.profile_edit.ui.activity.ProfileEditInfoActivity"
android:windowSoftInputMode="adjustResize" />

<receiver
android:name="org.stepic.droid.receivers.DownloadClickReceiver"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.android.synthetic.main.fragment_adaptive_rating.*
import kotlinx.android.synthetic.main.error_no_connection_with_button.*
import org.stepic.droid.R
import org.stepic.droid.adaptive.ui.adapters.AdaptiveRatingAdapter
import org.stepic.droid.analytic.AmplitudeAnalytic
import org.stepic.droid.base.App
import org.stepic.droid.base.FragmentBase
import org.stepic.droid.core.presenters.AdaptiveRatingPresenter
Expand Down Expand Up @@ -67,6 +68,13 @@ class AdaptiveRatingFragment: FragmentBase(), AdaptiveRatingView {
tryAgain.setOnClickListener { adaptiveRatingPresenter.retry() }
}

override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
if (isVisibleToUser) {
analytic.reportAmplitudeEvent(AmplitudeAnalytic.Adaptive.RATING_OPENED, mapOf(AmplitudeAnalytic.Adaptive.Params.COURSE to courseId.toString()))
}
}

override fun onLoading() {
error.visibility = View.GONE
progress.visibility = View.VISIBLE
Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/org/stepic/droid/analytic/AmplitudeAnalytic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package org.stepic.droid.analytic

interface AmplitudeAnalytic {
object Properties {
const val STEPIK_ID = "stepik_id"
const val SUBMISSIONS_COUNT = "submissions_count"
const val COURSES_COUNT = "courses_count"
const val SCREEN_ORIENTATION = "screen_orientation"
const val APPLICATION_ID = "application_id"
const val PUSH_PERMISSION = "push_permission"
const val STREAKS_NOTIFICATIONS_ENABLED = "streaks_notifications_enabled"
const val STEPIK_ID = "stepik_id"
const val SUBMISSIONS_COUNT = "submissions_count"
const val COURSES_COUNT = "courses_count"
const val SCREEN_ORIENTATION = "screen_orientation"
const val APPLICATION_ID = "application_id"
const val PUSH_PERMISSION = "push_permission"
const val STREAKS_NOTIFICATIONS_ENABLED = "streaks_notifications_enabled"
}

object Launch {
Expand Down Expand Up @@ -137,4 +137,17 @@ interface AmplitudeAnalytic {
const val LEVEL = "achievement_level"
}
}

object ProfileEdit {
const val SCREEN_OPENED = "Profile edit screen opened"
const val SAVED = "Profile edit saved"
}

object Adaptive {
const val RATING_OPENED = "Adaptive rating opened"

object Params {
const val COURSE = "course"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.stepic.droid.analytic.experiments

import org.stepic.droid.analytic.Analytic
import org.stepic.droid.preferences.SharedPreferenceHelper
import javax.inject.Inject

class CommentsTooltipSplitTest
@Inject
constructor(
analytics: Analytic,
sharedPreferenceHelper: SharedPreferenceHelper
) : SplitTest<CommentsTooltipSplitTest.Group>(
analytics,
sharedPreferenceHelper,

name = "comments",
groups = Group.values()
) {
enum class Group(
val isCommentsToolTipEnabled: Boolean
) : SplitTest.Group {
Control(isCommentsToolTipEnabled = false),
TooltipEnabled(isCommentsToolTipEnabled = true)
}
}
112 changes: 104 additions & 8 deletions app/src/main/java/org/stepic/droid/base/StepBaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.widget.NestedScrollView;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -14,36 +16,50 @@
import org.stepic.droid.analytic.Analytic;
import org.stepic.droid.core.commentcount.contract.CommentCountListener;
import org.stepic.droid.core.presenters.AnonymousPresenter;
import org.stepic.droid.core.presenters.CommentsBannerPresenter;
import org.stepic.droid.core.presenters.RouteStepPresenter;
import org.stepic.droid.core.presenters.contracts.AnonymousView;
import org.stepic.droid.core.presenters.contracts.CommentsView;
import org.stepic.droid.core.presenters.contracts.RouteStepView;
import org.stepic.droid.persistence.model.StepPersistentWrapper;
import org.stepic.droid.ui.custom.StepTextWrapper;
import org.stepik.android.model.Lesson;
import org.stepik.android.model.Section;
import org.stepik.android.model.Step;
import org.stepik.android.model.Unit;
import org.stepic.droid.storage.operations.DatabaseFacade;
import org.stepic.droid.ui.custom.StepTextWrapper;
import org.stepic.droid.ui.dialogs.LoadingProgressDialogFragment;
import org.stepic.droid.ui.dialogs.StepShareDialogFragment;
import org.stepic.droid.ui.util.PopupHelper;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.util.DisplayUtils;
import org.stepic.droid.util.ProgressHelper;
import org.stepic.droid.web.StepResponse;
import org.stepik.android.model.Lesson;
import org.stepik.android.model.Section;
import org.stepik.android.model.Step;
import org.stepik.android.model.Unit;
import org.stepik.android.view.ui.listener.FragmentViewPagerScrollStateListener;

import java.lang.ref.WeakReference;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import butterknife.BindView;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.BehaviorSubject;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static org.stepic.droid.util.RxUtilKt.zip;

public abstract class StepBaseFragment extends FragmentBase
implements RouteStepView,
AnonymousView,
CommentCountListener {
CommentsView,
CommentCountListener,
FragmentViewPagerScrollStateListener {

@BindView(R.id.open_comments_text)
protected TextView textForComment;
Expand All @@ -69,6 +85,10 @@ public abstract class StepBaseFragment extends FragmentBase
@BindView(R.id.previous_lesson_view)
protected View previousLessonView;

@BindView(R.id.rootScrollView)
@Nullable
protected NestedScrollView nestedScrollView;

protected StepPersistentWrapper stepWrapper;
protected Step step;
protected Lesson lesson;
Expand All @@ -92,9 +112,20 @@ public abstract class StepBaseFragment extends FragmentBase
@Inject
AnonymousPresenter anonymousPresenter;

@Inject
CommentsBannerPresenter commentsBannerPresenter;

@Inject
Client<CommentCountListener> commentCountListenerClient;

private CompositeDisposable uiCompositeDisposable = new CompositeDisposable();

private BehaviorSubject<FragmentViewPagerScrollStateListener.ScrollState> fragmentVisibilitySubject =
BehaviorSubject.create();

private BehaviorSubject<Boolean> commentsVisibilitySubject =
BehaviorSubject.createDefault(false);

@Override
protected void injectComponent() {
App.Companion
Expand Down Expand Up @@ -133,6 +164,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
commentCountListenerClient.subscribe(this);
routeStepPresenter.attachView(this);
anonymousPresenter.attachView(this);
commentsBannerPresenter.attachView(this);
anonymousPresenter.checkForAnonymous();
if (unit != null) {
nextLessonView.setOnClickListener(new View.OnClickListener() {
Expand All @@ -152,11 +184,36 @@ public void onClick(View view) {
routeStepPresenter.checkStepForFirst(step.getId(), lesson, unit);
routeStepPresenter.checkStepForLast(step.getId(), lesson, unit);
}

}

protected abstract void attachStepTextWrapper();
protected abstract void detachStepTextWrapper();
@Override
public void showCommentsBanner() {
Observable<ScrollState> visibilityObservable =
fragmentVisibilitySubject.filter(state -> state == ScrollState.ACTIVE);

Observable<Boolean> commentsObservable =
commentsVisibilitySubject.filter(isVisible -> isVisible);

uiCompositeDisposable.add(zip(visibilityObservable, commentsObservable)
.firstElement()
.ignoreElement()
.subscribe(() -> {
View view = nestedScrollView.findViewById(R.id.open_comments_text);
PopupHelper.INSTANCE.showPopupAnchoredToView(
getContext(),
view,
getString(R.string.step_comment_tooltip),
PopupHelper.PopupTheme.DARK_ABOVE,
true,
Gravity.TOP,
true,
true
);
commentsBannerPresenter.onBannerShown(section.getCourse());
}));
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
Expand All @@ -168,6 +225,22 @@ public void onClick(View v) {
getScreenManager().showLaunchScreen(getActivity());
}
});
nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView nestedScrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY == (nestedScrollView.getChildAt(0).getMeasuredHeight() - nestedScrollView.getMeasuredHeight())) {
commentsVisibilitySubject.onNext(DisplayUtils.isVisible(nestedScrollView, textForComment));
}
}
});
}

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
checkCommentsBanner();
}
}

private void updateCommentState() {
Expand All @@ -193,7 +266,6 @@ public void onClick(View v) {
}
}
});

int discussionCount = step.getDiscussionsCount();
if (discussionCount > 0) {
textForComment.setText(App.Companion.getAppContext().getResources().getQuantityString(R.plurals.open_comments, discussionCount, discussionCount));
Expand Down Expand Up @@ -231,8 +303,10 @@ public void onDestroyView() {
routeStepPresenter.detachView(this);
commentCountListenerClient.unsubscribe(this);
anonymousPresenter.detachView(this);
commentsBannerPresenter.detachView(this);
nextLessonView.setOnClickListener(null);
previousLessonView.setOnClickListener(null);
uiCompositeDisposable.clear();
super.onDestroyView();
}

Expand Down Expand Up @@ -359,4 +433,26 @@ public void onFailure(Call<StepResponse> call, Throwable t) {

}
}

@Override
public void onViewPagerScrollStateChanged(ScrollState scrollState) {
changeVisibilitySubjects(scrollState);
}

private void changeVisibilitySubjects(ScrollState scrollState) {
fragmentVisibilitySubject.onNext(scrollState);
if (scrollState == ScrollState.ACTIVE && nestedScrollView != null) {
commentsVisibilitySubject.onNext(DisplayUtils.isVisible(nestedScrollView, textForComment));
}
}

private void checkCommentsBanner() {
uiCompositeDisposable.add(Completable.timer(3, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
.subscribe(() -> {
if (section != null && step.getDiscussionsCount() > 0) {
changeVisibilitySubjects(ScrollState.ACTIVE);
commentsBannerPresenter.fetchCommentsBanner(section.getCourse());
}
}));
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/org/stepic/droid/core/ScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.stepic.droid.ui.fragments.CommentsFragment;
import org.stepic.droid.web.ViewAssignment;
import org.stepik.android.model.Tag;
import org.stepik.android.model.user.Profile;
import org.stepik.android.view.course.routing.CourseScreenTab;
import org.stepik.android.view.routing.deeplink.BranchRoute;
import org.stepik.android.view.video_player.model.VideoPlayerMediaData;
Expand Down Expand Up @@ -145,4 +146,8 @@ public interface ScreenManager {
void showAchievementsList(Context context, long userId, boolean isMyProfile);

void openDeepLink(Context context, BranchRoute route);

void showProfileEdit(Context context);
void showProfileEditInfo(Activity activity, Profile profile);
void showProfileEditPassword(Activity activity, long profileId);
}
24 changes: 24 additions & 0 deletions app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.stepic.droid.di.AppSingleton;
import org.stepic.droid.features.achievements.ui.activity.AchievementsListActivity;
import org.stepic.droid.util.UriExtensionsKt;
import org.stepik.android.model.user.Profile;
import org.stepik.android.view.course.routing.CourseScreenTab;
import org.stepik.android.view.course.ui.activity.CourseActivity;
import org.stepic.droid.model.CertificateViewItem;
Expand Down Expand Up @@ -70,6 +71,9 @@
import org.stepic.droid.util.StringUtil;
import org.stepic.droid.web.ViewAssignment;
import org.stepik.android.model.Tag;
import org.stepik.android.view.profile_edit.ui.activity.ProfileEditInfoActivity;
import org.stepik.android.view.profile_edit.ui.activity.ProfileEditActivity;
import org.stepik.android.view.profile_edit.ui.activity.ProfileEditPasswordActivity;
import org.stepik.android.view.routing.deeplink.BranchDeepLinkRouter;
import org.stepik.android.view.routing.deeplink.BranchRoute;
import org.stepik.android.view.video_player.model.VideoPlayerMediaData;
Expand Down Expand Up @@ -699,4 +703,24 @@ public void openDeepLink(Context context, BranchRoute route) {
}
}
}

@Override
public void showProfileEdit(Context context) {
if (context instanceof Activity) {
((Activity) context).overridePendingTransition(org.stepic.droid.R.anim.push_up, org.stepic.droid.R.anim.no_transition);
}
context.startActivity(ProfileEditActivity.Companion.createIntent(context));
}

@Override
public void showProfileEditInfo(Activity activity, Profile profile) {
activity.overridePendingTransition(org.stepic.droid.R.anim.push_up, org.stepic.droid.R.anim.no_transition);
activity.startActivityForResult(ProfileEditInfoActivity.Companion.createIntent(activity, profile), ProfileEditInfoActivity.REQUEST_CODE);
}

@Override
public void showProfileEditPassword(Activity activity, long profileId) {
activity.overridePendingTransition(org.stepic.droid.R.anim.push_up, org.stepic.droid.R.anim.no_transition);
activity.startActivityForResult(ProfileEditPasswordActivity.Companion.createIntent(activity, profileId), ProfileEditPasswordActivity.REQUEST_CODE);
}
}
Loading

0 comments on commit dbd00a3

Please sign in to comment.