diff --git a/app/build.gradle b/app/build.gradle index 9b64d87f23..d8a4310265 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1073 - versionName "0.10.73" + versionCode 1074 + versionName "0.10.74" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -120,8 +120,6 @@ dependencies { testImplementation 'junit:junit:4.13.2' implementation 'com.github.bumptech.glide:glide:4.16.0' kapt 'com.github.bumptech.glide:compiler:4.16.0' - implementation 'com.github.tiagohm.MarkdownView:library:0.19.0' - implementation 'com.github.tiagohm.MarkdownView:emoji:0.19.0' implementation 'com.opencsv:opencsv:5.8' implementation 'com.google.android.exoplayer:exoplayer:2.7.2' implementation 'de.hdodenhof:circleimageview:3.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 622899fec9..1ef4d39433 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 @@ -1,6 +1,8 @@ package org.ole.planet.myplanet.ui.course; +import static org.ole.planet.myplanet.MainApplication.context; + import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -26,6 +28,8 @@ import java.util.List; +import io.noties.markwon.Markwon; +import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Realm; import io.realm.RealmResults; @@ -36,6 +40,7 @@ public class CourseDetailFragment extends BaseContainerFragment implements OnRat RealmMyCourse courses; RealmUserModel user; String id; + private Markwon markwon; public CourseDetailFragment() { } @@ -46,6 +51,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) { if (getArguments() != null) { id = getArguments().getString("courseId"); } + markwon = Markwon.builder(context) + .usePlugin(MovementMethodPlugin.none()) + .build(); } @Override @@ -75,7 +83,7 @@ private void setCourseData() { fragmentCourseDetailBinding.method.setText(courses.getMethod()); fragmentCourseDetailBinding.gradeLevel.setText(courses.getGradeLevel()); fragmentCourseDetailBinding.language.setText(courses.getLanguageOfInstruction()); - fragmentCourseDetailBinding.description.loadMarkdown(courses.getDescription()); + markwon.setMarkdown(fragmentCourseDetailBinding.description, courses.getDescription()); fragmentCourseDetailBinding.noOfExams.setText(RealmStepExam.getNoOfExam(mRealm, id) + ""); final RealmResults resources = mRealm.where(RealmMyLibrary.class).equalTo("courseId", id).equalTo("resourceOffline", false).isNotNull("resourceLocalAddress").findAll(); setResourceButton(resources, fragmentCourseDetailBinding.btnResources); 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 081fb9482b..a0c36333e9 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 @@ -9,6 +9,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import org.ole.planet.myplanet.MainApplication; import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.base.BaseContainerFragment; import org.ole.planet.myplanet.databinding.FragmentCourseStepBinding; @@ -30,6 +31,8 @@ import java.util.List; import java.util.UUID; +import io.noties.markwon.Markwon; +import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Case; import io.realm.Realm; import io.realm.RealmResults; @@ -44,6 +47,7 @@ public class CourseStepFragment extends BaseContainerFragment implements CameraU List stepExams; RealmUserModel user; int stepNumber; + private Markwon markwon; public CourseStepFragment() { } @@ -56,6 +60,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) { stepNumber = getArguments().getInt("stepNumber"); } setUserVisibleHint(false); + markwon = Markwon.builder(MainApplication.context) + .usePlugin(MovementMethodPlugin.none()) + .build(); } @Override @@ -107,7 +114,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { if (resources != null) fragmentCourseStepBinding.btnResources.setText(getString(R.string.resources) + " ["+ resources.size() + "]"); hideTestIfNoQuestion(); fragmentCourseStepBinding.tvTitle.setText(step.getStepTitle()); - fragmentCourseStepBinding.description.loadMarkdown(step.getDescription()); + markwon.setMarkdown(fragmentCourseStepBinding.description, step.getDescription()); if (!RealmMyCourse.isMyCourse(user.getId(), step.getCourseId(), mRealm)) { fragmentCourseStepBinding.btnTakeTest.setVisibility(View.INVISIBLE); } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.java index c1467b31db..889cdce55e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/MarkdownViewerActivity.java @@ -7,20 +7,31 @@ import androidx.appcompat.app.AppCompatActivity; +import org.ole.planet.myplanet.MainApplication; import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.databinding.ActivityMarkdownViewerBinding; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import io.noties.markwon.Markwon; +import io.noties.markwon.movement.MovementMethodPlugin; public class MarkdownViewerActivity extends AppCompatActivity { private ActivityMarkdownViewerBinding activityMarkdownViewerBinding; private String fileName; + private Markwon markwon; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activityMarkdownViewerBinding = ActivityMarkdownViewerBinding.inflate(getLayoutInflater()); setContentView(activityMarkdownViewerBinding.getRoot()); + markwon = Markwon.builder(this) + .usePlugin(MovementMethodPlugin.none()) + .build(); renderMarkdownFile(); } @@ -38,7 +49,8 @@ private void renderMarkdownFile() { File markdownFile = new File(basePath, "ole/" + fileName); if (markdownFile.exists()) { - activityMarkdownViewerBinding.markdownView.loadMarkdownFromFile(markdownFile); + String markdownContent = readMarkdownFile(markdownFile); + markwon.setMarkdown(activityMarkdownViewerBinding.markdownView, markdownContent); } else { Toast.makeText(this, getString(R.string.unable_to_load) + fileName, Toast.LENGTH_LONG).show(); } @@ -46,4 +58,17 @@ private void renderMarkdownFile() { e.printStackTrace(); } } + + private String readMarkdownFile(File file) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(file)); + StringBuilder content = new StringBuilder(); + String line; + + while ((line = reader.readLine()) != null) { + content.append(line).append("\n"); + } + + reader.close(); + return content.toString(); + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_markdown_viewer.xml b/app/src/main/res/layout/activity_markdown_viewer.xml index 9d32c2012a..a71153b0d4 100644 --- a/app/src/main/res/layout/activity_markdown_viewer.xml +++ b/app/src/main/res/layout/activity_markdown_viewer.xml @@ -27,11 +27,11 @@ android:background="@drawable/custom_border" android:orientation="vertical"> - + /> diff --git a/app/src/main/res/layout/fragment_course_detail.xml b/app/src/main/res/layout/fragment_course_detail.xml index 87104b6388..488eb080a6 100644 --- a/app/src/main/res/layout/fragment_course_detail.xml +++ b/app/src/main/res/layout/fragment_course_detail.xml @@ -219,11 +219,11 @@ android:layout_height="match_parent" android:text="@string/description_colon" /> - + /> diff --git a/app/src/main/res/layout/fragment_course_step.xml b/app/src/main/res/layout/fragment_course_step.xml index a9db01e97b..aa52cb3ee9 100644 --- a/app/src/main/res/layout/fragment_course_step.xml +++ b/app/src/main/res/layout/fragment_course_step.xml @@ -55,7 +55,7 @@ android:textSize="@dimen/text_size_large" android:textStyle="bold" /> -