From 186a7504c128f263fe7558d5270f5789097757c5 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 4 Dec 2023 20:45:42 +0300 Subject: [PATCH] courses: better empty data handling (fixes #2786) (#2787) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/course/AdapterCourses.java | 13 ++++++++++--- .../ui/course/CourseDetailFragment.java | 17 +++++++++++++---- .../main/res/layout/fragment_course_detail.xml | 5 +++++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1aeba4388f..d850904641 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java index 9b8438efca..0d322a33db 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/AdapterCourses.java @@ -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); @@ -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; 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 bbd0aa45ee..5ae4633a12 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 @@ -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; @@ -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) + ""); @@ -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 steps = RealmCourseStep.getSteps(mRealm, courses.getCourseId()); fragmentCourseDetailBinding.stepsList.setLayoutManager(new LinearLayoutManager(getActivity())); diff --git a/app/src/main/res/layout/fragment_course_detail.xml b/app/src/main/res/layout/fragment_course_detail.xml index 103c37a36b..d9f3d0b1c5 100644 --- a/app/src/main/res/layout/fragment_course_detail.xml +++ b/app/src/main/res/layout/fragment_course_detail.xml @@ -112,6 +112,7 @@ @@ -130,6 +131,7 @@ @@ -148,6 +150,7 @@ @@ -166,6 +169,7 @@ @@ -202,6 +206,7 @@