Skip to content

Commit

Permalink
Merge pull request #74 from StepicOrg/release/1.27
Browse files Browse the repository at this point in the history
Release/1.27
  • Loading branch information
KirillMakarov authored Feb 8, 2017
2 parents f79fedb + 877d2d0 commit a6443da
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 43 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ obj/

maka-vlc/


/Google Play Android Developer-e6dc40a00d1f.json
/fastlane/
/fastlane/
6 changes: 4 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 119
versionName "1.26.4"
versionCode 120
versionName "1.27.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
Expand Down Expand Up @@ -187,6 +187,8 @@ dependencies {
compile('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.10.2@aar') {
transitive = true
}

compile 'com.caverock:androidsvg:1.2.1'
}

repositories {
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 @@ -166,8 +166,10 @@ interface Error {
java.lang.String GOOGLE_SERVICES_TOO_OLD = "google_services_too_old";
String VIDEO_PATH_WAS_NULL_WITH_INTERNET = "video_path_was_null_internet_enabled";
java.lang.String FAIL_REFRESH_TOKEN_ONLINE = "fail_refresh_token_online";
java.lang.String FAIL_REFRESH_TOKEN_ONLINE_EXTENDED = "fail_refresh_token_online_extended";
String COOKIE_MANAGER_ERROR = "cookie_manager_error";
String PENDING_INTENT_WAS_NULL = "pending_intent_null_streaks";
String FAIL_REFRESH_TOKEN_INLINE_GETTING = "fail_refresh_token_online_get";
java.lang.String COOKIE_WAS_EMPTY = "cookie_was_empty";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void onCreate(Bundle savedInstanceState) {
setHasOptionsMenu(true);
setRetainInstance(true);

isScreenCreated = true;

MainApplication.component()
.plus(new CourseListModule())
.inject(this);
Expand Down Expand Up @@ -104,7 +106,6 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bus.register(this);
courseListPresenter.attachView(this);
isScreenCreated = savedInstanceState == null;
courseListPresenter.restoreState();
}

Expand All @@ -113,6 +114,7 @@ public void onStart() {
super.onStart();
if (isScreenCreated) {
//reset all data
isScreenCreated = false;
needFilter = false;
courses.clear();
courseListPresenter.refreshData(getCourseType(), needFilter, false);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/stepic/droid/core/ProfilePresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ProfilePresenter(val threadPoolExecutor: ThreadPoolExecutor,
}
} else {
val userViewModelLocal = UserViewModel(fullName = user.getFirstAndLastName(),
imageLink = user.avatar,
imageLink = user.getAvatarPath(),
shortBio = stringOrEmpty(user.short_bio),
information = stringOrEmpty((user.details)),
isMyProfile = false,
Expand Down Expand Up @@ -133,7 +133,7 @@ class ProfilePresenter(val threadPoolExecutor: ThreadPoolExecutor,

private fun showProfileBase(profile: Profile, isMyProfile: Boolean) {
val userViewModelLocal = UserViewModel(fullName = profile.getFirstAndLastName(),
imageLink = profile.avatar,
imageLink = profile.getAvatarPath(),
shortBio = stringOrEmpty(profile.short_bio),
information = stringOrEmpty((profile.details)),
isMyProfile = isMyProfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ public void showVideo(Activity sourceActivity, String videoPath, long videoId) {
sourceActivity.startActivity(intent);
} else {
Uri videoUri = Uri.parse(videoPath);
String scheme = videoUri.getScheme();
if (scheme == null) {
videoUri = Uri.parse(AppConstants.FILE_SCHEME_PREFIX + videoPath);
}
Intent intent = new Intent(Intent.ACTION_VIEW, videoUri);
intent.setDataAndType(videoUri, "video/*");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.stepic.droid.model.StepikFilter
import org.stepic.droid.preferences.SharedPreferenceHelper
import org.stepic.droid.store.operations.DatabaseFacade
import org.stepic.droid.store.operations.Table
import org.stepic.droid.util.RWLocks
import org.stepic.droid.web.CoursesStepicResponse
import org.stepic.droid.web.IApi
import retrofit.Response
Expand Down Expand Up @@ -81,10 +82,19 @@ class PersistentCourseListPresenter(
if (response != null && response.isSuccess) {
val coursesFromInternet = response.body().courses

coursesFromInternet.filterNotNull().forEach {
databaseFacade.addCourse(it, courseType)
try {
//this lock need for not saving enrolled courses to database after user click logout
RWLocks.ClearEnrollmentsLock.writeLock().lock()
if (sharedPreferenceHelper.authResponseFromStore != null || courseType == Table.featured) {
coursesFromInternet.filterNotNull().forEach {
databaseFacade.addCourse(it, courseType)
}
}
} finally {
RWLocks.ClearEnrollmentsLock.writeLock().unlock()
}


hasNextPage.set(response.body().meta.has_next)
if (hasNextPage.get()) {
currentPage.set(response.body().meta.page + 1) // page for next loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.stepic.droid.preferences.SharedPreferenceHelper
import org.stepic.droid.preferences.UserPreferences
import org.stepic.droid.store.operations.DatabaseFacade
import org.stepic.droid.util.FileUtil
import org.stepic.droid.util.RWLocks
import org.stepic.droid.web.IApi
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -97,8 +98,13 @@ class ProfileMainFeedPresenter(private val sharedPreferenceHelper: SharedPrefere
}
}
FileUtil.cleanDirectory(directoryForClean)
databaseFacade.dropDatabase()
sharedPreferenceHelper.deleteAuthInfo()
try {
RWLocks.ClearEnrollmentsLock.writeLock().lock()
sharedPreferenceHelper.deleteAuthInfo()
databaseFacade.dropDatabase()
} finally {
RWLocks.ClearEnrollmentsLock.writeLock().unlock()
}
mainHandler.post {
view?.onLogoutSuccess()
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/org/stepic/droid/model/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class Profile(
val first_name: String? = null,
val last_name: String? = null,
val is_private: Boolean? = null,
val avatar: String? = null,
private val avatar: String? = null,
val language: String? = null,
val short_bio: String? = null,
val details: String? = null,
Expand All @@ -26,4 +26,9 @@ data class Profile(
val subscribed_for_news_ru: Boolean = false,
@SerializedName("email_addresses")
var emailAddresses: LongArray?
) : Serializable
) : Serializable {
fun getAvatarPath(): String? {
return avatar;
}

}
8 changes: 6 additions & 2 deletions app/src/main/java/org/stepic/droid/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ data class User(
var short_bio: String? = null,
var first_name: String? = null,
var last_name: String? = null,
var avatar: String? = null,
private val avatar: String? = null,
var level_title: String? = null,
var level: Int = 0,
var score_learn: Int = 0,
var score_teach: Int = 0,
var leaders: IntArray? = null
)
) {
fun getAvatarPath(): String? {
return avatar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.pm.PackageManager;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
Expand All @@ -23,7 +25,10 @@
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.GenericRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.caverock.androidsvg.SVG;
import com.facebook.login.LoginManager;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
Expand Down Expand Up @@ -62,7 +67,9 @@
import org.stepic.droid.util.DateTimeHelper;
import org.stepic.droid.util.ProfileExtensionKt;
import org.stepic.droid.util.ProgressHelper;
import org.stepic.droid.util.svg.GlideSvgRequestFactory;

import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -250,7 +257,7 @@ public void onBackPressed() {
finish();
return;
}
fragmentBackKeyIntercept();
fragmentBackKeyIntercept();//on back when fragment is changed (work for filter feature)
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentById(R.id.frame);
fragmentManager.popBackStackImmediate();
Expand Down Expand Up @@ -408,7 +415,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void setFragment(MenuItem menuItem) {
fragmentBackKeyIntercept(); //on back when fragment is changed (work for filter feature)
Fragment shortLifetimeRef = null;
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.frame);
String tag = null;
Expand Down Expand Up @@ -595,12 +601,22 @@ public void showProfile(@NotNull Profile profile) {
signInProfileView.setVisibility(View.INVISIBLE);
profileImage.setVisibility(View.VISIBLE);
userNameTextView.setVisibility(View.VISIBLE);
Glide
.with(MainFeedActivity.this)
.load(profile.getAvatar())
.asBitmap()
.placeholder(userPlaceholder)
.into(profileImage);
final String avatarPath = profile.getAvatarPath();
if (avatarPath != null && avatarPath.endsWith(AppConstants.SVG_EXTENSION)) {
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> svgRequestBuilder = GlideSvgRequestFactory.create(this, userPlaceholder);
Uri uri = Uri.parse(avatarPath);
svgRequestBuilder
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(uri)
.into(profileImage);
} else {
Glide
.with(MainFeedActivity.this)
.load(avatarPath)
.asBitmap()
.placeholder(userPlaceholder)
.into(profileImage);
}
userNameTextView.setText(ProfileExtensionKt.getFirstAndLastName(profile));
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.HapticFeedbackConstants;
Expand All @@ -13,7 +15,10 @@
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.GenericRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.caverock.androidsvg.SVG;

import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTimeZone;
Expand All @@ -31,7 +36,9 @@
import org.stepic.droid.util.ColorUtil;
import org.stepic.droid.util.DateTimeHelper;
import org.stepic.droid.util.RWLocks;
import org.stepic.droid.util.svg.GlideSvgRequestFactory;

import java.io.InputStream;
import java.util.Locale;

import butterknife.BindString;
Expand Down Expand Up @@ -228,6 +235,8 @@ abstract class GenericViewHolder extends RecyclerView.ViewHolder {
Drawable likeActiveDrawable;
Drawable likeEmptyDrawable;

final GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> svgRequestBuilder;

public GenericViewHolder(final View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
Expand Down Expand Up @@ -267,6 +276,7 @@ public void onClick(View v) {
likeEmptyDrawable.setColorFilter(ColorUtil.INSTANCE.getColorArgb(R.color.material_grey, context), PorterDuff.Mode.MULTIPLY);
likeActiveDrawable.setColorFilter(ColorUtil.INSTANCE.getColorArgb(R.color.stepic_blue_ribbon, context), PorterDuff.Mode.MULTIPLY);

svgRequestBuilder = GlideSvgRequestFactory.create(itemView.getContext(), placeholderUserIcon);
}

private void onClickMoreLayout(int adapterPosition) {
Expand Down Expand Up @@ -338,14 +348,22 @@ final void initialSetUp(CommentAdapterItem needUpdateAndComment) {
@NotNull
String userAvatar = "";
if (user != null) {
userAvatar = user.getAvatar() == null ? "" : user.getAvatar();
userAvatar = user.getAvatarPath() == null ? "" : user.getAvatarPath();
}

Glide.with(MainApplication.getAppContext())
.load(userAvatar)
.asBitmap()
.placeholder(placeholderUserIcon)
.into(userIcon);
if (userAvatar.endsWith(AppConstants.SVG_EXTENSION)) {
Uri uri = Uri.parse(userAvatar);
svgRequestBuilder
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.load(uri)
.into(userIcon);
} else {
Glide.with(MainApplication.getAppContext())
.load(userAvatar)
.asBitmap()
.placeholder(placeholderUserIcon)
.into(userIcon);
}

if (user != null) {
userName.setVisibility(View.VISIBLE);
Expand Down
Loading

0 comments on commit a6443da

Please sign in to comment.