Skip to content

Commit

Permalink
Merge pull request #82 from StepicOrg/release/1.33
Browse files Browse the repository at this point in the history
Release/1.33
  • Loading branch information
KirillMakarov authored May 3, 2017
2 parents 0b6d97d + 5e0b3b1 commit 888cd91
Show file tree
Hide file tree
Showing 26 changed files with 202 additions and 49 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
applicationId "org.stepic.droid"
minSdkVersion minSdk
targetSdkVersion 25
versionCode 150
versionName "1.32.3"
versionCode 152
versionName "1.33.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<activity
android:name="org.stepic.droid.ui.activities.LaunchActivity"
android:launchMode="singleTop"
android:launchMode="singleTask"
android:theme="@style/AppTheme.LoginLaunchRegistration">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
Expand Down
4 changes: 4 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 @@ -77,6 +77,7 @@ interface Interaction {
String CLICK_AUTH_FROM_STEPS = "click_auth_from_steps";
String SHARE_STEP_CLICK = "share_step_click";
String CLICK_TRY_STEP_AGAIN = "step_try_again";
String CLICK_TRY_STEP_AGAIN_AFTER_CORRECT = "step_try_again_after_correct";
String NO_DISCOUNTING_DIALOG = "discounting_dialog_no";
String YES_DISCOUNTING_DIALOG = "discounting_dialog_yes";
String CLICK_SETTINGS_FROM_NOTIFICATION = "click_settings_from_notification";
Expand Down Expand Up @@ -200,6 +201,9 @@ interface Error {
String LESSON_ACCESS_DENIED = "lesson_access_denied";
String SEARCH_COURSE_NO_INTERNET = "search_course_no_internet";
String SEARCH_COURSE_UNSUCCESSFUL = "search_course_unsuccessful";
String CHOICES_ARE_SMALLER = "choices_are_smaller";
String PREVIOUS_VIEW_NOT_DETACHED = "previous_view_not_detached";
String UNEXPECTED_VIEW = "unexpected_view";
}

interface Web {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public abstract class StepBaseFragment extends FragmentBase implements RouteStep


@Inject
RouteStepPresenter routeStepPresenter;
protected RouteStepPresenter routeStepPresenter;

@Inject
AnonymousPresenter anonymousPresenter;
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/stepic/droid/core/ProfilePresenter.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.stepic.droid.core

import org.stepic.droid.core.presenters.PresenterBase
import org.stepic.droid.analytic.Analytic
import org.stepic.droid.core.presenters.PresenterWithPotentialLeak
import org.stepic.droid.core.presenters.contracts.ProfileView

abstract class ProfilePresenter : PresenterBase<ProfileView>() {
abstract class ProfilePresenter (analytic: Analytic) : PresenterWithPotentialLeak<ProfileView>(analytic) {

abstract fun initProfile()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ class VideoLengthResolverImpl @Inject constructor() : VideoLengthResolver {
}
}

val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
val timeInMillis = java.lang.Long.parseLong(time)
val time: String? = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
val timeInMillis = try {
time?.toLong()
} catch (numberFormatException: NumberFormatException) {
null
}
return timeInMillis
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package org.stepic.droid.core.presenters

import android.support.annotation.CallSuper

abstract class PresenterBase<V> {
abstract class PresenterBase<V> : PresenterContract<V> {
@Volatile
var view: V? = null
private set

@CallSuper
open fun attachView(view: V) {
override fun attachView(view: V) {
val previousView = this.view

if (previousView != null) {
Expand All @@ -19,7 +19,7 @@ abstract class PresenterBase<V> {
}

@CallSuper
open fun detachView(view: V) {
override fun detachView(view: V) {
val previousView = this.view

if (previousView === view) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.stepic.droid.core.presenters

interface PresenterContract<V> {
fun attachView(view: V)
fun detachView(view: V)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.stepic.droid.core.presenters

import org.stepic.droid.analytic.Analytic

abstract class PresenterWithPotentialLeak<V>(protected val analytic: Analytic) : PresenterContract <V> {

@Volatile
var view: V? = null
private set

override fun attachView(view: V) {
val previousView = this.view

if (previousView != null) {
val exception = IllegalStateException("Previous view is not detached! previousView = " + previousView)
analytic.reportError(Analytic.Error.PREVIOUS_VIEW_NOT_DETACHED, exception)
}

this.view = view
}

override fun detachView(view: V) {
val previousView = this.view

if (previousView !== view) {
val exception = IllegalStateException("Unexpected view! previousView = $previousView, getView to unbind = $view")
analytic.reportError(Analytic.Error.UNEXPECTED_VIEW, exception)
}
this.view = null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ProfileMainFeedPresenter
private val mainHandler: MainHandler,
private val api: Api,
private val threadPoolExecutor: ThreadPoolExecutor,
private val analytic: Analytic,
private val stepikLogoutManager: StepikLogoutManager) : PresenterBase<ProfileMainFeedView>() {
analytic: Analytic,
private val stepikLogoutManager: StepikLogoutManager) : PresenterWithPotentialLeak<ProfileMainFeedView>(analytic) {

val isProfileFetching = AtomicBoolean(false)
var profile: Profile? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import javax.inject.Inject
class ProfilePresenterImpl
@Inject constructor(
private val threadPoolExecutor: ThreadPoolExecutor,
private val analytic: Analytic,
analytic: Analytic,
private val mainHandler: MainHandler,
private val api: Api,
private val sharedPreferences: SharedPreferenceHelper) : ProfilePresenter() {
private val sharedPreferences: SharedPreferenceHelper) : ProfilePresenter(analytic) {

private var isLoading: Boolean = false //main thread only
private var userViewModel: UserViewModel? = null //both threads, but access only when isLoading = false, write isLoading = true.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.stepic.droid.storage

import android.app.DownloadManager
import android.database.Cursor
import android.support.annotation.WorkerThread
import org.stepic.droid.di.AppSingleton
import org.stepic.droid.model.DownloadEntity
import org.stepic.droid.storage.operations.DatabaseFacade
import java.util.concurrent.ThreadPoolExecutor
import javax.inject.Inject
import javax.inject.Singleton

@AppSingleton
class InitialDownloadUpdater
Expand Down Expand Up @@ -43,8 +43,8 @@ class InitialDownloadUpdater

val query = DownloadManager.Query()
query.setFilterById(*currentDownloadingEntitiesMap.keys.toLongArray())
val cursor = systemDownloadManager.query(query)
cursor.use { cursor ->
val cursor : Cursor? = systemDownloadManager.query(query)
cursor?.use { cursor ->
cursor.moveToFirst()
while (!cursor.isAfterLast) {
val columnStatus = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ public void run() {
return true;
case R.id.profile:
// do not close drawer for profile
screenManager.openProfile(this);
// TODO: 02.05.17 make it async or show "sign in" in profile
if (sharedPreferenceHelper.getAuthResponseFromStore() == null) {
screenManager.showLaunchScreen(MainFeedActivity.this);
} else {
screenManager.openProfile(this);
}
return true;
case R.id.feedback:
new Handler().postDelayed(new Runnable() {
Expand Down Expand Up @@ -690,7 +695,7 @@ public void onLogoutSuccess() {
if (googleApiClient != null && googleApiClient.isConnected()) {
Auth.GoogleSignInApi.signOut(googleApiClient);
}
screenManager.showLaunchScreen(this);
screenManager.showLaunchScreenAfterLogout(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ public SelectViewHolder(View itemView) {
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position > 0) {
FillBlankComponent fillBlankComponent = componentList.get(getAdapterPosition());
int adapterPosition = getAdapterPosition();
if (position > 0 && adapterPosition >= 0 && adapterPosition < componentList.size()) {
FillBlankComponent fillBlankComponent = componentList.get(adapterPosition);
String answer = fillBlankComponent.getOptions().get(position - 1);
changeAnswerAtPosition(getAdapterPosition(), answer);
changeAnswerAtPosition(adapterPosition, answer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.squareup.otto.Subscribe;

import org.stepic.droid.R;
import org.stepic.droid.analytic.Analytic;
import org.stepic.droid.events.InternetIsEnabledEvent;
import org.stepic.droid.events.comments.NewCommentWasAddedOrUpdateEvent;
import org.stepic.droid.events.steps.StepWasUpdatedEvent;
Expand Down Expand Up @@ -128,7 +129,12 @@ protected void onRestoreSubmission() {

for (int i = 0; i < choiceContainer.getChildCount(); i++) {
StepikOptionView view = (StepikOptionView) choiceContainer.getChildAt(i);
view.setChecked(choices.get(i));
if (choices.size() > i) {
//// sometimes choices can be empty
view.setChecked(choices.get(i));
} else {
analytic.reportEventWithName(Analytic.Error.CHOICES_ARE_SMALLER, submission.getId() + "");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.stepic.droid.model.Step;
import org.stepic.droid.model.Unit;
import org.stepic.droid.ui.adapters.StepFragmentAdapter;
import org.stepic.droid.ui.listeners.NextMoveable;
import org.stepic.droid.util.AppConstants;
import org.stepic.droid.util.ProgressHelper;
import org.stepic.droid.util.resolvers.StepHelper;
Expand All @@ -47,7 +48,7 @@
import butterknife.BindString;
import butterknife.BindView;

public class LessonFragment extends FragmentBase implements LessonView, LessonTrackingView {
public class LessonFragment extends FragmentBase implements LessonView, LessonTrackingView, NextMoveable {
private static final String FROM_PREVIOUS_KEY = "fromPrevKey";
private static final String SIMPLE_UNIT_ID_KEY = "simpleUnitId";
private static final String SIMPLE_LESSON_ID_KEY = "simpleLessonId";
Expand Down Expand Up @@ -495,4 +496,22 @@ void showViewPager(boolean needShow) {
private void trackStepOpening(@NonNull Step step) {
stepTrackingPresenter.trackStepType(step);
}

@Override
public boolean moveNext() {
if (viewPager == null || viewPager.getAdapter() == null) {
return false;
}

int currentItem = viewPager.getCurrentItem();
int lastIndex = viewPager.getAdapter().getCount() - 1;
if (currentItem < lastIndex) {
viewPager.setCurrentItem(currentItem + 1, true);
return true;
} else if (currentItem == lastIndex) {
return false;
}

return false;
}
}
Loading

0 comments on commit 888cd91

Please sign in to comment.