From b1f3bc6a2270e11e194eb75c51ed723307afb9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 26 Jan 2017 13:19:31 +0300 Subject: [PATCH 01/14] update gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aa02d7f7c9..2ed53ce5fb 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,7 @@ build/ #NDK obj/ -maka-vlc/ \ No newline at end of file +maka-vlc/ + +/Google Play Android Developer-e6dc40a00d1f.json +/fastlane/ From 0b90f4f8c215d720e47e27b8d92dacb8d3c11768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 26 Jan 2017 14:42:49 +0300 Subject: [PATCH 02/14] support svg for Instructors & fake data --- app/build.gradle | 2 + .../java/org/stepic/droid/model/Profile.kt | 15 ++++++- .../main/java/org/stepic/droid/model/User.kt | 18 ++++++++- .../droid/ui/adapters/InstructorAdapter.java | 33 +++++++++++++--- .../util/svg/GlideSvgRequestFactory.java | 29 ++++++++++++++ .../org/stepic/droid/util/svg/SvgDecoder.java | 35 +++++++++++++++++ .../droid/util/svg/SvgDrawableTranscoder.java | 28 +++++++++++++ .../util/svg/SvgSoftwareLayerSetter.java | 39 +++++++++++++++++++ 8 files changed, 191 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/org/stepic/droid/util/svg/GlideSvgRequestFactory.java create mode 100644 app/src/main/java/org/stepic/droid/util/svg/SvgDecoder.java create mode 100644 app/src/main/java/org/stepic/droid/util/svg/SvgDrawableTranscoder.java create mode 100644 app/src/main/java/org/stepic/droid/util/svg/SvgSoftwareLayerSetter.java diff --git a/app/build.gradle b/app/build.gradle index 132ddeda3e..e2f67f1e66 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/org/stepic/droid/model/Profile.kt b/app/src/main/java/org/stepic/droid/model/Profile.kt index 438ec0567d..4f19a243c0 100644 --- a/app/src/main/java/org/stepic/droid/model/Profile.kt +++ b/app/src/main/java/org/stepic/droid/model/Profile.kt @@ -1,6 +1,7 @@ package org.stepic.droid.model import com.google.gson.annotations.SerializedName +import org.stepic.droid.BuildConfig import java.io.Serializable data class Profile( @@ -26,4 +27,16 @@ data class Profile( val subscribed_for_news_ru: Boolean = false, @SerializedName("email_addresses") var emailAddresses: LongArray? -) : Serializable +) : Serializable { + fun getSvgImagePath(): String? { + if (BuildConfig.DEBUG) { + return "https://stepik.org/static/frontend/topbar_logo.svg" //fixme: remove debug + } else { + if (avatar != null && avatar.endsWith(".svg", ignoreCase = true)) { + return avatar + } else { + return null + } + } + } +} diff --git a/app/src/main/java/org/stepic/droid/model/User.kt b/app/src/main/java/org/stepic/droid/model/User.kt index a42c5d6f6c..2b2b1f5237 100644 --- a/app/src/main/java/org/stepic/droid/model/User.kt +++ b/app/src/main/java/org/stepic/droid/model/User.kt @@ -1,5 +1,7 @@ package org.stepic.droid.model +import org.stepic.droid.BuildConfig + data class User( var id: Int = 0, var profile: Int = 0, @@ -8,10 +10,22 @@ data class User( var short_bio: String? = null, var first_name: String? = null, var last_name: String? = null, - var avatar: String? = null, + 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 - ) \ No newline at end of file +) { + fun getSvgAvatarPath(): String? { + if (BuildConfig.DEBUG) { + return "https://stepik.org/static/frontend/topbar_logo.svg" //fixme: remove debug + } else { + if (avatar != null && avatar.endsWith(".svg", ignoreCase = true)) { + return avatar + } else { + return null + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java b/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java index 07cc1993d3..5c7ba534d1 100644 --- a/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java +++ b/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java @@ -1,7 +1,10 @@ package org.stepic.droid.ui.adapters; import android.app.Activity; +import android.content.Context; 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.LayoutInflater; @@ -10,7 +13,10 @@ import android.widget.ImageView; 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.stepic.droid.R; import org.stepic.droid.analytic.Analytic; @@ -18,7 +24,9 @@ import org.stepic.droid.core.ScreenManager; import org.stepic.droid.model.User; import org.stepic.droid.util.UserExtensionKt; +import org.stepic.droid.util.svg.GlideSvgRequestFactory; +import java.io.InputStream; import java.util.List; import javax.inject.Inject; @@ -66,11 +74,21 @@ public void onBindViewHolder(InstructorViewHolder holder, int position) { String firstLastNameString = UserExtensionKt.getFirstAndLastName(instructor); holder.firstLastName.setText(firstLastNameString); holder.courseShortBio.setText(instructor.getShort_bio()); - Glide.with(activity) - .load(instructor.getAvatar()) - .asBitmap() - .placeholder(placeholder) - .into(holder.instructorIcon); + String svgAvatarPath = instructor.getSvgAvatarPath(); + if (svgAvatarPath == null) { + Glide.with(activity) + .load(instructor.getAvatar()) + .asBitmap() + .placeholder(placeholder) + .into(holder.instructorIcon); + } else { + Uri uri = Uri.parse(svgAvatarPath); + holder.svgRequestBuilder + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .load(uri) + .into(holder.instructorIcon); + + } } @@ -90,6 +108,8 @@ public class InstructorViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.course_short_bio) TextView courseShortBio; + final GenericRequestBuilder svgRequestBuilder; + public InstructorViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); @@ -99,6 +119,9 @@ public void onClick(View v) { InstructorAdapter.this.onClickInstructor(getAdapterPosition()); } }); + + final Context context = itemView.getContext(); + svgRequestBuilder = GlideSvgRequestFactory.create(context, InstructorAdapter.this.placeholder); } } } diff --git a/app/src/main/java/org/stepic/droid/util/svg/GlideSvgRequestFactory.java b/app/src/main/java/org/stepic/droid/util/svg/GlideSvgRequestFactory.java new file mode 100644 index 0000000000..a9829996cb --- /dev/null +++ b/app/src/main/java/org/stepic/droid/util/svg/GlideSvgRequestFactory.java @@ -0,0 +1,29 @@ +package org.stepic.droid.util.svg; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.PictureDrawable; +import android.net.Uri; + +import com.bumptech.glide.GenericRequestBuilder; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.model.StreamEncoder; +import com.bumptech.glide.load.resource.file.FileToStreamDecoder; +import com.caverock.androidsvg.SVG; + +import java.io.InputStream; + +public class GlideSvgRequestFactory { + public static GenericRequestBuilder create(Context context, Drawable placeholder) { + return Glide.with(context) + .using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class) + .from(Uri.class) + .as(SVG.class) + .transcode(new SvgDrawableTranscoder(), PictureDrawable.class) + .sourceEncoder(new StreamEncoder()) + .cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder())) + .decoder(new SvgDecoder()) + .placeholder(placeholder) + .listener(new SvgSoftwareLayerSetter()); + } +} diff --git a/app/src/main/java/org/stepic/droid/util/svg/SvgDecoder.java b/app/src/main/java/org/stepic/droid/util/svg/SvgDecoder.java new file mode 100644 index 0000000000..5e1316ebb0 --- /dev/null +++ b/app/src/main/java/org/stepic/droid/util/svg/SvgDecoder.java @@ -0,0 +1,35 @@ +package org.stepic.droid.util.svg; + +import com.bumptech.glide.load.ResourceDecoder; +import com.bumptech.glide.load.engine.Resource; +import com.bumptech.glide.load.resource.SimpleResource; +import com.caverock.androidsvg.PreserveAspectRatio; +import com.caverock.androidsvg.SVG; +import com.caverock.androidsvg.SVGParseException; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Decodes an SVG internal representation from an {@link InputStream}. + */ +public class SvgDecoder implements ResourceDecoder { + + @Override + public Resource decode(InputStream source, int width, int height) throws IOException { + try { + SVG svg = SVG.getFromInputStream(source); + svg.setDocumentHeight(height); + svg.setDocumentWidth(width); + svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX); + return new SimpleResource(svg); + } catch (SVGParseException ex) { + throw new IOException("Cannot load SVG from stream", ex); + } + } + + @Override + public String getId() { + return "SvgDecoder.org.stepic.droid.util.svg"; + } +} diff --git a/app/src/main/java/org/stepic/droid/util/svg/SvgDrawableTranscoder.java b/app/src/main/java/org/stepic/droid/util/svg/SvgDrawableTranscoder.java new file mode 100644 index 0000000000..3b2a3a8ccc --- /dev/null +++ b/app/src/main/java/org/stepic/droid/util/svg/SvgDrawableTranscoder.java @@ -0,0 +1,28 @@ +package org.stepic.droid.util.svg; + +import android.graphics.Picture; +import android.graphics.drawable.PictureDrawable; + +import com.bumptech.glide.load.engine.Resource; +import com.bumptech.glide.load.resource.SimpleResource; +import com.bumptech.glide.load.resource.transcode.ResourceTranscoder; +import com.caverock.androidsvg.SVG; + +/** + * Convert the {@link SVG}'s internal representation to an Android-compatible one + * ({@link Picture}). + */ +public class SvgDrawableTranscoder implements ResourceTranscoder { + @Override + public Resource transcode(Resource toTranscode) { + SVG svg = toTranscode.get(); + Picture picture = svg.renderToPicture(); + PictureDrawable drawable = new PictureDrawable(picture); + return new SimpleResource(drawable); + } + + @Override + public String getId() { + return "SvgDrawableTranscoder.org.stepic.droid.util.svg"; + } +} diff --git a/app/src/main/java/org/stepic/droid/util/svg/SvgSoftwareLayerSetter.java b/app/src/main/java/org/stepic/droid/util/svg/SvgSoftwareLayerSetter.java new file mode 100644 index 0000000000..8b30b5598f --- /dev/null +++ b/app/src/main/java/org/stepic/droid/util/svg/SvgSoftwareLayerSetter.java @@ -0,0 +1,39 @@ +package org.stepic.droid.util.svg; + + +import android.annotation.TargetApi; +import android.graphics.drawable.PictureDrawable; +import android.net.Uri; +import android.os.Build; +import android.widget.ImageView; + +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.target.ImageViewTarget; +import com.bumptech.glide.request.target.Target; + +/** + * Listener which updates the {@link ImageView} to be software rendered, because + * {@link com.caverock.androidsvg.SVG SVG}/{@link android.graphics.Picture Picture} can't render on + * a hardware backed {@link android.graphics.Canvas Canvas}. + */ +@TargetApi(Build.VERSION_CODES.HONEYCOMB) +public class SvgSoftwareLayerSetter implements RequestListener { + + @Override + public boolean onException(Exception e, Uri model, Target target, boolean isFirstResource) { + ImageView view = ((ImageViewTarget) target).getView(); + if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { + view.setLayerType(ImageView.LAYER_TYPE_NONE, null); + } + return false; + } + + @Override + public boolean onResourceReady(PictureDrawable resource, Uri model, Target target, boolean isFromMemoryCache, boolean isFirstResource) { + ImageView view = ((ImageViewTarget) target).getView(); + if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) { + view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null); + } + return false; + } +} \ No newline at end of file From 6925a1878b91cc35097b0b2706d7a98cfbc01c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 26 Jan 2017 14:48:17 +0300 Subject: [PATCH 03/14] add svg support at profile fragment --- .../droid/ui/fragments/ProfileFragment.java | 30 +++++++++++++++---- .../org/stepic/droid/util/AppConstants.java | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/stepic/droid/ui/fragments/ProfileFragment.java b/app/src/main/java/org/stepic/droid/ui/fragments/ProfileFragment.java index b96435c8d2..63b706c7f8 100644 --- a/app/src/main/java/org/stepic/droid/ui/fragments/ProfileFragment.java +++ b/app/src/main/java/org/stepic/droid/ui/fragments/ProfileFragment.java @@ -4,6 +4,8 @@ import android.app.Activity; import android.content.Intent; import android.graphics.drawable.Drawable; +import android.graphics.drawable.PictureDrawable; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; @@ -16,7 +18,10 @@ import android.widget.ImageView; 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.DateTime; @@ -36,6 +41,10 @@ import org.stepic.droid.ui.custom.BetterSwitch; import org.stepic.droid.ui.dialogs.TimeIntervalPickerDialogFragment; import org.stepic.droid.ui.util.TimeIntervalUtil; +import org.stepic.droid.util.AppConstants; +import org.stepic.droid.util.svg.GlideSvgRequestFactory; + +import java.io.InputStream; import javax.inject.Inject; @@ -290,12 +299,21 @@ public void showNameImageShortBio(@NotNull UserViewModel userViewModel) { mainInfoRoot.setVisibility(View.VISIBLE); profileName.setText(userViewModel.getFullName()); - Glide - .with(getContext()) - .load(userViewModel.getImageLink()) - .asBitmap() - .placeholder(userPlaceholder) - .into(profileImage); + if (userViewModel.getImageLink() != null && userViewModel.getImageLink().endsWith(AppConstants.SVG_EXTENSION)) { + GenericRequestBuilder svgRequestBuilder = GlideSvgRequestFactory.create(getContext(), userPlaceholder); + Uri uri = Uri.parse(userViewModel.getImageLink()); + svgRequestBuilder + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .load(uri) + .into(profileImage); + + } else { + Glide.with(getContext()) + .load(userViewModel.getImageLink()) + .asBitmap() + .placeholder(userPlaceholder) + .into(profileImage); + } if (userViewModel.getShortBio().isEmpty() && userViewModel.getInformation().isEmpty()) { aboutMeRoot.setVisibility(View.GONE); diff --git a/app/src/main/java/org/stepic/droid/util/AppConstants.java b/app/src/main/java/org/stepic/droid/util/AppConstants.java index f169dfe1bf..267555098e 100644 --- a/app/src/main/java/org/stepic/droid/util/AppConstants.java +++ b/app/src/main/java/org/stepic/droid/util/AppConstants.java @@ -5,6 +5,8 @@ public class AppConstants { + public static final String SVG_EXTENSION = ".svg"; + public static final String USER_LOG_IN = "user_login_clicked"; public static final String KEY_COURSE_BUNDLE = "course"; public static final String KEY_COURSE_LONG_ID = "course_id_key"; From 5b9330e99097103a1cc73a056d84c81fb2fdfcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 26 Jan 2017 15:04:38 +0300 Subject: [PATCH 04/14] support svg for Main feed profile, profile of user, profiles of other users, instructors, comments --- .../java/org/stepic/droid/model/Profile.kt | 15 +--------- .../main/java/org/stepic/droid/model/User.kt | 24 ++++++++-------- .../droid/ui/activities/MainFeedActivity.java | 28 +++++++++++++++---- .../droid/ui/adapters/CommentsAdapter.java | 28 +++++++++++++++---- .../droid/ui/adapters/InstructorAdapter.java | 2 +- 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/org/stepic/droid/model/Profile.kt b/app/src/main/java/org/stepic/droid/model/Profile.kt index 4f19a243c0..438ec0567d 100644 --- a/app/src/main/java/org/stepic/droid/model/Profile.kt +++ b/app/src/main/java/org/stepic/droid/model/Profile.kt @@ -1,7 +1,6 @@ package org.stepic.droid.model import com.google.gson.annotations.SerializedName -import org.stepic.droid.BuildConfig import java.io.Serializable data class Profile( @@ -27,16 +26,4 @@ data class Profile( val subscribed_for_news_ru: Boolean = false, @SerializedName("email_addresses") var emailAddresses: LongArray? -) : Serializable { - fun getSvgImagePath(): String? { - if (BuildConfig.DEBUG) { - return "https://stepik.org/static/frontend/topbar_logo.svg" //fixme: remove debug - } else { - if (avatar != null && avatar.endsWith(".svg", ignoreCase = true)) { - return avatar - } else { - return null - } - } - } -} +) : Serializable diff --git a/app/src/main/java/org/stepic/droid/model/User.kt b/app/src/main/java/org/stepic/droid/model/User.kt index 2b2b1f5237..de606315aa 100644 --- a/app/src/main/java/org/stepic/droid/model/User.kt +++ b/app/src/main/java/org/stepic/droid/model/User.kt @@ -1,7 +1,5 @@ package org.stepic.droid.model -import org.stepic.droid.BuildConfig - data class User( var id: Int = 0, var profile: Int = 0, @@ -17,15 +15,15 @@ data class User( var score_teach: Int = 0, var leaders: IntArray? = null ) { - fun getSvgAvatarPath(): String? { - if (BuildConfig.DEBUG) { - return "https://stepik.org/static/frontend/topbar_logo.svg" //fixme: remove debug - } else { - if (avatar != null && avatar.endsWith(".svg", ignoreCase = true)) { - return avatar - } else { - return null - } - } - } +// fun getSvgAvatarPath(): String? { +// if (BuildConfig.DEBUG) { +// return "https://stepik.org/static/frontend/topbar_logo.svg" //fixme: remove debug +// } else { +// if (avatar != null && avatar.endsWith(".svg", ignoreCase = true)) { +// return avatar +// } else { +// return null +// } +// } +// } } \ No newline at end of file diff --git a/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java b/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java index 49f437a430..db5a76dd70 100644 --- a/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java +++ b/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java @@ -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; @@ -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; @@ -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; @@ -595,12 +602,21 @@ 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); + if (profile.getAvatar() != null && profile.getAvatar().endsWith(AppConstants.SVG_EXTENSION)) { + GenericRequestBuilder svgRequestBuilder = GlideSvgRequestFactory.create(this, userPlaceholder); + Uri uri = Uri.parse(profile.getAvatar()); + svgRequestBuilder + .diskCacheStrategy(DiskCacheStrategy.SOURCE) + .load(uri) + .into(profileImage); + } else { + Glide + .with(MainFeedActivity.this) + .load(profile.getAvatar()) + .asBitmap() + .placeholder(userPlaceholder) + .into(profileImage); + } userNameTextView.setText(ProfileExtensionKt.getFirstAndLastName(profile)); profileImage.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java b/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java index e1645e482b..7f85971b54 100644 --- a/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java +++ b/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java @@ -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; @@ -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; @@ -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; @@ -228,6 +235,8 @@ abstract class GenericViewHolder extends RecyclerView.ViewHolder { Drawable likeActiveDrawable; Drawable likeEmptyDrawable; + final GenericRequestBuilder svgRequestBuilder; + public GenericViewHolder(final View itemView) { super(itemView); ButterKnife.bind(this, itemView); @@ -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) { @@ -341,11 +351,19 @@ final void initialSetUp(CommentAdapterItem needUpdateAndComment) { userAvatar = user.getAvatar() == null ? "" : user.getAvatar(); } - 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); diff --git a/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java b/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java index 5c7ba534d1..b27c26283d 100644 --- a/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java +++ b/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java @@ -74,7 +74,7 @@ public void onBindViewHolder(InstructorViewHolder holder, int position) { String firstLastNameString = UserExtensionKt.getFirstAndLastName(instructor); holder.firstLastName.setText(firstLastNameString); holder.courseShortBio.setText(instructor.getShort_bio()); - String svgAvatarPath = instructor.getSvgAvatarPath(); + String svgAvatarPath = instructor.getAvatar(); if (svgAvatarPath == null) { Glide.with(activity) .load(instructor.getAvatar()) From 33d111c6d1dde6d7312792e58b4fb4c667fdd090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 26 Jan 2017 15:24:32 +0300 Subject: [PATCH 05/14] resolve svg profile and svg more generic --- .../org/stepic/droid/core/ProfilePresenter.kt | 4 ++-- .../java/org/stepic/droid/model/Profile.kt | 15 +++++++++--- .../main/java/org/stepic/droid/model/User.kt | 23 ++++++++----------- .../droid/ui/activities/MainFeedActivity.java | 7 +++--- .../droid/ui/adapters/CommentsAdapter.java | 2 +- .../droid/ui/adapters/InstructorAdapter.java | 4 ++-- .../droid/ui/fragments/CommentsFragment.kt | 3 ++- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/stepic/droid/core/ProfilePresenter.kt b/app/src/main/java/org/stepic/droid/core/ProfilePresenter.kt index dfe2074199..89e580a095 100644 --- a/app/src/main/java/org/stepic/droid/core/ProfilePresenter.kt +++ b/app/src/main/java/org/stepic/droid/core/ProfilePresenter.kt @@ -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, @@ -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, diff --git a/app/src/main/java/org/stepic/droid/model/Profile.kt b/app/src/main/java/org/stepic/droid/model/Profile.kt index 438ec0567d..9d647605f8 100644 --- a/app/src/main/java/org/stepic/droid/model/Profile.kt +++ b/app/src/main/java/org/stepic/droid/model/Profile.kt @@ -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, @@ -25,5 +25,14 @@ data class Profile( val subscribed_for_news_en: Boolean = false, val subscribed_for_news_ru: Boolean = false, @SerializedName("email_addresses") - var emailAddresses: LongArray? -) : Serializable + var emailAddresses: LongArray?, + private val svgAvatar: String? = null +) : Serializable{ + fun getAvatarPath(): String? { + if (svgAvatar != null) { + return svgAvatar; + } else { + return avatar; + } + } +} diff --git a/app/src/main/java/org/stepic/droid/model/User.kt b/app/src/main/java/org/stepic/droid/model/User.kt index de606315aa..8effe7d092 100644 --- a/app/src/main/java/org/stepic/droid/model/User.kt +++ b/app/src/main/java/org/stepic/droid/model/User.kt @@ -8,22 +8,19 @@ data class User( var short_bio: String? = null, var first_name: String? = null, var last_name: String? = null, - val 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 + var leaders: IntArray? = null, + private val svgAvatar: String? = null ) { -// fun getSvgAvatarPath(): String? { -// if (BuildConfig.DEBUG) { -// return "https://stepik.org/static/frontend/topbar_logo.svg" //fixme: remove debug -// } else { -// if (avatar != null && avatar.endsWith(".svg", ignoreCase = true)) { -// return avatar -// } else { -// return null -// } -// } -// } + fun getAvatarPath(): String? { + if (svgAvatar != null) { + return svgAvatar; + } else { + return avatar; + } + } } \ No newline at end of file diff --git a/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java b/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java index db5a76dd70..a24e042293 100644 --- a/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java +++ b/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java @@ -602,9 +602,10 @@ public void showProfile(@NotNull Profile profile) { signInProfileView.setVisibility(View.INVISIBLE); profileImage.setVisibility(View.VISIBLE); userNameTextView.setVisibility(View.VISIBLE); - if (profile.getAvatar() != null && profile.getAvatar().endsWith(AppConstants.SVG_EXTENSION)) { + final String avatarPath = profile.getAvatarPath(); + if (avatarPath != null && avatarPath.endsWith(AppConstants.SVG_EXTENSION)) { GenericRequestBuilder svgRequestBuilder = GlideSvgRequestFactory.create(this, userPlaceholder); - Uri uri = Uri.parse(profile.getAvatar()); + Uri uri = Uri.parse(avatarPath); svgRequestBuilder .diskCacheStrategy(DiskCacheStrategy.SOURCE) .load(uri) @@ -612,7 +613,7 @@ public void showProfile(@NotNull Profile profile) { } else { Glide .with(MainFeedActivity.this) - .load(profile.getAvatar()) + .load(avatarPath) .asBitmap() .placeholder(userPlaceholder) .into(profileImage); diff --git a/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java b/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java index 7f85971b54..8319939b83 100644 --- a/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java +++ b/app/src/main/java/org/stepic/droid/ui/adapters/CommentsAdapter.java @@ -348,7 +348,7 @@ final void initialSetUp(CommentAdapterItem needUpdateAndComment) { @NotNull String userAvatar = ""; if (user != null) { - userAvatar = user.getAvatar() == null ? "" : user.getAvatar(); + userAvatar = user.getAvatarPath() == null ? "" : user.getAvatarPath(); } if (userAvatar.endsWith(AppConstants.SVG_EXTENSION)) { diff --git a/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java b/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java index b27c26283d..b36fc73b3d 100644 --- a/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java +++ b/app/src/main/java/org/stepic/droid/ui/adapters/InstructorAdapter.java @@ -74,10 +74,10 @@ public void onBindViewHolder(InstructorViewHolder holder, int position) { String firstLastNameString = UserExtensionKt.getFirstAndLastName(instructor); holder.firstLastName.setText(firstLastNameString); holder.courseShortBio.setText(instructor.getShort_bio()); - String svgAvatarPath = instructor.getAvatar(); + String svgAvatarPath = instructor.getAvatarPath(); if (svgAvatarPath == null) { Glide.with(activity) - .load(instructor.getAvatar()) + .load(instructor.getAvatarPath()) .asBitmap() .placeholder(placeholder) .into(holder.instructorIcon); diff --git a/app/src/main/java/org/stepic/droid/ui/fragments/CommentsFragment.kt b/app/src/main/java/org/stepic/droid/ui/fragments/CommentsFragment.kt index 296275b8b8..7f83938c09 100644 --- a/app/src/main/java/org/stepic/droid/ui/fragments/CommentsFragment.kt +++ b/app/src/main/java/org/stepic/droid/ui/fragments/CommentsFragment.kt @@ -35,6 +35,7 @@ import org.stepic.droid.ui.util.ContextMenuRecyclerView import org.stepic.droid.util.ColorUtil import org.stepic.droid.util.ProgressHelper import org.stepic.droid.util.StringUtil +import org.stepic.droid.util.getFirstAndLastName import org.stepic.droid.web.DiscussionProxyResponse import org.stepic.droid.web.VoteResponse import retrofit.Callback @@ -187,7 +188,7 @@ class CommentsFragment : FragmentBase(), SwipeRefreshLayout.OnRefreshListener { val commentUser: User? = comment.user?.let { commentManager.getUserById(it) } if (commentUser?.first_name?.isNotBlank() ?: false || commentUser?.last_name?.isNotBlank() ?: false) { - val userNameText: String? = commentUser?.first_name + " " + commentUser?.last_name + val userNameText: String? = commentUser?.getFirstAndLastName() val spannableUserName = SpannableString(userNameText) spannableUserName.setSpan(ForegroundColorSpan(ColorUtil.getColorArgb(R.color.black)), 0, spannableUserName.length, 0) From 06b1b93fc16ef6267a1aa0eeb9d3aeb049b7b7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9C=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Fri, 27 Jan 2017 16:05:42 +0300 Subject: [PATCH 06/14] lock delete auth and delete databases & downloading courses --- .../presenters/PersistentCourseListPresenter.kt | 13 +++++++++++-- .../core/presenters/ProfileMainFeedPresenter.kt | 10 ++++++++-- .../main/java/org/stepic/droid/util/RWLocks.java | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt b/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt index e8d5d00e83..cc342d3812 100644 --- a/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt +++ b/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt @@ -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 @@ -81,10 +82,18 @@ class PersistentCourseListPresenter( if (response != null && response.isSuccess) { val coursesFromInternet = response.body().courses - coursesFromInternet.filterNotNull().forEach { - databaseFacade.addCourse(it, courseType) + try { + 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 diff --git a/app/src/main/java/org/stepic/droid/core/presenters/ProfileMainFeedPresenter.kt b/app/src/main/java/org/stepic/droid/core/presenters/ProfileMainFeedPresenter.kt index 69213e42b0..ea23ce1e67 100644 --- a/app/src/main/java/org/stepic/droid/core/presenters/ProfileMainFeedPresenter.kt +++ b/app/src/main/java/org/stepic/droid/core/presenters/ProfileMainFeedPresenter.kt @@ -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 @@ -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() } diff --git a/app/src/main/java/org/stepic/droid/util/RWLocks.java b/app/src/main/java/org/stepic/droid/util/RWLocks.java index aae29c0028..803fc7e6b3 100644 --- a/app/src/main/java/org/stepic/droid/util/RWLocks.java +++ b/app/src/main/java/org/stepic/droid/util/RWLocks.java @@ -8,4 +8,5 @@ public class RWLocks { public static final ReentrantReadWriteLock DownloadLock = new ReentrantReadWriteLock(); public static final ReentrantReadWriteLock CancelLock = new ReentrantReadWriteLock(); public static final ReentrantReadWriteLock LoadMoreLock = new ReentrantReadWriteLock(); + public static final ReentrantReadWriteLock ClearEnrollmentsLock = new ReentrantReadWriteLock(); } From a1f2b340b845cf00420bb081a8b9ea698ac40671 Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Fri, 27 Jan 2017 16:23:07 +0300 Subject: [PATCH 07/14] add description for locking of loading courses --- .../droid/core/presenters/PersistentCourseListPresenter.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt b/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt index cc342d3812..d1f56d203b 100644 --- a/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt +++ b/app/src/main/java/org/stepic/droid/core/presenters/PersistentCourseListPresenter.kt @@ -83,6 +83,7 @@ class PersistentCourseListPresenter( val coursesFromInternet = response.body().courses 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 { From 14d8621d909f4a8e482da41dd535cf07df755e15 Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Fri, 27 Jan 2017 17:21:54 +0300 Subject: [PATCH 08/14] fix bug, when filters were not applying on loading next page #Apps-932 fixed --- .../org/stepic/droid/base/CoursesDatabaseFragmentBase.java | 4 +++- .../java/org/stepic/droid/ui/activities/MainFeedActivity.java | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/stepic/droid/base/CoursesDatabaseFragmentBase.java b/app/src/main/java/org/stepic/droid/base/CoursesDatabaseFragmentBase.java index 2d65877ec8..499ac23fcc 100644 --- a/app/src/main/java/org/stepic/droid/base/CoursesDatabaseFragmentBase.java +++ b/app/src/main/java/org/stepic/droid/base/CoursesDatabaseFragmentBase.java @@ -70,6 +70,8 @@ public void onCreate(Bundle savedInstanceState) { setHasOptionsMenu(true); setRetainInstance(true); + isScreenCreated = true; + MainApplication.component() .plus(new CourseListModule()) .inject(this); @@ -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(); } @@ -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); diff --git a/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java b/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java index 49f437a430..67a584d461 100644 --- a/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java +++ b/app/src/main/java/org/stepic/droid/ui/activities/MainFeedActivity.java @@ -250,7 +250,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(); @@ -408,7 +408,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; From 12de0e33888df4bd6dabc3c2777485d65eb8f5f4 Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Fri, 27 Jan 2017 17:30:12 +0300 Subject: [PATCH 09/14] remove field for avatar at Profile & User --- .../main/java/org/stepic/droid/model/Profile.kt | 16 ++++++---------- app/src/main/java/org/stepic/droid/model/User.kt | 11 +++-------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/stepic/droid/model/Profile.kt b/app/src/main/java/org/stepic/droid/model/Profile.kt index 9d647605f8..8170343e2e 100644 --- a/app/src/main/java/org/stepic/droid/model/Profile.kt +++ b/app/src/main/java/org/stepic/droid/model/Profile.kt @@ -25,14 +25,10 @@ data class Profile( val subscribed_for_news_en: Boolean = false, val subscribed_for_news_ru: Boolean = false, @SerializedName("email_addresses") - var emailAddresses: LongArray?, - private val svgAvatar: String? = null -) : Serializable{ - fun getAvatarPath(): String? { - if (svgAvatar != null) { - return svgAvatar; - } else { - return avatar; - } - } + var emailAddresses: LongArray? +) : Serializable { + fun getAvatarPath(): String? { + return avatar; + } + } diff --git a/app/src/main/java/org/stepic/droid/model/User.kt b/app/src/main/java/org/stepic/droid/model/User.kt index 8effe7d092..739e147806 100644 --- a/app/src/main/java/org/stepic/droid/model/User.kt +++ b/app/src/main/java/org/stepic/droid/model/User.kt @@ -13,14 +13,9 @@ data class User( var level: Int = 0, var score_learn: Int = 0, var score_teach: Int = 0, - var leaders: IntArray? = null, - private val svgAvatar: String? = null -) { + var leaders: IntArray? = null + ) { fun getAvatarPath(): String? { - if (svgAvatar != null) { - return svgAvatar; - } else { - return avatar; - } + return avatar; } } \ No newline at end of file From 0b21d7cbd6b14a841bd318b937a157657a72fb00 Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Fri, 3 Feb 2017 09:52:52 +0300 Subject: [PATCH 10/14] add extended log for refresh error (see #Apps-941) --- .../org/stepic/droid/analytic/Analytic.java | 2 ++ .../org/stepic/droid/web/RetrofitRESTApi.java | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/stepic/droid/analytic/Analytic.java b/app/src/main/java/org/stepic/droid/analytic/Analytic.java index 6bb6fa23f0..622c87fd10 100644 --- a/app/src/main/java/org/stepic/droid/analytic/Analytic.java +++ b/app/src/main/java/org/stepic/droid/analytic/Analytic.java @@ -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"; } interface Web { diff --git a/app/src/main/java/org/stepic/droid/web/RetrofitRESTApi.java b/app/src/main/java/org/stepic/droid/web/RetrofitRESTApi.java index a1021c97f7..d143a450c7 100644 --- a/app/src/main/java/org/stepic/droid/web/RetrofitRESTApi.java +++ b/app/src/main/java/org/stepic/droid/web/RetrofitRESTApi.java @@ -162,20 +162,38 @@ public Response intercept(Chain chain) throws IOException { .build(); } } else if (isNeededUpdate(response)) { + retrofit.Response authenticationStepicResponse; try { - response = oAuthService.updateToken(config.getRefreshGrantType(), response.getRefresh_token()).execute().body(); + authenticationStepicResponse = oAuthService.updateToken(config.getRefreshGrantType(), response.getRefresh_token()).execute(); + response = authenticationStepicResponse.body(); } catch (Exception e) { analytic.reportError(Analytic.Error.CANT_UPDATE_TOKEN, e); return chain.proceed(newRequest); } if (response == null || !response.isSuccess()) { //it is worst case: + + String message; if (response == null) { message = "response was null"; } else { message = response.toString(); } + + String extendedMessage = ""; + if (authenticationStepicResponse == null) { + extendedMessage = "rawResponse was null"; + } else if (authenticationStepicResponse.isSuccess()) { + extendedMessage = "was success " + authenticationStepicResponse.code(); + } else { + try { + extendedMessage = "failed " + authenticationStepicResponse.code() + " " + authenticationStepicResponse.errorBody().string(); + } catch (Exception ex) { + analytic.reportError(Analytic.Error.FAIL_REFRESH_TOKEN_INLINE_GETTING, ex); + } + } + analytic.reportError(Analytic.Error.FAIL_REFRESH_TOKEN_ONLINE_EXTENDED, new FailRefreshException(extendedMessage)); analytic.reportError(Analytic.Error.FAIL_REFRESH_TOKEN_ONLINE, new FailRefreshException(message)); analytic.reportEvent(Analytic.Web.UPDATE_TOKEN_FAILED); return chain.proceed(newRequest); From 23bc05f3c641a07033ede8dc3181acbc868cb18b Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Fri, 3 Feb 2017 09:54:12 +0300 Subject: [PATCH 11/14] update app version to 1.27 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ec894d1933..c35077e656 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "org.stepic.droid" minSdkVersion minSdk targetSdkVersion 25 - versionCode 118 - versionName "1.26.3" + versionCode 119 + versionName "1.27" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" // Enabling multidex support. multiDexEnabled true From fd021c8066a6d58f1059956c21d3d28d0e16e3aa Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Wed, 8 Feb 2017 13:58:34 +0300 Subject: [PATCH 12/14] remove setting of volume of video to 150 (now is 100 by default) --- app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt b/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt index b3167d4ebc..0ba6b1d7fb 100644 --- a/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt +++ b/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt @@ -214,7 +214,6 @@ class VideoFragment : FragmentBase(), IVLCVout.Callback, VideoWithTimestampView val media = Media(libvlc, uri) mediaPlayer?.media = media media.release() - mediaPlayer?.volume = 150 mediaPlayer?.rate = userPreferences.videoPlaybackRate.rateFloat isEndReached = false From 643e2f85ea4c4f204de53e2b7b62f75fbf57656d Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Wed, 8 Feb 2017 15:52:09 +0300 Subject: [PATCH 13/14] fix bug, when some external players are not opened the video --- .../main/java/org/stepic/droid/core/ScreenManagerImpl.java | 4 ++++ .../main/java/org/stepic/droid/ui/fragments/VideoFragment.kt | 4 ++++ app/src/main/java/org/stepic/droid/util/AppConstants.java | 2 ++ 3 files changed, 10 insertions(+) diff --git a/app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java b/app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java index e41b228a2d..7e47beff8d 100644 --- a/app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java +++ b/app/src/main/java/org/stepic/droid/core/ScreenManagerImpl.java @@ -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 { diff --git a/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt b/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt index 0ba6b1d7fb..1d10237773 100644 --- a/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt +++ b/app/src/main/java/org/stepic/droid/ui/fragments/VideoFragment.kt @@ -29,6 +29,7 @@ import org.stepic.droid.events.audio.AudioFocusLossEvent import org.stepic.droid.preferences.VideoPlaybackRate import org.stepic.droid.ui.custom.TouchDispatchableFrameLayout import org.stepic.droid.util.AndroidDevices +import org.stepic.droid.util.AppConstants import org.stepic.droid.util.TimeUtil import org.videolan.libvlc.IVLCVout import org.videolan.libvlc.LibVLC @@ -209,6 +210,9 @@ class VideoFragment : FragmentBase(), IVLCVout.Callback, VideoWithTimestampView uri = Uri.fromFile(file) } else { uri = Uri.parse(filePath) + if (uri?.scheme == null) { + uri = Uri.parse(AppConstants.FILE_SCHEME_PREFIX + filePath) + } } val media = Media(libvlc, uri) diff --git a/app/src/main/java/org/stepic/droid/util/AppConstants.java b/app/src/main/java/org/stepic/droid/util/AppConstants.java index 267555098e..677a7b13d8 100644 --- a/app/src/main/java/org/stepic/droid/util/AppConstants.java +++ b/app/src/main/java/org/stepic/droid/util/AppConstants.java @@ -5,6 +5,8 @@ public class AppConstants { + + public static final String FILE_SCHEME_PREFIX = "file://"; public static final String SVG_EXTENSION = ".svg"; public static final String USER_LOG_IN = "user_login_clicked"; From 877d2d0d83e86d903a380b3db5915399504c11fe Mon Sep 17 00:00:00 2001 From: Kirlill Makarov Date: Wed, 8 Feb 2017 15:52:40 +0300 Subject: [PATCH 14/14] update version to 1.27.1 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c35077e656..81fd7fb91b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "org.stepic.droid" minSdkVersion minSdk targetSdkVersion 25 - versionCode 119 - versionName "1.27" + versionCode 120 + versionName "1.27.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" // Enabling multidex support. multiDexEnabled true