Skip to content

Commit

Permalink
courses: better empty data handling (fixes #2786) (#2787)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Dec 4, 2023
1 parent 7318f53 commit 186a750
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1179
versionName "0.11.79"
versionCode 1180
versionName "0.11.80"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int
viewHolder.rowCourseBinding.title.setText(courseList.get(position).getCourseTitle());
viewHolder.rowCourseBinding.description.setText(courseList.get(position).getDescription());
markwon.setMarkdown(viewHolder.rowCourseBinding.description, courseList.get(position).getDescription());

viewHolder.rowCourseBinding.gradLevel.setText(context.getString(R.string.grade_level_colon) + courseList.get(position).getGradeLevel());
viewHolder.rowCourseBinding.subjectLevel.setText(context.getString(R.string.subject_level_colon) + courseList.get(position).getSubjectLevel());
setTextViewContent(viewHolder.rowCourseBinding.gradLevel, courseList.get(position).getGradeLevel(), viewHolder.rowCourseBinding.gradLevel, context.getString(R.string.grade_level_colon));
setTextViewContent(viewHolder.rowCourseBinding.subjectLevel, courseList.get(position).getSubjectLevel(), viewHolder.rowCourseBinding.subjectLevel, context.getString(R.string.subject_level_colon));
viewHolder.rowCourseBinding.checkbox.setChecked(selectedItems.contains(courseList.get(position)));
viewHolder.rowCourseBinding.courseProgress.setMax(courseList.get(position).getnumberOfSteps());
displayTagCloud(viewHolder.rowCourseBinding.flexboxDrawable, position);
Expand All @@ -182,6 +181,14 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int
}
}

private void setTextViewContent(TextView textView, String content, View layout, String prefix) {
if (content.isEmpty()) {
layout.setVisibility(View.GONE);
} else {
textView.setText(prefix + content);
}
}

public boolean areAllSelected(){
if (selectedItems.size() != courseList.size()) {
areAllSelected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -93,10 +94,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}

private void setCourseData() {
fragmentCourseDetailBinding.subjectLevel.setText(courses.getSubjectLevel());
fragmentCourseDetailBinding.method.setText(courses.getMethod());
fragmentCourseDetailBinding.gradeLevel.setText(courses.getGradeLevel());
fragmentCourseDetailBinding.language.setText(courses.getLanguageOfInstruction());
setTextViewVisibility(fragmentCourseDetailBinding.subjectLevel, courses.getSubjectLevel(), fragmentCourseDetailBinding.ltSubjectLevel);
setTextViewVisibility(fragmentCourseDetailBinding.method, courses.getMethod(), fragmentCourseDetailBinding.ltMethod);
setTextViewVisibility(fragmentCourseDetailBinding.gradeLevel, courses.getGradeLevel(), fragmentCourseDetailBinding.ltGradeLevel);
setTextViewVisibility(fragmentCourseDetailBinding.language, courses.getLanguageOfInstruction(), fragmentCourseDetailBinding.ltLanguage);
String markdownContentWithLocalPaths = CourseStepFragment.prependBaseUrlToImages(courses.getDescription(), "file://" + MainApplication.context.getExternalFilesDir(null) + "/ole/");
markwon.setMarkdown(fragmentCourseDetailBinding.description, markdownContentWithLocalPaths);
fragmentCourseDetailBinding.noOfExams.setText(RealmStepExam.getNoOfExam(mRealm, id) + "");
Expand All @@ -108,6 +109,14 @@ private void setCourseData() {
setStepsList();
}

private void setTextViewVisibility(TextView textView, String content, View layout) {
if (content.isEmpty()) {
layout.setVisibility(View.GONE);
} else {
textView.setText(content);
}
}

private void setStepsList() {
List<RealmCourseStep> steps = RealmCourseStep.getSteps(mRealm, courses.getCourseId());
fragmentCourseDetailBinding.stepsList.setLayoutManager(new LinearLayoutManager(getActivity()));
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/fragment_course_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/ltSubjectLevel"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand All @@ -130,6 +131,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/ltGradeLevel"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand All @@ -148,6 +150,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/ltLanguage"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand All @@ -166,6 +169,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/ltMethod"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down Expand Up @@ -202,6 +206,7 @@
</LinearLayout>

<LinearLayout
android:id="@+id/ltDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Expand Down

0 comments on commit 186a750

Please sign in to comment.