From 18e8ccc0139bcabf31df7fb4323ed9f0195dd390 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 21 Nov 2023 20:38:28 +0300 Subject: [PATCH 01/12] actions: archive `REQUEST_INSTALL_PACKAGES` permission (fixes #2718) (#2719) Co-authored-by: dogi --- app/build.gradle | 4 +- .../myplanet/base/BaseContainerFragment.kt | 77 +++++++++---------- .../myplanet/base/PermissionActivity.java | 12 +-- .../ui/dashboard/DashboardActivity.java | 13 ++-- 4 files changed, 52 insertions(+), 54 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fa5ad27f08..929a74e789 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1152 - versionName "0.11.52" + versionCode 1153 + versionName "0.11.53" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt b/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt index f7f6b077bf..05aadd06ba 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt @@ -1,14 +1,11 @@ package org.ole.planet.myplanet.base -import android.app.Activity import android.content.Context import android.content.DialogInterface import android.content.Intent import android.content.SharedPreferences import android.net.Uri -import android.os.Build import android.os.Bundle -import android.provider.Settings import android.text.TextUtils import android.util.Log import android.view.LayoutInflater @@ -19,7 +16,6 @@ import android.widget.ArrayAdapter import android.widget.Button import android.widget.TextView import android.widget.Toast -import androidx.annotation.RequiresApi import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.AppCompatRatingBar import androidx.core.content.FileProvider @@ -27,7 +23,6 @@ import com.google.gson.JsonObject import io.realm.RealmResults import org.ole.planet.myplanet.MainApplication import org.ole.planet.myplanet.R -import org.ole.planet.myplanet.base.PermissionActivity.hasInstallPermission import org.ole.planet.myplanet.callback.OnHomeItemClickListener import org.ole.planet.myplanet.callback.OnRatingChangeListener import org.ole.planet.myplanet.model.RealmMyLibrary @@ -35,7 +30,13 @@ import org.ole.planet.myplanet.service.UserProfileDbHandler import org.ole.planet.myplanet.service.UserProfileDbHandler.KEY_RESOURCE_DOWNLOAD import org.ole.planet.myplanet.service.UserProfileDbHandler.KEY_RESOURCE_OPEN import org.ole.planet.myplanet.ui.course.AdapterCourses -import org.ole.planet.myplanet.ui.viewer.* +import org.ole.planet.myplanet.ui.viewer.AudioPlayerActivity +import org.ole.planet.myplanet.ui.viewer.CSVViewerActivity +import org.ole.planet.myplanet.ui.viewer.ImageViewerActivity +import org.ole.planet.myplanet.ui.viewer.MarkdownViewerActivity +import org.ole.planet.myplanet.ui.viewer.PDFReaderActivity +import org.ole.planet.myplanet.ui.viewer.TextFileViewerActivity +import org.ole.planet.myplanet.ui.viewer.VideoPlayerActivity import org.ole.planet.myplanet.utilities.FileUtils import org.ole.planet.myplanet.utilities.Utilities import java.io.File @@ -45,9 +46,9 @@ abstract class BaseContainerFragment : BaseResourceFragment() { var rating: TextView? = null var ratingBar: AppCompatRatingBar? = null lateinit var profileDbHandler: UserProfileDbHandler - private val INSTALL_UNKNOWN_SOURCES_REQUEST_CODE = 112 - var hasInstallPermission = hasInstallPermission(MainApplication.context) - private var currentLibrary: RealmMyLibrary? = null +// private val INSTALL_UNKNOWN_SOURCES_REQUEST_CODE = 112 +// var hasInstallPermission = hasInstallPermission(MainApplication.context) +// private var currentLibrary: RealmMyLibrary? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -145,7 +146,6 @@ abstract class BaseContainerFragment : BaseResourceFragment() { } } - @RequiresApi(Build.VERSION_CODES.O) fun checkMoreFileExtensions(extension: String?, items: RealmMyLibrary) { when (extension) { "txt" -> openIntent(items, TextFileViewerActivity::class.java) @@ -158,9 +158,8 @@ abstract class BaseContainerFragment : BaseResourceFragment() { } } - @RequiresApi(Build.VERSION_CODES.O) private fun installApk(items: RealmMyLibrary) { - currentLibrary = items +// currentLibrary = items val directory = File(MainApplication.context.getExternalFilesDir(null).toString() + "/ole" + "/" + items.id) if (!directory.exists()) { if (!directory.mkdirs()) { @@ -184,22 +183,22 @@ abstract class BaseContainerFragment : BaseResourceFragment() { intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK if (intent.resolveActivity(requireActivity().packageManager) != null) { - if (hasInstallPermission(MainApplication.context)) { +// if (hasInstallPermission(MainApplication.context)) { startActivity(intent) - } else { - requestInstallPermission() - } +// } else { +// requestInstallPermission() +// } } else { Utilities.toast(activity,"No app to handle the installation") } } - @RequiresApi(Build.VERSION_CODES.O) - private fun requestInstallPermission() { - val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) - intent.data = Uri.parse("package:" + MainApplication.context.packageName) - startActivityForResult(intent, INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) - } +// @RequiresApi(Build.VERSION_CODES.O) +// private fun requestInstallPermission() { +// val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) +// intent.data = Uri.parse("package:" + MainApplication.context.packageName) +// startActivityForResult(intent, INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) +// } fun openFileType(items: RealmMyLibrary, videotype: String) { val mimetype = Utilities.getMimeType(items.resourceLocalAddress) @@ -299,22 +298,22 @@ abstract class BaseContainerFragment : BaseResourceFragment() { } } - @RequiresApi(Build.VERSION_CODES.O) - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (requestCode == INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) { - if (resultCode == Activity.RESULT_OK) { - if (currentLibrary != null) { - installApk(currentLibrary!!) - currentLibrary = null - } - } else { - Utilities.toast(requireActivity(), getString(R.string.permissions_denied)) - } - } - } +// @RequiresApi(Build.VERSION_CODES.O) +// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { +// super.onActivityResult(requestCode, resultCode, data) +// if (requestCode == INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) { +// if (resultCode == Activity.RESULT_OK) { +// if (currentLibrary != null) { +// installApk(currentLibrary!!) +// currentLibrary = null +// } +// } else { +// Utilities.toast(requireActivity(), getString(R.string.permissions_denied)) +// } +// } +// } - open fun handleBackPressed() { - requireActivity().onBackPressed() - } +// open fun handleBackPressed() { +// requireActivity().onBackPressed() +// } } diff --git a/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.java b/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.java index 2d85f3fcfa..d66d72b49e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.java @@ -28,12 +28,12 @@ public boolean checkPermission(String strPermission) { return result == PackageManager.PERMISSION_GRANTED; } - public static boolean hasInstallPermission(android.content.Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - return context.getPackageManager().canRequestPackageInstalls(); - } - return true; - } +// public static boolean hasInstallPermission(android.content.Context context) { +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { +// return context.getPackageManager().canRequestPackageInstalls(); +// } +// return true; +// } public void checkUsagesPermission() { if (!getUsagesPermission(this)) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.java index 5c550230ae..5b47bf5530 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.java @@ -35,7 +35,6 @@ import com.mikepenz.materialdrawer.model.interfaces.Nameable; import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.base.BaseContainerFragment; import org.ole.planet.myplanet.callback.OnHomeItemClickListener; import org.ole.planet.myplanet.databinding.ActivityDashboardBinding; import org.ole.planet.myplanet.databinding.CustomTabBinding; @@ -429,12 +428,12 @@ public void onBackPressed() { super.onBackPressed(); } - Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container); - if (fragment instanceof BaseContainerFragment) { - ((BaseContainerFragment) fragment).handleBackPressed(); - } else { - super.onBackPressed(); - } +// Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container); +// if (fragment instanceof BaseContainerFragment) { +// ((BaseContainerFragment) fragment).handleBackPressed(); +// } else { +// super.onBackPressed(); +// } } @Override From fde9cde28e5088417deade2916841be54db3bd1b Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 22 Nov 2023 20:00:26 +0300 Subject: [PATCH 02/12] actions: comment `REQUEST_INSTALL_PACKAGES` in manifest (fixes #2720) (#2721) Co-authored-by: dogi --- app/build.gradle | 4 ++-- app/src/main/AndroidManifest.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 929a74e789..0339af50cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1153 - versionName "0.11.53" + versionCode 1154 + versionName "0.11.54" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c2eb9fee5..2b61e7bb08 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,7 +30,7 @@ - + Date: Wed, 22 Nov 2023 20:17:15 +0300 Subject: [PATCH 03/12] settings: more cloud switch stability (fixes #2722) (#2723) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../ole/planet/myplanet/ui/sync/LoginActivity.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0339af50cd..f789ea9e82 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1154 - versionName "0.11.54" + versionCode 1155 + versionName "0.11.55" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java index 00fb468e65..269fccda61 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.java @@ -808,9 +808,16 @@ public void onNothingSelected(AdapterView adapterView) { } }); dialogServerUrlBinding.switchServerUrl.setOnCheckedChangeListener((compoundBtn, b) -> { - settings.edit().putBoolean("switchCloudUrl", b).commit(); - dialogServerUrlBinding.spnCloud.setVisibility(b ? View.VISIBLE : View.GONE); - setUrlAndPin(dialogServerUrlBinding.switchServerUrl.isChecked()); + if (b) { + settings.edit().putBoolean("switchCloudUrl", true).commit(); + dialogServerUrlBinding.spnCloud.setVisibility(View.VISIBLE); + setUrlAndPin(dialogServerUrlBinding.switchServerUrl.isChecked()); + } else { + settings.edit().putBoolean("switchCloudUrl", false).commit(); + dialogServerUrlBinding.spnCloud.setVisibility(View.GONE); + setUrlAndPin(!dialogServerUrlBinding.switchServerUrl.isChecked()); + } + }); serverUrl.addTextChangedListener(new MyTextWatcher(serverUrl)); dialogServerUrlBinding.switchServerUrl.setChecked(settings.getBoolean("switchCloudUrl", false)); From 7aee51528c724dfb0864203851688071f026df63 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:42:23 -0500 Subject: [PATCH 04/12] actions: bump `com.opencsv:opencsv` to 5.9 (fixes #2727) (#2726) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dogi --- app/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f789ea9e82..cc7d256626 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1155 - versionName "0.11.55" + versionCode 1156 + versionName "0.11.56" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -119,7 +119,7 @@ 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.opencsv:opencsv:5.8' + implementation 'com.opencsv:opencsv:5.9' implementation 'com.google.android.exoplayer:exoplayer:2.7.2' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'org.osmdroid:osmdroid-android:6.1.17' From a5425874a766509df6cadff097e3fe4e41f81927 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:34:17 -0500 Subject: [PATCH 05/12] actions: bump `org.jetbrains.kotlin:kotlin-gradle-plugin` to 1.9.21 (fixes #2732) (#2728) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dogi --- app/build.gradle | 4 ++-- build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cc7d256626..55ee24b371 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1156 - versionName "0.11.56" + versionCode 1157 + versionName "0.11.57" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/build.gradle b/build.gradle index 5f3f0ef4c6..2e67f33cd6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.9.20' + ext.kotlin_version = '1.9.21' ext { setup = [ compileSdk: 34, From e29a4701aaa85532cae9b09ea98ee567b7a0a099 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:42:37 -0500 Subject: [PATCH 06/12] actions: bump `org.jetbrains.kotlin:kotlin-bom` to 1.9.21 (fixes #2733) (#2729) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dogi --- app/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 55ee24b371..a931e4e94b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1157 - versionName "0.11.57" + versionCode 1158 + versionName "0.11.58" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -136,7 +136,7 @@ dependencies { implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' implementation 'com.applandeo:material-calendar-view:1.9.0' implementation "androidx.work:work-runtime:2.8.1" - implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.9.20")) + implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.9.21")) } realm { syncEnabled = true From 707a23b634efaeb1fc5e42e39feb466c4bc35602 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 27 Nov 2023 20:23:47 +0300 Subject: [PATCH 07/12] courses: hide previous at test start (fixes #2735) (#2736) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../ole/planet/myplanet/ui/course/TakeCourseFragment.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a931e4e94b..98bfd0c050 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1158 - versionName "0.11.58" + versionCode 1159 + versionName "0.11.59" 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/TakeCourseFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/TakeCourseFragment.java index 53572069d3..0e11d94e06 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/TakeCourseFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/TakeCourseFragment.java @@ -82,7 +82,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { fragmentTakeCourseBinding.viewPagerCourse.setAdapter(new CoursePagerAdapter(getChildFragmentManager(), courseId, RealmCourseStep.getStepIds(mRealm, courseId))); fragmentTakeCourseBinding.viewPagerCourse.addOnPageChangeListener(this); if (fragmentTakeCourseBinding.viewPagerCourse.getCurrentItem() == 0) { - fragmentTakeCourseBinding.previousStep.setTextColor(getResources().getColor(R.color.md_grey_500)); + fragmentTakeCourseBinding.previousStep.setVisibility(View.GONE); } setCourseData(); @@ -178,7 +178,7 @@ private void onClickNext() { private void onClickPrevious() { if (fragmentTakeCourseBinding.viewPagerCourse.getCurrentItem() - 1 == 0) { - fragmentTakeCourseBinding.previousStep.setTextColor(getResources().getColor(R.color.md_grey_500)); + fragmentTakeCourseBinding.previousStep.setVisibility(View.GONE); } } @@ -188,7 +188,7 @@ public void onClick(View view) { case R.id.next_step: if (isValidClickRight()) { fragmentTakeCourseBinding.viewPagerCourse.setCurrentItem(fragmentTakeCourseBinding.viewPagerCourse.getCurrentItem() + 1); - fragmentTakeCourseBinding.previousStep.setTextColor(getResources().getColor(R.color.md_white_1000)); + fragmentTakeCourseBinding.previousStep.setVisibility(View.VISIBLE); } onClickNext(); break; From 63c781aa0c744e4e29021f9d4b9a5acdc2159c74 Mon Sep 17 00:00:00 2001 From: BryanGazali <46581520+BryanGazali@users.noreply.github.com> Date: Tue, 28 Nov 2023 01:53:17 +0800 Subject: [PATCH 08/12] courses: add finish at test end (fixes #1957) (#2734) Co-authored-by: Gideon Okuro Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/course/TakeCourseFragment.java | 8 ++++++++ app/src/main/res/layout/fragment_take_course.xml | 13 +++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 98bfd0c050..7aa8157ed1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1159 - versionName "0.11.59" + versionCode 1160 + versionName "0.11.60" 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/TakeCourseFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/TakeCourseFragment.java index 0e11d94e06..e0433ba4df 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/TakeCourseFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/TakeCourseFragment.java @@ -94,6 +94,7 @@ private void setListeners() { fragmentTakeCourseBinding.nextStep.setOnClickListener(this); fragmentTakeCourseBinding.previousStep.setOnClickListener(this); fragmentTakeCourseBinding.btnRemove.setOnClickListener(this); + fragmentTakeCourseBinding.finishStep.setOnClickListener(this); fragmentTakeCourseBinding.courseProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { @@ -173,12 +174,16 @@ public void onPageScrollStateChanged(int state) { private void onClickNext() { if (fragmentTakeCourseBinding.viewPagerCourse.getCurrentItem() == steps.size()) { fragmentTakeCourseBinding.nextStep.setTextColor(getResources().getColor(R.color.md_grey_500)); + fragmentTakeCourseBinding.nextStep.setVisibility(View.GONE); + fragmentTakeCourseBinding.finishStep.setVisibility(View.VISIBLE); } } private void onClickPrevious() { if (fragmentTakeCourseBinding.viewPagerCourse.getCurrentItem() - 1 == 0) { fragmentTakeCourseBinding.previousStep.setVisibility(View.GONE); + fragmentTakeCourseBinding.nextStep.setVisibility(View.VISIBLE); + fragmentTakeCourseBinding.finishStep.setVisibility(View.GONE); } } @@ -198,6 +203,9 @@ public void onClick(View view) { fragmentTakeCourseBinding.viewPagerCourse.setCurrentItem(fragmentTakeCourseBinding.viewPagerCourse.getCurrentItem() - 1); } break; + case R.id.finish_step: + getActivity().getSupportFragmentManager().popBackStack(); + break; case R.id.btn_remove: addRemoveCourse(); break; diff --git a/app/src/main/res/layout/fragment_take_course.xml b/app/src/main/res/layout/fragment_take_course.xml index 0c61351b27..409bbcfb60 100644 --- a/app/src/main/res/layout/fragment_take_course.xml +++ b/app/src/main/res/layout/fragment_take_course.xml @@ -102,6 +102,19 @@ android:textColor="@color/md_white_1000" app:drawableRightCompat="@drawable/ic_right_arrow" /> + + Date: Mon, 27 Nov 2023 21:14:12 +0300 Subject: [PATCH 09/12] courses: display images as on planet (fixes #2730) (#2731) Co-authored-by: mutugiii Co-authored-by: dogi --- app/build.gradle | 5 ++- .../myplanet/model/RealmCourseStep.java | 26 ++++++++++++ .../planet/myplanet/model/RealmMyCourse.java | 12 ++++++ .../ui/course/CourseDetailFragment.java | 17 +++++++- .../ui/course/CourseStepFragment.java | 40 +++++++++++++++++-- 5 files changed, 94 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7aa8157ed1..5dd8c40f76 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1160 - versionName "0.11.60" + versionCode 1161 + versionName "0.11.61" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -131,6 +131,7 @@ dependencies { implementation 'org.jetbrains:annotations:24.1.0' 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 "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/model/RealmCourseStep.java b/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseStep.java index 6427ebd25e..a3bf9a99e3 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseStep.java +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmCourseStep.java @@ -1,13 +1,19 @@ package org.ole.planet.myplanet.model; +import static org.ole.planet.myplanet.MainApplication.context; + import android.util.Base64; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.ole.planet.myplanet.utilities.JsonUtils; +import org.ole.planet.myplanet.utilities.Utilities; +import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import io.realm.Realm; @@ -31,12 +37,32 @@ public static void insertCourseSteps(String myCoursesID, JsonArray steps, int nu JsonObject stepContainer = steps.get(step).getAsJsonObject(); myCourseStepDB.setStepTitle(JsonUtils.getString("stepTitle", stepContainer)); myCourseStepDB.setDescription(JsonUtils.getString("description", stepContainer)); + String description = JsonUtils.getString("description", stepContainer); + ArrayList links = extractLinks(description); + ArrayList concatenatedLinks = new ArrayList<>(); + + String baseUrl = Utilities.getUrl(); + for (String link : links) { + String concatenatedLink = baseUrl +"/"+ link; + concatenatedLinks.add(concatenatedLink); + } + Utilities.openDownloadService(context, concatenatedLinks); myCourseStepDB.setNoOfResources(JsonUtils.getJsonArray("resources", stepContainer).size()); insertCourseStepsAttachments(myCoursesID, step_id, JsonUtils.getJsonArray("resources", stepContainer), mRealm); insertExam(stepContainer, mRealm, step_id, step + 1, myCoursesID); } } + public static ArrayList extractLinks(String text) { + ArrayList links = new ArrayList<>(); + Pattern pattern = Pattern.compile("!\\[.*?\\]\\((.*?)\\)"); + Matcher matcher = pattern.matcher(text); + while (matcher.find()) { + links.add(matcher.group(1)); + } + return links; + } + private static void insertExam(JsonObject stepContainer, Realm mRealm, String step_id, int i, String myCoursesID) { if (stepContainer.has("exam")) { JsonObject object = stepContainer.getAsJsonObject("exam"); diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmMyCourse.java b/app/src/main/java/org/ole/planet/myplanet/model/RealmMyCourse.java index 7781f76476..b84b057d27 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmMyCourse.java +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmMyCourse.java @@ -1,5 +1,7 @@ package org.ole.planet.myplanet.model; +import static org.ole.planet.myplanet.MainApplication.context; + import android.content.SharedPreferences; import android.text.TextUtils; @@ -49,6 +51,16 @@ public static void insertMyCourses(String userId, JsonObject myCousesDoc, Realm myMyCoursesDB.setCourseTitle(JsonUtils.getString("courseTitle", myCousesDoc)); myMyCoursesDB.setMemberLimit(JsonUtils.getInt("memberLimit", myCousesDoc)); myMyCoursesDB.setDescription(JsonUtils.getString("description", myCousesDoc)); + String description = JsonUtils.getString("description", myCousesDoc); + ArrayList links = RealmCourseStep.extractLinks(description); + ArrayList concatenatedLinks = new ArrayList<>(); + + String baseUrl = Utilities.getUrl(); + for (String link : links) { + String concatenatedLink = baseUrl +"/"+ link; + concatenatedLinks.add(concatenatedLink); + } + Utilities.openDownloadService(context, concatenatedLinks); myMyCoursesDB.setMethod(JsonUtils.getString("method", myCousesDoc)); myMyCoursesDB.setGradeLevel(JsonUtils.getString("gradeLevel", myCousesDoc)); myMyCoursesDB.setSubjectLevel(JsonUtils.getString("subjectLevel", myCousesDoc)); 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 1ef4d39433..bbd0aa45ee 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 @@ -14,6 +14,7 @@ import com.google.gson.JsonObject; +import org.ole.planet.myplanet.MainApplication; import org.ole.planet.myplanet.base.BaseContainerFragment; import org.ole.planet.myplanet.callback.OnRatingChangeListener; import org.ole.planet.myplanet.databinding.FragmentCourseDetailBinding; @@ -28,7 +29,11 @@ import java.util.List; +import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; +import io.noties.markwon.MarkwonPlugin; +import io.noties.markwon.image.ImagesPlugin; +import io.noties.markwon.image.file.FileSchemeHandler; import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Realm; import io.realm.RealmResults; @@ -52,7 +57,16 @@ public void onCreate(@Nullable Bundle savedInstanceState) { id = getArguments().getString("courseId"); } markwon = Markwon.builder(context) + .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()) + ); + } + }) .build(); } @@ -83,7 +97,8 @@ private void setCourseData() { fragmentCourseDetailBinding.method.setText(courses.getMethod()); fragmentCourseDetailBinding.gradeLevel.setText(courses.getGradeLevel()); fragmentCourseDetailBinding.language.setText(courses.getLanguageOfInstruction()); - markwon.setMarkdown(fragmentCourseDetailBinding.description, courses.getDescription()); + String markdownContentWithLocalPaths = CourseStepFragment.prependBaseUrlToImages(courses.getDescription(), "file://" + MainApplication.context.getExternalFilesDir(null) + "/ole/"); + markwon.setMarkdown(fragmentCourseDetailBinding.description, markdownContentWithLocalPaths); 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 f172ff020f..a8444ef703 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 @@ -1,5 +1,6 @@ package org.ole.planet.myplanet.ui.course; +import static org.ole.planet.myplanet.MainApplication.context; import android.os.Bundle; import android.text.Spannable; @@ -9,6 +10,7 @@ import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; @@ -34,8 +36,14 @@ import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; +import io.noties.markwon.MarkwonPlugin; +import io.noties.markwon.image.ImagesPlugin; +import io.noties.markwon.image.file.FileSchemeHandler; import io.noties.markwon.movement.MovementMethodPlugin; import io.realm.Case; import io.realm.Realm; @@ -64,8 +72,17 @@ public void onCreate(@Nullable Bundle savedInstanceState) { stepNumber = getArguments().getInt("stepNumber"); } setUserVisibleHint(false); - markwon = Markwon.builder(MainApplication.context) + markwon = Markwon.builder(context) + .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()) + ); + } + }) .build(); } @@ -120,9 +137,10 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { if (resources != null) fragmentCourseStepBinding.btnResources.setText(getString(R.string.resources) + " ["+ resources.size() + "]"); hideTestIfNoQuestion(); fragmentCourseStepBinding.tvTitle.setText(step.getStepTitle()); - markwon.setMarkdown(fragmentCourseStepBinding.description, step.getDescription()); + String markdownContentWithLocalPaths = prependBaseUrlToImages(step.getDescription(), "file://" + MainApplication.context.getExternalFilesDir(null) + "/ole/"); + markwon.setMarkdown(fragmentCourseStepBinding.description, markdownContentWithLocalPaths); fragmentCourseStepBinding.description.setMovementMethod(LinkMovementMethod.getInstance()); - + if (!RealmMyCourse.isMyCourse(user.getId(), step.getCourseId(), mRealm)) { fragmentCourseStepBinding.btnTakeTest.setVisibility(View.INVISIBLE); } @@ -202,4 +220,20 @@ public void onDownloadComplete() { public void onImageCapture(String fileUri) { } + public static String prependBaseUrlToImages(String markdownContent, String baseUrl) { + String pattern = "!\\[.*?\\]\\((.*?)\\)"; + Pattern imagePattern = Pattern.compile(pattern); + Matcher matcher = imagePattern.matcher(markdownContent); + + StringBuffer result = new StringBuffer(); + while (matcher.find()) { + String relativePath = matcher.group(1); + String modifiedPath = relativePath.replaceFirst("resources/", ""); + String fullUrl = baseUrl + modifiedPath; + matcher.appendReplacement(result, "![](" + fullUrl + ")"); + } + matcher.appendTail(result); + + return result.toString(); + } } From 4153434c89456e151dcd46e30927892e9fabf704 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 28 Nov 2023 20:11:43 +0300 Subject: [PATCH 10/12] login: better new member flow (fixes #2738) (#2739) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/userprofile/BecomeMemberActivity.kt | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5dd8c40f76..d15a95034b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1161 - versionName "0.11.61" + versionCode 1162 + versionName "0.11.62" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/BecomeMemberActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/BecomeMemberActivity.kt index bb82ab2355..1b69869d1e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/BecomeMemberActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/BecomeMemberActivity.kt @@ -263,14 +263,14 @@ class BecomeMemberActivity : BaseActivity() { finish() } + val intent = Intent(this, LoginActivity::class.java) if (guest){ - val intent = Intent(this, LoginActivity::class.java) intent.putExtra("username", username) intent.putExtra("guest", guest) - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(intent) - finish() } + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + startActivity(intent) + finish() } } From 9b7406225c0d07e5e0a8ea8ba3b8dabcc3047b74 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 29 Nov 2023 19:54:09 +0300 Subject: [PATCH 11/12] actions: refactor `download` model to kotlin (fixes #2741) (#2745) Co-authored-by: dogi --- app/build.gradle | 4 +- .../myplanet/base/BaseResourceFragment.java | 12 +- .../callback/ProgressBroadcastReceiver.java | 2 +- .../datamanager/MyDownloadService.java | 26 ++-- .../ole/planet/myplanet/model/Download.java | 118 ------------------ .../org/ole/planet/myplanet/model/Download.kt | 59 +++++++++ .../myplanet/service/AutoSyncWorker.java | 4 +- .../ui/sync/ProcessUserDataActivity.java | 10 +- 8 files changed, 88 insertions(+), 147 deletions(-) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/model/Download.java create mode 100644 app/src/main/java/org/ole/planet/myplanet/model/Download.kt diff --git a/app/build.gradle b/app/build.gradle index d15a95034b..7738ecbb3d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1162 - versionName "0.11.62" + versionCode 1163 + versionName "0.11.63" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseResourceFragment.java b/app/src/main/java/org/ole/planet/myplanet/base/BaseResourceFragment.java index 0a780bf71a..ea3f7169ff 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/BaseResourceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/base/BaseResourceFragment.java @@ -88,10 +88,10 @@ public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(MESSAGE_PROGRESS) && prgDialog != null) { Download download = intent.getParcelableExtra("download"); - if (!download.isFailed()) { + if (!download.failed) { setProgress(download); } else { - DialogUtils.showError(prgDialog, download.getMessage()); + DialogUtils.showError(prgDialog, download.message); } } } @@ -171,11 +171,11 @@ public void notAvailable() { } public void setProgress(Download download) { - prgDialog.setProgress(download.getProgress()); - if (!TextUtils.isEmpty(download.getFileName())) { - prgDialog.setTitle(download.getFileName()); + prgDialog.setProgress(download.progress); + if (!TextUtils.isEmpty(download.fileName)) { + prgDialog.setTitle(download.fileName); } - if (download.isCompleteAll()) { + if (download.completeAll) { DialogUtils.showError(prgDialog, getString(R.string.all_files_downloaded_successfully)); onDownloadComplete(); } diff --git a/app/src/main/java/org/ole/planet/myplanet/callback/ProgressBroadcastReceiver.java b/app/src/main/java/org/ole/planet/myplanet/callback/ProgressBroadcastReceiver.java index d2f0ed25f4..95ef702a13 100644 --- a/app/src/main/java/org/ole/planet/myplanet/callback/ProgressBroadcastReceiver.java +++ b/app/src/main/java/org/ole/planet/myplanet/callback/ProgressBroadcastReceiver.java @@ -20,7 +20,7 @@ public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(MESSAGE_PROGRESS)) { Download download = intent.getParcelableExtra("download"); if (onProgressChange != null) { - onProgressChange.onProgressChange(String.format("Downloading file %d/%d KB\n%d%% Completed.", download.getCurrentFileSize(), download.getTotalFileSize(), download.getProgress())); + onProgressChange.onProgressChange(String.format("Downloading file %d/%d KB\n%d%% Completed.", download.currentFileSize, download.totalFileSize, download.progress)); } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/MyDownloadService.java b/app/src/main/java/org/ole/planet/myplanet/datamanager/MyDownloadService.java index ce7c58adfc..18e76f2162 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/MyDownloadService.java +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/MyDownloadService.java @@ -98,8 +98,8 @@ private void downloadFiled(String message) { notificationManager.notify(0, notificationBuilder.build()); Download d = new Download(); completeAll = false; - d.setFailed(true); - d.setMessage(message); + d.failed = true; + d.message = message; sendIntent(d); stopSelf(); } @@ -119,11 +119,11 @@ private void downloadFile(ResponseBody body) throws IOException { int progress = (int) ((total * 100) / fileSize); long currentTime = System.currentTimeMillis() - startTime; Download download = new Download(); - download.setFileName(FileUtils.getFileNameFromUrl(url)); - download.setTotalFileSize(totalFileSize); + download.fileName = FileUtils.getFileNameFromUrl(url); + download.totalFileSize = totalFileSize; if (currentTime > 1000 * timeCount) { - download.setCurrentFileSize((int) current); - download.setProgress(progress); + download.currentFileSize= (int) current; + download.progress = progress; sendNotification(download); timeCount++; } @@ -151,10 +151,10 @@ private void closeStreams(OutputStream output, InputStream bis) throws IOExcepti } private void sendNotification(Download download) { - download.setFileName("Downloading : " + FileUtils.getFileNameFromUrl(url)); + download.fileName = "Downloading : " + FileUtils.getFileNameFromUrl(url); sendIntent(download); - notificationBuilder.setProgress(100, download.getProgress(), false); - notificationBuilder.setContentText("Downloading file " + download.getCurrentFileSize() + "/" + totalFileSize + " KB"); + notificationBuilder.setProgress(100, download.progress, false); + notificationBuilder.setContentText("Downloading file " + download.currentFileSize + "/" + totalFileSize + " KB"); notificationManager.notify(0, notificationBuilder.build()); } @@ -167,12 +167,12 @@ private void sendIntent(Download download) { private void onDownloadComplete() { if (outputFile.length() > 0) changeOfflineStatus(); Download download = new Download(); - download.setFileName(FileUtils.getFileNameFromUrl(url)); - download.setFileUrl(url); - download.setProgress(100); + download.fileName = FileUtils.getFileNameFromUrl(url); + download.fileUrl = url; + download.progress = 100; if (currentIndex == urls.size() - 1) { completeAll = true; - download.setCompleteAll(true); + download.completeAll = true; } sendIntent(download); notificationManager.cancel(0); diff --git a/app/src/main/java/org/ole/planet/myplanet/model/Download.java b/app/src/main/java/org/ole/planet/myplanet/model/Download.java deleted file mode 100644 index 8730f9752f..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/model/Download.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.ole.planet.myplanet.model; - -import android.os.Parcel; -import android.os.Parcelable; - -public class Download implements Parcelable { - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public Download createFromParcel(Parcel in) { - return new Download(in); - } - - public Download[] newArray(int size) { - return new Download[size]; - } - }; - private String fileName; - private int progress; - private int currentFileSize; - private int totalFileSize; - private boolean completeAll; - private boolean failed; - private String message; - private String fileUrl; - - public Download() {} - - private Download(Parcel in) { - fileName = in.readString(); - progress = in.readInt(); - currentFileSize = in.readInt(); - totalFileSize = in.readInt(); - completeAll = in.readByte() != 0; - failed = in.readByte() != 0; - message = in.readString(); - fileUrl = in.readString(); - } - - public String getFileUrl() { - return fileUrl; - } - - public void setFileUrl(String fileUrl) { - this.fileUrl = fileUrl; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean isCompleteAll() { - return completeAll; - } - - public void setCompleteAll(boolean completeAll) { - this.completeAll = completeAll; - } - - public int getProgress() { - return progress; - } - - public void setProgress(int progress) { - this.progress = progress; - } - - public int getCurrentFileSize() { - return currentFileSize; - } - - public void setCurrentFileSize(int currentFileSize) { - this.currentFileSize = currentFileSize; - } - - public int getTotalFileSize() { - return totalFileSize; - } - - public void setTotalFileSize(int totalFileSize) { - this.totalFileSize = totalFileSize; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - @Override - public int describeContents() { - return 0; - } - - public boolean isFailed() { - return failed; - } - - public void setFailed(boolean failed) { - this.failed = failed; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(fileName); - dest.writeInt(progress); - dest.writeInt(currentFileSize); - dest.writeInt(totalFileSize); - dest.writeByte((byte) (completeAll ? 1 : 0)); - dest.writeByte((byte) (failed ? 1 : 0)); - dest.writeString(message); - dest.writeString(fileUrl); - } -} \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/model/Download.kt b/app/src/main/java/org/ole/planet/myplanet/model/Download.kt new file mode 100644 index 0000000000..45747586ef --- /dev/null +++ b/app/src/main/java/org/ole/planet/myplanet/model/Download.kt @@ -0,0 +1,59 @@ +package org.ole.planet.myplanet.model + +import android.os.Parcel +import android.os.Parcelable + +class Download() : Parcelable { + @JvmField + var fileName: String? = null + @JvmField + var progress: Int = 0 + @JvmField + var currentFileSize: Int = 0 + @JvmField + var totalFileSize: Int = 0 + @JvmField + var completeAll: Boolean = false + @JvmField + var failed: Boolean = false + @JvmField + var message: String? = null + @JvmField + var fileUrl: String? = null + + constructor(parcel: Parcel) : this() { + fileName = parcel.readString() + progress = parcel.readInt() + currentFileSize = parcel.readInt() + totalFileSize = parcel.readInt() + completeAll = parcel.readByte() != 0.toByte() + failed = parcel.readByte() != 0.toByte() + message = parcel.readString() + fileUrl = parcel.readString() + } + + override fun writeToParcel(parcel: Parcel, flags: Int) { + parcel.writeString(fileName) + parcel.writeInt(progress) + parcel.writeInt(currentFileSize) + parcel.writeInt(totalFileSize) + parcel.writeByte(if (completeAll) 1 else 0) + parcel.writeByte(if (failed) 1 else 0) + parcel.writeString(message) + parcel.writeString(fileUrl) + } + + override fun describeContents(): Int { + return 0 + } + + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): Download { + return Download(parcel) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } +} diff --git a/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.java b/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.java index bb0f265fd9..5e7252ce99 100644 --- a/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.java +++ b/app/src/main/java/org/ole/planet/myplanet/service/AutoSyncWorker.java @@ -77,8 +77,8 @@ private boolean isMyServiceRunning(Class serviceClass) { public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(MESSAGE_PROGRESS)) { Download download = intent.getParcelableExtra("download"); - if (!download.isFailed() && download.isCompleteAll()) { - FileUtils.installApk(context, download.getFileUrl()); + if (!download.failed && download.completeAll) { + FileUtils.installApk(context, download.fileUrl); } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.java index 7cc84863c5..f2c3fa6056 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/ProcessUserDataActivity.java @@ -62,15 +62,15 @@ public boolean validateEditText(EditText textField, TextInputLayout textLayout, } public void checkDownloadResult(Download download, ProgressDialog progressDialog) { - if (!download.isFailed()) { - progressDialog.setMessage(getString(R.string.downloading) + download.getProgress() + "% " + getString(R.string.complete)); - if (download.isCompleteAll()) { + if (!download.failed) { + progressDialog.setMessage(getString(R.string.downloading) + download.progress + "% " + getString(R.string.complete)); + if (download.completeAll) { progressDialog.dismiss(); - FileUtils.installApk(this, download.getFileUrl()); + FileUtils.installApk(this, download.fileUrl); } } else { progressDialog.dismiss(); - DialogUtils.showError(progressDialog, download.getMessage()); + DialogUtils.showError(progressDialog, download.message); } } From 0bcf39759a84b864f0ece373ec9524baf49b255f Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 29 Nov 2023 20:05:45 +0300 Subject: [PATCH 12/12] actions: refactor `FeedbackReply` model to kotlin (fixes #2742) (#2746) Co-authored-by: dogi --- app/build.gradle | 4 +-- .../planet/myplanet/model/FeedbackReply.java | 35 ------------------- .../planet/myplanet/model/FeedbackReply.kt | 3 ++ .../ui/feedback/FeedbackDetailActivity.java | 6 ++-- 4 files changed, 8 insertions(+), 40 deletions(-) delete mode 100644 app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.java create mode 100644 app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.kt diff --git a/app/build.gradle b/app/build.gradle index 7738ecbb3d..601fff3c42 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1163 - versionName "0.11.63" + versionCode 1164 + versionName "0.11.64" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.java b/app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.java deleted file mode 100644 index a16c7da244..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.ole.planet.myplanet.model; - -public class FeedbackReply { - String message, user, date; - - public FeedbackReply(String message, String user, String date) { - this.message = message; - this.user = user; - this.date = date; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getDate() { - return date; - } - - public void setDate(String date) { - this.date = date; - } -} diff --git a/app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.kt b/app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.kt new file mode 100644 index 0000000000..4b7b885f37 --- /dev/null +++ b/app/src/main/java/org/ole/planet/myplanet/model/FeedbackReply.kt @@ -0,0 +1,3 @@ +package org.ole.planet.myplanet.model + +class FeedbackReply(@JvmField var message: String, @JvmField var user: String, @JvmField var date: String) diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java index 3cfd0862b9..c7b2708249 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailActivity.java @@ -149,9 +149,9 @@ public ReplyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTyp @Override public void onBindViewHolder(@NonNull ReplyViewHolder holder, int position) { - rowFeedbackReplyBinding.tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(replyList.get(position).getDate()))); - rowFeedbackReplyBinding.tvUser.setText(replyList.get(position).getUser()); - rowFeedbackReplyBinding.tvMessage.setText(replyList.get(position).getMessage()); + rowFeedbackReplyBinding.tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(replyList.get(position).date))); + rowFeedbackReplyBinding.tvUser.setText(replyList.get(position).user); + rowFeedbackReplyBinding.tvMessage.setText(replyList.get(position).message); } @Override