From 65ae47bb0ae1f174ed5fdb979c1d7c97b1736eca Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 5 Dec 2023 20:38:28 +0300 Subject: [PATCH] courses: auto image size (fixes #2793) (#2794) Co-authored-by: dogi --- app/build.gradle | 6 ++++-- .../myplanet/ui/course/CourseDetailFragment.java | 11 +++++++++-- .../myplanet/ui/course/CourseStepFragment.java | 13 ++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ea45a70b81..b577d31069 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1181 - versionName "0.11.81" + versionCode 1182 + versionName "0.11.82" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -132,6 +132,8 @@ dependencies { implementation 'com.github.kizitonwose:CalendarView:1.1.0' implementation "io.noties.markwon:editor:4.6.2" implementation "io.noties.markwon:image:4.6.2" + implementation "io.noties.markwon:html:4.6.2" + implementation 'com.caverock:androidsvg-aar:1.4' implementation "androidx.core:core-ktx:1.12.0" implementation "com.github.VaibhavLakhera:Circular-Progress-View:0.1.2" implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseDetailFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseDetailFragment.java index 5ae4633a12..747626fb9b 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseDetailFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseDetailFragment.java @@ -33,8 +33,11 @@ import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonPlugin; +import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.image.ImagesPlugin; import io.noties.markwon.image.file.FileSchemeHandler; +import io.noties.markwon.image.network.NetworkSchemeHandler; +import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler; import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Realm; import io.realm.RealmResults; @@ -58,13 +61,17 @@ public void onCreate(@Nullable Bundle savedInstanceState) { id = getArguments().getString("courseId"); } markwon = Markwon.builder(context) + .usePlugin(HtmlPlugin.create()) .usePlugin(ImagesPlugin.create()) .usePlugin(MovementMethodPlugin.none()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configure(@NonNull MarkwonPlugin.Registry registry) { - registry.require(ImagesPlugin.class, imagesPlugin -> - imagesPlugin.addSchemeHandler(FileSchemeHandler.create()) + registry.require(ImagesPlugin.class, imagesPlugin -> { + imagesPlugin.addSchemeHandler(FileSchemeHandler.create()); + imagesPlugin.addSchemeHandler(NetworkSchemeHandler.create()); + imagesPlugin.addSchemeHandler(OkHttpNetworkSchemeHandler.create()); + } ); } }) diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseStepFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseStepFragment.java index da9d94242c..d2c113b440 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseStepFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseStepFragment.java @@ -42,8 +42,11 @@ import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonPlugin; +import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.image.ImagesPlugin; import io.noties.markwon.image.file.FileSchemeHandler; +import io.noties.markwon.image.network.NetworkSchemeHandler; +import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler; import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Case; import io.realm.Realm; @@ -73,13 +76,17 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } setUserVisibleHint(false); markwon = Markwon.builder(context) + .usePlugin(HtmlPlugin.create()) .usePlugin(ImagesPlugin.create()) .usePlugin(MovementMethodPlugin.none()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configure(@NonNull MarkwonPlugin.Registry registry) { - registry.require(ImagesPlugin.class, imagesPlugin -> - imagesPlugin.addSchemeHandler(FileSchemeHandler.create()) + registry.require(ImagesPlugin.class, imagesPlugin -> { + imagesPlugin.addSchemeHandler(FileSchemeHandler.create()); + imagesPlugin.addSchemeHandler(NetworkSchemeHandler.create()); + imagesPlugin.addSchemeHandler(OkHttpNetworkSchemeHandler.create()); + } ); } }) @@ -230,7 +237,7 @@ public static String prependBaseUrlToImages(String markdownContent, String baseU String relativePath = matcher.group(1); String modifiedPath = relativePath.replaceFirst("resources/", ""); String fullUrl = baseUrl + modifiedPath; - matcher.appendReplacement(result, "![](" + fullUrl + ")"); + matcher.appendReplacement(result, ""); } matcher.appendTail(result);