Skip to content

Commit

Permalink
courses: use markwon for all markdowns (fixes #2561) (#2562)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Oct 4, 2023
1 parent ea1c4e4 commit 095f0e4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -36,6 +40,7 @@ public class CourseDetailFragment extends BaseContainerFragment implements OnRat
RealmMyCourse courses;
RealmUserModel user;
String id;
private Markwon markwon;

public CourseDetailFragment() {
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -44,6 +47,7 @@ public class CourseStepFragment extends BaseContainerFragment implements CameraU
List<RealmStepExam> stepExams;
RealmUserModel user;
int stepNumber;
private Markwon markwon;

public CourseStepFragment() {
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -38,12 +49,26 @@ 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();
}
} catch (Exception e) {
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();
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_markdown_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
android:background="@drawable/custom_border"
android:orientation="vertical">

<br.tiagohm.markdownview.MarkdownView
<TextView
android:id="@+id/markdown_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:escapeHtml="false" />
/>

</LinearLayout>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_course_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@
android:layout_height="match_parent"
android:text="@string/description_colon" />

<br.tiagohm.markdownview.MarkdownView
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:escapeHtml="false" />
/>
</LinearLayout>


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_course_step.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:textSize="@dimen/text_size_large"
android:textStyle="bold" />

<br.tiagohm.markdownview.MarkdownView
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down

0 comments on commit 095f0e4

Please sign in to comment.