From 4a1f0ec16081f9302e1e3c3960eb5f4b7408ebdd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 13:59:17 -0400 Subject: [PATCH 01/80] addons: bump `org.osmdroid:osmdroid-android` to 6.1.16 (fixes #2412) (#2400) 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 +++--- app/src/main/res/values/versions.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a4e084a5a2..e5276e380f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1001 - versionName "0.10.1" + versionCode 1002 + versionName "0.10.2" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -118,7 +118,7 @@ dependencies { implementation 'com.opencsv:opencsv:3.9' implementation 'com.google.android.exoplayer:exoplayer:2.7.2' implementation 'de.hdodenhof:circleimageview:3.1.0' - implementation 'org.osmdroid:osmdroid-android:6.1.0' + implementation 'org.osmdroid:osmdroid-android:6.1.16' implementation 'com.github.clans:fab:1.6.4' implementation 'com.borax12.materialdaterangepicker:library:2.0' implementation 'com.nex3z:toggle-button-group:1.1.9' diff --git a/app/src/main/res/values/versions.xml b/app/src/main/res/values/versions.xml index 15134c02e4..806b4987c3 100644 --- a/app/src/main/res/values/versions.xml +++ b/app/src/main/res/values/versions.xml @@ -1,4 +1,4 @@ - 0.10.1 + 0.10.2 From c00aaf3ffa6f6918a39d337e2fe4a9ce9f08450d Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 5 Sep 2023 21:12:47 +0300 Subject: [PATCH 02/80] resources: bump `com.opencsv:opencsv` to 5.8 (fixes #2406) (#2407) Co-authored-by: dogi --- app/build.gradle | 6 +++--- .../planet/myplanet/ui/viewer/CSVViewerActivity.java | 11 +++++++++-- app/src/main/res/values/versions.xml | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e5276e380f..036f6bf3a7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1002 - versionName "0.10.2" + versionCode 1003 + versionName "0.10.3" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -115,7 +115,7 @@ dependencies { kapt 'com.github.bumptech.glide:compiler:4.13.0' implementation 'com.github.tiagohm.MarkdownView:library:0.19.0' implementation 'com.github.tiagohm.MarkdownView:emoji:0.19.0' - implementation 'com.opencsv:opencsv:3.9' + implementation 'com.opencsv:opencsv:5.8' implementation 'com.google.android.exoplayer:exoplayer:2.7.2' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'org.osmdroid:osmdroid-android:6.1.16' diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java index 831dccd3bd..8d9a4f5ae8 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java @@ -7,10 +7,11 @@ import androidx.appcompat.app.AppCompatActivity; +import com.opencsv.CSVParserBuilder; import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.utilities.Utilities; import java.io.File; import java.io.FileReader; @@ -44,6 +45,7 @@ private void renderCSVFile() { mCSVNameTitle.setVisibility(View.VISIBLE); } + try { File csvFile; if (fileName.startsWith("/")) { @@ -53,7 +55,12 @@ private void renderCSVFile() { csvFile = new File(basePath, "ole/" + fileName); } - CSVReader reader = new CSVReader(new FileReader(csvFile), ',', '"'); + CSVReader reader = new CSVReaderBuilder(new FileReader(csvFile)) + .withCSVParser(new CSVParserBuilder() + .withSeparator(',') + .withQuoteChar('"') + .build()) + .build(); List allRows = reader.readAll(); diff --git a/app/src/main/res/values/versions.xml b/app/src/main/res/values/versions.xml index 806b4987c3..e2263de0b2 100644 --- a/app/src/main/res/values/versions.xml +++ b/app/src/main/res/values/versions.xml @@ -1,4 +1,4 @@ - 0.10.2 + 0.10.3 From e63c064ea4c1c679203eede38e79c83b64f17027 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 14:46:04 -0400 Subject: [PATCH 03/80] all: bump `com.google.android.material:material` to 1.9.0 (fixes #2403) (#2324) Signed-off-by: dependabot[bot] Co-authored-by: dogi Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gideon Okuro --- .github/dependabot.yml | 3 ++- app/build.gradle | 6 +++--- app/src/main/res/layout/app_bar_bell.xml | 2 +- app/src/main/res/values/versions.xml | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 629c68ce83..bf665f74f1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,4 +12,5 @@ updates: - package-ecosystem: "gradle" directory: "/" schedule: - interval: "weekly" + interval: "daily" + open-pull-requests-limit: 10 diff --git a/app/build.gradle b/app/build.gradle index 036f6bf3a7..3c525d9c0a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1003 - versionName "0.10.3" + versionCode 1004 + versionName "0.10.4" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -23,7 +23,7 @@ android { } } configurations.all { - resolutionStrategy.force 'com.google.android.material:material:1.0.0' + resolutionStrategy.force 'com.google.android.material:material:1.9.0' } buildTypes { release { diff --git a/app/src/main/res/layout/app_bar_bell.xml b/app/src/main/res/layout/app_bar_bell.xml index 56e994d425..a4763808e0 100644 --- a/app/src/main/res/layout/app_bar_bell.xml +++ b/app/src/main/res/layout/app_bar_bell.xml @@ -37,7 +37,7 @@ + android:layout_height="?android:attr/actionBarSize" /> - 0.10.3 + 0.10.4 From b3b935d5ad03f116a68a8fd77d4f9d1b01a660dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:07:49 -0400 Subject: [PATCH 04/80] actions: bump `actions/checkout` to 4 (fixes #2422) (#2413) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dogi --- .github/workflows/android-build.yml | 2 +- .github/workflows/android-release.yml | 2 +- app/build.gradle | 4 ++-- app/src/main/res/values/versions.xml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android-build.yml b/.github/workflows/android-build.yml index b0db9c546b..c0848fbe01 100644 --- a/.github/workflows/android-build.yml +++ b/.github/workflows/android-build.yml @@ -16,7 +16,7 @@ jobs: BUILD_TOOLS_VERSION: "30.0.2" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: setup JDK 17 uses: actions/setup-java@v3 with: diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml index bdc956d131..a208c98e5f 100644 --- a/.github/workflows/android-release.yml +++ b/.github/workflows/android-release.yml @@ -17,7 +17,7 @@ jobs: steps: - name: checkout repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: set more env run: echo "BRANCHNAME="${GITHUB_REF##*/} >> $GITHUB_ENV diff --git a/app/build.gradle b/app/build.gradle index 3c525d9c0a..925de42069 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1004 - versionName "0.10.4" + versionCode 1005 + versionName "0.10.5" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/res/values/versions.xml b/app/src/main/res/values/versions.xml index 26f4db643b..18076707b3 100644 --- a/app/src/main/res/values/versions.xml +++ b/app/src/main/res/values/versions.xml @@ -1,4 +1,4 @@ - 0.10.4 + 0.10.5 From b22b3de77471e1a3bab7099b730018c478fd44fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:18:30 -0400 Subject: [PATCH 05/80] login: bump `de.rtner:PBKDF2` to 1.1.4 (fixes #2426) (#2414) 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 +++--- app/src/main/res/values/versions.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 925de42069..d14a939f4c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1005 - versionName "0.10.5" + versionCode 1006 + versionName "0.10.6" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -108,7 +108,7 @@ dependencies { implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' - implementation 'de.rtner:PBKDF2:1.1.2' + implementation 'de.rtner:PBKDF2:1.1.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13.2' implementation 'com.github.bumptech.glide:glide:4.13.0' diff --git a/app/src/main/res/values/versions.xml b/app/src/main/res/values/versions.xml index 18076707b3..9ae7079b21 100644 --- a/app/src/main/res/values/versions.xml +++ b/app/src/main/res/values/versions.xml @@ -1,4 +1,4 @@ - 0.10.5 + 0.10.6 From db2342e9961118bafd54b5e7f47ad13a04d095de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:30:35 -0400 Subject: [PATCH 06/80] sync: bump `io.realm:realm-gradle-plugin` to 10.16.1 (fixes #2428) (#2421) 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 ++-- app/src/main/res/values/versions.xml | 2 +- build.gradle | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d14a939f4c..36e564c9b2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1006 - versionName "0.10.6" + versionCode 1007 + versionName "0.10.7" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/res/values/versions.xml b/app/src/main/res/values/versions.xml index 9ae7079b21..bd850e03eb 100644 --- a/app/src/main/res/values/versions.xml +++ b/app/src/main/res/values/versions.xml @@ -1,4 +1,4 @@ - 0.10.6 + 0.10.7 diff --git a/build.gradle b/build.gradle index f85dee803b..e76a82611a 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:8.0.0' - classpath "io.realm:realm-gradle-plugin:10.15.1" + classpath "io.realm:realm-gradle-plugin:10.16.1" classpath "com.google.dagger:hilt-android-gradle-plugin:2.44" classpath 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' From 8d55822cb167b36303c06ea64077526aafa18776 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 6 Sep 2023 20:22:17 +0300 Subject: [PATCH 07/80] actions: refactor `AndroidManifest.xml` (fixes #2423) (#2427) Co-authored-by: dogi --- app/build.gradle | 4 ++-- app/src/main/AndroidManifest.xml | 3 +-- app/src/main/res/values/versions.xml | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 36e564c9b2..77cc109fe0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1007 - versionName "0.10.7" + versionCode 1008 + versionName "0.10.8" 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 8c604226b2..ff378b97f0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> - 0.10.7 + 0.10.8 From aa1f9984a3aa774d9734ce278bda8a2aa7ab9871 Mon Sep 17 00:00:00 2001 From: dogi Date: Wed, 6 Sep 2023 14:01:53 -0400 Subject: [PATCH 08/80] actions: bump `versionName` only in `build.gradle` (fixes #2429) (#2430) --- .gitignore | 3 +++ app/build.gradle | 16 ++++++++++++++-- app/src/main/res/values/versions.xml | 4 ---- 3 files changed, 17 insertions(+), 6 deletions(-) delete mode 100644 app/src/main/res/values/versions.xml diff --git a/.gitignore b/.gitignore index 1a1290a852..72882161a7 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ assets # Android Studio captures folder captures + +# version.xml out of build.gradle +app/src/main/res/values/versions.xml diff --git a/app/build.gradle b/app/build.gradle index 77cc109fe0..bcd2032d70 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1008 - versionName "0.10.8" + versionCode 1009 + versionName "0.10.9" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -65,6 +65,18 @@ android { } } +task generateVersionsXml { + def versionName = android.defaultConfig.versionName + doLast { + def versionsXmlFile = file('src/main/res/values/versions.xml') + versionsXmlFile.text = """ + + $versionName +""" + } +} +preBuild.dependsOn generateVersionsXml + repositories { mavenCentral() jcenter() diff --git a/app/src/main/res/values/versions.xml b/app/src/main/res/values/versions.xml deleted file mode 100644 index 217675a3e1..0000000000 --- a/app/src/main/res/values/versions.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 0.10.8 - From 4885dbd995eadfa2699ded0cba1bd5b06d1c9dc7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:07:34 -0400 Subject: [PATCH 09/80] actions: bump `com.google.dagger:hilt-android-gradle-plugin` to 2.48 (fixes #2432) (#2416) 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 bcd2032d70..8374918ccf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1009 - versionName "0.10.9" + versionCode 1010 + versionName "0.10.10" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/build.gradle b/build.gradle index e76a82611a..31d1363d13 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:8.0.0' classpath "io.realm:realm-gradle-plugin:10.16.1" - classpath "com.google.dagger:hilt-android-gradle-plugin:2.44" + classpath "com.google.dagger:hilt-android-gradle-plugin:2.48" classpath 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" From 372dfd95729d9db2965ba5ea6fb2906a5aeb9547 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 7 Sep 2023 18:19:10 +0300 Subject: [PATCH 10/80] resources: no empty rating submission (fixes #2391) (#2393) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/rating/RatingFragment.java | 16 +++++++++++++++- app/src/main/res/layout/fragment_rating.xml | 8 ++++++++ app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-ne/strings.xml | 1 + app/src/main/res/values-so/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8374918ccf..ca66fe9031 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1010 - versionName "0.10.10" + versionCode 1011 + versionName "0.10.11" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/rating/RatingFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/rating/RatingFragment.java index e04f02a2a9..0674bd7df4 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/rating/RatingFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/rating/RatingFragment.java @@ -13,6 +13,7 @@ import com.google.gson.Gson; +import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.callback.OnRatingChangeListener; import org.ole.planet.myplanet.databinding.FragmentRatingBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; @@ -83,8 +84,21 @@ public void onActivityCreated(Bundle savedInstanceState) { fragmentRatingBinding.ratingBar.setRating(previousRating.getRate()); fragmentRatingBinding.etComment.setText(previousRating.getComment()); } + fragmentRatingBinding.ratingBar.setOnRatingBarChangeListener((ratingBar, rating, fromUser) -> { + if (fromUser) { + fragmentRatingBinding.ratingError.setVisibility(View.GONE); + } + }); + fragmentRatingBinding.btnCancel.setOnClickListener(view -> dismiss()); - fragmentRatingBinding.btnSubmit.setOnClickListener(view -> saveRating()); + fragmentRatingBinding.btnSubmit.setOnClickListener(view -> { + if(fragmentRatingBinding.ratingBar.getRating() == 0.0){ + fragmentRatingBinding.ratingError.setVisibility(View.VISIBLE); + fragmentRatingBinding.ratingError.setText(getString(R.string.kindly_give_a_rating)); + } else { + saveRating(); + } + }); } private void saveRating() { diff --git a/app/src/main/res/layout/fragment_rating.xml b/app/src/main/res/layout/fragment_rating.xml index 2c10e76005..078efa4ed4 100644 --- a/app/src/main/res/layout/fragment_rating.xml +++ b/app/src/main/res/layout/fragment_rating.xml @@ -24,6 +24,14 @@ android:stepSize="1" android:theme="@style/RatingBar" /> + مرات الوقت AI Chat + يرجى التقييم \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f6173d99a0..67d72e430f 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -943,5 +943,6 @@ veces tiempo AI Chat + Por favor, dé una calificación diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 75a6a19b30..3762516539 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -943,5 +943,6 @@ fois temps AI Chat + Veuillez donner une note diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index d663193d74..c01f7acdf3 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -943,5 +943,6 @@ पल्टीहरू समय AI Chat + कृपया मूल्याङ्कन दिनुहोस् \ No newline at end of file diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index ea8994119e..6aea0b8f54 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -932,5 +932,6 @@ magaalada waqtiga AI Chat + si naxariis leh u bixi rating \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5985179a0..6f9ac8d1f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1032,5 +1032,6 @@ times time AI Chat + Kindly give a rating From 80645869daa7f01e21af7763b9ac6945c0109e11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:18:13 -0400 Subject: [PATCH 11/80] community: bump `com.applandeo:material-calendar-view` to 1.7.0 (fixes #2437) (#2435) 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 ca66fe9031..140bd886e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1011 - versionName "0.10.11" + versionCode 1012 + versionName "0.10.12" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -142,7 +142,7 @@ dependencies { implementation "androidx.core:core-ktx:1.10.1" implementation "com.github.VaibhavLakhera:Circular-Progress-View:0.1.2" implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' - implementation 'com.applandeo:material-calendar-view:1.4.0' + implementation 'com.applandeo:material-calendar-view:1.7.0' implementation "androidx.work:work-runtime:2.8.1" implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")) } From 9f0687c9802f1f3ef836bd6bdbd4aa77b21797d4 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 7 Sep 2023 19:30:20 +0300 Subject: [PATCH 12/80] resources: record, store and add video (fixes #2377) (#2397) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/library/AddResourceFragment.java | 74 ++++++++++++------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 140bd886e7..c1d2203082 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1012 - versionName "0.10.12" + versionCode 1013 + versionName "0.10.13" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java index e6b21010c1..15c3c4d149 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java @@ -2,10 +2,14 @@ import static android.app.Activity.RESULT_OK; +import android.app.Activity; import android.app.Dialog; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; @@ -52,6 +56,7 @@ public class AddResourceFragment extends BottomSheetDialogFragment { FloatingActionButton floatingActionButton; AudioRecorderService audioRecorderService; File output; + private Uri videoUri; public AddResourceFragment() { } @@ -151,7 +156,7 @@ public void onRecordStarted() { public void onRecordStopped(String outputFile) { tvTime.setText(""); dialog.dismiss(); - startIntent(outputFile); +// startIntent(outputFile); floatingActionButton.setImageResource(R.drawable.ic_mic); } @@ -164,22 +169,26 @@ public void onError(String error) { private void dispatchTakeVideoIntent() { Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); - Uri videoUri = FileProvider.getUriForFile(getActivity(), "org.ole.planet.myplanet.fileprovider", createVideoFile()); + videoUri = createVideoFileUri(); // Assign the Uri to videoURI takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri); - takeVideoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); - if (takeVideoIntent.resolveActivity(getActivity().getPackageManager()) != null) { + if (takeVideoIntent.resolveActivity(requireActivity().getPackageManager()) != null) { startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE); } } + private Uri createVideoFileUri() { + ContentValues values = new ContentValues(); + values.put(MediaStore.Video.Media.TITLE, "Video_" + UUID.randomUUID().toString()); + values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4"); - private File createVideoFile() { - File videoDir = new File(Utilities.SD_PATH + "/video/"); - videoDir.mkdirs(); - File videoFile = new File(videoDir, UUID.randomUUID().toString() + ".mp4"); - return videoFile; - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + values.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_MOVIES + "/ole/video"); + } + videoUri = requireActivity().getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values); + + return videoUri; + } public void takePhoto() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); @@ -199,32 +208,47 @@ public void takePhoto() { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { - Uri url = null; - String path = ""; + Uri uri = null; +// String path = ""; if (requestCode == REQUEST_CAPTURE_PICTURE) { - if (output != null) { - url = Uri.fromFile(output); - path = url.getPath(); - } - } else { - url = data.getData(); - path = FileUtils.getRealPathFromURI(getActivity(), url); - if (TextUtils.isEmpty(path)) { - path = FileUtils.getImagePath(getActivity(), url); - } +// if (output != null) { +// url = Uri.fromFile(output); +// path = url.getPath(); +// } + } else if (requestCode == REQUEST_VIDEO_CAPTURE) { + uri = videoUri; } - startIntent(path); + startIntent(uri, requestCode); } } - private void startIntent(String path) { - if (!TextUtils.isEmpty(path)) { + private void startIntent(Uri uri, int requestCode) { + String path = null; + + if (requestCode == REQUEST_CAPTURE_PICTURE || requestCode == REQUEST_VIDEO_CAPTURE) { + path = getRealPathFromUri(uri); + } + + if (path != null && !path.isEmpty()) { addResource(path); } else { Utilities.toast(getActivity(), getString(R.string.invalid_resource_url)); } } + private String getRealPathFromUri(Uri uri) { + String[] projection = {MediaStore.Images.Media.DATA}; + + try (Cursor cursor = requireActivity().getContentResolver().query(uri, projection, null, null, null)) { + if (cursor != null && cursor.moveToFirst()) { + int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + return cursor.getString(columnIndex); + } + } + + return ""; + } + private void addResource(String path) { if (type == 0) { startActivity(new Intent(getActivity(), AddResourceActivity.class).putExtra("resource_local_url", path)); From c906218a0a4f3f50413d386c18ca8f49b7bef31a Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 7 Sep 2023 19:42:43 +0300 Subject: [PATCH 13/80] courses: only one naming convention (fixes #2340) (#2431) Co-authored-by: dogi --- app/build.gradle | 4 +- .../datamanager/FileUploadService.java | 4 +- .../myplanet/model/RealmSubmitPhotos.java | 73 +++++++++---------- .../myplanet/ui/exam/BaseExamFragment.java | 14 ++-- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c1d2203082..b8254df1d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1013 - versionName "0.10.13" + versionCode 1014 + versionName "0.10.14" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/FileUploadService.java b/app/src/main/java/org/ole/planet/myplanet/datamanager/FileUploadService.java index afa0261634..861ea41c81 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/FileUploadService.java +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/FileUploadService.java @@ -39,8 +39,8 @@ public void uploadAttachment(String id, String rev, RealmMyLibrary personal, Suc } public void uploadAttachment(String id, String rev, RealmSubmitPhotos personal, SuccessListener listener) { - File f = new File(personal.getPhoto_location()); - String name = FileUtils.getFileNameFromUrl(personal.getPhoto_location()); + File f = new File(personal.getPhotoLocation()); + String name = FileUtils.getFileNameFromUrl(personal.getPhotoLocation()); upload_doc(id, rev, "%s/submissions/%s/%s", f, name, listener); } diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmitPhotos.java b/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmitPhotos.java index c3fd683cb4..e9cc1f30df 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmitPhotos.java +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmitPhotos.java @@ -9,53 +9,52 @@ public class RealmSubmitPhotos extends RealmObject { private String id; private String _id; private String _rev; - private String submission_id; - private String course_id; - private String Exam_id; - private String member_id; + private String submissionId; + private String courseId; + private String ExamId; + private String memberId; private String date; - private String unique_id; - private String photo_location; + private String uniqueId; + private String photoLocation; private boolean uploaded; public void setId(String id) { this.id = id; } - public String getId() { return id; } - public void setSubmission_id(String submission_id) { - this.submission_id = submission_id; + public void setSubmissionId(String submissionId) { + this.submissionId = submissionId; } - public String getSubmission_id() { - return submission_id; + public String getSubmissionId() { + return submissionId; } - public void setCourse_id(String course_id) { - this.course_id = course_id; + public void setCourseId(String courseId) { + this.courseId = courseId; } - public String getCourse_id() { - return course_id; + public String getCourseId() { + return courseId; } - public void setExam_id(String exam_id) { - Exam_id = exam_id; + public void setExamId(String examId) { + ExamId = examId; } - public String getExam_id() { - return Exam_id; + public String getExamId() { + return ExamId; } - public void setMember_id(String member_id) { - this.member_id = member_id; + public void setMemberId(String memberId) { + this.memberId = memberId; } - public String getMember_id() { - return member_id; + public String getMemberId() { + return memberId; } public void setDate(String date) { @@ -66,20 +65,20 @@ public String getDate() { return date; } - public void setUnique_id(String unique_id) { - this.unique_id = unique_id; + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; } - public String getUnique_id() { - return unique_id; + public String getUniqueId() { + return uniqueId; } - public void setPhoto_location(String photo_location) { - this.photo_location = photo_location; + public void setPhotoLocation(String photo_location) { + this.photoLocation = photoLocation; } - public String getPhoto_location() { - return photo_location; + public String getPhotoLocation() { + return photoLocation; } public void set_id(String _id) { @@ -122,14 +121,14 @@ public boolean getUploaded() { public static JsonObject serializeRealmSubmitPhotos(RealmSubmitPhotos submit) { JsonObject obj = new JsonObject(); obj.addProperty("id", submit.getId()); - obj.addProperty("submission_id", submit.getSubmission_id()); + obj.addProperty("submissionId", submit.getSubmissionId()); obj.addProperty("type", "photo"); - obj.addProperty("course_id", submit.getCourse_id()); - obj.addProperty("exam_id", submit.getExam_id()); - obj.addProperty("member_id", submit.getMember_id()); + obj.addProperty("courseId", submit.getCourseId()); + obj.addProperty("examId", submit.getExamId()); + obj.addProperty("memberId", submit.getMemberId()); obj.addProperty("date", submit.getDate()); - obj.addProperty("mac_address", submit.getUnique_id()); - obj.addProperty("photo_location", submit.getPhoto_location()); + obj.addProperty("macAddress", submit.getUniqueId()); + obj.addProperty("photoLocation", submit.getPhotoLocation()); return obj; } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/exam/BaseExamFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/exam/BaseExamFragment.java index 7d68c965cb..6366f437ba 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/exam/BaseExamFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/exam/BaseExamFragment.java @@ -181,15 +181,15 @@ public void addAnswer(CompoundButton compoundButton) { public void insert_into_submitPhotos(String submit_id) { mRealm.beginTransaction(); RealmSubmitPhotos submit = mRealm.createObject(RealmSubmitPhotos.class, UUID.randomUUID().toString()); - submit.setSubmission_id(submit_id); - submit.setExam_id(exam.getId()); - submit.setCourse_id(exam.getCourseId()); - submit.setMember_id(user.getId()); + submit.setSubmissionId(submit_id); + submit.setExamId(exam.getId()); + submit.setCourseId(exam.getCourseId()); + submit.setMemberId(user.getId()); submit.setDate(date); - submit.setUnique_id(unique_id); - submit.setPhoto_location(photo_path); + submit.setUniqueId(unique_id); + submit.setPhotoLocation(photo_path); submit.setUploaded(false); - Utilities.log(submit.getPhoto_location()); + Utilities.log(submit.getPhotoLocation()); Utilities.log("insert_into_submitPhotos"); mRealm.commitTransaction(); } From df14a51b0a00f97017f09f943ab05db9688cfcce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:54:36 -0400 Subject: [PATCH 14/80] actions: bump `com.github.bumptech.glide:glide` to 4.16.0 (fixes #2438) (#2417) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dogi --- app/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b8254df1d5..e6d762545f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1014 - versionName "0.10.14" + versionCode 1015 + versionName "0.10.15" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -123,8 +123,8 @@ dependencies { implementation 'de.rtner:PBKDF2:1.1.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13.2' - implementation 'com.github.bumptech.glide:glide:4.13.0' - kapt 'com.github.bumptech.glide:compiler:4.13.0' + 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' From 344c5568cb62324c707d29c3007dd37d7f53c2ba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:07:31 -0400 Subject: [PATCH 15/80] actions: bump `com.firebase:firebase-jobdispatcher` to 0.8.6 (fixes #2439) (#2418) 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 e6d762545f..2fb4bc823b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1015 - versionName "0.10.15" + versionCode 1016 + versionName "0.10.16" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -116,7 +116,7 @@ dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' implementation 'com.google.android:flexbox:1.0.0' implementation 'com.squareup.picasso:picasso:2.71828' - implementation 'com.firebase:firebase-jobdispatcher:0.8.5' + implementation 'com.firebase:firebase-jobdispatcher:0.8.6' implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' From 714db45a5a59e13ec3dbed6c2dc59e7b7cf72edd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 05:34:57 -0400 Subject: [PATCH 16/80] actions: bump `com.google.code.gson:gson` to 2.10.1 (fixes #2445) (#2420) 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 2fb4bc823b..2f1465d767 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1016 - versionName "0.10.16" + versionCode 1017 + versionName "0.10.17" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -89,7 +89,7 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.afollestad.material-dialogs:commons:0.9.6.0' - implementation 'com.google.code.gson:gson:2.10' + implementation 'com.google.code.gson:gson:2.10.1' implementation 'org.codehaus.jackson:jackson-mapper-asl:1.5.0' implementation('com.mikepenz:materialdrawer:6.1.1@aar') { transitive = true From 747f62922d05546b45425478940b28ab9c5dd30b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:06:58 -0400 Subject: [PATCH 17/80] actions: bump `com.google.android:flexbox` to 2.0.1 (fixes #2447) (#2444) 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 2f1465d767..a7aa523717 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1017 - versionName "0.10.17" + versionCode 1018 + versionName "0.10.18" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -114,7 +114,7 @@ dependencies { implementation 'com.mikepenz:crossfadedrawerlayout:1.0.1@aar' implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' - implementation 'com.google.android:flexbox:1.0.0' + implementation 'com.google.android:flexbox:2.0.1' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.firebase:firebase-jobdispatcher:0.8.6' implementation 'androidx.cardview:cardview:1.0.0' From bd2832856be4432fc3dfeba5f2d40f8125122fb0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:20:17 -0400 Subject: [PATCH 18/80] actions: bump `androidx.annotation:annotation` to 1.7.0 (fixes #2448) (#2443) 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 a7aa523717..ec646eb5be 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1018 - versionName "0.10.18" + versionCode 1019 + versionName "0.10.19" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -96,7 +96,7 @@ dependencies { } implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.recyclerview:recyclerview:1.3.0' - implementation 'androidx.annotation:annotation:1.6.0' + implementation 'androidx.annotation:annotation:1.7.0' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.exifinterface:exifinterface:1.3.6' implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar' From 7671178e41bb6f8a4e0fb78a3a570c4e5d9c6635 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:55:30 -0400 Subject: [PATCH 19/80] actions: bump `org.codehaus.jackson:jackson-mapper-asl` to 1.9.13-atlassian-2 (fixes #2449) (#2441) 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 ec646eb5be..cda593638e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1019 - versionName "0.10.19" + versionCode 1020 + versionName "0.10.20" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -90,7 +90,7 @@ dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.afollestad.material-dialogs:commons:0.9.6.0' implementation 'com.google.code.gson:gson:2.10.1' - implementation 'org.codehaus.jackson:jackson-mapper-asl:1.5.0' + implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13-atlassian-2' implementation('com.mikepenz:materialdrawer:6.1.1@aar') { transitive = true } From b5f942b34aed8748904e9e4b7ede54eac47ae87f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:39:23 -0400 Subject: [PATCH 20/80] actions: bump `com.mikepenz:google-material-typeface` to 4.0.0.2-kotlin (fixes #2460) (#2452) 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 cda593638e..fb77eb7619 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1020 - versionName "0.10.20" + versionCode 1021 + versionName "0.10.21" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -99,7 +99,7 @@ dependencies { implementation 'androidx.annotation:annotation:1.7.0' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.exifinterface:exifinterface:1.3.6' - implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar' + implementation 'com.mikepenz:google-material-typeface:4.0.0.2-kotlin@aar' implementation 'com.mikepenz:fontawesome-typeface:5.3.1.1@aar' implementation 'com.mikepenz:octicons-typeface:3.2.0.5@aar' From a8503aab75c5fdaaea136a0fe02543e2b915cad5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:03:26 -0400 Subject: [PATCH 21/80] actions: bump `com.mikepenz:fontawesome-typeface` to 5.13.3.0-kotlin (fixes #2461) (#2453) 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 fb77eb7619..4da2ee8d1a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1021 - versionName "0.10.21" + versionCode 1022 + versionName "0.10.22" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -100,7 +100,7 @@ dependencies { implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.exifinterface:exifinterface:1.3.6' implementation 'com.mikepenz:google-material-typeface:4.0.0.2-kotlin@aar' - implementation 'com.mikepenz:fontawesome-typeface:5.3.1.1@aar' + implementation 'com.mikepenz:fontawesome-typeface:5.13.3.0-kotlin@aar' implementation 'com.mikepenz:octicons-typeface:3.2.0.5@aar' implementation 'com.mikepenz:itemanimators:1.1.0@aar' From c271f7286f03b96279aea324949806944f8522bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:15:02 -0400 Subject: [PATCH 22/80] actions: bump `com.nex3z:toggle-button-group` to 1.2.3 (fixes #2462) (#2450) 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 4da2ee8d1a..290c1271db 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1022 - versionName "0.10.22" + versionCode 1023 + versionName "0.10.23" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -133,7 +133,7 @@ dependencies { implementation 'org.osmdroid:osmdroid-android:6.1.16' implementation 'com.github.clans:fab:1.6.4' implementation 'com.borax12.materialdaterangepicker:library:2.0' - implementation 'com.nex3z:toggle-button-group:1.1.9' + implementation 'com.nex3z:toggle-button-group:1.2.3' implementation 'com.sa90.materialarcmenu:library:2.0.0' implementation project(':library') implementation 'org.jetbrains:annotations:24.0.1' From 8a3fe9112ca0755ac83d7bf23e9085d69ff2ef21 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:35:08 -0400 Subject: [PATCH 23/80] actions: bump `androidx.core:core-ktx` to 1.12.0 (fixes #2446) (#2442) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gideon Okuro Co-authored-by: dogi --- app/build.gradle | 37 +++++++++++++++++++------------------ build.gradle | 6 +++--- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 290c1271db..918b5e0279 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,13 +5,13 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'dagger.hilt.android.plugin' apply plugin: 'realm-android' android { - compileSdkVersion 33 + compileSdkVersion 34 defaultConfig { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1023 - versionName "0.10.23" + versionCode 1024 + versionName "0.10.24" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -35,30 +35,31 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - packagingOptions { - exclude 'META-INF/DEPENDENCIES' - exclude 'META-INF/LICENSE' - exclude 'META-INF/LICENSE.txt' - exclude 'META-INF/license.txt' - exclude 'META-INF/NOTICE' - exclude 'META-INF/NOTICE.txt' - exclude 'META-INF/notice.txt' - exclude 'META-INF/ASL2.0' + resources { + excludes += [ + 'META-INF/DEPENDENCIES', + 'META-INF/LICENSE', + 'META-INF/LICENSE.txt', + 'META-INF/license.txt', + 'META-INF/NOTICE', + 'META-INF/NOTICE.txt', + 'META-INF/notice.txt', + 'META-INF/ASL2.0' + ] + } } - lintOptions { - abortOnError false - } compileOptions { targetCompatibility JavaVersion.VERSION_11 sourceCompatibility JavaVersion.VERSION_11 } - namespace 'org.ole.planet.myplanet' - lint { + lintOptions { abortOnError false } + + namespace 'org.ole.planet.myplanet' buildFeatures { viewBinding = true @@ -139,7 +140,7 @@ dependencies { implementation 'org.jetbrains:annotations:24.0.1' implementation 'com.github.kizitonwose:CalendarView:0.3.1' implementation "io.noties.markwon:editor:4.6.2" - implementation "androidx.core:core-ktx:1.10.1" + 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' implementation 'com.applandeo:material-calendar-view:1.7.0' diff --git a/build.gradle b/build.gradle index 31d1363d13..15900ab310 100644 --- a/build.gradle +++ b/build.gradle @@ -3,10 +3,10 @@ buildscript { ext.kotlin_version = '1.7.10' ext { setup = [ - compileSdk: 33, + compileSdk: 34, buildTools: "28.0.0", minSdk : 19, - targetSdk : 33 + targetSdk : 34 ] versions = [ supportLib: "28.0.0" @@ -19,7 +19,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:8.0.0' + classpath 'com.android.tools.build:gradle:8.1.1' classpath "io.realm:realm-gradle-plugin:10.16.1" classpath "com.google.dagger:hilt-android-gradle-plugin:2.48" From 492263c0d3cec01098462e6c368dd1275b06a84e Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 11 Sep 2023 23:49:26 +0300 Subject: [PATCH 24/80] login: equalize username validation across myPlanet and planet (fixes #2456) (#2457) Co-authored-by: dogi --- app/build.gradle | 4 +- .../myplanet/ui/sync/LoginActivity.java | 19 ++++++++ .../ui/userprofile/BecomeMemberActivity.kt | 43 ++++++++++++++++++- app/src/main/res/values-ar/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-ne/strings.xml | 2 + app/src/main/res/values-so/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 9 files changed, 75 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 918b5e0279..8202a301cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1024 - versionName "0.10.24" + versionCode 1025 + versionName "0.10.25" 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 765a044df1..86c8fd1d05 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 @@ -280,6 +280,25 @@ public void declareMoreElements() { if (NetworkUtils.isNetworkConnected()) { service.syncPlanetServers(mRealm, success -> Utilities.toast(LoginActivity.this, success)); } + + inputName.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + String lowercaseText = s.toString().toLowerCase(Locale.ROOT); + if (!s.toString().equals(lowercaseText)) { + inputName.setText(lowercaseText); + inputName.setSelection(lowercaseText.length()); + } + } + + @Override + public void afterTextChanged(Editable s) { + } + }); } private void setUplanguageButton() { 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 257c4e577f..67d9d5152e 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 @@ -76,6 +76,36 @@ class BecomeMemberActivity : BaseActivity() { settings = getSharedPreferences(SyncActivity.PREFS_NAME, Context.MODE_PRIVATE) textChangedListener(mRealm) + et_username.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + s?.let { + val firstChar = if (it.isNotEmpty()) it[0] else null + + val hasInvalidCharacters = it.any { char -> + char != '_' && char != '.' && char != '-' && + !Character.isDigit(char) && !Character.isLetter(char) + } + + if (firstChar != null && !Character.isDigit(firstChar) && !Character.isLetter(firstChar)) { + et_username.error = getString(R.string.must_start_with_letter_or_number) + } else if (hasInvalidCharacters) { + et_username.error = getString(R.string.only_letters_numbers_and_are_allowed) + } else { + val lowercaseText = it.toString().toLowerCase(Locale.ROOT) + if (it.toString() != lowercaseText) { + et_username.setText(lowercaseText) + et_username.setSelection(lowercaseText.length) + } + et_username.error = null + } + } + } + + override fun afterTextChanged(s: Editable?) {} + }) + btn_cancel.setOnClickListener { finish() } @@ -99,11 +129,22 @@ class BecomeMemberActivity : BaseActivity() { else { Utilities.toast(this, getString(R.string.please_select_gender)) } - if (username!!.isEmpty()) { + val firstChar = if (username!!.isNotEmpty()) username[0] else null + val hasInvalidCharacters = username.any { char -> + char != '_' && char != '.' && char != '-' && + !Character.isDigit(char) && !Character.isLetter(char) + } + + if (username.isEmpty()) { et_username.error = getString(R.string.please_enter_a_username) } else if (username.contains(" ")) { et_username.error = getString(R.string.invalid_username) + } else if (firstChar != null && !Character.isDigit(firstChar) && !Character.isLetter(firstChar)) { + et_username.error = getString(R.string.must_start_with_letter_or_number) + } else if (hasInvalidCharacters) { + et_username.error = getString(R.string.only_letters_numbers_and_are_allowed) } + if (password!!.isEmpty()) { et_password.error = getString(R.string.please_enter_a_password) } else if (password != repassword) { diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 141d45ae5c..e188091f92 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -939,5 +939,7 @@ الوقت AI Chat يرجى التقييم + يجب أن تبدأ بحرف أو رقم + يُسمح فقط بالحروف والأرقام و "_" و "." و "-" \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 67d72e430f..8b13339870 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -944,5 +944,7 @@ tiempo AI Chat Por favor, dé una calificación + Debe comenzar con una letra o número + Solo se permiten letras, números, "_" , ".", y "-" diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 3762516539..8f4e8a07ee 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -944,5 +944,7 @@ temps AI Chat Veuillez donner une note + Doit commencer par une lettre ou un chiffre + Seules les lettres, les chiffres, "_" , ".", et "-" sont autorisés diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index c01f7acdf3..87ea47a424 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -944,5 +944,7 @@ समय AI Chat कृपया मूल्याङ्कन दिनुहोस् + पात्र वा नम्बरसँग सुरु गर्नु पर्दछ + केवल अक्षर, नम्बर, "_" , ".", र "-" पाएको छ \ No newline at end of file diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index 6aea0b8f54..58c0ab0271 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -933,5 +933,7 @@ waqtiga AI Chat si naxariis leh u bixi rating + Waa in la bilaabo lambarka ama tirada + Waxaad ka ogolaan kartaa lambarka, tirada, "_", ".", iyo "-" \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f9ac8d1f0..70d79d7be4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1033,5 +1033,7 @@ time AI Chat Kindly give a rating + Must start with letter or number + Only letters, numbers and "_" , ".", "-" are allowed From 2c9b2b995b61e41cfde5900619dc0964a5571d74 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 12 Sep 2023 22:22:06 +0300 Subject: [PATCH 25/80] actions: unbump `com.mikepenz:*-typeface` to uncrashing (fixes #2475) (#2477) Co-authored-by: dogi --- app/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8202a301cd..323fd613f8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1025 - versionName "0.10.25" + versionCode 1026 + versionName "0.10.26" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -100,8 +100,8 @@ dependencies { implementation 'androidx.annotation:annotation:1.7.0' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.exifinterface:exifinterface:1.3.6' - implementation 'com.mikepenz:google-material-typeface:4.0.0.2-kotlin@aar' - implementation 'com.mikepenz:fontawesome-typeface:5.13.3.0-kotlin@aar' + implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar' + implementation 'com.mikepenz:fontawesome-typeface:5.3.1.1@aar' implementation 'com.mikepenz:octicons-typeface:3.2.0.5@aar' implementation 'com.mikepenz:itemanimators:1.1.0@aar' From f42332543ae6d39f22bd3a3ef3ab2cbf2ff06c56 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:06:03 -0400 Subject: [PATCH 26/80] actions: bump `com.google.dagger:hilt-android-compiler` to 2.48 (fixes #2473) (#2465) 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 323fd613f8..3ae50c246a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1026 - versionName "0.10.26" + versionCode 1027 + versionName "0.10.27" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -109,7 +109,7 @@ dependencies { implementation 'com.github.jeancsanchez:jcplayer:2.7.2' implementation "com.google.dagger:hilt-android:2.44" - kapt "com.google.dagger:hilt-android-compiler:2.44" + kapt "com.google.dagger:hilt-android-compiler:2.48" implementation 'com.mikepenz:crossfader:1.5.1@aar' implementation 'com.mikepenz:crossfadedrawerlayout:1.0.1@aar' From b02fd99b5dc7aafa1ca6c15217cb1b6c03684f2b Mon Sep 17 00:00:00 2001 From: dogi Date: Tue, 12 Sep 2023 16:35:05 -0400 Subject: [PATCH 27/80] actions: working signed release apk (fixes #2478) (#2479) --- .github/workflows/android-release.yml | 24 +++++++++++------------- app/build.gradle | 9 ++------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml index a208c98e5f..a00ec5829e 100644 --- a/.github/workflows/android-release.yml +++ b/.github/workflows/android-release.yml @@ -45,8 +45,8 @@ jobs: ./gradlew assembleRelease bundleRelease ls -alR app/build/outputs mkdir -p sign - cp app/build/outputs/bundle/release/app-release.aab sign/myPlanet.aab - cp app/build/outputs/apk/release/myPlanet-build.apk sign/myPlanet.apk + cp app/build/outputs/bundle/release/app-release.aab sign/. + cp app/build/outputs/apk/release/app-release-unsigned.apk sign/. - name: sign release APK and AAB uses: dogi/sign-android-release@v3.0.1 @@ -57,18 +57,16 @@ jobs: keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} keyPassword: ${{ secrets.KEY_PASSWORD }} - - name: copy builds to directory and generate sha256 + - name: copy builds to output and generate sha256 run: | mkdir -p output - cd output - cp ../sign/myPlanet.* . - cp ../app/build/outputs/apk/release/myPlanet-build.apk . - sha256sum myPlanet.apk > myPlanet.apk.sha256 - sha256sum myPlanet.aab > myPlanet.aab.sha256 - cd - + cp sign/app-release-unsigned-signed.apk output/myPlanet.apk + cp sign/app-release.aab output/myPlanet.aab + sha256sum output/myPlanet.apk > output/myPlanet.apk.sha256 + sha256sum output/myPlanet.aab > output/myPlanet.aab.sha256 ls -alR output - - name: publish to playstore + - name: publish AAB to playstore if: github.ref == 'refs/heads/master' uses: r0adkll/upload-google-play@v1.1.1 with: @@ -79,7 +77,7 @@ jobs: releaseName: "${{ env.ANDROID_VERSION_CODE }} (${{ env.ANDROID_VERSION_NAME }})" status: completed - - name: rename APK/AAB with version and branch for artifact + - name: rename APK and AAB with version and branch for artifact if: github.ref != 'refs/heads/master' run: | mv output/myPlanet.apk output/myPlanet-${{ env.ANDROID_VERSION_NAME }}-${{ env.BRANCHNAME }}.apk @@ -88,7 +86,7 @@ jobs: mv output/myPlanet.aab.sha256 output/myPlanet-${{ env.ANDROID_VERSION_NAME }}-${{ env.BRANCHNAME }}.aab.sha256 ls -alR output - - name: upload APK/AAB as build artifact + - name: upload APK and AAB as build artifact if: github.ref != 'refs/heads/master' uses: actions/upload-artifact@v3 with: @@ -96,7 +94,7 @@ jobs: path: output/* retention-days: 9 - - name: release signed APK and AAB on GitHub + - name: release APK and AAB on GitHub if: github.ref == 'refs/heads/master' uses: svenstaro/upload-release-action@v2 with: diff --git a/app/build.gradle b/app/build.gradle index 3ae50c246a..7ca878f27d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,17 +10,12 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 19 targetSdkVersion 33 - versionCode 1027 - versionName "0.10.27" + versionCode 1028 + versionName "0.10.28" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true multiDexEnabled true - applicationVariants.all { variant -> - variant.outputs.all { output -> - outputFileName = new File("myPlanet-build.apk") - } - } } configurations.all { resolutionStrategy.force 'com.google.android.material:material:1.9.0' From f5e0c19ea5302df9ac883b70d4d92a2cf18266ee Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 13 Sep 2023 20:09:52 +0300 Subject: [PATCH 28/80] actions: bump `minSdkVersion` in gradle to 21 (fixes #2454) (#2483) Co-authored-by: dogi --- app/build.gradle | 8 ++++---- build.gradle | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7ca878f27d..eae19b77fd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,10 +8,10 @@ android { compileSdkVersion 34 defaultConfig { applicationId "org.ole.planet.myplanet" - minSdkVersion 19 - targetSdkVersion 33 - versionCode 1028 - versionName "0.10.28" + minSdkVersion 21 + targetSdkVersion 34 + versionCode 1029 + versionName "0.10.29" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/build.gradle b/build.gradle index 15900ab310..4e9c6bdca4 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { setup = [ compileSdk: 34, buildTools: "28.0.0", - minSdk : 19, + minSdk : 21, targetSdk : 34 ] versions = [ From 81dda0cafbf1903fbbc062754d52f8473e8fc2e0 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 13 Sep 2023 20:24:06 +0300 Subject: [PATCH 29/80] actions: handle `nullException` for wifi switch (fixes #2480) (#2482) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/sync/DashboardElementActivity.java | 46 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index eae19b77fd..f4f55b2fc6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1029 - versionName "0.10.29" + versionCode 1030 + versionName "0.10.30" 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/DashboardElementActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.java index 61f702cb5f..0c8f8faead 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.java @@ -52,6 +52,7 @@ public abstract class DashboardElementActivity extends AppCompatActivity impleme public UserProfileDbHandler profileDbHandler; boolean doubleBackToExitPressedOnce; private SharedPreferences settings; + private MenuItem goOnline; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -86,6 +87,7 @@ public void onClickTabItems(int position) { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_dashboard, menu); + goOnline = menu.findItem(R.id.menu_goOnline); return true; } @@ -99,7 +101,7 @@ public void openCallFragment(Fragment newfragment, String tag) { @Override public boolean onPrepareOptionsMenu(Menu menu) { - menu.findItem(R.id.menu_goOnline).setVisible(Constants.showBetaFeature(Constants.KEY_SYNC, this)); + goOnline.setVisible(Constants.showBetaFeature(Constants.KEY_SYNC, this)); return super.onPrepareOptionsMenu(menu); } @@ -108,6 +110,7 @@ public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_goOnline) { wifiStatusSwitch(); + return true; } else if (id == R.id.menu_logout) { logout(); } else if (id == R.id.action_feedback) { @@ -129,26 +132,27 @@ protected void syncNow() { @SuppressLint("RestrictedApi") public void wifiStatusSwitch() { - ActionMenuItemView goOnline = findViewById(R.id.menu_goOnline); - Drawable resIcon = getResources().getDrawable(R.drawable.goonline); - ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); - NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - - Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); - startActivity(intent); - - if (mWifi.isConnected()) { - wifi.setWifiEnabled(false); - resIcon.mutate().setColorFilter(getApplicationContext().getResources().getColor(R.color.green), PorterDuff.Mode.SRC_ATOP); - goOnline.setIcon(resIcon); - Toast.makeText(this, getString(R.string.wifi_is_turned_off_saving_battery_power), Toast.LENGTH_LONG).show(); - } else { - wifi.setWifiEnabled(true); - Toast.makeText(this, getString(R.string.turning_on_wifi_please_wait), Toast.LENGTH_LONG).show(); - (new Handler()).postDelayed(this::connectToWifi, 5000); - resIcon.mutate().setColorFilter(getApplicationContext().getResources().getColor(R.color.accent), PorterDuff.Mode.SRC_ATOP); - goOnline.setIcon(resIcon); + if (goOnline != null) { + Drawable resIcon = getResources().getDrawable(R.drawable.goonline); + ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); + NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + + Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); + startActivity(intent); + + if (mWifi.isConnected()) { + wifi.setWifiEnabled(false); + resIcon.mutate().setColorFilter(getApplicationContext().getResources().getColor(R.color.green), PorterDuff.Mode.SRC_ATOP); + goOnline.setIcon(resIcon); + Toast.makeText(this, getString(R.string.wifi_is_turned_off_saving_battery_power), Toast.LENGTH_LONG).show(); + } else { + wifi.setWifiEnabled(true); + Toast.makeText(this, getString(R.string.turning_on_wifi_please_wait), Toast.LENGTH_LONG).show(); + (new Handler()).postDelayed(this::connectToWifi, 5000); + resIcon.mutate().setColorFilter(getApplicationContext().getResources().getColor(R.color.accent), PorterDuff.Mode.SRC_ATOP); + goOnline.setIcon(resIcon); + } } } From 8fc6139ff8e91a16f064c749ca1b7ee20ddcc5b4 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 13 Sep 2023 22:12:15 +0300 Subject: [PATCH 30/80] addons: refactor reference activity (fixes #2369) (#2375) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/references/ReferenceFragment.java | 46 ++++++++----------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f4f55b2fc6..4230042b7c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1030 - versionName "0.10.30" + versionCode 1031 + versionName "0.10.31" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/references/ReferenceFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/references/ReferenceFragment.java index 545a8ba7e8..d1f4108001 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/references/ReferenceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/references/ReferenceFragment.java @@ -6,8 +6,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -16,6 +14,8 @@ import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.callback.OnHomeItemClickListener; +import org.ole.planet.myplanet.databinding.FragmentReferenceBinding; +import org.ole.planet.myplanet.databinding.RowReferenceBinding; import org.ole.planet.myplanet.model.Reference; import org.ole.planet.myplanet.ui.dictionary.DictionaryActivity; import org.ole.planet.myplanet.ui.map.OfflineMapActivity; @@ -24,7 +24,8 @@ import java.util.List; public class ReferenceFragment extends Fragment { - RecyclerView rvReference; + private FragmentReferenceBinding fragmentReferenceBinding; + private RowReferenceBinding rowReferenceBinding; OnHomeItemClickListener homeItemClickListener; public ReferenceFragment() { @@ -39,38 +40,35 @@ public void onAttach(Context context) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_reference, container, false); + fragmentReferenceBinding = FragmentReferenceBinding.inflate(inflater, container, false); List list = new ArrayList<>(); list.add(new Reference(getString(R.string.maps), android.R.drawable.ic_dialog_map)); list.add(new Reference(getString(R.string.engilsh_dictionary), R.drawable.ic_dictionary)); - rvReference = v.findViewById(R.id.rv_references); - rvReference.setLayoutManager(new GridLayoutManager(getActivity(), 3)); + fragmentReferenceBinding.rvReferences.setLayoutManager(new GridLayoutManager(getActivity(), 3)); setRecyclerAdapter(list); - return v; + return fragmentReferenceBinding.getRoot(); } private void setRecyclerAdapter(List list) { - rvReference.setAdapter(new RecyclerView.Adapter() { + fragmentReferenceBinding.rvReferences.setAdapter(new RecyclerView.Adapter() { @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new ViewHolderReference(LayoutInflater.from(getActivity()).inflate(R.layout.row_reference, parent, false)); + rowReferenceBinding = RowReferenceBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new ViewHolderReference(rowReferenceBinding.getRoot()); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolderReference) { - ((ViewHolderReference) holder).title.setText(list.get(position).getTitle()); - ((ViewHolderReference) holder).icon.setImageResource(list.get(position).getIcon()); - holder.itemView.setOnClickListener(view -> { - if (position == 0) - startActivity(new Intent(getActivity(), OfflineMapActivity.class)); - else { - startActivity(new Intent(getActivity(), DictionaryActivity.class)); - } - ; - }); - } + rowReferenceBinding.title.setText(list.get(position).getTitle()); + rowReferenceBinding.icon.setImageResource(list.get(position).getIcon()); + rowReferenceBinding.getRoot().setOnClickListener(view -> { + if (position == 0) + startActivity(new Intent(getActivity(), OfflineMapActivity.class)); + else { + startActivity(new Intent(getActivity(), DictionaryActivity.class)); + } + }); } @Override @@ -80,14 +78,10 @@ public int getItemCount() { }); } - class ViewHolderReference extends RecyclerView.ViewHolder { - TextView title; - ImageView icon; + static class ViewHolderReference extends RecyclerView.ViewHolder { public ViewHolderReference(View itemView) { super(itemView); - title = itemView.findViewById(R.id.title); - icon = itemView.findViewById(R.id.icon); } } } From 3e42e9f42e6ba9b00d5bf4197982a83d52c155d0 Mon Sep 17 00:00:00 2001 From: Caleb Langat Date: Wed, 13 Sep 2023 22:25:04 +0300 Subject: [PATCH 31/80] login: improve check version (fixes #2474) (#2469) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../java/org/ole/planet/myplanet/datamanager/Service.java | 3 ++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4230042b7c..f73777c423 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1031 - versionName "0.10.31" + versionCode 1032 + versionName "0.10.32" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.java b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.java index 3891b9443e..46e726d11a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.java +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.java @@ -13,6 +13,7 @@ import com.google.gson.JsonObject; import org.ole.planet.myplanet.MainApplication; +import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.callback.SuccessListener; import org.ole.planet.myplanet.model.MyPlanet; import org.ole.planet.myplanet.model.RealmCommunity; @@ -100,7 +101,7 @@ public void onFailure(Call call, Throwable t) { public void checkVersion(CheckVersionCallback callback, SharedPreferences settings) { ApiInterface retrofitInterface = ApiClient.getClient().create(ApiInterface.class); if (settings.getString("couchdbURL", "").isEmpty()) { - callback.onError("Config not awailable.", true); + callback.onError(context.getString(R.string.config_not_available), true); return; } retrofitInterface.checkVersion(Utilities.getUpdateUrl(settings)).enqueue(new Callback() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70d79d7be4..531a1daeaf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1035,5 +1035,6 @@ Kindly give a rating Must start with letter or number Only letters, numbers and "_" , ".", "-" are allowed + Config not available. From 564a4541207a38f7250313294876c5a4e5befe8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Sep 2023 12:45:20 -0400 Subject: [PATCH 32/80] addons: bump `org.osmdroid:osmdroid-android` to 6.1.17 (fixes #2493) (#2486) 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 f73777c423..1732ef44c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1032 - versionName "0.10.32" + versionCode 1033 + versionName "0.10.33" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -126,7 +126,7 @@ dependencies { implementation 'com.opencsv:opencsv:5.8' implementation 'com.google.android.exoplayer:exoplayer:2.7.2' implementation 'de.hdodenhof:circleimageview:3.1.0' - implementation 'org.osmdroid:osmdroid-android:6.1.16' + implementation 'org.osmdroid:osmdroid-android:6.1.17' implementation 'com.github.clans:fab:1.6.4' implementation 'com.borax12.materialdaterangepicker:library:2.0' implementation 'com.nex3z:toggle-button-group:1.2.3' From 6c354220469186f417a5d9f61258bb56aea703d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Sep 2023 13:04:45 -0400 Subject: [PATCH 33/80] actions: bump `androidx.recyclerview:recyclerview` to 1.3.1 (fixes #2494) (#2481) 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 1732ef44c3..27fc0e3d61 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1033 - versionName "0.10.33" + versionCode 1034 + versionName "0.10.34" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -91,7 +91,7 @@ dependencies { transitive = true } implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.recyclerview:recyclerview:1.3.0' + implementation 'androidx.recyclerview:recyclerview:1.3.1' implementation 'androidx.annotation:annotation:1.7.0' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.exifinterface:exifinterface:1.3.6' From 4689961ad800f579a203a88efe1ce578176ad908 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 14 Sep 2023 20:19:19 +0300 Subject: [PATCH 34/80] courses: refactor take exam module (fixes #2484) (#2490) Co-authored-by: dogi --- app/build.gradle | 4 +- .../myplanet/ui/exam/TakeExamFragment.java | 85 +++++++------------ .../ui/exam/UserInformationFragment.java | 67 +++++---------- 3 files changed, 58 insertions(+), 98 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 27fc0e3d61..e51448176f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1034 - versionName "0.10.34" + versionCode 1035 + versionName "0.10.35" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/exam/TakeExamFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/exam/TakeExamFragment.java index 1a4edd8b44..b3fe408145 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/exam/TakeExamFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/exam/TakeExamFragment.java @@ -1,33 +1,28 @@ package org.ole.planet.myplanet.ui.exam; - import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.core.widget.NestedScrollView; - import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.RadioButton; -import android.widget.RadioGroup; -import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.core.widget.NestedScrollView; import com.google.android.material.snackbar.Snackbar; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentTakeExamBinding; import org.ole.planet.myplanet.model.RealmAnswer; import org.ole.planet.myplanet.model.RealmCertification; import org.ole.planet.myplanet.model.RealmExamQuestion; import org.ole.planet.myplanet.model.RealmSubmission; import org.ole.planet.myplanet.service.UserProfileDbHandler; +import org.ole.planet.myplanet.utilities.CameraUtils; import org.ole.planet.myplanet.utilities.JsonParserUtils; import org.ole.planet.myplanet.utilities.JsonUtils; import org.ole.planet.myplanet.utilities.KeyboardUtils; @@ -42,14 +37,8 @@ import io.realm.RealmQuery; import io.realm.Sort; -import org.ole.planet.myplanet.utilities.CameraUtils; - public class TakeExamFragment extends BaseExamFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, CameraUtils.ImageCaptureCallback { - TextView tvQuestionCount, header, body; - EditText etAnswer; - Button btnSubmit; - RadioGroup listChoices; - LinearLayout llCheckbox; + private FragmentTakeExamBinding fragmentTakeExamBinding; Markwon markwon; boolean isCertified; NestedScrollView container; @@ -59,20 +48,12 @@ public TakeExamFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_take_exam, parent, false); + fragmentTakeExamBinding = FragmentTakeExamBinding.inflate(inflater, parent, false); listAns = new HashMap<>(); - tvQuestionCount = view.findViewById(R.id.tv_question_count); - header = view.findViewById(R.id.tv_header); - body = view.findViewById(R.id.tv_body); - llCheckbox = view.findViewById(R.id.ll_checkbox); - etAnswer = view.findViewById(R.id.et_answer); - btnSubmit = view.findViewById(R.id.btn_submit); - listChoices = view.findViewById(R.id.group_choices); - container = view.findViewById(R.id.container); markwon = Markwon.create(getActivity()); UserProfileDbHandler dbHandler = new UserProfileDbHandler(getActivity()); user = dbHandler.getUserModel(); - return view; + return fragmentTakeExamBinding.getRoot(); } @Override @@ -80,7 +61,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initExam(); questions = mRealm.where(RealmExamQuestion.class).equalTo("examId", exam.getId()).findAll(); - tvQuestionCount.setText(getString(R.string.Q1) + questions.size()); + fragmentTakeExamBinding.tvQuestionCount.setText(getString(R.string.Q1) + questions.size()); RealmQuery q = mRealm.where(RealmSubmission.class).equalTo("userId", user.getId()).equalTo("parentId", (!TextUtils.isEmpty(exam.getCourseId())) ? id + "@" + exam.getCourseId() : id).sort("startTime", Sort.DESCENDING); if (type.equals("exam")) q = q.equalTo("status", "pending"); @@ -93,9 +74,9 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { startExam(questions.get(currentIndex)); } else { container.setVisibility(View.GONE); - btnSubmit.setVisibility(View.GONE); - tvQuestionCount.setText(R.string.no_questions); - Snackbar.make(tvQuestionCount, R.string.no_questions_available, Snackbar.LENGTH_LONG).show(); + fragmentTakeExamBinding.btnSubmit.setVisibility(View.GONE); + fragmentTakeExamBinding.tvQuestionCount.setText(R.string.no_questions); + Snackbar.make(fragmentTakeExamBinding.tvQuestionCount, R.string.no_questions_available, Snackbar.LENGTH_LONG).show(); } } @@ -124,44 +105,44 @@ private void createSubmission() { @Override public void startExam(RealmExamQuestion question) { - tvQuestionCount.setText(getString(R.string.Q) + (currentIndex + 1) + "/" + questions.size()); + fragmentTakeExamBinding.tvQuestionCount.setText(getString(R.string.Q) + (currentIndex + 1) + "/" + questions.size()); setButtonText(); - listChoices.removeAllViews(); - llCheckbox.removeAllViews(); - etAnswer.setVisibility(View.GONE); - listChoices.setVisibility(View.GONE); - llCheckbox.setVisibility(View.GONE); + fragmentTakeExamBinding.groupChoices.removeAllViews(); + fragmentTakeExamBinding.llCheckbox.removeAllViews(); + fragmentTakeExamBinding.etAnswer.setVisibility(View.GONE); + fragmentTakeExamBinding.groupChoices.setVisibility(View.GONE); + fragmentTakeExamBinding.llCheckbox.setVisibility(View.GONE); clearAnswer(); if (sub.getAnswers().size() > currentIndex) { ans = sub.getAnswers().get(currentIndex).getValue(); } if (question.getType().equalsIgnoreCase("select")) { - listChoices.setVisibility(View.VISIBLE); - etAnswer.setVisibility(View.GONE); + fragmentTakeExamBinding.groupChoices.setVisibility(View.VISIBLE); + fragmentTakeExamBinding.etAnswer.setVisibility(View.GONE); selectQuestion(question, ans); } else if (question.getType().equalsIgnoreCase("input") || question.getType().equalsIgnoreCase("textarea")) { - setMarkdownViewAndShowInput(etAnswer, question.getType(), ans); + setMarkdownViewAndShowInput(fragmentTakeExamBinding.etAnswer, question.getType(), ans); } else if (question.getType().equalsIgnoreCase("selectMultiple")) { - llCheckbox.setVisibility(View.VISIBLE); - etAnswer.setVisibility(View.GONE); + fragmentTakeExamBinding.llCheckbox.setVisibility(View.VISIBLE); + fragmentTakeExamBinding.etAnswer.setVisibility(View.GONE); showCheckBoxes(question, ans); } - header.setText(question.getHeader()); - markwon.setMarkdown(body, question.getBody()); - btnSubmit.setOnClickListener(this); + fragmentTakeExamBinding.tvHeader.setText(question.getHeader()); + markwon.setMarkdown(fragmentTakeExamBinding.tvBody, question.getBody()); + fragmentTakeExamBinding.btnSubmit.setOnClickListener(this); } private void clearAnswer() { ans = ""; - etAnswer.setText(""); + fragmentTakeExamBinding.etAnswer.setText(""); listAns.clear(); } public void setButtonText() { if (currentIndex == questions.size() - 1) { - btnSubmit.setText(R.string.finish); + fragmentTakeExamBinding.btnSubmit.setText(R.string.finish); } else { - btnSubmit.setText(R.string.submit); + fragmentTakeExamBinding.btnSubmit.setText(R.string.submit); } } @@ -188,7 +169,7 @@ public void addRadioButton(String choice, String oldAnswer) { rdBtn.setText(choice); rdBtn.setChecked(choice.equals(oldAnswer)); rdBtn.setOnCheckedChangeListener(this); - listChoices.addView(rdBtn); + fragmentTakeExamBinding.groupChoices.addView(rdBtn); } public void addCompoundButton(JsonObject choice, boolean isRadio, String oldAnswer) { @@ -197,8 +178,8 @@ public void addCompoundButton(JsonObject choice, boolean isRadio, String oldAnsw rdBtn.setTag(JsonUtils.getString("id", choice)); rdBtn.setChecked(JsonUtils.getString("id", choice).equals(oldAnswer)); rdBtn.setOnCheckedChangeListener(this); - if (isRadio) listChoices.addView(rdBtn); - else llCheckbox.addView(rdBtn); + if (isRadio) fragmentTakeExamBinding.groupChoices.addView(rdBtn); + else fragmentTakeExamBinding.llCheckbox.addView(rdBtn); } @Override @@ -226,7 +207,7 @@ private void capturePhoto() { private void showTextInput(String type) { if (type.equalsIgnoreCase("input") || type.equalsIgnoreCase("textarea")) { - ans = etAnswer.getText().toString(); + ans = fragmentTakeExamBinding.etAnswer.getText().toString(); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/exam/UserInformationFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/exam/UserInformationFragment.java index c73df414ca..ef67abcd3d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/exam/UserInformationFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/exam/UserInformationFragment.java @@ -7,21 +7,15 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.DatePicker; -import android.widget.EditText; import android.widget.RadioButton; -import android.widget.RadioGroup; -import android.widget.Spinner; -import android.widget.TextView; - -import androidx.fragment.app.Fragment; import com.google.gson.JsonObject; import org.ole.planet.myplanet.MainApplication; import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.base.BaseDialogFragment; +import org.ole.planet.myplanet.databinding.FragmentUserInformationBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmSubmission; import org.ole.planet.myplanet.model.RealmUserModel; @@ -34,12 +28,8 @@ import io.realm.Realm; public class UserInformationFragment extends BaseDialogFragment implements View.OnClickListener { - EditText etFname, etMname, etLname, etPhone, etEmail; - TextView tvBirthDate; + private FragmentUserInformationBinding fragmentUserInformationBinding; String dob = ""; - RadioGroup rbGender; - Spinner spnLang, spnLvl; - Button btnSubmit, btnCancel; Realm mRealm; RealmSubmission submissions; RealmUserModel userModel; @@ -60,13 +50,13 @@ private static void setArgs(UserInformationFragment f, String id) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_user_information, container, false); + fragmentUserInformationBinding = FragmentUserInformationBinding.inflate(inflater, container, false); mRealm = new DatabaseService(getActivity()).getRealmInstance(); userModel = new UserProfileDbHandler(requireContext()).getUserModel(); if (!TextUtils.isEmpty(id)) submissions = mRealm.where(RealmSubmission.class).equalTo("id", id).findFirst(); - initViews(v); - return v; + initViews(); + return fragmentUserInformationBinding.getRoot(); } @Override @@ -74,27 +64,16 @@ public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } - private void initViews(View v) { - etEmail = v.findViewById(R.id.et_email); - etFname = v.findViewById(R.id.et_fname); - etMname = v.findViewById(R.id.et_mname); - etLname = v.findViewById(R.id.et_lname); - etPhone = v.findViewById(R.id.et_phone); - tvBirthDate = v.findViewById(R.id.txt_dob); - rbGender = v.findViewById(R.id.rb_gender); - spnLang = v.findViewById(R.id.spn_lang); - spnLvl = v.findViewById(R.id.spn_level); - btnCancel = v.findViewById(R.id.btn_cancel); - btnSubmit = v.findViewById(R.id.btn_submit); - etEmail.setText(userModel.getEmail() + ""); - etFname.setText(userModel.getFirstName() + ""); - etLname.setText(userModel.getLastName() + ""); - etPhone.setText(userModel.getPhoneNumber() + ""); - tvBirthDate.setText(userModel.getDob() + ""); + private void initViews() { + fragmentUserInformationBinding.etEmail.setText(userModel.getEmail() + ""); + fragmentUserInformationBinding.etFname.setText(userModel.getFirstName() + ""); + fragmentUserInformationBinding.etLname.setText(userModel.getLastName() + ""); + fragmentUserInformationBinding.etPhone.setText(userModel.getPhoneNumber() + ""); + fragmentUserInformationBinding.txtDob.setText(userModel.getDob() + ""); dob = userModel.getDob(); - btnCancel.setOnClickListener(this); - btnSubmit.setOnClickListener(this); - tvBirthDate.setOnClickListener(this); + fragmentUserInformationBinding.btnCancel.setOnClickListener(this); + fragmentUserInformationBinding.btnSubmit.setOnClickListener(this); + fragmentUserInformationBinding.txtDob.setOnClickListener(this); } @Override @@ -113,18 +92,18 @@ public void onClick(View view) { } private void submitForm() { - String fname = etFname.getText().toString().trim(); - String lname = etLname.getText().toString().trim(); - String mName = etMname.getText().toString().trim(); - String phone = etPhone.getText().toString().trim(); - String email = etEmail.getText().toString().trim(); + String fname = fragmentUserInformationBinding.etFname.getText().toString().trim(); + String lname = fragmentUserInformationBinding.etLname.getText().toString().trim(); + String mName = fragmentUserInformationBinding.etMname.getText().toString().trim(); + String phone = fragmentUserInformationBinding.etPhone.getText().toString().trim(); + String email = fragmentUserInformationBinding.etEmail.getText().toString().trim(); String gender = ""; - RadioButton rbSelected = getView().findViewById(rbGender.getCheckedRadioButtonId()); + RadioButton rbSelected = getView().findViewById(fragmentUserInformationBinding.rbGender.getCheckedRadioButtonId()); if (rbSelected != null) { gender = rbSelected.getText().toString(); } - String level = spnLvl.getSelectedItem().toString(); - String lang = spnLang.getSelectedItem().toString(); + String level = fragmentUserInformationBinding.spnLevel.getSelectedItem().toString(); + String lang = fragmentUserInformationBinding.spnLang.getSelectedItem().toString(); if (TextUtils.isEmpty(id)) { String userId = userModel.getId(); String finalGender = gender; @@ -185,7 +164,7 @@ private void showDatePickerDialog() { @Override public void onDateSet(DatePicker datePicker, int i, int i1, int i2) { dob = String.format(Locale.US, "%04d-%02d-%02d", i, i1 + 1, i2); - tvBirthDate.setText(dob); + fragmentUserInformationBinding.txtDob.setText(dob); } }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.show(); From e67301c07667376b0b92cb63302af9ac353c2f76 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 14 Sep 2023 20:31:14 +0300 Subject: [PATCH 35/80] resources: refactor viewer modules (fixes #2390) (#2394) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/viewer/AudioPlayerActivity.java | 30 +++++++------- .../myplanet/ui/viewer/CSVViewerActivity.java | 24 ++++-------- .../ui/viewer/ImageViewerActivity.java | 23 ++++------- .../ui/viewer/MarkdownViewerActivity.java | 23 ++++------- .../myplanet/ui/viewer/PDFReaderActivity.java | 39 +++++++------------ .../ui/viewer/TextFileViewerActivity.java | 25 ++++-------- .../ui/viewer/VideoPlayerActivity.java | 12 +++--- 8 files changed, 67 insertions(+), 113 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e51448176f..55e1f9de43 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1035 - versionName "0.10.35" + versionCode 1036 + versionName "0.10.36" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java index fe082fe0f6..5b5ad05c3e 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java @@ -1,33 +1,33 @@ package org.ole.planet.myplanet.ui.viewer; -import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; import android.view.MenuItem; import android.view.View; +import androidx.appcompat.app.AppCompatActivity; + import com.example.jean.jcplayer.JcPlayerManagerListener; import com.example.jean.jcplayer.general.JcStatus; import com.example.jean.jcplayer.model.JcAudio; -import com.example.jean.jcplayer.view.JcPlayerView; import org.jetbrains.annotations.NotNull; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityAudioPlayerBinding; import org.ole.planet.myplanet.utilities.Utilities; import java.io.File; import java.util.ArrayList; public class AudioPlayerActivity extends AppCompatActivity implements JcPlayerManagerListener { - JcPlayerView jcplayer; + private ActivityAudioPlayerBinding activityAudioPlayerBinding; ArrayList jcAudios; boolean isFullPath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_audio_player); - jcplayer = findViewById(R.id.jcplayer); + activityAudioPlayerBinding = ActivityAudioPlayerBinding.inflate(getLayoutInflater()); + setContentView(activityAudioPlayerBinding.getRoot()); String filePath = getIntent().getStringExtra("TOUCHED_FILE"); jcAudios = new ArrayList<>(); isFullPath = getIntent().getBooleanExtra("isFullPath", false); @@ -41,10 +41,10 @@ protected void onCreate(Bundle savedInstanceState) { } jcAudios.add(JcAudio.createFromFilePath(fullPath)); - jcplayer.initPlaylist(jcAudios, null); - jcplayer.getRootView().findViewById(R.id.btnNext).setVisibility(View.GONE); - jcplayer.getRootView().findViewById(R.id.btnPrev).setVisibility(View.GONE); - jcplayer.getRootView().findViewById(R.id.btnRepeatOne).setVisibility(View.GONE); + activityAudioPlayerBinding.jcplayer.initPlaylist(jcAudios, null); + activityAudioPlayerBinding.jcplayer.getRootView().findViewById(R.id.btnNext).setVisibility(View.GONE); + activityAudioPlayerBinding.jcplayer.getRootView().findViewById(R.id.btnPrev).setVisibility(View.GONE); + activityAudioPlayerBinding.jcplayer.getRootView().findViewById(R.id.btnRepeatOne).setVisibility(View.GONE); } @Override @@ -58,22 +58,22 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override protected void onPause() { super.onPause(); - if (jcplayer != null && jcplayer.isPlaying()) { - jcplayer.pause(); + if (activityAudioPlayerBinding.jcplayer != null && activityAudioPlayerBinding.jcplayer.isPlaying()) { + activityAudioPlayerBinding.jcplayer.pause(); } } @Override protected void onStop() { super.onStop(); - if (jcplayer != null) jcplayer.kill(); + if (activityAudioPlayerBinding.jcplayer != null) activityAudioPlayerBinding.jcplayer.kill(); } @Override protected void onResume() { super.onResume(); - if (jcplayer != null && jcAudios.size() > 0) { - jcplayer.playAudio(jcAudios.get(0)); + if (activityAudioPlayerBinding.jcplayer != null && jcAudios.size() > 0) { + activityAudioPlayerBinding.jcplayer.playAudio(jcAudios.get(0)); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java index 8d9a4f5ae8..7a2024f16d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/CSVViewerActivity.java @@ -3,7 +3,6 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; -import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; @@ -11,7 +10,7 @@ import com.opencsv.CSVReader; import com.opencsv.CSVReaderBuilder; -import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityCsvviewerBinding; import java.io.File; import java.io.FileReader; @@ -19,30 +18,23 @@ import java.util.List; public class CSVViewerActivity extends AppCompatActivity { - - private TextView mCSVNameTitle; - private TextView mCSVContent; + private ActivityCsvviewerBinding activityCsvviewerBinding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_csvviewer); - declareElements(); + activityCsvviewerBinding = ActivityCsvviewerBinding.inflate(getLayoutInflater()); + setContentView(activityCsvviewerBinding.getRoot()); renderCSVFile(); } - private void declareElements() { - mCSVNameTitle = (TextView) findViewById(R.id.csvFileName); - mCSVContent = (TextView) findViewById(R.id.csvFileContent); - } - private void renderCSVFile() { Intent csvFileOpenIntent = getIntent(); String fileName = csvFileOpenIntent.getStringExtra("TOUCHED_FILE"); if (fileName != null && !fileName.isEmpty()) { - mCSVNameTitle.setText(fileName); - mCSVNameTitle.setVisibility(View.VISIBLE); + activityCsvviewerBinding.csvFileName.setText(fileName); + activityCsvviewerBinding.csvFileName.setVisibility(View.VISIBLE); } @@ -65,8 +57,8 @@ private void renderCSVFile() { List allRows = reader.readAll(); for (String[] row : allRows) { - mCSVContent.append(Arrays.toString(row)); - mCSVContent.append("\n"); + activityCsvviewerBinding.csvFileContent.append(Arrays.toString(row)); + activityCsvviewerBinding.csvFileContent.append("\n"); } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java index eca24286b0..b771316907 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java @@ -3,43 +3,34 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import com.bumptech.glide.Glide; -import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.utilities.Utilities; +import org.ole.planet.myplanet.databinding.ActivityImageViewerBinding; import java.io.File; public class ImageViewerActivity extends AppCompatActivity { - private TextView mImageFileNameTitle; - private ImageView mImageViewer; + private ActivityImageViewerBinding activityImageViewerBinding; private boolean isFullPath = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_image_viewer); - declareElements(); + activityImageViewerBinding = ActivityImageViewerBinding.inflate(getLayoutInflater()); + setContentView(activityImageViewerBinding.getRoot()); renderImageFile(); } - private void declareElements() { - mImageFileNameTitle = (TextView) findViewById(R.id.imageFileName); - mImageViewer = (ImageView) findViewById(R.id.imageViewer); - } - private void renderImageFile() { isFullPath = getIntent().getBooleanExtra("isFullPath", false); Intent imageOpenIntent = getIntent(); String fileName = imageOpenIntent.getStringExtra("TOUCHED_FILE"); if (fileName != null && !fileName.isEmpty()) { - mImageFileNameTitle.setText(fileName); - mImageFileNameTitle.setVisibility(View.VISIBLE); + activityImageViewerBinding.imageFileName.setText(fileName); + activityImageViewerBinding.imageFileName.setVisibility(View.VISIBLE); } try { @@ -50,7 +41,7 @@ private void renderImageFile() { File basePath = getExternalFilesDir(null); imageFile = new File(basePath, "ole/" + fileName); } - Glide.with(getApplicationContext()).load(imageFile).into(mImageViewer); + Glide.with(getApplicationContext()).load(imageFile).into(activityImageViewerBinding.imageViewer); } catch (Exception e) { e.printStackTrace(); } 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 ca66d1db85..c1467b31db 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 @@ -3,43 +3,34 @@ import android.content.Intent; import android.os.Bundle; import android.view.View; -import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.utilities.Utilities; +import org.ole.planet.myplanet.databinding.ActivityMarkdownViewerBinding; import java.io.File; -import br.tiagohm.markdownview.MarkdownView; - public class MarkdownViewerActivity extends AppCompatActivity { - private TextView mMarkdownNameTitle; - private MarkdownView mMarkdownContent; + private ActivityMarkdownViewerBinding activityMarkdownViewerBinding; private String fileName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_markdown_viewer); - declareElements(); + activityMarkdownViewerBinding = ActivityMarkdownViewerBinding.inflate(getLayoutInflater()); + setContentView(activityMarkdownViewerBinding.getRoot()); renderMarkdownFile(); } - private void declareElements() { - mMarkdownNameTitle = (TextView) findViewById(R.id.markdownFileName); - mMarkdownContent = (MarkdownView) findViewById(R.id.markdown_view); - } - private void renderMarkdownFile() { Intent markdownOpenIntent = getIntent(); String fileName = markdownOpenIntent.getStringExtra("TOUCHED_FILE"); if (fileName != null && !fileName.isEmpty()) { - mMarkdownNameTitle.setText(fileName); - mMarkdownNameTitle.setVisibility(View.VISIBLE); + activityMarkdownViewerBinding.markdownFileName.setText(fileName); + activityMarkdownViewerBinding.markdownFileName.setVisibility(View.VISIBLE); } try { @@ -47,7 +38,7 @@ private void renderMarkdownFile() { File markdownFile = new File(basePath, "ole/" + fileName); if (markdownFile.exists()) { - mMarkdownContent.loadMarkdownFromFile(markdownFile); + activityMarkdownViewerBinding.markdownView.loadMarkdownFromFile(markdownFile); } else { Toast.makeText(this, getString(R.string.unable_to_load) + fileName, Toast.LENGTH_LONG).show(); } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.java index c9b2d2ae9e..651992b848 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/PDFReaderActivity.java @@ -2,23 +2,20 @@ import android.content.Intent; import android.os.Bundle; - -import androidx.appcompat.app.AppCompatActivity; - import android.text.TextUtils; import android.util.Log; import android.view.View; -import android.widget.TextView; import android.widget.Toast; -import com.github.barteksc.pdfviewer.PDFView; +import androidx.appcompat.app.AppCompatActivity; + import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener; import com.github.barteksc.pdfviewer.listener.OnPageChangeListener; import com.github.barteksc.pdfviewer.listener.OnPageErrorListener; import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle; -import com.github.clans.fab.FloatingActionButton; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityPdfreaderBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmMyLibrary; import org.ole.planet.myplanet.service.AudioRecorderService; @@ -32,11 +29,9 @@ import io.realm.Realm; public class PDFReaderActivity extends AppCompatActivity implements OnPageChangeListener, OnLoadCompleteListener, OnPageErrorListener, AudioRecorderService.AudioRecordListener { + private ActivityPdfreaderBinding activityPdfreaderBinding; private static final String TAG = "PDF Reader Log"; - private TextView mPdfFileNameTitle; private String fileName; - private PDFView pdfView; - private FloatingActionButton fabRecord, fabPlay; private AudioRecorderService audioRecorderService; private RealmMyLibrary library; private Realm mRealm; @@ -44,23 +39,17 @@ public class PDFReaderActivity extends AppCompatActivity implements OnPageChange @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_pdfreader); + activityPdfreaderBinding = ActivityPdfreaderBinding.inflate(getLayoutInflater()); + setContentView(activityPdfreaderBinding.getRoot()); audioRecorderService = new AudioRecorderService().setAudioRecordListener(this); mRealm = new DatabaseService(this).getRealmInstance(); if (getIntent().hasExtra("resourceId")) { String resourceID = getIntent().getStringExtra("resourceId"); library = mRealm.where(RealmMyLibrary.class).equalTo("id", resourceID).findFirst(); } - declareElements(); renderPdfFile(); - } - private void declareElements() { - mPdfFileNameTitle = findViewById(R.id.pdfFileName); - pdfView = findViewById(R.id.pdfView); - fabRecord = findViewById(R.id.fab_record); - fabPlay = findViewById(R.id.fab_play); - fabRecord.setOnClickListener(view -> { + activityPdfreaderBinding.fabRecord.setOnClickListener(view -> { if (audioRecorderService.isRecording()) { audioRecorderService.stopRecording(); } else { @@ -68,7 +57,7 @@ private void declareElements() { } }); - fabPlay.setOnClickListener(view -> { + activityPdfreaderBinding.fabPlay.setOnClickListener(view -> { if (library != null && !TextUtils.isEmpty(library.getTranslationAudioPath())) { IntentUtils.openAudioFile(this, library.getTranslationAudioPath()); } @@ -79,15 +68,15 @@ private void renderPdfFile() { Intent pdfOpenIntent = getIntent(); fileName = pdfOpenIntent.getStringExtra("TOUCHED_FILE"); if (fileName != null && !fileName.isEmpty()) { - mPdfFileNameTitle.setText(fileName); - mPdfFileNameTitle.setVisibility(View.VISIBLE); + activityPdfreaderBinding.pdfFileName.setText(fileName); + activityPdfreaderBinding.pdfFileName.setVisibility(View.VISIBLE); } File file = new File(getExternalFilesDir(null), "ole/" + fileName); if (file.exists()) { try { Utilities.log(file.getAbsolutePath()); - pdfView.fromFile(file).defaultPage(0).enableAnnotationRendering(true).onLoad(this).onPageChange(this).scrollHandle(new DefaultScrollHandle(this)).load(); + activityPdfreaderBinding.pdfView.fromFile(file).defaultPage(0).enableAnnotationRendering(true).onLoad(this).onPageChange(this).scrollHandle(new DefaultScrollHandle(this)).load(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), getString(R.string.unable_to_load) + fileName, Toast.LENGTH_LONG).show(); @@ -112,7 +101,7 @@ public void onPageError(int page, Throwable t) { public void onRecordStarted() { Utilities.toast(this, getString(R.string.recording_started)); NotificationUtil.create(this, R.drawable.ic_mic, "Recording Audio", getString(R.string.ole_is_recording_audio)); - fabRecord.setImageResource(R.drawable.ic_stop); + activityPdfreaderBinding.fabRecord.setImageResource(R.drawable.ic_stop); } @Override @@ -123,7 +112,7 @@ public void onRecordStopped(String outputFile) { updateTranslation(outputFile); AddResourceFragment.showAlert(this, outputFile); } - fabRecord.setImageResource(R.drawable.ic_mic); + activityPdfreaderBinding.fabRecord.setImageResource(R.drawable.ic_mic); } private void updateTranslation(String outputFile) { @@ -146,6 +135,6 @@ protected void onDestroy() { public void onError(String error) { NotificationUtil.cancellAll(this); Utilities.toast(this, error); - fabRecord.setImageResource(R.drawable.ic_mic); + activityPdfreaderBinding.fabRecord.setImageResource(R.drawable.ic_mic); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.java index 9aa756fd75..4759dcb587 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/TextFileViewerActivity.java @@ -2,43 +2,34 @@ import android.content.Intent; import android.os.Bundle; +import android.view.View; import androidx.appcompat.app.AppCompatActivity; -import android.view.View; -import android.widget.TextView; - -import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.utilities.Utilities; +import org.ole.planet.myplanet.databinding.ActivityTextfileViewerBinding; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class TextFileViewerActivity extends AppCompatActivity { - private TextView mTextFileNameTitle; - private TextView mTextFileContent; + private ActivityTextfileViewerBinding activityTextfileViewerBinding; private String fileName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_textfile_viewer); - declareElements(); + activityTextfileViewerBinding = ActivityTextfileViewerBinding.inflate(getLayoutInflater()); + setContentView(activityTextfileViewerBinding.getRoot()); renderTextFile(); } - private void declareElements() { - mTextFileNameTitle = (TextView) findViewById(R.id.textFileName); - mTextFileContent = (TextView) findViewById(R.id.textFileContent); - } - private void renderTextFile() { Intent textFileOpenIntent = getIntent(); fileName = textFileOpenIntent.getStringExtra("TOUCHED_FILE"); if (fileName != null && !fileName.isEmpty()) { - mTextFileNameTitle.setText(fileName); - mTextFileNameTitle.setVisibility(View.VISIBLE); + activityTextfileViewerBinding.textFileName.setText(fileName); + activityTextfileViewerBinding.textFileName.setVisibility(View.VISIBLE); } renderTextFileThread(); } @@ -59,7 +50,7 @@ public void run() { text.append('\n'); } reader.close(); - mTextFileContent.setText(text.toString()); + activityTextfileViewerBinding.textFileContent.setText(text.toString()); } catch (Exception e) { e.printStackTrace(); } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/VideoPlayerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/VideoPlayerActivity.java index d8def1be03..ef0bc09c8d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/VideoPlayerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/VideoPlayerActivity.java @@ -17,7 +17,6 @@ import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector; -import com.google.android.exoplayer2.ui.SimpleExoPlayerView; import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; @@ -28,6 +27,7 @@ import com.google.gson.Gson; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityExoPlayerVideoBinding; import org.ole.planet.myplanet.ui.sync.SyncActivity; import org.ole.planet.myplanet.utilities.AuthSessionUpdater; import org.ole.planet.myplanet.utilities.Utilities; @@ -36,8 +36,8 @@ import java.util.Map; public class VideoPlayerActivity extends AppCompatActivity implements AuthSessionUpdater.AuthCallback { + private ActivityExoPlayerVideoBinding activityExoPlayerVideoBinding; SimpleExoPlayer exoPlayer; - SimpleExoPlayerView exoPlayerView; String auth = ""; String videoURL = ""; SharedPreferences settings; @@ -45,9 +45,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements AuthSessio @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_exo_player_video); + activityExoPlayerVideoBinding = ActivityExoPlayerVideoBinding.inflate(getLayoutInflater()); + setContentView(activityExoPlayerVideoBinding.getRoot()); settings = getSharedPreferences(SyncActivity.PREFS_NAME, MODE_PRIVATE); - exoPlayerView = findViewById(R.id.exo_player_simple); Intent intentExtras = getIntent(); Bundle extras = intentExtras.getExtras(); @@ -89,7 +89,7 @@ public void streamVideoFromUrl(String videoUrl, String auth) { ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoUri, defaultHttpDataSourceFactory, extractorsFactory, null, null); - exoPlayerView.setPlayer(exoPlayer); + activityExoPlayerVideoBinding.exoPlayerSimple.setPlayer(exoPlayer); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(true); } @@ -109,7 +109,7 @@ public void prepareExoPlayerFromFileUri(String uristring) { DataSource.Factory factory = () -> fileDataSource; MediaSource audioSource = new ExtractorMediaSource(fileDataSource.getUri(), factory, new DefaultExtractorsFactory(), null, null); - exoPlayerView.setPlayer(exoPlayer); + activityExoPlayerVideoBinding.exoPlayerSimple.setPlayer(exoPlayer); exoPlayer.prepare(audioSource); exoPlayer.setPlayWhenReady(true); } From 69cfab781f6422873948d2d26f24727d1044e6ff Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 14 Sep 2023 20:43:05 +0300 Subject: [PATCH 36/80] enterprises: refactor module (fixes #2458) (#2459) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/enterprises/AdapterCalendar.java | 43 +++++----- .../ui/enterprises/AdapterFinance.java | 54 ++++++------ .../enterprises/EnterpriseCalendarFragment.kt | 70 +++++++--------- .../ui/enterprises/FinanceFragment.java | 82 +++++++------------ 5 files changed, 103 insertions(+), 150 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 55e1f9de43..f5dd57850c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1036 - versionName "0.10.36" + versionCode 1037 + versionName "0.10.37" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterCalendar.java b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterCalendar.java index 0e0b4f3b22..c94fa1ef41 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterCalendar.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterCalendar.java @@ -2,20 +2,19 @@ import android.content.Context; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.RowTeamCalendarBinding; import org.ole.planet.myplanet.model.RealmMeetup; import org.ole.planet.myplanet.utilities.TimeUtils; import java.util.List; -class AdapterCalendar extends RecyclerView.Adapter { +public class AdapterCalendar extends RecyclerView.Adapter { + private RowTeamCalendarBinding rowTeamCalendarBinding; private Context context; private List list; @@ -26,21 +25,21 @@ public AdapterCalendar(Context context, List list) { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_team_calendar, parent, false); - return new ViewHolderCalendar(v); + public ViewHolderCalendar onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowTeamCalendarBinding = RowTeamCalendarBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new ViewHolderCalendar(rowTeamCalendarBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolderCalendar) { - ((ViewHolderCalendar) holder).title.setText(list.get(position).getTitle()); - ((ViewHolderCalendar) holder).description.setText(list.get(position).getDescription()); - if (list.get(position).getStartDate() == list.get(position).getEndDate()) { - ((ViewHolderCalendar) holder).date.setText(TimeUtils.formatDate(list.get(position).getStartDate())); - } else { - ((ViewHolderCalendar) holder).date.setText(TimeUtils.formatDate(list.get(position).getStartDate()) + " to " + TimeUtils.formatDate(list.get(position).getEndDate())); - } + public void onBindViewHolder(@NonNull ViewHolderCalendar holder, int position) { + RealmMeetup meetup = list.get(position); + rowTeamCalendarBinding.tvTitle.setText(meetup.getTitle()); + rowTeamCalendarBinding.tvDescription.setText(meetup.getDescription()); + + if (meetup.getStartDate() == meetup.getEndDate()) { + rowTeamCalendarBinding.tvDate.setText(TimeUtils.formatDate(meetup.getStartDate())); + } else { + rowTeamCalendarBinding.tvDate.setText(TimeUtils.formatDate(meetup.getStartDate()) + " to " + TimeUtils.formatDate(meetup.getEndDate())); } } @@ -49,14 +48,12 @@ public int getItemCount() { return list.size(); } - class ViewHolderCalendar extends RecyclerView.ViewHolder { - TextView title, description, date; + public static class ViewHolderCalendar extends RecyclerView.ViewHolder { + RowTeamCalendarBinding rowTeamCalendarBinding; - public ViewHolderCalendar(View itemView) { - super(itemView); - title = itemView.findViewById(R.id.tv_title); - description = itemView.findViewById(R.id.tv_description); - date = itemView.findViewById(R.id.tv_date); + public ViewHolderCalendar(RowTeamCalendarBinding rowTeamCalendarBinding) { + super(rowTeamCalendarBinding.getRoot()); + this.rowTeamCalendarBinding = rowTeamCalendarBinding; } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterFinance.java b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterFinance.java index dac270afe3..851fe943c3 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterFinance.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/AdapterFinance.java @@ -7,23 +7,22 @@ import android.graphics.drawable.LayerDrawable; import android.text.TextUtils; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.RowFinanceBinding; import org.ole.planet.myplanet.model.RealmMyTeam; import org.ole.planet.myplanet.utilities.TimeUtils; import org.ole.planet.myplanet.utilities.Utilities; import io.realm.RealmResults; -public class AdapterFinance extends RecyclerView.Adapter { - +public class AdapterFinance extends RecyclerView.Adapter { + private RowFinanceBinding rowFinanceBinding; private Context context; private RealmResults list; @@ -34,29 +33,28 @@ public AdapterFinance(Context context, RealmResults list) { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_finance, parent, false); - return new ViewHolderFinance(v); + public ViewHolderFinance onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowFinanceBinding = RowFinanceBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new ViewHolderFinance(rowFinanceBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolderFinance) { - ((ViewHolderFinance) holder).date.setText(TimeUtils.formatDate(list.get(position).getDate(), "MMM dd, yyyy")); - ((ViewHolderFinance) holder).note.setText(list.get(position).getDescription()); + public void onBindViewHolder(@NonNull ViewHolderFinance holder, int position) { + rowFinanceBinding.date.setText(TimeUtils.formatDate(list.get(position).getDate(), "MMM dd, yyyy")); + rowFinanceBinding.note.setText(list.get(position).getDescription()); Utilities.log("Type " + list.get(position).getDate()); if (TextUtils.equals(list.get(position).getType().toLowerCase(), "debit")) { - ((ViewHolderFinance) holder).debit.setText(list.get(position).getAmount() + ""); - ((ViewHolderFinance) holder).credit.setText(" -"); - ((ViewHolderFinance) holder).credit.setTextColor(Color.BLACK); + rowFinanceBinding.debit.setText(list.get(position).getAmount() + ""); + rowFinanceBinding.credit.setText(" -"); + rowFinanceBinding.credit.setTextColor(Color.BLACK); } else { - ((ViewHolderFinance) holder).credit.setText(list.get(position).getAmount() + ""); - ((ViewHolderFinance) holder).debit.setText(" -"); - ((ViewHolderFinance) holder).debit.setTextColor(Color.BLACK); + rowFinanceBinding.credit.setText(list.get(position).getAmount() + ""); + rowFinanceBinding.debit.setText(" -"); + rowFinanceBinding.debit.setTextColor(Color.BLACK); } - ((ViewHolderFinance) holder).balance.setText(getBalance(position) + ""); - updateBackgroundColor(((ViewHolderFinance) holder).row, position); - } + rowFinanceBinding.balance.setText(getBalance(position) + ""); + updateBackgroundColor(rowFinanceBinding.llayout, position); + } private String getBalance(int position) { @@ -90,18 +88,12 @@ public void updateBackgroundColor(LinearLayout layout, int position) { } } - class ViewHolderFinance extends RecyclerView.ViewHolder { - TextView date, note, credit, debit, balance; - LinearLayout row; + public static class ViewHolderFinance extends RecyclerView.ViewHolder { + RowFinanceBinding rowFinanceBinding; - public ViewHolderFinance(View itemView) { - super(itemView); - row = itemView.findViewById(R.id.llayout); - date = itemView.findViewById(R.id.date); - note = itemView.findViewById(R.id.note); - credit = itemView.findViewById(R.id.credit); - debit = itemView.findViewById(R.id.debit); - balance = itemView.findViewById(R.id.balance); + public ViewHolderFinance(RowFinanceBinding rowFinanceBinding) { + super(rowFinanceBinding.getRoot()); + this.rowFinanceBinding = rowFinanceBinding; } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt index 5eaeca9df7..5dd2a90991 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt @@ -8,11 +8,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.RadioButton -import android.widget.RadioGroup import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat -import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.gson.Gson @@ -25,6 +23,8 @@ import kotlinx.android.synthetic.main.calendar_day.view.* import kotlinx.android.synthetic.main.calendar_month.view.* import kotlinx.android.synthetic.main.fragment_enterprise_calendar.* import org.ole.planet.myplanet.R +import org.ole.planet.myplanet.databinding.AddMeetupBinding +import org.ole.planet.myplanet.databinding.FragmentEnterpriseCalendarBinding import org.ole.planet.myplanet.model.RealmMeetup import org.ole.planet.myplanet.ui.team.BaseTeamFragment import org.ole.planet.myplanet.utilities.DialogUtils @@ -35,59 +35,45 @@ import org.threeten.bp.temporal.WeekFields import java.util.* class EnterpriseCalendarFragment : BaseTeamFragment() { + private lateinit var fragmentEnterpriseCalendarBinding: FragmentEnterpriseCalendarBinding lateinit var list: List - lateinit var startDate: TextView - lateinit var startTime: TextView - lateinit var endDate: TextView - lateinit var endTime: TextView lateinit var start: Calendar lateinit var end: Calendar - lateinit var rvCalendar: RecyclerView override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val v = inflater.inflate(R.layout.fragment_enterprise_calendar, container, false) + fragmentEnterpriseCalendarBinding = FragmentEnterpriseCalendarBinding.inflate(inflater, container, false) start = Calendar.getInstance() end = Calendar.getInstance() - var fab = v.findViewById(R.id.add_event) - showHideFab(fab) - v.findViewById(R.id.add_event).setOnClickListener { showMeetupAlert() } - rvCalendar = v.findViewById(R.id.rv_calendar) - return v + showHideFab() + fragmentEnterpriseCalendarBinding.addEvent.setOnClickListener { showMeetupAlert() } + return fragmentEnterpriseCalendarBinding.root } - private fun showHideFab(fab: View) { + private fun showHideFab() { if (arguments!!.getBoolean("fromLogin", false)) { - fab.visibility = View.GONE + fragmentEnterpriseCalendarBinding.addEvent.visibility = View.GONE } else if (user != null) { - if (user.isManager || user.isLeader) fab.visibility = View.VISIBLE - else fab.visibility = View.GONE + if (user.isManager || user.isLeader) fragmentEnterpriseCalendarBinding.addEvent.visibility = View.VISIBLE + else fragmentEnterpriseCalendarBinding.addEvent.visibility = View.GONE } else { - fab.visibility = View.GONE + fragmentEnterpriseCalendarBinding.addEvent.visibility = View.GONE } } private fun showMeetupAlert() { - val v = LayoutInflater.from(activity).inflate(R.layout.add_meetup, null) - val title = v.findViewById(R.id.et_title) - val location = v.findViewById(R.id.et_location) - val description = v.findViewById(R.id.et_description) - val radioGroup = v.findViewById(R.id.rg_recuring) - startDate = v.findViewById(R.id.tv_start_date) - startTime = v.findViewById(R.id.tv_start_time) - endDate = v.findViewById(R.id.tv_end_date) - endTime = v.findViewById(R.id.tv_end_time) - setDatePickerListener(startDate, start) - setDatePickerListener(endDate, end) - setTimePicker(startTime) - setTimePicker(endTime) - - AlertDialog.Builder(requireActivity()).setView(v) + val addMeetupBinding = AddMeetupBinding.inflate(layoutInflater) + setDatePickerListener(addMeetupBinding.tvStartDate, start) + setDatePickerListener(addMeetupBinding.tvEndDate, end) + setTimePicker(addMeetupBinding.tvStartTime) + setTimePicker(addMeetupBinding.tvEndTime) + + AlertDialog.Builder(requireActivity()).setView(addMeetupBinding.root) .setPositiveButton("Save") { _, _ -> - val ttl = title.text.toString() - val desc = description.text.toString() - val loc = location.text.toString() + val ttl = addMeetupBinding.etTitle.text.toString() + val desc = addMeetupBinding.etDescription.text.toString() + val loc = addMeetupBinding.etLocation.text.toString() if (ttl.isEmpty()) { Utilities.toast(activity, getString(R.string.title_is_required)) } else if (desc.isEmpty()) { @@ -104,9 +90,9 @@ class EnterpriseCalendarFragment : BaseTeamFragment() { meetup.creator = user.id meetup.startDate = start.timeInMillis if (end != null) meetup.endDate = end.timeInMillis - meetup.endTime = endTime.text.toString() - meetup.startTime = startTime.text.toString() - val rb = v.findViewById(radioGroup.checkedRadioButtonId) + meetup.endTime = addMeetupBinding.tvEndTime.text.toString() + meetup.startTime = addMeetupBinding.tvStartTime.text.toString() + val rb = addMeetupBinding.rgRecuring.findViewById(addMeetupBinding.rgRecuring.checkedRadioButtonId) if (rb != null) { meetup.recurring = rb.text.toString() } @@ -116,7 +102,7 @@ class EnterpriseCalendarFragment : BaseTeamFragment() { meetup.teamId = teamId mRealm.commitTransaction() Utilities.toast(activity, getString(R.string.meetup_added)) - rvCalendar.adapter?.notifyDataSetChanged() + fragmentEnterpriseCalendarBinding.rvCalendar.adapter?.notifyDataSetChanged() calendarView.notifyCalendarChanged() } }.setNegativeButton("Cancel", null).show() @@ -154,8 +140,8 @@ class EnterpriseCalendarFragment : BaseTeamFragment() { Utilities.log(teamId) list = mRealm.where(RealmMeetup::class.java).equalTo("teamId", teamId) .greaterThanOrEqualTo("endDate", TimeUtils.currentDateLong()).findAll() - rvCalendar.layoutManager = LinearLayoutManager(activity) - rvCalendar.adapter = AdapterCalendar(activity, list) + fragmentEnterpriseCalendarBinding.rvCalendar.layoutManager = LinearLayoutManager(activity) + fragmentEnterpriseCalendarBinding.rvCalendar.adapter = AdapterCalendar(activity, list) calendarView.inDateStyle = InDateStyle.ALL_MONTHS calendarView.outDateStyle = OutDateStyle.END_OF_ROW calendarView.hasBoundaries = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/FinanceFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/FinanceFragment.java index f5b51acd74..190b3494cd 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/FinanceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/FinanceFragment.java @@ -5,20 +5,14 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.github.clans.fab.FloatingActionButton; -import com.google.android.material.textfield.TextInputLayout; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.AddTransactionBinding; +import org.ole.planet.myplanet.databinding.FragmentFinanceBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmMyTeam; import org.ole.planet.myplanet.ui.team.BaseTeamFragment; @@ -34,18 +28,11 @@ import io.realm.Sort; public class FinanceFragment extends BaseTeamFragment { - RecyclerView rvFinance; - FloatingActionButton fab; - TextView nodata; + private FragmentFinanceBinding fragmentFinanceBinding; + private AddTransactionBinding addTransactionBinding; Realm mRealm; - ImageView imgDate; AdapterFinance adapterFinance; - TextInputLayout tlNote; - Spinner spnType; - TextInputLayout tlAmount; - LinearLayout llDate; Calendar date; - TextView tvSelectDate; RealmResults list; boolean isAsc = false; @@ -54,7 +41,7 @@ public class FinanceFragment extends BaseTeamFragment { date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, monthOfYear); date.set(Calendar.DAY_OF_MONTH, dayOfMonth); - if (date != null) tvSelectDate.setText(TimeUtils.formatDateTZ(date.getTimeInMillis())); + if (date != null) addTransactionBinding.tvSelectDate.setText(TimeUtils.formatDateTZ(date.getTimeInMillis())); }; public FinanceFragment() { @@ -62,25 +49,20 @@ public FinanceFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_finance, container, false); + fragmentFinanceBinding = FragmentFinanceBinding.inflate(inflater, container, false); mRealm = new DatabaseService(getActivity()).getRealmInstance(); - rvFinance = v.findViewById(R.id.rv_finance); - fab = v.findViewById(R.id.add_transaction); - nodata = v.findViewById(R.id.tv_nodata); - imgDate = v.findViewById(R.id.img_date); - llDate = v.findViewById(R.id.ll_date); date = Calendar.getInstance(); - v.findViewById(R.id.btn_filter).setOnClickListener(view -> { + fragmentFinanceBinding.btnFilter.setOnClickListener(view -> { showDatePickerDialog(); }); - llDate.setOnClickListener(view -> { - imgDate.setRotation(imgDate.getRotation() + 180); + fragmentFinanceBinding.llDate.setOnClickListener(view -> { + fragmentFinanceBinding.imgDate.setRotation(fragmentFinanceBinding.imgDate.getRotation() + 180); list = mRealm.where(RealmMyTeam.class).notEqualTo("status", "archived").equalTo("teamId", teamId).equalTo("docType", "transaction").sort("date", isAsc ? Sort.DESCENDING : Sort.ASCENDING).findAll(); adapterFinance = new AdapterFinance(getActivity(), list); - rvFinance.setAdapter(adapterFinance); + fragmentFinanceBinding.rvFinance.setAdapter(adapterFinance); isAsc = !isAsc; }); - return v; + return fragmentFinanceBinding.getRoot(); } private void showDatePickerDialog() { @@ -93,7 +75,7 @@ private void showDatePickerDialog() { Utilities.log("" + start.getTimeInMillis() + " " + end.getTimeInMillis()); list = mRealm.where(RealmMyTeam.class).equalTo("teamId", teamId).equalTo("docType", "transaction").between("date", start.getTimeInMillis(), end.getTimeInMillis()).sort("date", Sort.DESCENDING).findAll(); adapterFinance = new AdapterFinance(getActivity(), list); - rvFinance.setAdapter(adapterFinance); + fragmentFinanceBinding.rvFinance.setAdapter(adapterFinance); calculateTotal(list); }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show(getActivity().getFragmentManager(), ""); } @@ -102,17 +84,17 @@ private void showDatePickerDialog() { public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (user.isManager() || user.isLeader()) { - fab.setVisibility(View.VISIBLE); + fragmentFinanceBinding.addTransaction.setVisibility(View.VISIBLE); } else { - fab.setVisibility(View.GONE); + fragmentFinanceBinding.addTransaction.setVisibility(View.GONE); } - fab.setOnClickListener(view -> addTransaction()); + fragmentFinanceBinding.addTransaction.setOnClickListener(view -> addTransaction()); list = mRealm.where(RealmMyTeam.class).notEqualTo("status", "archived").equalTo("teamId", teamId).equalTo("docType", "transaction").sort("date", Sort.DESCENDING).findAll(); adapterFinance = new AdapterFinance(getActivity(), list); - rvFinance.setLayoutManager(new LinearLayoutManager(getActivity())); - rvFinance.setAdapter(adapterFinance); + fragmentFinanceBinding.rvFinance.setLayoutManager(new LinearLayoutManager(getActivity())); + fragmentFinanceBinding.rvFinance.setAdapter(adapterFinance); calculateTotal(list); - showNoData(nodata, list.size()); + showNoData(fragmentFinanceBinding.tvNodata, list.size()); } private void calculateTotal(List list) { @@ -126,20 +108,20 @@ private void calculateTotal(List list) { } } int total = credit - debit; - ((TextView) getView().findViewById(R.id.tv_debit)).setText(debit + ""); - ((TextView) getView().findViewById(R.id.tv_credit)).setText(credit + ""); - ((TextView) getView().findViewById(R.id.tv_balance)).setText(total + ""); + fragmentFinanceBinding.tvDebit.setText(debit + ""); + fragmentFinanceBinding.tvCredit.setText(credit + ""); + fragmentFinanceBinding.tvBalance.setText(total + ""); if (total >= 0) - ((TextView) getView().findViewById(R.id.balance_caution)).setVisibility(View.GONE); + fragmentFinanceBinding.balanceCaution.setVisibility(View.GONE); } private void addTransaction() { new AlertDialog.Builder(getActivity()).setView(setUpAlertUi()).setTitle(R.string.add_transaction).setPositiveButton("Submit", (dialogInterface, i) -> { - String type = spnType.getSelectedItem().toString(); + String type = addTransactionBinding.spnType.getSelectedItem().toString(); Utilities.log(type + " type"); - String note = tlNote.getEditText().getText().toString().trim(); - String amount = tlAmount.getEditText().getText().toString().trim(); + String note = addTransactionBinding.tlNote.getEditText().getText().toString().trim(); + String amount = addTransactionBinding.tlAmount.getEditText().getText().toString().trim(); if (note.isEmpty()) { Utilities.toast(getActivity(), getString(R.string.note_is_required)); @@ -153,7 +135,7 @@ private void addTransaction() { }, () -> { Utilities.toast(getActivity(), getString(R.string.transaction_added)); adapterFinance.notifyDataSetChanged(); - showNoData(nodata, adapterFinance.getItemCount()); + showNoData(fragmentFinanceBinding.tvNodata, adapterFinance.getItemCount()); calculateTotal(list); }); } @@ -177,13 +159,9 @@ private void createTransactionObject(Realm realm, String type, String note, Stri } private View setUpAlertUi() { - View v = LayoutInflater.from(getActivity()).inflate(R.layout.add_transaction, null); - spnType = v.findViewById(R.id.spn_type); - tlNote = v.findViewById(R.id.tl_note); - tlAmount = v.findViewById(R.id.tl_amount); - tvSelectDate = v.findViewById(R.id.tv_select_date); - tvSelectDate.setOnClickListener(view -> new DatePickerDialog(getActivity(), listener, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)).show()); - - return v; + addTransactionBinding = AddTransactionBinding.inflate(LayoutInflater.from(getActivity())); // Replace with your actual binding class name + addTransactionBinding.tvSelectDate.setOnClickListener(view -> new DatePickerDialog(getActivity(), listener, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)).show()); + + return addTransactionBinding.getRoot(); } } From de852bbf9b508818e83bdda9ef8ab366420942cb Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 15 Sep 2023 19:52:17 +0300 Subject: [PATCH 37/80] addons: capture and add an image to resources (fixes #2370) (#2398) Co-authored-by: dogi --- .github/dependabot.yml | 4 +- app/build.gradle | 4 +- .../ui/library/AddResourceFragment.java | 28 +++++------ .../ui/viewer/ImageViewerActivity.java | 50 +++++++++++++++---- 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index bf665f74f1..9436e87d36 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,9 +8,9 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "weekly" + interval: "daily" - package-ecosystem: "gradle" directory: "/" schedule: interval: "daily" - open-pull-requests-limit: 10 + open-pull-requests-limit: 12 diff --git a/app/build.gradle b/app/build.gradle index f5dd57850c..e918af5c14 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1037 - versionName "0.10.37" + versionCode 1038 + versionName "0.10.38" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java index 15c3c4d149..4049eab498 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java @@ -56,6 +56,7 @@ public class AddResourceFragment extends BottomSheetDialogFragment { FloatingActionButton floatingActionButton; AudioRecorderService audioRecorderService; File output; + private Uri photoURI; private Uri videoUri; public AddResourceFragment() { @@ -190,31 +191,30 @@ private Uri createVideoFileUri() { return videoUri; } public void takePhoto() { - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); - output = new File(dir, UUID.randomUUID().toString() + ".jpg"); + ContentValues values = new ContentValues(); + values.put(MediaStore.Images.Media.TITLE, "Photo_" + UUID.randomUUID().toString()); + values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); - // Generate a content URI using FileProvider - Uri photoURI = FileProvider.getUriForFile(requireContext(), "org.ole.planet.myplanet.fileprovider", output); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + values.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "/ole/photo"); + } - // Grant temporary permission to the camera app to access the file - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + photoURI = requireActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); - // Set the output URI + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); - startActivityForResult(intent, REQUEST_CAPTURE_PICTURE); + + if (intent.resolveActivity(requireActivity().getPackageManager()) != null) { + startActivityForResult(intent, REQUEST_CAPTURE_PICTURE); + } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri uri = null; -// String path = ""; if (requestCode == REQUEST_CAPTURE_PICTURE) { -// if (output != null) { -// url = Uri.fromFile(output); -// path = url.getPath(); -// } + uri = photoURI; } else if (requestCode == REQUEST_VIDEO_CAPTURE) { uri = videoUri; } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java index b771316907..72818b9906 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/ImageViewerActivity.java @@ -7,14 +7,19 @@ import androidx.appcompat.app.AppCompatActivity; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.RequestOptions; import org.ole.planet.myplanet.databinding.ActivityImageViewerBinding; import java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ImageViewerActivity extends AppCompatActivity { private ActivityImageViewerBinding activityImageViewerBinding; private boolean isFullPath = false; + String fileName; @Override protected void onCreate(Bundle savedInstanceState) { @@ -27,23 +32,46 @@ protected void onCreate(Bundle savedInstanceState) { private void renderImageFile() { isFullPath = getIntent().getBooleanExtra("isFullPath", false); Intent imageOpenIntent = getIntent(); - String fileName = imageOpenIntent.getStringExtra("TOUCHED_FILE"); + fileName = imageOpenIntent.getStringExtra("TOUCHED_FILE"); if (fileName != null && !fileName.isEmpty()) { activityImageViewerBinding.imageFileName.setText(fileName); activityImageViewerBinding.imageFileName.setVisibility(View.VISIBLE); } - try { - File imageFile; - if (isFullPath) { - imageFile = new File(fileName); - } else { - File basePath = getExternalFilesDir(null); - imageFile = new File(basePath, "ole/" + fileName); + if (fileName.matches(".*[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}.*")) { + displayCapturedImage(); + } else { + try { + File imageFile; + if (isFullPath) { + imageFile = new File(fileName); + } else { + File basePath = getExternalFilesDir(null); + imageFile = new File(basePath, "ole/" + fileName); + } + Glide.with(getApplicationContext()).load(imageFile).into(activityImageViewerBinding.imageViewer); + + } catch (Exception e) { + e.printStackTrace(); } - Glide.with(getApplicationContext()).load(imageFile).into(activityImageViewerBinding.imageViewer); - } catch (Exception e) { - e.printStackTrace(); } } + + private void displayCapturedImage() { + Pattern uuidPattern = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/"); + Matcher matcher = uuidPattern.matcher(fileName); + + if (matcher.find()) { + fileName = fileName.substring(matcher.group().length()); + } + + RequestOptions requestOptions = new RequestOptions() + .diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true); + + Glide.with(this) + .load(fileName) + .apply(requestOptions) + .into(activityImageViewerBinding.imageViewer); + } } From b6f485542800aec59c980b7657ef54e8dcfafc5b Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 15 Sep 2023 20:32:45 +0300 Subject: [PATCH 38/80] addons: record and add an audio to resources (fixes #2376) (#2408) Co-authored-by: dogi --- app/build.gradle | 4 +- .../service/AudioRecorderService.java | 48 ++++++++++++++----- .../ui/library/AddResourceFragment.java | 11 ++++- .../ui/viewer/AudioPlayerActivity.java | 36 ++++++++++++-- 4 files changed, 78 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e918af5c14..4ad116461c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1038 - versionName "0.10.38" + versionCode 1039 + versionName "0.10.39" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/service/AudioRecorderService.java b/app/src/main/java/org/ole/planet/myplanet/service/AudioRecorderService.java index 0d40e59f89..d6fa10e3da 100644 --- a/app/src/main/java/org/ole/planet/myplanet/service/AudioRecorderService.java +++ b/app/src/main/java/org/ole/planet/myplanet/service/AudioRecorderService.java @@ -1,10 +1,14 @@ package org.ole.planet.myplanet.service; +import static org.ole.planet.myplanet.MainApplication.context; + +import android.database.Cursor; import android.media.MediaRecorder; +import android.net.Uri; import android.os.Environment; +import android.provider.MediaStore; import java.io.File; -import java.io.IOException; import java.util.UUID; public class AudioRecorderService { @@ -30,13 +34,11 @@ public AudioRecorderService setAudioRecordListener(AudioRecordListener audioReco } public void startRecording() { - outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + UUID.randomUUID().toString() + ".aac"; - File f = new File(outputFile); - createFileIfNotExists(f); + outputFile = createAudioFile(); myAudioRecorder = new MediaRecorder(); myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS); - myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB); + myAudioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); myAudioRecorder.setOutputFile(outputFile); try { myAudioRecorder.prepare(); @@ -50,14 +52,34 @@ public void startRecording() { } } - private void createFileIfNotExists(File f) { - if (!f.exists()) { - try { - f.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } + private String createAudioFile() { + String audioFileName; + File audioFile; + int attempt = 0; + + do { + audioFileName = UUID.randomUUID().toString() + ".aac"; + audioFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), audioFileName); + attempt++; + } while (audioFile.exists() && attempt < 100); + + if (attempt >= 100) { + return null; + } + + return audioFile.getAbsolutePath(); + } + + private String getFilePathFromUri(Uri uri) { + String filePath = null; + String[] projection = {MediaStore.Audio.Media.DATA}; + Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); + filePath = cursor.getString(columnIndex); + cursor.close(); } + return filePath; } public boolean isRecording() { @@ -80,4 +102,4 @@ public interface AudioRecordListener { void onError(String error); } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java index 4049eab498..c03a648a94 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/library/AddResourceFragment.java @@ -157,7 +157,7 @@ public void onRecordStarted() { public void onRecordStopped(String outputFile) { tvTime.setText(""); dialog.dismiss(); -// startIntent(outputFile); + audioStartIntent(outputFile); floatingActionButton.setImageResource(R.drawable.ic_mic); } @@ -236,6 +236,14 @@ private void startIntent(Uri uri, int requestCode) { } } + private void audioStartIntent(String path) { + if (!TextUtils.isEmpty(path)) { + addResource(path); + } else { + Utilities.toast(getActivity(), getString(R.string.invalid_resource_url)); + } + } + private String getRealPathFromUri(Uri uri) { String[] projection = {MediaStore.Images.Media.DATA}; @@ -247,6 +255,7 @@ private String getRealPathFromUri(Uri uri) { } return ""; + } private void addResource(String path) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java index 5b5ad05c3e..ce01cc4714 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/viewer/AudioPlayerActivity.java @@ -17,22 +17,32 @@ import java.io.File; import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class AudioPlayerActivity extends AppCompatActivity implements JcPlayerManagerListener { private ActivityAudioPlayerBinding activityAudioPlayerBinding; ArrayList jcAudios; boolean isFullPath; + String filePath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activityAudioPlayerBinding = ActivityAudioPlayerBinding.inflate(getLayoutInflater()); setContentView(activityAudioPlayerBinding.getRoot()); - String filePath = getIntent().getStringExtra("TOUCHED_FILE"); + filePath = getIntent().getStringExtra("TOUCHED_FILE"); jcAudios = new ArrayList<>(); isFullPath = getIntent().getBooleanExtra("isFullPath", false); - String fullPath; + if (filePath.matches(".*[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}//.*")) { + playRecordedAudio(); + } else { + playDownloadedAudio(); + } + } + private void playDownloadedAudio() { + String fullPath; if (isFullPath) { fullPath = filePath; } else { @@ -41,10 +51,26 @@ protected void onCreate(Bundle savedInstanceState) { } jcAudios.add(JcAudio.createFromFilePath(fullPath)); + initializeJCPlayer(); + } + + private void playRecordedAudio() { + Pattern uuidPattern = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/"); + Matcher matcher = uuidPattern.matcher(filePath); + + if (matcher.find()) { + filePath = filePath.substring(matcher.group().length()); + } + jcAudios.add(JcAudio.createFromFilePath(filePath)); + initializeJCPlayer(); + } + + private void initializeJCPlayer() { activityAudioPlayerBinding.jcplayer.initPlaylist(jcAudios, null); - activityAudioPlayerBinding.jcplayer.getRootView().findViewById(R.id.btnNext).setVisibility(View.GONE); - activityAudioPlayerBinding.jcplayer.getRootView().findViewById(R.id.btnPrev).setVisibility(View.GONE); - activityAudioPlayerBinding.jcplayer.getRootView().findViewById(R.id.btnRepeatOne).setVisibility(View.GONE); + View rootView = activityAudioPlayerBinding.jcplayer.getRootView(); + rootView.findViewById(R.id.btnNext).setVisibility(View.GONE); + rootView.findViewById(R.id.btnPrev).setVisibility(View.GONE); + rootView.findViewById(R.id.btnRepeatOne).setVisibility(View.GONE); } @Override From 36e7e4bf86b0c16228b883640487bb1681f6aa7d Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 15 Sep 2023 21:07:54 +0300 Subject: [PATCH 39/80] chat: refactor towards more stability (fixes #2485) (#2500) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4ad116461c..f90e23605e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1039 - versionName "0.10.39" + versionCode 1040 + versionName "0.10.40" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt index 312eccedf7..d2f332dd50 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt @@ -104,7 +104,8 @@ class ChatActivity : AppCompatActivity() { call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { Log.d("response", "${response.body()}") - if (response.body()!!.status == "Success") { + val responseBody = response.body() + if (responseBody != null && responseBody.status == "Success") { val chatModel = response.body() val history: ArrayList = chatModel?.history ?: ArrayList() From fbb7f52608e4f5a21a261358b1ac69bac1cd3a03 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 15 Sep 2023 21:23:46 +0300 Subject: [PATCH 40/80] chat: refactor and cleanup (fixes #2498) (#2501) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f90e23605e..2d8567d4dc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1040 - versionName "0.10.40" + versionCode 1041 + versionName "0.10.41" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt index d2f332dd50..283f838875 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.text.Editable import android.text.TextUtils import android.text.TextWatcher -import android.util.Log import android.view.View import android.view.ViewGroup import androidx.activity.OnBackPressedCallback @@ -100,10 +99,8 @@ class ChatActivity : AppCompatActivity() { val apiInterface = ApiClient.getClient().create(ApiInterface::class.java) val call = apiInterface.chatGpt(Utilities.getHostUrl(), content) - Log.d("content", "$content") call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { - Log.d("response", "${response.body()}") val responseBody = response.body() if (responseBody != null && responseBody.status == "Success") { val chatModel = response.body() @@ -122,7 +119,6 @@ class ChatActivity : AppCompatActivity() { } else { activityChatBinding.textGchatIndicator.visibility = View.VISIBLE activityChatBinding.textGchatIndicator.text = "${response.body()!!.message}" - Log.d("failed chat message", "${response.body()!!.message}") } activityChatBinding.buttonGchatSend.isEnabled = true @@ -131,7 +127,6 @@ class ChatActivity : AppCompatActivity() { } override fun onFailure(call: Call, t: Throwable) { - Log.d("onFailure chat message", "${t.message}") activityChatBinding.textGchatIndicator.visibility = View.VISIBLE activityChatBinding.textGchatIndicator.text = "${t.message}" activityChatBinding.buttonGchatSend.isEnabled = true From bf4f56b5a9695a78782b0e8413ee341a41dcba05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:20:03 -0400 Subject: [PATCH 41/80] actions: bump `pl.droidsonroids.gif:android-gif-drawable` to 1.2.28 (fixes #2470) (#2463) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gideon Okuro Co-authored-by: dogi --- app/build.gradle | 7 ++++--- build.gradle | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2d8567d4dc..34864634cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1041 - versionName "0.10.41" + versionCode 1042 + versionName "0.10.42" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -77,6 +77,7 @@ repositories { mavenCentral() jcenter() maven { url "https://jitpack.io" } + maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } dependencies { @@ -109,7 +110,7 @@ dependencies { implementation 'com.mikepenz:crossfader:1.5.1@aar' implementation 'com.mikepenz:crossfadedrawerlayout:1.0.1@aar' implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1' - implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.28' implementation 'com.google.android:flexbox:2.0.1' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.firebase:firebase-jobdispatcher:0.8.6' diff --git a/build.gradle b/build.gradle index 4e9c6bdca4..e7797c7788 100644 --- a/build.gradle +++ b/build.gradle @@ -15,15 +15,12 @@ buildscript { repositories { mavenCentral() - maven { url "https://oss.sonatype.org/content/repositories/snapshots" } google() } dependencies { classpath 'com.android.tools.build:gradle:8.1.1' classpath "io.realm:realm-gradle-plugin:10.16.1" classpath "com.google.dagger:hilt-android-gradle-plugin:2.48" - - classpath 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From fc31c73e3596e4519875984d2bb4da22dd420c15 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:33:43 -0400 Subject: [PATCH 42/80] actions: bump `com.github.kizitonwose:CalendarView` to 1.1.0 (fixes #2471) (#2466) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gideon Okuro Co-authored-by: dogi --- app/build.gradle | 6 +++--- .../main/java/org/ole/planet/myplanet/MainApplication.java | 2 -- .../myplanet/ui/enterprises/EnterpriseCalendarFragment.kt | 7 +++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 34864634cd..1bfe6ab3f8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1042 - versionName "0.10.42" + versionCode 1043 + versionName "0.10.43" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -134,7 +134,7 @@ dependencies { implementation 'com.sa90.materialarcmenu:library:2.0.0' implementation project(':library') implementation 'org.jetbrains:annotations:24.0.1' - implementation 'com.github.kizitonwose:CalendarView:0.3.1' + implementation 'com.github.kizitonwose:CalendarView:1.1.0' implementation "io.noties.markwon:editor:4.6.2" implementation "androidx.core:core-ktx:1.12.0" implementation "com.github.VaibhavLakhera:Circular-Progress-View:0.1.2" diff --git a/app/src/main/java/org/ole/planet/myplanet/MainApplication.java b/app/src/main/java/org/ole/planet/myplanet/MainApplication.java index 261c1d9207..8e2eba4200 100644 --- a/app/src/main/java/org/ole/planet/myplanet/MainApplication.java +++ b/app/src/main/java/org/ole/planet/myplanet/MainApplication.java @@ -19,7 +19,6 @@ import com.firebase.jobdispatcher.Lifetime; import com.firebase.jobdispatcher.RetryStrategy; import com.firebase.jobdispatcher.Trigger; -import com.jakewharton.threetenabp.AndroidThreeTen; import org.ole.planet.myplanet.callback.TeamPageListener; import org.ole.planet.myplanet.datamanager.DatabaseService; @@ -65,7 +64,6 @@ public void onCreate() { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); builder.detectFileUriExposure(); - AndroidThreeTen.init(this); // Set up auto-sync using WorkManager if (preferences.getBoolean("autoSync", false) && preferences.contains("autoSyncInterval")) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt index 5dd2a90991..8a7ff96faf 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/enterprises/EnterpriseCalendarFragment.kt @@ -3,12 +3,14 @@ package org.ole.planet.myplanet.ui.enterprises import android.app.DatePickerDialog import android.app.TimePickerDialog import android.graphics.Color +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.RadioButton import android.widget.TextView +import androidx.annotation.RequiresApi import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager @@ -30,10 +32,11 @@ import org.ole.planet.myplanet.ui.team.BaseTeamFragment import org.ole.planet.myplanet.utilities.DialogUtils import org.ole.planet.myplanet.utilities.TimeUtils import org.ole.planet.myplanet.utilities.Utilities -import org.threeten.bp.YearMonth -import org.threeten.bp.temporal.WeekFields +import java.time.YearMonth +import java.time.temporal.WeekFields import java.util.* +@RequiresApi(Build.VERSION_CODES.O) class EnterpriseCalendarFragment : BaseTeamFragment() { private lateinit var fragmentEnterpriseCalendarBinding: FragmentEnterpriseCalendarBinding lateinit var list: List From e26b0961f2e56c9ce61837809bf7c47b6631dc46 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Mon, 18 Sep 2023 20:03:18 +0300 Subject: [PATCH 43/80] sync: harden realm towards null exceptions (fixes #2506) (#2507) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../planet/myplanet/service/UploadManager.java | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1bfe6ab3f8..9408445145 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1043 - versionName "0.10.43" + versionCode 1044 + versionName "0.10.44" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java b/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java index 313467d812..3169b2ab4d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java +++ b/app/src/main/java/org/ole/planet/myplanet/service/UploadManager.java @@ -6,6 +6,7 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.ole.planet.myplanet.MainApplication; @@ -232,14 +233,21 @@ public void uploadFeedback(final SuccessListener listener) { try { Response res; res = apiInterface.postDoc(Utilities.getHeader(), "application/json", Utilities.getUrl() + "/feedback", RealmFeedback.serializeFeedback(feedback)).execute(); - if (res.body() != null) { - Utilities.log(new Gson().toJson(res.body())); - JsonObject r = (JsonObject) res.body(); - feedback.set_rev(r.get("rev").getAsString()); - feedback.set_id(r.get("id").getAsString()); + JsonObject r = (JsonObject) res.body(); + if (r != null) { + JsonElement revElement = r.get("rev"); + JsonElement idElement = r.get("id"); + + if (revElement != null && idElement != null) { + feedback.set_rev(revElement.getAsString()); + feedback.set_id(idElement.getAsString()); + } else { + Utilities.log("Missing 'rev' or 'id' elements in the JSON response"); + } } else { Utilities.log("ERRRRRRRR " + res.errorBody().string()); } + } catch (IOException e) { e.printStackTrace(); } From 957fafd64f857e25a18f8ad4a8ea32de6639517b Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Tue, 19 Sep 2023 20:41:45 +0300 Subject: [PATCH 44/80] chat: handle null exception (fixes #2510) (#2511) Co-authored-by: dogi --- app/build.gradle | 4 +-- .../planet/myplanet/ui/chat/ChatActivity.kt | 31 ++++++++++++------- app/src/main/res/values-ar/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-ne/strings.xml | 1 + app/src/main/res/values-so/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9408445145..2e5bc782e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1044 - versionName "0.10.44" + versionCode 1045 + versionName "0.10.45" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt index 283f838875..189217e497 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import okhttp3.MediaType import okhttp3.RequestBody +import org.ole.planet.myplanet.R import org.ole.planet.myplanet.databinding.ActivityChatBinding import org.ole.planet.myplanet.datamanager.ApiClient import org.ole.planet.myplanet.datamanager.ApiInterface @@ -102,23 +103,29 @@ class ChatActivity : AppCompatActivity() { call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { val responseBody = response.body() - if (responseBody != null && responseBody.status == "Success") { - val chatModel = response.body() - val history: ArrayList = chatModel?.history ?: ArrayList() - - val lastItem = history.lastOrNull() - if (lastItem != null) { - if (lastItem.response != null) { - val responseBody = lastItem.response - val chatResponse = response.body()?.chat - if (chatResponse != null) { - mAdapter.addResponse(chatResponse) + if (responseBody != null) { + if (responseBody.status == "Success") { + val chatModel = response.body() + val history: ArrayList = chatModel?.history ?: ArrayList() + + val lastItem = history.lastOrNull() + if (lastItem != null) { + if (lastItem.response != null) { + val responseBody = lastItem.response + val chatResponse = response.body()?.chat + if (chatResponse != null) { + mAdapter.addResponse(chatResponse) + } } } + } else { + activityChatBinding.textGchatIndicator.visibility = View.VISIBLE + activityChatBinding.textGchatIndicator.text = "${response.body()!!.message}" } } else { activityChatBinding.textGchatIndicator.visibility = View.VISIBLE - activityChatBinding.textGchatIndicator.text = "${response.body()!!.message}" + activityChatBinding.textGchatIndicator.text = + getString(R.string.request_failed_please_retry) } activityChatBinding.buttonGchatSend.isEnabled = true diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index e188091f92..3e83cae61b 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -941,5 +941,6 @@ يرجى التقييم يجب أن تبدأ بحرف أو رقم يُسمح فقط بالحروف والأرقام و "_" و "." و "-" + الطلب فشل، يرجى إعادة المحاولة \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8b13339870..54579d6329 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -946,5 +946,6 @@ Por favor, dé una calificación Debe comenzar con una letra o número Solo se permiten letras, números, "_" , ".", y "-" + La solicitud ha fallado, por favor inténtelo de nuevo diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8f4e8a07ee..bb23a97f5a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -946,5 +946,6 @@ Veuillez donner une note Doit commencer par une lettre ou un chiffre Seules les lettres, les chiffres, "_" , ".", et "-" sont autorisés + La demande a échoué, veuillez réessayer diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index 87ea47a424..3b186f4e2c 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -946,5 +946,6 @@ कृपया मूल्याङ्कन दिनुहोस् पात्र वा नम्बरसँग सुरु गर्नु पर्दछ केवल अक्षर, नम्बर, "_" , ".", र "-" पाएको छ + अनुरोध असफल भयो, कृपया पुन: प्रयास गर्नुहोस् \ No newline at end of file diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index 58c0ab0271..c34152f379 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -935,5 +935,6 @@ si naxariis leh u bixi rating Waa in la bilaabo lambarka ama tirada Waxaad ka ogolaan kartaa lambarka, tirada, "_", ".", iyo "-" + Codka lama yimaado, fadlan dib ugu ciyaar \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 531a1daeaf..a2e7b0c879 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1036,5 +1036,6 @@ Must start with letter or number Only letters, numbers and "_" , ".", "-" are allowed Config not available. + Request failed, please retry From f5c9deaf66f33a164d75b9160454a7be554e356a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Sep 2023 05:37:53 -0400 Subject: [PATCH 45/80] actions: bump `r0adkll/upload-google-play` to 1.1.2 (fixes #2513) (#2512) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dogi --- .github/workflows/android-release.yml | 2 +- app/build.gradle | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml index a00ec5829e..0c72829e5c 100644 --- a/.github/workflows/android-release.yml +++ b/.github/workflows/android-release.yml @@ -68,7 +68,7 @@ jobs: - name: publish AAB to playstore if: github.ref == 'refs/heads/master' - uses: r0adkll/upload-google-play@v1.1.1 + uses: r0adkll/upload-google-play@v1.1.2 with: serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }} packageName: org.ole.planet.myplanet diff --git a/app/build.gradle b/app/build.gradle index 2e5bc782e7..f7e47d8e60 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1045 - versionName "0.10.45" + versionCode 1046 + versionName "0.10.46" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true From c51584be629bc023409274513ede9e0e8d3a9a70 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 20 Sep 2023 19:53:47 +0300 Subject: [PATCH 46/80] actions: remove `org.codehaus.jackson:jackson-mapper-asl` (fixes #2514) (#2515) Co-authored-by: dogi --- app/build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f7e47d8e60..312a34f155 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1046 - versionName "0.10.46" + versionCode 1047 + versionName "0.10.47" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -87,7 +87,6 @@ dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.afollestad.material-dialogs:commons:0.9.6.0' implementation 'com.google.code.gson:gson:2.10.1' - implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13-atlassian-2' implementation('com.mikepenz:materialdrawer:6.1.1@aar') { transitive = true } From e5e48515ed98494d5bb2b632ae42452b2acd89c6 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 21 Sep 2023 19:28:40 +0300 Subject: [PATCH 47/80] feedback: refactor using viewbinding (fixes #2491) (#2497) Co-authored-by: dogi --- app/build.gradle | 4 +- .../myplanet/ui/feedback/AdapterFeedback.java | 57 +++++----- .../ui/feedback/FeedbackDetailActivity.java | 101 ++++++++---------- .../ui/feedback/FeedbackFragment.java | 49 ++++----- .../ui/feedback/FeedbackListFragment.java | 21 ++-- 5 files changed, 98 insertions(+), 134 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 312a34f155..8db5ed2333 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1047 - versionName "0.10.47" + versionCode 1048 + versionName "0.10.48" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java index 93d44ef706..b6d67cd007 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/AdapterFeedback.java @@ -2,16 +2,14 @@ import android.content.Context; import android.content.Intent; +import android.view.LayoutInflater; +import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.RowFeedbackBinding; import org.ole.planet.myplanet.model.RealmFeedback; import org.ole.planet.myplanet.utilities.TimeUtils; @@ -19,7 +17,8 @@ import io.realm.RealmResults; -public class AdapterFeedback extends RecyclerView.Adapter { +public class AdapterFeedback extends RecyclerView.Adapter { + private RowFeedbackBinding rowFeedbackBinding; private Context context; private List list; @@ -35,26 +34,24 @@ public void updateData(RealmResults newData) { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_feedback, parent, false); - return new ViewHolderFeedback(v); + public ViewHolderFeedback onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowFeedbackBinding = RowFeedbackBinding.inflate(LayoutInflater.from(context), parent, false); + return new ViewHolderFeedback(rowFeedbackBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolderFeedback) { - ((ViewHolderFeedback) holder).tvTitle.setText(list.get(position).getTitle()); - ((ViewHolderFeedback) holder).tvType.setText(list.get(position).getType()); - ((ViewHolderFeedback) holder).tvPriority.setText(list.get(position).getPriority()); - ((ViewHolderFeedback) holder).tvStatus.setText(list.get(position).getStatus()); - if ("yes".equalsIgnoreCase(list.get(position).getPriority())) - ((ViewHolderFeedback) holder).tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_primary)); - else - ((ViewHolderFeedback) holder).tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_grey)); - ((ViewHolderFeedback) holder).tvStatus.setBackground(context.getResources().getDrawable("open".equalsIgnoreCase(list.get(position).getStatus()) ? R.drawable.bg_primary : R.drawable.bg_grey)); - ((ViewHolderFeedback) holder).tvOpenDate.setText(TimeUtils.getFormatedDate(Long.parseLong(list.get(position).getOpenTime()))); - holder.itemView.setOnClickListener(v -> context.startActivity(new Intent(context, FeedbackDetailActivity.class).putExtra("id", list.get(position).getId()))); - } + public void onBindViewHolder(@NonNull ViewHolderFeedback holder, int position) { + rowFeedbackBinding.tvTitle.setText(list.get(position).getTitle()); + rowFeedbackBinding.tvType.setText(list.get(position).getType()); + rowFeedbackBinding.tvPriority.setText(list.get(position).getPriority()); + rowFeedbackBinding.tvStatus.setText(list.get(position).getStatus()); + if ("yes".equalsIgnoreCase(list.get(position).getPriority())) + rowFeedbackBinding.tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_primary)); + else + rowFeedbackBinding.tvPriority.setBackground(context.getResources().getDrawable(R.drawable.bg_grey)); + rowFeedbackBinding.tvStatus.setBackground(context.getResources().getDrawable("open".equalsIgnoreCase(list.get(position).getStatus()) ? R.drawable.bg_primary : R.drawable.bg_grey)); + rowFeedbackBinding.tvOpenDate.setText(TimeUtils.getFormatedDate(Long.parseLong(list.get(position).getOpenTime()))); + rowFeedbackBinding.getRoot().setOnClickListener(v -> context.startActivity(new Intent(context, FeedbackDetailActivity.class).putExtra("id", list.get(position).getId()))); } @Override @@ -62,16 +59,12 @@ public int getItemCount() { return list.size(); } - class ViewHolderFeedback extends RecyclerView.ViewHolder { - TextView tvTitle, tvType, tvPriority, tvStatus, tvOpenDate; + public static class ViewHolderFeedback extends RecyclerView.ViewHolder { + RowFeedbackBinding rowFeedbackBinding; - public ViewHolderFeedback(View itemView) { - super(itemView); - tvPriority = itemView.findViewById(R.id.tv_priority); - tvStatus = itemView.findViewById(R.id.tv_status); - tvType = itemView.findViewById(R.id.tv_type); - tvTitle = itemView.findViewById(R.id.tv_title); - tvOpenDate = itemView.findViewById(R.id.tv_open_date); + public ViewHolderFeedback(RowFeedbackBinding rowFeedbackBinding) { + super(rowFeedbackBinding.getRoot()); + this.rowFeedbackBinding = rowFeedbackBinding; } } } 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 6135ca6846..3cfd0862b9 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 @@ -1,13 +1,6 @@ package org.ole.planet.myplanet.ui.feedback; import android.content.Context; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; @@ -16,15 +9,19 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ActivityFeedbackDetailBinding; +import org.ole.planet.myplanet.databinding.RowFeedbackReplyBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.FeedbackReply; import org.ole.planet.myplanet.model.RealmFeedback; @@ -37,44 +34,36 @@ import io.realm.Realm; public class FeedbackDetailActivity extends AppCompatActivity { - - private RecyclerView rv_feedback_reply; + private ActivityFeedbackDetailBinding activityFeedbackDetailBinding; private RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager layoutManager; - Button closeButton, replyButton; - EditText editText; RealmFeedback feedback; Realm realm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_feedback_detail); + activityFeedbackDetailBinding = ActivityFeedbackDetailBinding.inflate(getLayoutInflater()); + setContentView(activityFeedbackDetailBinding.getRoot()); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); setTitle(R.string.feedback); realm = new DatabaseService(this).getRealmInstance(); feedback = realm.where(RealmFeedback.class).equalTo("id", getIntent().getStringExtra("id")).findFirst(); - TextView tvMessage = findViewById(R.id.tv_message); - TextView tvDate = findViewById(R.id.tv_date); if (!TextUtils.isEmpty(feedback.getOpenTime())) - tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(feedback.getOpenTime()))); - else tvDate.setText(R.string.date_n_a); - tvMessage.setText(TextUtils.isEmpty(feedback.getMessage()) ? "N/A" : feedback.getMessage()); - closeButton = findViewById(R.id.close_feedback); - replyButton = findViewById(R.id.reply_feedback); - editText = findViewById(R.id.feedback_reply_edit_text); + activityFeedbackDetailBinding.tvDate.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(feedback.getOpenTime()))); + else activityFeedbackDetailBinding.tvDate.setText(R.string.date_n_a); + activityFeedbackDetailBinding.tvMessage.setText(TextUtils.isEmpty(feedback.getMessage()) ? "N/A" : feedback.getMessage()); setUpReplies(); } public void setUpReplies() { - rv_feedback_reply = (RecyclerView) findViewById(R.id.rv_feedback_reply); - rv_feedback_reply.setHasFixedSize(true); + activityFeedbackDetailBinding.rvFeedbackReply.setHasFixedSize(true); layoutManager = new LinearLayoutManager(this); - rv_feedback_reply.setLayoutManager(layoutManager); + activityFeedbackDetailBinding.rvFeedbackReply.setLayoutManager(layoutManager); mAdapter = new RvFeedbackAdapter(feedback.getMessageList(), getApplicationContext()); - rv_feedback_reply.setAdapter(mAdapter); - closeButton.setOnClickListener(view -> { + activityFeedbackDetailBinding.rvFeedbackReply.setAdapter(mAdapter); + activityFeedbackDetailBinding.closeFeedback.setOnClickListener(view -> { realm.executeTransactionAsync(realm1 -> { RealmFeedback feedback1 = realm1.where(RealmFeedback.class).equalTo("id", getIntent().getStringExtra("id")).findFirst(); feedback1.setStatus("Closed"); @@ -83,11 +72,11 @@ public void setUpReplies() { }); }); - replyButton.setOnClickListener(r -> { - if (TextUtils.isEmpty(editText.getText().toString().trim())) { - editText.setError("Kindly enter reply message"); + activityFeedbackDetailBinding.replyFeedback.setOnClickListener(r -> { + if (TextUtils.isEmpty(activityFeedbackDetailBinding.feedbackReplyEditText.getText().toString().trim())) { + activityFeedbackDetailBinding.feedbackReplyEditText.setError("Kindly enter reply message"); } else { - String message = editText.getText().toString().trim(); + String message = activityFeedbackDetailBinding.feedbackReplyEditText.getText().toString().trim(); JsonObject object = new JsonObject(); object.addProperty("message", message); object.addProperty("time", new Date().getTime() + ""); @@ -95,18 +84,18 @@ public void setUpReplies() { String id = feedback.getId(); addReply(object, id); mAdapter = new RvFeedbackAdapter(feedback.getMessageList(), getApplicationContext()); - rv_feedback_reply.setAdapter(mAdapter); - editText.setText(""); - editText.clearFocus(); + activityFeedbackDetailBinding.rvFeedbackReply.setAdapter(mAdapter); + activityFeedbackDetailBinding.feedbackReplyEditText.setText(""); + activityFeedbackDetailBinding.feedbackReplyEditText.clearFocus(); } }); } public void updateForClosed() { if (feedback.getStatus().equalsIgnoreCase("Closed")) { - closeButton.setEnabled(false); - replyButton.setEnabled(false); - editText.setVisibility(View.INVISIBLE); + activityFeedbackDetailBinding.closeFeedback.setEnabled(false); + activityFeedbackDetailBinding.replyFeedback.setEnabled(false); + activityFeedbackDetailBinding.feedbackReplyEditText.setVisibility(View.INVISIBLE); navigateToFeedbackListFragment(); } } @@ -131,7 +120,7 @@ public void addReply(JsonObject obj, String id) { }, () -> { updateForClosed(); mAdapter = new RvFeedbackAdapter(feedback.getMessageList(), getApplicationContext()); - rv_feedback_reply.setAdapter(mAdapter); + activityFeedbackDetailBinding.rvFeedbackReply.setAdapter(mAdapter); }); } @@ -142,42 +131,42 @@ public boolean onOptionsItemSelected(MenuItem item) { } public class RvFeedbackAdapter extends RecyclerView.Adapter { + private RowFeedbackReplyBinding rowFeedbackReplyBinding; private List replyList; Context context; - public class ReplyViewHolder extends RecyclerView.ViewHolder { - public TextView tv_message, tv_date, tv_user; - - public ReplyViewHolder(View v) { - super(v); - tv_message = v.findViewById(R.id.tv_message); - tv_user = v.findViewById(R.id.tv_user); - tv_date = v.findViewById(R.id.tv_date); - } - } - public RvFeedbackAdapter(List replyList, Context context) { this.replyList = replyList; this.context = context; } + @NonNull @Override - public RvFeedbackAdapter.ReplyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_feedback_reply, parent, false); - return new RvFeedbackAdapter.ReplyViewHolder(v); + public ReplyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowFeedbackReplyBinding = RowFeedbackReplyBinding.inflate(LayoutInflater.from(context), parent, false); + return new ReplyViewHolder(rowFeedbackReplyBinding); } @Override public void onBindViewHolder(@NonNull ReplyViewHolder holder, int position) { - holder.tv_date.setText(TimeUtils.getFormatedDateWithTime(Long.parseLong(replyList.get(position).getDate()))); - holder.tv_user.setText(replyList.get(position).getUser()); - holder.tv_message.setText(replyList.get(position).getMessage()); + 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()); } @Override public int getItemCount() { return replyList.size(); } + + public class ReplyViewHolder extends RecyclerView.ViewHolder { + RowFeedbackReplyBinding rowFeedbackReplyBinding; + + public ReplyViewHolder(RowFeedbackReplyBinding rowFeedbackReplyBinding) { + super(rowFeedbackReplyBinding.getRoot()); + this.rowFeedbackReplyBinding = rowFeedbackReplyBinding; + } + } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java index 8669a3bf55..d7c68c7099 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackFragment.java @@ -1,25 +1,20 @@ package org.ole.planet.myplanet.ui.feedback; import android.os.Bundle; - -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; - -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.EditText; import android.widget.RadioButton; -import android.widget.RadioGroup; import android.widget.Toast; -import com.google.android.material.textfield.TextInputLayout; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; + import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentFeedbackBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmFeedback; import org.ole.planet.myplanet.model.RealmUserModel; @@ -32,9 +27,7 @@ import io.realm.Realm; public class FeedbackFragment extends DialogFragment implements View.OnClickListener { - EditText etMessage; - RadioGroup rgType, rgUrgent; - TextInputLayout tlMessage, tlUrgent, tlType; + private FragmentFeedbackBinding fragmentFeedbackBinding; Realm mRealm; DatabaseService databaseService; RealmUserModel model; @@ -60,7 +53,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_feedback, container, false); + fragmentFeedbackBinding = FragmentFeedbackBinding.inflate(inflater, container, false); databaseService = new DatabaseService(getActivity()); mRealm = databaseService.getRealmInstance(); model = new UserProfileDbHandler(getActivity()).getUserModel(); @@ -69,15 +62,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa } else { user = "Anonymous"; } - etMessage = v.findViewById(R.id.et_message); - rgUrgent = v.findViewById(R.id.rg_urgent); - rgType = v.findViewById(R.id.rg_type); - tlMessage = v.findViewById(R.id.tl_message); - tlUrgent = v.findViewById(R.id.tl_urgent); - tlType = v.findViewById(R.id.tl_type); - v.findViewById(R.id.btn_submit).setOnClickListener(this); - v.findViewById(R.id.btn_cancel).setOnClickListener(this); - return v; + fragmentFeedbackBinding.btnSubmit.setOnClickListener(this); + fragmentFeedbackBinding.btnCancel.setOnClickListener(this); + return fragmentFeedbackBinding.getRoot(); } @Override @@ -97,19 +84,19 @@ public void onClick(View view) { } private void validateAndSaveData() { - final String message = etMessage.getText().toString().trim(); + final String message = fragmentFeedbackBinding.etMessage.getText().toString().trim(); if (message.isEmpty()) { - tlMessage.setError(getString(R.string.please_enter_feedback)); + fragmentFeedbackBinding.tlMessage.setError(getString(R.string.please_enter_feedback)); return; } - RadioButton rbUrgent = getView().findViewById(rgUrgent.getCheckedRadioButtonId()); - RadioButton rbType = getView().findViewById(rgType.getCheckedRadioButtonId()); + RadioButton rbUrgent = getView().findViewById(fragmentFeedbackBinding.rgUrgent.getCheckedRadioButtonId()); + RadioButton rbType = getView().findViewById(fragmentFeedbackBinding.rgType.getCheckedRadioButtonId()); if (rbUrgent == null) { - tlUrgent.setError(getString(R.string.feedback_priority_is_required)); + fragmentFeedbackBinding.tlUrgent.setError(getString(R.string.feedback_priority_is_required)); return; } if (rbType == null) { - tlType.setError(getString(R.string.feedback_type_is_required)); + fragmentFeedbackBinding.tlType.setError(getString(R.string.feedback_type_is_required)); return; } final String urgent = rbUrgent.getText().toString(); @@ -137,9 +124,9 @@ public String[] getArgumentArray(String message) { } private void clearError() { - tlUrgent.setError(""); - tlType.setError(""); - tlMessage.setError(""); + fragmentFeedbackBinding.tlUrgent.setError(""); + fragmentFeedbackBinding.tlType.setError(""); + fragmentFeedbackBinding.tlMessage.setError(""); } private void saveData(Realm realm, String urgent, String type, String message) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java index 5486701f30..56bb95cc0a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackListFragment.java @@ -5,14 +5,12 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentFeedbackListBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmFeedback; import org.ole.planet.myplanet.model.RealmUserModel; @@ -24,8 +22,7 @@ import io.realm.RealmResults; public class FeedbackListFragment extends Fragment implements FeedbackFragment.OnFeedbackSubmittedListener { - TextView etMessage; - RecyclerView rvFeedbacks; + private FragmentFeedbackListBinding fragmentFeedbackListBinding; Realm mRealm; RealmUserModel userModel; @@ -35,27 +32,25 @@ public FeedbackListFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_feedback_list, container, false); - etMessage = v.findViewById(R.id.et_message); - rvFeedbacks = v.findViewById(R.id.rv_feedback); + fragmentFeedbackListBinding = FragmentFeedbackListBinding.inflate(inflater, container, false); mRealm = new DatabaseService(getActivity()).getRealmInstance(); userModel = new UserProfileDbHandler(getActivity()).getUserModel(); - v.findViewById(R.id.fab).setOnClickListener(vi -> { + fragmentFeedbackListBinding.fab.setOnClickListener(vi -> { FeedbackFragment feedbackFragment = new FeedbackFragment(); feedbackFragment.setOnFeedbackSubmittedListener(this); feedbackFragment.show(getChildFragmentManager(), ""); }); - return v; + return fragmentFeedbackListBinding.getRoot(); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - rvFeedbacks.setLayoutManager(new LinearLayoutManager(getActivity())); + fragmentFeedbackListBinding.rvFeedback.setLayoutManager(new LinearLayoutManager(getActivity())); List list = mRealm.where(RealmFeedback.class).equalTo("owner", userModel.getName()).findAll(); if (userModel.isManager()) list = mRealm.where(RealmFeedback.class).findAll(); AdapterFeedback adapterFeedback = new AdapterFeedback(getActivity(), list); - rvFeedbacks.setAdapter(adapterFeedback); + fragmentFeedbackListBinding.rvFeedback.setAdapter(adapterFeedback); } @Override @@ -70,7 +65,7 @@ public void onFeedbackSubmitted() { RealmResults updatedList = mRealm.where(RealmFeedback.class).equalTo("owner", userModel.getName()).findAll(); if (userModel.isManager()) updatedList = mRealm.where(RealmFeedback.class).findAll(); AdapterFeedback adapterFeedback = new AdapterFeedback(getActivity(), updatedList); - rvFeedbacks.setAdapter(adapterFeedback); + fragmentFeedbackListBinding.rvFeedback.setAdapter(adapterFeedback); adapterFeedback.notifyDataSetChanged(); }); } From 1a7848be354b33b167a3237a34ac2e7d1d13e619 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 21 Sep 2023 19:38:42 +0300 Subject: [PATCH 48/80] enterprises: only future dates for deadlines (fixes #2496) (#2503) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/team/teamTask/TeamTaskFragment.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8db5ed2333..1341141024 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1048 - versionName "0.10.48" + versionCode 1049 + versionName "0.10.49" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamTask/TeamTaskFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamTask/TeamTaskFragment.java index 94c3a1ac6c..fec7f96190 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamTask/TeamTaskFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamTask/TeamTaskFragment.java @@ -96,7 +96,14 @@ private void showTaskAlert(RealmTeamTask t) { } Calendar myCalendar = Calendar.getInstance(); - datePicker.setOnClickListener(view -> new DatePickerDialog(getActivity(), listener, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show()); + datePicker.setOnClickListener(view -> { + DatePickerDialog datePickerDialog = new DatePickerDialog( + getContext(), listener, myCalendar.get(Calendar.YEAR), + myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH) + ); + datePickerDialog.getDatePicker().setMinDate(myCalendar.getTimeInMillis()); + datePickerDialog.show(); + }); new AlertDialog.Builder(getActivity()).setTitle(R.string.add_task).setView(v).setPositiveButton(R.string.save, (dialogInterface, i) -> { String task = title.getText().toString(); From 533cf1278e3eade15f90f6e5dedbf202feb76daf Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 21 Sep 2023 19:50:04 +0300 Subject: [PATCH 49/80] enterprises: show only for community news (fixes #2495) (#2502) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../java/org/ole/planet/myplanet/ui/news/AdapterNews.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1341141024..ebe27c451c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1049 - versionName "0.10.49" + versionCode 1050 + versionName "0.10.50" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java b/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java index 0728682da8..38b74d0d3a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/news/AdapterNews.java @@ -110,7 +110,9 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi ((ViewHolderNews) holder).btnReply.setVisibility(fromLogin ? View.GONE : View.VISIBLE); loadImage(holder, news); showReplyButton(holder, news, position); - holder.itemView.setOnClickListener(v -> context.startActivity(new Intent(context, NewsDetailActivity.class).putExtra("newsId", list.get(position).getId()))); + if(news.isCommunityNews()) { + holder.itemView.setOnClickListener(v -> context.startActivity(new Intent(context, NewsDetailActivity.class).putExtra("newsId", list.get(position).getId()))); + } addLabels(holder, news); showChips(holder, news); } From 17db610227bbd16dd43db97b8115c204858a3837 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 22 Sep 2023 19:37:54 +0300 Subject: [PATCH 50/80] enterprises: show username when no fullname (fixes #2499) (#2504) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../myplanet/ui/team/teamMember/AdapterJoinedMember.java | 6 +++++- .../myplanet/ui/team/teamMember/AdapterMemberRequest.java | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ebe27c451c..e1c2ae5a74 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1050 - versionName "0.10.50" + versionCode 1051 + versionName "0.10.51" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java index bf057160ce..114726daec 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java @@ -58,7 +58,11 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof ViewHolderUser) { String[] overflowMenuOptions; - ((ViewHolderUser) holder).tvTitle.setText(list.get(position).toString()); + if (list.get(position).toString().equals(" ")) { + ((ViewHolderUser) holder).tvTitle.setText(list.get(position).getName()); + } else { + ((ViewHolderUser) holder).tvTitle.setText(list.get(position).toString()); + } ((ViewHolderUser) holder).tvDescription.setText(list.get(position).getRoleAsString() + " (" + RealmTeamLog.getVisitCount(mRealm, list.get(position).getName(), teamId) + " " + context.getString(R.string.visits) + " )"); Picasso.get() .load(list.get(position).getUserImage()) diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterMemberRequest.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterMemberRequest.java index 32e60732df..d60cc03b16 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterMemberRequest.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterMemberRequest.java @@ -45,7 +45,11 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof ViewHolderUser) { - ((ViewHolderUser) holder).name.setText(list.get(position).toString()); + if (list.get(position).toString().equals(" ")) { + ((ViewHolderUser) holder).name.setText(list.get(position).getName()); + } else { + ((ViewHolderUser) holder).name.setText(list.get(position).toString()); + } ((ViewHolderUser) holder).buttonAccept.setOnClickListener(view -> { acceptReject(list.get(position), true, position); @@ -86,4 +90,4 @@ public ViewHolderUser(View itemView) { buttonReject = itemView.findViewById(R.id.btn_reject); } } -} +} \ No newline at end of file From ffaffa3f785fb548cf460bcbc60b6adefb1bdd57 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 22 Sep 2023 19:55:11 +0300 Subject: [PATCH 51/80] profile: implement viewbinding (fixes #2409) (#2508) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/team/teamCourse/AdapterTeamCourse.java | 50 ++--- .../team/teamMember/AdapterJoinedMember.java | 44 +++-- .../ui/userprofile/AchievementFragment.java | 185 ++++++++---------- .../ui/userprofile/AdapterOtherInfo.java | 36 ++-- .../ui/userprofile/BecomeMemberActivity.kt | 98 ++++------ .../userprofile/EditAchievementFragment.java | 143 ++++++-------- .../ui/userprofile/UserDetailFragment.java | 43 ++-- .../ui/userprofile/UserProfileFragment.java | 129 +++++++++--- 9 files changed, 385 insertions(+), 347 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e1c2ae5a74..7a566c1f37 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1051 - versionName "0.10.51" + versionCode 1052 + versionName "0.10.52" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamCourse/AdapterTeamCourse.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamCourse/AdapterTeamCourse.java index c2f87d3d71..2d4e8b7a35 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamCourse/AdapterTeamCourse.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamCourse/AdapterTeamCourse.java @@ -3,26 +3,26 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + import org.ole.planet.myplanet.R; import org.ole.planet.myplanet.callback.OnHomeItemClickListener; +import org.ole.planet.myplanet.databinding.RowTeamResourceBinding; import org.ole.planet.myplanet.model.RealmMyCourse; import org.ole.planet.myplanet.model.RealmMyTeam; import org.ole.planet.myplanet.ui.course.TakeCourseFragment; -import org.ole.planet.myplanet.ui.userprofile.AdapterOtherInfo; import java.util.List; import io.realm.Realm; -public class AdapterTeamCourse extends RecyclerView.Adapter { +public class AdapterTeamCourse extends RecyclerView.Adapter { + private RowTeamResourceBinding rowTeamResourceBinding; private Context context; private List list; private OnHomeItemClickListener listener; @@ -41,26 +41,24 @@ public AdapterTeamCourse(Context context, List list, Realm mRealm @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_team_resource, parent, false); - return new AdapterOtherInfo.ViewHolderOtherInfo(v); + public ViewHolderTeamCourse onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowTeamResourceBinding = RowTeamResourceBinding.inflate(LayoutInflater.from(context), parent, false); + return new ViewHolderTeamCourse(rowTeamResourceBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof AdapterOtherInfo.ViewHolderOtherInfo) { - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvTitle.setText(list.get(position).getCourseTitle()); - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvDescription.setText(list.get(position).getDescription()); - holder.itemView.setOnClickListener(v -> { - if (listener != null) { - Bundle b = new Bundle(); - b.putString("id", list.get(position).getCourseId()); - listener.openCallFragment(TakeCourseFragment.newInstance(b)); - } - }); - if (!settings.getString("userId", "--").equalsIgnoreCase(teamCreator)) { - holder.itemView.findViewById(R.id.iv_remove).setVisibility(View.GONE); + public void onBindViewHolder(@NonNull ViewHolderTeamCourse holder, int position) { + rowTeamResourceBinding.tvTitle.setText(list.get(position).getCourseTitle()); + rowTeamResourceBinding.tvDescription.setText(list.get(position).getDescription()); + holder.itemView.setOnClickListener(v -> { + if (listener != null) { + Bundle b = new Bundle(); + b.putString("id", list.get(position).getCourseId()); + listener.openCallFragment(TakeCourseFragment.newInstance(b)); } + }); + if (!settings.getString("userId", "--").equalsIgnoreCase(teamCreator)) { + holder.itemView.findViewById(R.id.iv_remove).setVisibility(View.GONE); } } @@ -69,4 +67,12 @@ public int getItemCount() { return list.size(); } + public static class ViewHolderTeamCourse extends RecyclerView.ViewHolder { + public RowTeamResourceBinding rowTeamResourceBinding; + + public ViewHolderTeamCourse(RowTeamResourceBinding rowTeamResourceBinding) { + super(rowTeamResourceBinding.getRoot()); + this.rowTeamResourceBinding = rowTeamResourceBinding; + } + } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java index 114726daec..77859c3a27 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/teamMember/AdapterJoinedMember.java @@ -15,6 +15,9 @@ import com.squareup.picasso.Picasso; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.ItemTitleDescBinding; +import org.ole.planet.myplanet.databinding.RowJoinedUserBinding; +import org.ole.planet.myplanet.databinding.RowOtherInfoBinding; import org.ole.planet.myplanet.model.RealmMyTeam; import org.ole.planet.myplanet.model.RealmTeamLog; import org.ole.planet.myplanet.model.RealmUserModel; @@ -28,6 +31,7 @@ import io.realm.Realm; public class AdapterJoinedMember extends RecyclerView.Adapter { + private RowJoinedUserBinding rowJoinedUserBinding; private Context context; private List list; private Realm mRealm; @@ -50,8 +54,10 @@ public AdapterJoinedMember(Context context, List list, Realm mRe @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_joined_user, parent, false); - return new ViewHolderUser(v); + rowJoinedUserBinding = RowJoinedUserBinding.inflate(LayoutInflater.from(context), parent, false); + return new ViewHolderUser(rowJoinedUserBinding); +// View v = LayoutInflater.from(context).inflate(R.layout.row_joined_user, parent, false); +// return new ViewHolderUser(v); } @Override @@ -59,24 +65,24 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi if (holder instanceof ViewHolderUser) { String[] overflowMenuOptions; if (list.get(position).toString().equals(" ")) { - ((ViewHolderUser) holder).tvTitle.setText(list.get(position).getName()); + rowJoinedUserBinding.tvTitle.setText(list.get(position).getName()); } else { - ((ViewHolderUser) holder).tvTitle.setText(list.get(position).toString()); + rowJoinedUserBinding.tvTitle.setText(list.get(position).toString()); } - ((ViewHolderUser) holder).tvDescription.setText(list.get(position).getRoleAsString() + " (" + RealmTeamLog.getVisitCount(mRealm, list.get(position).getName(), teamId) + " " + context.getString(R.string.visits) + " )"); + rowJoinedUserBinding.tvDescription.setText(list.get(position).getRoleAsString() + " (" + RealmTeamLog.getVisitCount(mRealm, list.get(position).getName(), teamId) + " " + context.getString(R.string.visits) + " )"); Picasso.get() .load(list.get(position).getUserImage()) .placeholder(R.drawable.profile) .error(R.drawable.profile) - .into(((ViewHolderUser) holder).memberImage); + .into(rowJoinedUserBinding.memberImage); boolean isLoggedInUserTeamLeader = this.teamLeaderId != null && this.teamLeaderId.equals(this.currentUser.getId()); // If the current user card is the logged in user/team leader if (this.teamLeaderId.equals(list.get(position).getId())) { - ((ViewHolderUser) holder).isLeader.setVisibility(View.VISIBLE); - ((ViewHolderUser) holder).isLeader.setText("("+ R.string.team_leader +")"); + rowJoinedUserBinding.tvIsLeader.setVisibility(View.VISIBLE); + rowJoinedUserBinding.tvIsLeader.setText("("+ R.string.team_leader +")"); } else { - ((ViewHolderUser) holder).isLeader.setVisibility(View.GONE); + rowJoinedUserBinding.tvIsLeader.setVisibility(View.GONE); overflowMenuOptions = new String[]{context.getString(R.string.remove), context.getString(R.string.make_leader)}; checkUserAndShowOverflowMenu((ViewHolderUser) holder, position, overflowMenuOptions, isLoggedInUserTeamLeader); } @@ -89,8 +95,8 @@ private void checkUserAndShowOverflowMenu(@NonNull ViewHolderUser holder, int po * of the team we are looking at and shows/hides the overflow menu accordingly. */ if (isLoggedInUserTeamLeader) { - holder.icMore.setVisibility(View.VISIBLE); - holder.icMore.setOnClickListener(view -> { + rowJoinedUserBinding.icMore.setVisibility(View.VISIBLE); + rowJoinedUserBinding.icMore.setOnClickListener(view -> { new AlertDialog.Builder(context).setItems(overflowMenuOptions, (dialogInterface, i) -> { if (i == 0) { reject(list.get(position), position); @@ -100,7 +106,7 @@ private void checkUserAndShowOverflowMenu(@NonNull ViewHolderUser holder, int po }).setNegativeButton(R.string.dismiss, null).show(); }); } else { - holder.icMore.setVisibility(View.GONE); + rowJoinedUserBinding.icMore.setVisibility(View.GONE); } } @@ -137,16 +143,12 @@ public int getItemCount() { return list.size(); } - class ViewHolderUser extends AdapterOtherInfo.ViewHolderOtherInfo { - ImageView icMore; - CircleImageView memberImage; - TextView isLeader; + class ViewHolderUser extends RecyclerView.ViewHolder { + public RowJoinedUserBinding rowJoinedUserBinding; - public ViewHolderUser(View itemView) { - super(itemView); - icMore = itemView.findViewById(R.id.ic_more); - isLeader = itemView.findViewById(R.id.tv_is_leader); - memberImage = itemView.findViewById(R.id.memberImage); + public ViewHolderUser(RowJoinedUserBinding rowJoinedUserBinding) { + super(rowJoinedUserBinding.getRoot()); + this.rowJoinedUserBinding = rowJoinedUserBinding; } } } \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AchievementFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AchievementFragment.java index 617faa32f0..e9ef509b57 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AchievementFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AchievementFragment.java @@ -5,15 +5,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.google.android.flexbox.FlexboxLayout; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -23,6 +18,9 @@ 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.FragmentAchievementBinding; +import org.ole.planet.myplanet.databinding.LayoutButtonPrimaryBinding; +import org.ole.planet.myplanet.databinding.RowAchievementBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmAchievement; import org.ole.planet.myplanet.model.RealmMyLibrary; @@ -36,10 +34,10 @@ import io.realm.Realm; public class AchievementFragment extends BaseContainerFragment { - TextView tvGoal, tvAchievement, tvPurpose, tvName, tvFirstName; - RecyclerView rvOther; + private FragmentAchievementBinding fragmentAchievementBinding; + private RowAchievementBinding rowAchievementBinding; + private LayoutButtonPrimaryBinding layoutButtonPrimaryBinding; Realm mRealm; - LinearLayout llAchievement; RealmUserModel user; OnHomeItemClickListener listener; RealmAchievement achievement; @@ -56,124 +54,107 @@ public AchievementFragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_achievement, container, false); + fragmentAchievementBinding = FragmentAchievementBinding.inflate(inflater, container, false); mRealm = new DatabaseService(MainApplication.context).getRealmInstance(); user = new UserProfileDbHandler(MainApplication.context).getUserModel(); - rvOther = v.findViewById(R.id.rv_other_info); - tvGoal = v.findViewById(R.id.tv_goals); - tvName = v.findViewById(R.id.tv_name); - tvFirstName = v.findViewById(R.id.tv_first_name); - tvPurpose = v.findViewById(R.id.tv_purpose); - llAchievement = v.findViewById(R.id.ll_achievement); - tvAchievement = v.findViewById(R.id.tv_achievement_header); - v.findViewById(R.id.btn_edit).setOnClickListener(vi -> { + fragmentAchievementBinding.btnEdit.setOnClickListener(vi -> { if (listener != null) listener.openCallFragment(new EditAchievementFragment()); }); - return v; + return fragmentAchievementBinding.getRoot(); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); achievement = mRealm.where(RealmAchievement.class).equalTo("_id", user.getId() + "@" + user.getPlanetCode()).findFirst(); - tvFirstName.setText(user.getFirstName()); - tvName.setText(String.format("%s %s %s", user.getFirstName(), user.getMiddleName(), user.getLastName())); + fragmentAchievementBinding.tvFirstName.setText(user.getFirstName()); + fragmentAchievementBinding.tvName.setText(String.format("%s %s %s", user.getFirstName(), user.getMiddleName(), user.getLastName())); if (achievement != null) { - tvGoal.setText(achievement.getGoals()); - tvPurpose.setText(achievement.getPurpose()); - tvAchievement.setText(achievement.getAchievementsHeader()); - llAchievement.removeAllViews(); + fragmentAchievementBinding.tvGoals.setText(achievement.getGoals()); + fragmentAchievementBinding.tvPurpose.setText(achievement.getPurpose()); + fragmentAchievementBinding.tvAchievementHeader.setText(achievement.getAchievementsHeader()); + fragmentAchievementBinding.llAchievement.removeAllViews(); for (String s : achievement.getAchievements()) { - View v = LayoutInflater.from(MainApplication.context).inflate(R.layout.row_achievement, null); - createView(v, s); - llAchievement.addView(v); + rowAchievementBinding = RowAchievementBinding.inflate(LayoutInflater.from(MainApplication.context)); + JsonElement ob = new Gson().fromJson(s, JsonElement.class); + if (ob instanceof JsonObject) { + rowAchievementBinding.tvDescription.setText(JsonUtils.getString("description", ob.getAsJsonObject())); + rowAchievementBinding.tvDate.setText(JsonUtils.getString("date", ob.getAsJsonObject())); + rowAchievementBinding.tvTitle.setText(JsonUtils.getString("title", ob.getAsJsonObject())); + ArrayList libraries = getList(((JsonObject) ob).getAsJsonArray("resources")); + if (!JsonUtils.getString("description", ob.getAsJsonObject()).isEmpty() && libraries.size() > 0) { + rowAchievementBinding.llRow.setOnClickListener(view -> { + rowAchievementBinding.llDesc.setVisibility(rowAchievementBinding.llDesc.getVisibility() == View.GONE ? View.VISIBLE : View.GONE); + rowAchievementBinding.tvTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, (rowAchievementBinding.llDesc.getVisibility() == View.GONE ? R.drawable.ic_down : R.drawable.ic_up), 0); + }); + for (RealmMyLibrary lib : libraries) { + layoutButtonPrimaryBinding = LayoutButtonPrimaryBinding.inflate(LayoutInflater.from(MainApplication.context)); + layoutButtonPrimaryBinding.getRoot().setText(lib.getTitle()); + layoutButtonPrimaryBinding.getRoot().setCompoundDrawablesWithIntrinsicBounds(0, 0, (lib.isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download), 0); + layoutButtonPrimaryBinding.getRoot().setOnClickListener(view -> { + if (lib.isResourceOffline()) { + openResource(lib); + } else { + ArrayList a = new ArrayList<>(); + a.add(Utilities.getUrl(lib, settings)); + startDownload(a); + } + }); + rowAchievementBinding.flexboxResources.addView(layoutButtonPrimaryBinding.getRoot()); + } + } else { + rowAchievementBinding.tvTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + createAchievementList(); + fragmentAchievementBinding.rvOtherInfo.setLayoutManager(new LinearLayoutManager(MainApplication.context)); + fragmentAchievementBinding.rvOtherInfo.setAdapter(new AdapterOtherInfo(MainApplication.context, achievement.getreferences())); + } + mRealm.addChangeListener(realm -> { + if (fragmentAchievementBinding.llAchievement != null) fragmentAchievementBinding.llAchievement.removeAllViews(); + createAchievementList(); + }); + } else { + rowAchievementBinding.getRoot().setVisibility(View.GONE); + } + fragmentAchievementBinding.llAchievement.addView(rowAchievementBinding.getRoot()); } - rvOther.setLayoutManager(new LinearLayoutManager(MainApplication.context)); - rvOther.setAdapter(new AdapterOtherInfo(MainApplication.context, achievement.getreferences())); - } - } - - private void createView(View v, String s) { - JsonElement ob = new Gson().fromJson(s, JsonElement.class); - if (ob instanceof JsonObject) { - populateAchievementList(ob, v); - } else { - v.setVisibility(View.GONE); + fragmentAchievementBinding.rvOtherInfo.setLayoutManager(new LinearLayoutManager(MainApplication.context)); + fragmentAchievementBinding.rvOtherInfo.setAdapter(new AdapterOtherInfo(MainApplication.context, achievement.getreferences())); } } - private void populateAchievementList(JsonElement ob, View v) { - TextView title = v.findViewById(R.id.tv_title); - TextView date = v.findViewById(R.id.tv_date); - TextView description = v.findViewById(R.id.tv_description); - LinearLayout llRow = v.findViewById(R.id.ll_row); - LinearLayout llDesc = v.findViewById(R.id.ll_desc); - FlexboxLayout flexboxLayout = v.findViewById(R.id.flexbox_resources); - description.setText(JsonUtils.getString("description", ob.getAsJsonObject())); - date.setText(JsonUtils.getString("date", ob.getAsJsonObject())); - title.setText(JsonUtils.getString("title", ob.getAsJsonObject())); - ArrayList libraries = getList(((JsonObject) ob).getAsJsonArray("resources")); - if (!JsonUtils.getString("description", ob.getAsJsonObject()).isEmpty() && libraries.size() > 0) { - llRow.setOnClickListener(view -> { - llDesc.setVisibility(llDesc.getVisibility() == View.GONE ? View.VISIBLE : View.GONE); - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, (llDesc.getVisibility() == View.GONE ? R.drawable.ic_down : R.drawable.ic_up), 0); - }); - showResourceButtons(flexboxLayout, libraries); - } else { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - createAchievementList(); - rvOther.setLayoutManager(new LinearLayoutManager(MainApplication.context)); - rvOther.setAdapter(new AdapterOtherInfo(MainApplication.context, achievement.getreferences())); - } - mRealm.addChangeListener(realm -> { - if (llAchievement != null) llAchievement.removeAllViews(); - createAchievementList(); - }); - } - private void createAchievementList() { for (String s : achievement.getAchievements()) { - View v = LayoutInflater.from(MainApplication.context).inflate(R.layout.row_achievement, null); - TextView title = v.findViewById(R.id.tv_title); - TextView date = v.findViewById(R.id.tv_date); - TextView description = v.findViewById(R.id.tv_description); - LinearLayout llRow = v.findViewById(R.id.ll_row); - LinearLayout llDesc = v.findViewById(R.id.ll_desc); - FlexboxLayout flexboxLayout = v.findViewById(R.id.flexbox_resources); + rowAchievementBinding = RowAchievementBinding.inflate(LayoutInflater.from(MainApplication.context)); JsonElement ob = new Gson().fromJson(s, JsonElement.class); if (ob instanceof JsonObject) { - description.setText(JsonUtils.getString("description", ob.getAsJsonObject())); - date.setText(JsonUtils.getString("date", ob.getAsJsonObject())); - title.setText(JsonUtils.getString("title", ob.getAsJsonObject())); + rowAchievementBinding.tvDescription.setText(JsonUtils.getString("description", ob.getAsJsonObject())); + rowAchievementBinding.tvDate.setText(JsonUtils.getString("date", ob.getAsJsonObject())); + rowAchievementBinding.tvTitle.setText(JsonUtils.getString("title", ob.getAsJsonObject())); ArrayList libraries = getList(((JsonObject) ob).getAsJsonArray("resources")); - llRow.setOnClickListener(view -> { - llDesc.setVisibility(llDesc.getVisibility() == View.GONE ? View.VISIBLE : View.GONE); - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, (llDesc.getVisibility() == View.GONE ? R.drawable.ic_down : R.drawable.ic_up), 0); + rowAchievementBinding.llRow.setOnClickListener(view -> { + rowAchievementBinding.llDesc.setVisibility(rowAchievementBinding.llDesc.getVisibility() == View.GONE ? View.VISIBLE : View.GONE); + rowAchievementBinding.tvTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, (rowAchievementBinding.llDesc.getVisibility() == View.GONE ? R.drawable.ic_down : R.drawable.ic_up), 0); }); - showResourceButtons(flexboxLayout, libraries); + for (RealmMyLibrary lib : libraries) { + layoutButtonPrimaryBinding = LayoutButtonPrimaryBinding.inflate(LayoutInflater.from(MainApplication.context)); + layoutButtonPrimaryBinding.getRoot().setText(lib.getTitle()); + layoutButtonPrimaryBinding.getRoot().setCompoundDrawablesWithIntrinsicBounds(0, 0, (lib.isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download), 0); + layoutButtonPrimaryBinding.getRoot().setOnClickListener(view -> { + if (lib.isResourceOffline()) { + openResource(lib); + } else { + ArrayList a = new ArrayList<>(); + a.add(Utilities.getUrl(lib, settings)); + startDownload(a); + } + }); + rowAchievementBinding.flexboxResources.addView(layoutButtonPrimaryBinding.getRoot()); + } } else { - v.setVisibility(View.GONE); + rowAchievementBinding.getRoot().setVisibility(View.GONE); } - llAchievement.addView(v); - } - } - - private void showResourceButtons(FlexboxLayout flexboxLayout, ArrayList libraries) { - for (RealmMyLibrary lib : libraries) { - Button b = (Button) LayoutInflater.from(MainApplication.context).inflate(R.layout.layout_button_primary, null); - b.setText(lib.getTitle()); - b.setCompoundDrawablesWithIntrinsicBounds(0, 0, (lib.isResourceOffline() ? R.drawable.ic_eye : R.drawable.ic_download), 0); - b.setOnClickListener(view -> { - if (lib.isResourceOffline()) { - openResource(lib); - } else { - ArrayList a = new ArrayList<>(); - a.add(Utilities.getUrl(lib, settings)); - startDownload(a); - } - }); - flexboxLayout.addView(b); + fragmentAchievementBinding.llAchievement.addView(rowAchievementBinding.getRoot()); } } @@ -186,4 +167,4 @@ private ArrayList getList(JsonArray array) { } return libraries; } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AdapterOtherInfo.java b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AdapterOtherInfo.java index 9b89c7f2f5..768c318bfb 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AdapterOtherInfo.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/AdapterOtherInfo.java @@ -2,9 +2,7 @@ import android.content.Context; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -12,12 +10,13 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; -import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.RowOtherInfoBinding; import org.ole.planet.myplanet.utilities.JsonUtils; import java.util.List; -public class AdapterOtherInfo extends RecyclerView.Adapter { +public class AdapterOtherInfo extends RecyclerView.Adapter { + private RowOtherInfoBinding rowOtherInfoBinding; private Context context; private List list; @@ -28,17 +27,21 @@ public AdapterOtherInfo(Context context, List list) { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.row_other_info, parent, false); - return new ViewHolderOtherInfo(v); + public ViewHolderOtherInfo onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowOtherInfoBinding = RowOtherInfoBinding.inflate(LayoutInflater.from(context), parent, false); + return new ViewHolderOtherInfo(rowOtherInfoBinding); } @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof ViewHolderOtherInfo) { - JsonObject object = new Gson().fromJson(list.get(position), JsonObject.class); - String res = JsonUtils.getString("name", object) + "\n" + JsonUtils.getString("relationship", object) + "\n" + JsonUtils.getString("phone", object) + "\n" + JsonUtils.getString("email", object) + "\n"; - ((ViewHolderOtherInfo) holder).tvDescription.setText(res); + public void onBindViewHolder(@NonNull ViewHolderOtherInfo holder, int position) { + if (position < list.size()) { + String jsonString = list.get(position); + JsonObject object = new Gson().fromJson(jsonString, JsonObject.class); + String res = JsonUtils.getString("name", object) + "\n" + + JsonUtils.getString("relationship", object) + "\n" + + JsonUtils.getString("phone", object) + "\n" + + JsonUtils.getString("email", object) + "\n"; + holder.rowOtherInfoBinding.tvDescription.setText(res); } } @@ -48,12 +51,11 @@ public int getItemCount() { } public static class ViewHolderOtherInfo extends RecyclerView.ViewHolder { - public TextView tvTitle, tvDescription; + public RowOtherInfoBinding rowOtherInfoBinding; - public ViewHolderOtherInfo(View itemView) { - super(itemView); - tvTitle = itemView.findViewById(R.id.tv_title); - tvDescription = itemView.findViewById(R.id.tv_description); + public ViewHolderOtherInfo(RowOtherInfoBinding rowOtherInfoBinding) { + super(rowOtherInfoBinding.getRoot()); + this.rowOtherInfoBinding = rowOtherInfoBinding; } } } 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 67d9d5152e..6fb045832c 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 @@ -9,28 +9,13 @@ import android.text.TextWatcher import android.view.View import android.widget.ArrayAdapter import android.widget.RadioButton -import android.widget.Spinner import com.google.gson.JsonArray import com.google.gson.JsonObject import io.realm.Realm -import kotlinx.android.synthetic.main.activity_become_member.btn_cancel -import kotlinx.android.synthetic.main.activity_become_member.btn_submit -import kotlinx.android.synthetic.main.activity_become_member.et_email -import kotlinx.android.synthetic.main.activity_become_member.et_fname -import kotlinx.android.synthetic.main.activity_become_member.et_lname -import kotlinx.android.synthetic.main.activity_become_member.et_mname -import kotlinx.android.synthetic.main.activity_become_member.et_password -import kotlinx.android.synthetic.main.activity_become_member.et_phone -import kotlinx.android.synthetic.main.activity_become_member.et_re_password -import kotlinx.android.synthetic.main.activity_become_member.et_username -import kotlinx.android.synthetic.main.activity_become_member.pbar -import kotlinx.android.synthetic.main.activity_become_member.rb_gender -import kotlinx.android.synthetic.main.activity_become_member.spn_lang -import kotlinx.android.synthetic.main.activity_become_member.spn_level -import kotlinx.android.synthetic.main.activity_become_member.txt_dob import org.ole.planet.myplanet.MainApplication import org.ole.planet.myplanet.R import org.ole.planet.myplanet.base.BaseActivity +import org.ole.planet.myplanet.databinding.ActivityBecomeMemberBinding import org.ole.planet.myplanet.datamanager.DatabaseService import org.ole.planet.myplanet.datamanager.Service import org.ole.planet.myplanet.model.RealmUserModel @@ -43,7 +28,7 @@ import java.util.Calendar import java.util.Locale class BecomeMemberActivity : BaseActivity() { - + private lateinit var activityBecomeMemberBinding: ActivityBecomeMemberBinding var dob: String = ""; lateinit var settings: SharedPreferences private fun showDatePickerDialog() { @@ -51,7 +36,7 @@ class BecomeMemberActivity : BaseActivity() { val dpd = DatePickerDialog( this, { _, i, i1, i2 -> dob = String.format(Locale.US, "%04d-%02d-%02d", i, i1 + 1, i2) - txt_dob.text = dob + activityBecomeMemberBinding.txtDob.text = dob }, now[Calendar.YEAR], now[Calendar.MONTH], now[Calendar.DAY_OF_MONTH] ) dpd.datePicker.maxDate = now.timeInMillis @@ -60,23 +45,23 @@ class BecomeMemberActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_become_member) + activityBecomeMemberBinding = ActivityBecomeMemberBinding.inflate(layoutInflater) + setContentView(activityBecomeMemberBinding.root) supportActionBar?.setHomeButtonEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true) var mRealm: Realm = DatabaseService(this).realmInstance; var user = UserProfileDbHandler(this).userModel; val languages = resources.getStringArray(R.array.language) - val languageSpinner = findViewById(R.id.spn_lang) as Spinner val adapter = ArrayAdapter(this, R.layout.become_a_member_spinner_layout, languages) - languageSpinner.adapter = adapter - txt_dob.setOnClickListener { + activityBecomeMemberBinding.spnLang.adapter = adapter + activityBecomeMemberBinding.txtDob.setOnClickListener { showDatePickerDialog() } settings = getSharedPreferences(SyncActivity.PREFS_NAME, Context.MODE_PRIVATE) textChangedListener(mRealm) - et_username.addTextChangedListener(object : TextWatcher { + activityBecomeMemberBinding.etUsername.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { @@ -89,16 +74,16 @@ class BecomeMemberActivity : BaseActivity() { } if (firstChar != null && !Character.isDigit(firstChar) && !Character.isLetter(firstChar)) { - et_username.error = getString(R.string.must_start_with_letter_or_number) + activityBecomeMemberBinding.etUsername.error = getString(R.string.must_start_with_letter_or_number) } else if (hasInvalidCharacters) { - et_username.error = getString(R.string.only_letters_numbers_and_are_allowed) + activityBecomeMemberBinding.etUsername.error = getString(R.string.only_letters_numbers_and_are_allowed) } else { val lowercaseText = it.toString().toLowerCase(Locale.ROOT) if (it.toString() != lowercaseText) { - et_username.setText(lowercaseText) - et_username.setSelection(lowercaseText.length) + activityBecomeMemberBinding.etUsername.setText(lowercaseText) + activityBecomeMemberBinding.etUsername.setSelection(lowercaseText.length) } - et_username.error = null + activityBecomeMemberBinding.etUsername.error = null } } } @@ -106,29 +91,30 @@ class BecomeMemberActivity : BaseActivity() { override fun afterTextChanged(s: Editable?) {} }) - btn_cancel.setOnClickListener { + activityBecomeMemberBinding.btnCancel.setOnClickListener { finish() } - btn_submit.setOnClickListener { - var username: String? = et_username.text.toString() - var password: String? = et_password.text.toString() - var repassword: String? = et_re_password.text.toString() - var fname: String? = et_fname.text.toString() - var lname: String? = et_lname.text.toString() - var mname: String? = et_mname.text.toString() - var email: String? = et_email.text.toString() - var language: String? = spn_lang.selectedItem.toString() - var phoneNumber: String? = et_phone.text.toString() + activityBecomeMemberBinding.btnSubmit.setOnClickListener { + var username: String? = activityBecomeMemberBinding.etUsername.text.toString() + var password: String? = activityBecomeMemberBinding.etPassword.text.toString() + var repassword: String? = activityBecomeMemberBinding.etRePassword.text.toString() + var fname: String? = activityBecomeMemberBinding.etFname.text.toString() + var lname: String? = activityBecomeMemberBinding.etLname.text.toString() + var mname: String? = activityBecomeMemberBinding.etMname.text.toString() + var email: String? = activityBecomeMemberBinding.etEmail.text.toString() + var language: String? = activityBecomeMemberBinding.spnLang.selectedItem.toString() + var phoneNumber: String? = activityBecomeMemberBinding.etPhone.text.toString() var birthDate: String? = dob - var level: String? = spn_level.selectedItem.toString() + var level: String? = activityBecomeMemberBinding.spnLevel.selectedItem.toString() var rb: RadioButton? = - findViewById(rb_gender.checkedRadioButtonId) as RadioButton? + findViewById(activityBecomeMemberBinding.rbGender.checkedRadioButtonId) as RadioButton? var gender: String? = "" if (rb != null) gender = rb.text.toString() else { Utilities.toast(this, getString(R.string.please_select_gender)) } + val firstChar = if (username!!.isNotEmpty()) username[0] else null val hasInvalidCharacters = username.any { char -> char != '_' && char != '.' && char != '-' && @@ -136,28 +122,28 @@ class BecomeMemberActivity : BaseActivity() { } if (username.isEmpty()) { - et_username.error = getString(R.string.please_enter_a_username) + activityBecomeMemberBinding.etUsername.error = getString(R.string.please_enter_a_username) } else if (username.contains(" ")) { - et_username.error = getString(R.string.invalid_username) + activityBecomeMemberBinding.etUsername.error = getString(R.string.invalid_username) } else if (firstChar != null && !Character.isDigit(firstChar) && !Character.isLetter(firstChar)) { - et_username.error = getString(R.string.must_start_with_letter_or_number) + activityBecomeMemberBinding.etUsername.error = getString(R.string.must_start_with_letter_or_number) } else if (hasInvalidCharacters) { - et_username.error = getString(R.string.only_letters_numbers_and_are_allowed) + activityBecomeMemberBinding.etUsername.error = getString(R.string.only_letters_numbers_and_are_allowed) } if (password!!.isEmpty()) { - et_password.error = getString(R.string.please_enter_a_password) + activityBecomeMemberBinding.etPassword.error = getString(R.string.please_enter_a_password) } else if (password != repassword) { - et_re_password.error = getString(R.string.password_doesn_t_match) + activityBecomeMemberBinding.etRePassword.error = getString(R.string.password_doesn_t_match) } if (email!!.isNotEmpty() && !Utilities.isValidEmail(email)) { - et_email.error = getString(R.string.invalid_email) + activityBecomeMemberBinding.etEmail.error = getString(R.string.invalid_email) } if (level == null) { Utilities.toast(this, getString(R.string.level_is_required)); } if (password.isEmpty() && phoneNumber!!.isNotEmpty()) { - et_re_password.setText(phoneNumber) + activityBecomeMemberBinding.etRePassword.setText(phoneNumber) password = phoneNumber ///Add dialog that using phone as password , Agree / disagree } @@ -226,10 +212,10 @@ class BecomeMemberActivity : BaseActivity() { var roles = JsonArray() roles.add("learner") obj.add("roles", roles) - pbar.visibility = View.VISIBLE + activityBecomeMemberBinding.pbar.visibility = View.VISIBLE Service(this).becomeMember(mRealm, obj) { res -> runOnUiThread { - pbar.visibility = View.GONE + activityBecomeMemberBinding.pbar.visibility = View.GONE Utilities.toast(this, res) } finish() @@ -238,10 +224,10 @@ class BecomeMemberActivity : BaseActivity() { } private fun textChangedListener(mRealm: Realm) { - et_username.addTextChangedListener(object : TextWatcher { + activityBecomeMemberBinding.etUsername.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable) { - if (RealmUserModel.isUserExists(mRealm, et_username.text.toString())) { - et_username.error = getString(R.string.username_taken) + if (RealmUserModel.isUserExists(mRealm, activityBecomeMemberBinding.etUsername.text.toString())) { + activityBecomeMemberBinding.etUsername.error = getString(R.string.username_taken) return } } @@ -253,9 +239,9 @@ class BecomeMemberActivity : BaseActivity() { } }) - et_password.addTextChangedListener(object : TextWatcher { + activityBecomeMemberBinding.etPassword.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable) { - et_re_password.isEnabled = et_password.text.toString().isNotEmpty() + activityBecomeMemberBinding.etRePassword.isEnabled = activityBecomeMemberBinding.etPassword.text.toString().isNotEmpty() } override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/EditAchievementFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/EditAchievementFragment.java index 193a37279f..4570dff647 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/EditAchievementFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/EditAchievementFragment.java @@ -5,22 +5,25 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; -import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.AppCompatTextView; import com.google.android.flexbox.FlexboxLayout; -import com.google.android.material.textfield.TextInputLayout; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.AlertAddAttachmentBinding; +import org.ole.planet.myplanet.databinding.AlertReferenceBinding; +import org.ole.planet.myplanet.databinding.EditAttachementBinding; +import org.ole.planet.myplanet.databinding.EditOtherInfoBinding; +import org.ole.planet.myplanet.databinding.FragmentEditAchievementBinding; +import org.ole.planet.myplanet.databinding.MyLibraryAlertdialogBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmAchievement; import org.ole.planet.myplanet.model.RealmMyLibrary; @@ -38,36 +41,41 @@ import fisk.chipcloud.ChipCloudConfig; public class EditAchievementFragment extends BaseAchievementFragment implements DatePickerDialog.OnDateSetListener { + private FragmentEditAchievementBinding fragmentEditAchievementBinding; + private EditAttachementBinding editAttachementBinding; + private EditOtherInfoBinding editOtherInfoBinding; + private AlertReferenceBinding alertReferenceBinding; + private AlertAddAttachmentBinding alertAddAttachmentBinding; + private MyLibraryAlertdialogBinding myLibraryAlertdialogBinding; public EditAchievementFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_edit_achievement, container, false); + fragmentEditAchievementBinding = FragmentEditAchievementBinding.inflate(inflater, container, false); mRealm = new DatabaseService(getActivity()).getRealmInstance(); user = new UserProfileDbHandler(getActivity()).getUserModel(); achievementArray = new JsonArray(); achievement = mRealm.where(RealmAchievement.class).equalTo("_id", user.getId() + "@" + user.getPlanetCode()).findFirst(); - createView(v); initializeData(); setListeners(); if (achievementArray != null) showAchievementAndInfo(); if (referenceArray != null) showreference(); - return v; + return fragmentEditAchievementBinding.getRoot(); } private void setListeners() { - btnUpdate.setOnClickListener(view -> { + fragmentEditAchievementBinding.btnUpdate.setOnClickListener(view -> { if (!mRealm.isInTransaction()) mRealm.beginTransaction(); setUserInfo(); setAchievementInfo(); getActivity().onBackPressed(); mRealm.commitTransaction(); }); - btnCancel.setOnClickListener(view -> getActivity().onBackPressed()); - btnAddAchievement.setOnClickListener(vi -> showAddachievementAlert(null)); - btnOther.setOnClickListener(view -> showreferenceDialog(null)); - tvDob.setOnClickListener(view -> { + fragmentEditAchievementBinding.btnCancel.setOnClickListener(view -> getActivity().onBackPressed()); + fragmentEditAchievementBinding.btnAchievement.setOnClickListener(vi -> showAddachievementAlert(null)); + fragmentEditAchievementBinding.btnOther.setOnClickListener(view -> showreferenceDialog(null)); + fragmentEditAchievementBinding.txtDob.setOnClickListener(view -> { Calendar now = Calendar.getInstance(); DatePickerDialog dpd = new DatePickerDialog(getActivity(), this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.getDatePicker().setMaxDate(Calendar.getInstance().getTimeInMillis()); @@ -75,82 +83,62 @@ private void setListeners() { }); } - private void createView(View v) { - etGoals = v.findViewById(R.id.et_goals); - llachievement = v.findViewById(R.id.ll_attachment); - llOthers = v.findViewById(R.id.ll_other_info); - etPurpose = v.findViewById(R.id.et_purpose); - etAchievement = v.findViewById(R.id.et_achievement); - etName = v.findViewById(R.id.et_fname); - etMiddleName = v.findViewById(R.id.et_mname); - etLastName = v.findViewById(R.id.et_lname); - etBirthPlace = v.findViewById(R.id.et_birthplace); - tvDob = v.findViewById(R.id.txt_dob); - btnAddAchievement = v.findViewById(R.id.btn_achievement); - btnOther = v.findViewById(R.id.btn_other); - btnUpdate = v.findViewById(R.id.btn_update); - btnCancel = v.findViewById(R.id.btn_cancel); - checkBox = v.findViewById(R.id.cb_send_to_nation); - } - private void showAchievementAndInfo() { ChipCloudConfig config = Utilities.getCloudConfig().selectMode(ChipCloud.SelectMode.single); - llachievement.removeAllViews(); + fragmentEditAchievementBinding.llAttachment.removeAllViews(); for (JsonElement e : achievementArray) { - View v = LayoutInflater.from(getActivity()).inflate(R.layout.edit_attachement, null); - ((TextView) v.findViewById(R.id.tv_title)).setText(e.getAsJsonObject().get("title").getAsString()); - FlexboxLayout flexboxLayout = v.findViewById(R.id.flexbox); + editAttachementBinding = EditAttachementBinding.inflate(LayoutInflater.from(getActivity())); + editAttachementBinding.tvTitle.setText(e.getAsJsonObject().get("title").getAsString()); + FlexboxLayout flexboxLayout = editAttachementBinding.flexbox; flexboxLayout.removeAllViews(); final ChipCloud chipCloud = new ChipCloud(getActivity(), flexboxLayout, config); for (JsonElement element : e.getAsJsonObject().getAsJsonArray("resources")) { chipCloud.addChip(element.getAsJsonObject().get("title").getAsString()); } - v.findViewById(R.id.iv_delete).setOnClickListener(view -> { + editAttachementBinding.ivDelete.setOnClickListener(view -> { achievementArray.remove(e); showAchievementAndInfo(); }); - v.findViewById(R.id.edit).setOnClickListener(V -> { + editAttachementBinding.edit.setOnClickListener(V -> { showAddachievementAlert(e.getAsJsonObject()); }); - llachievement.addView(v); + View editAttachementView = editAttachementBinding.getRoot(); + fragmentEditAchievementBinding.llAttachment.addView(editAttachementView); } } private void showreference() { - llOthers.removeAllViews(); + fragmentEditAchievementBinding.llOtherInfo.removeAllViews(); for (JsonElement e : referenceArray) { - View v = LayoutInflater.from(getActivity()).inflate(R.layout.edit_other_info, null); - ((TextView) v.findViewById(R.id.tv_title)).setText(e.getAsJsonObject().get("name").getAsString()); - v.findViewById(R.id.iv_delete).setOnClickListener(view -> { + editOtherInfoBinding = EditOtherInfoBinding.inflate(LayoutInflater.from(getActivity())); + editOtherInfoBinding.tvTitle.setText(e.getAsJsonObject().get("name").getAsString()); + editOtherInfoBinding.ivDelete.setOnClickListener(view -> { referenceArray.remove(e); showreference(); }); - v.findViewById(R.id.edit).setOnClickListener(vi -> { + editOtherInfoBinding.edit.setOnClickListener(vi -> { showreferenceDialog(e.getAsJsonObject()); }); - llOthers.addView(v); + View editOtherInfoView = editOtherInfoBinding.getRoot(); + fragmentEditAchievementBinding.llOtherInfo.addView(editOtherInfoView); } } private void showreferenceDialog(JsonObject object) { - View v = LayoutInflater.from(getActivity()).inflate(R.layout.alert_reference, null); - EditText etName = v.findViewById(R.id.et_name); - TextInputLayout tlName = v.findViewById(R.id.tl_name); - EditText etRelation = v.findViewById(R.id.et_relationship); - EditText etPhone = v.findViewById(R.id.et_phone); - EditText etEmail = v.findViewById(R.id.et_email); - EditText[] ar = {etName, etPhone, etEmail, etRelation}; + alertReferenceBinding = AlertReferenceBinding.inflate(LayoutInflater.from(getActivity())); + EditText[] ar = {alertReferenceBinding.etName, alertReferenceBinding.etPhone, alertReferenceBinding.etEmail, alertReferenceBinding.etRelationship}; setPrevReference(ar, object); - AlertDialog d = DialogUtils.getAlertDialog(getActivity(), getString(R.string.add_reference), v); + View alertReferenceView = alertReferenceBinding.getRoot(); + AlertDialog d = DialogUtils.getAlertDialog(getActivity(), getString(R.string.add_reference), alertReferenceView); d.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> { - String name = etName.getText().toString().trim(); + String name = alertReferenceBinding.etName.getText().toString().trim(); if (name.isEmpty()) { - tlName.setError(getString(R.string.name_is_required)); + alertReferenceBinding.tlName.setError(getString(R.string.name_is_required)); return; } if (object != null) referenceArray.remove(object); if (referenceArray == null) referenceArray = new JsonArray(); - referenceArray.add(RealmAchievement.createReference(name, etRelation, etPhone, etEmail)); + referenceArray.add(RealmAchievement.createReference(name, alertReferenceBinding.etRelationship, alertReferenceBinding.etPhone, alertReferenceBinding.etEmail)); showreference(); d.dismiss(); }); @@ -168,18 +156,24 @@ private void setPrevReference(EditText[] ar, JsonObject object) { String date = ""; private void showAddachievementAlert(JsonObject object) { - View v = LayoutInflater.from(getActivity()).inflate(R.layout.alert_add_attachment, null); - Button btnAddResource = v.findViewById(R.id.btn_add_resources); - EditText etDescription = v.findViewById(R.id.et_desc); - EditText etTitle = v.findViewById(R.id.et_title); - AppCompatTextView tvDate = v.findViewById(R.id.tv_date); - initAchievementDatePicker(tvDate); + alertAddAttachmentBinding = AlertAddAttachmentBinding.inflate(LayoutInflater.from(getActivity())); + alertAddAttachmentBinding.tvDate.setOnClickListener(view -> { + Calendar now = Calendar.getInstance(); + DatePickerDialog dpd = new DatePickerDialog(getActivity(), (datePicker, i, i1, i2) -> { + date = String.format(Locale.US, "%04d-%02d-%02d", i, i1 + 1, i2); + alertAddAttachmentBinding.tvDate.setText(date); + }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); + dpd.getDatePicker().setMaxDate(now.getTimeInMillis()); + dpd.show(); + }); + resourceArray = new JsonArray(); - List prevList = setUpOldAchievement(object, etDescription, etTitle, tvDate); - btnAddResource.setOnClickListener(view -> showResourseListDialog(prevList)); - new AlertDialog.Builder(getActivity()).setTitle(R.string.add_achievement).setIcon(R.drawable.ic_edit).setView(v).setCancelable(false).setPositiveButton("Submit", (dialogInterface, i) -> { - String desc = etDescription.getText().toString().trim(); - String title = etTitle.getText().toString().trim(); + List prevList = setUpOldAchievement(object, alertAddAttachmentBinding.etDesc, alertAddAttachmentBinding.etTitle, (AppCompatTextView) alertAddAttachmentBinding.tvDate); + alertAddAttachmentBinding.btnAddResources.setOnClickListener(view -> showResourseListDialog(prevList)); + View alertAddAttachmentView = alertAddAttachmentBinding.getRoot(); + new AlertDialog.Builder(getActivity()).setTitle(R.string.add_achievement).setIcon(R.drawable.ic_edit).setView(alertAddAttachmentView).setCancelable(false).setPositiveButton("Submit", (dialogInterface, i) -> { + String desc = alertAddAttachmentBinding.etDesc.getText().toString().trim(); + String title = alertAddAttachmentBinding.etTitle.getText().toString().trim(); if (title.isEmpty()) { Toast.makeText(getActivity(), getString(R.string.title_is_required), Toast.LENGTH_SHORT).show(); return; @@ -205,18 +199,6 @@ private List setUpOldAchievement(JsonObject object, EditText etDescripti return prevList; } - private void initAchievementDatePicker(TextView tvDate) { - tvDate.setOnClickListener(view -> { - Calendar now = Calendar.getInstance(); - DatePickerDialog dpd = new DatePickerDialog(getActivity(), (datePicker, i, i1, i2) -> { - date = String.format(Locale.US, "%04d-%02d-%02d", i, i1 + 1, i2); - tvDate.setText(date); - }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); - dpd.getDatePicker().setMaxDate(now.getTimeInMillis()); - dpd.show(); - }); - } - private void saveAchievement(String desc, String title) { JsonObject object = new JsonObject(); object.addProperty("description", desc); @@ -231,9 +213,10 @@ private void showResourseListDialog(List prevList) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.select_resources); List list = mRealm.where(RealmMyLibrary.class).findAll(); - View v = LayoutInflater.from(getActivity()).inflate(R.layout.my_library_alertdialog, null); - CheckboxListView lv = createResourceList(v, list, prevList); - builder.setView(v); + myLibraryAlertdialogBinding = MyLibraryAlertdialogBinding.inflate(LayoutInflater.from(getActivity())); + View myLibraryAlertdialogView = myLibraryAlertdialogBinding.getRoot(); + CheckboxListView lv = createResourceList(myLibraryAlertdialogView, list, prevList); + builder.setView(myLibraryAlertdialogView); builder.setPositiveButton("Ok", (dialogInterface, i) -> { ArrayList items = lv.getSelectedItemsList(); resourceArray = new JsonArray(); @@ -245,6 +228,6 @@ private void showResourseListDialog(List prevList) { @Override public void onDateSet(DatePicker datePicker, int i, int i1, int i2) { - tvDob.setText(String.format(Locale.US, "%04d-%02d-%02d", i, i1 + 1, i2)); + fragmentEditAchievementBinding.txtDob.setText(String.format(Locale.US, "%04d-%02d-%02d", i, i1 + 1, i2)); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserDetailFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserDetailFragment.java index e196ea7923..f17dc3f48f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserDetailFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserDetailFragment.java @@ -1,6 +1,9 @@ package org.ole.planet.myplanet.ui.userprofile; import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -8,11 +11,9 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentUserDetailBinding; +import org.ole.planet.myplanet.databinding.ItemTitleDescBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmUserModel; import org.ole.planet.myplanet.service.UserProfileDbHandler; @@ -25,7 +26,8 @@ import io.realm.Realm; public class UserDetailFragment extends Fragment { - RecyclerView rvUserDetail; + private FragmentUserDetailBinding fragmentUserDetailBinding; + private ItemTitleDescBinding itemTitleDescBinding; String userId; Realm mRealm; RealmUserModel user; @@ -43,14 +45,13 @@ public void onCreate(Bundle savedInstanceState) { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_user_detail, container, false); - rvUserDetail = v.findViewById(R.id.rv_user_detail); - rvUserDetail.setLayoutManager(new GridLayoutManager(getActivity(), 2)); + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentUserDetailBinding = FragmentUserDetailBinding.inflate(inflater, container, false); + fragmentUserDetailBinding.rvUserDetail.setLayoutManager(new GridLayoutManager(getActivity(), 2)); mRealm = new DatabaseService(getActivity()).getRealmInstance(); db = new UserProfileDbHandler(getActivity()); user = mRealm.where(RealmUserModel.class).equalTo("id", userId).findFirst(); - return v; + return fragmentUserDetailBinding.getRoot(); } class Detail { @@ -70,18 +71,19 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { return; } List list = getList(user, db); - rvUserDetail.setAdapter(new RecyclerView.Adapter() { + fragmentUserDetailBinding.rvUserDetail.setAdapter(new RecyclerView.Adapter() { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new AdapterOtherInfo.ViewHolderOtherInfo(LayoutInflater.from(getActivity()).inflate(R.layout.item_title_desc, parent, false)); + public ViewHolderUserDetail onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + itemTitleDescBinding = ItemTitleDescBinding.inflate(LayoutInflater.from(getActivity()), parent, false); + return new ViewHolderUserDetail(itemTitleDescBinding); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof AdapterOtherInfo.ViewHolderOtherInfo) { - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvTitle.setText(list.get(position).title); - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvDescription.setText(list.get(position).description); + if (holder instanceof ViewHolderUserDetail) { + itemTitleDescBinding.tvTitle.setText(list.get(position).title); + itemTitleDescBinding.tvDescription.setText(list.get(position).description); } } @@ -89,6 +91,15 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi public int getItemCount() { return list.size(); } + + class ViewHolderUserDetail extends RecyclerView.ViewHolder { + public ItemTitleDescBinding itemTitleDescBinding; + + public ViewHolderUserDetail(ItemTitleDescBinding itemTitleDescBinding) { + super(itemTitleDescBinding.getRoot()); + this.itemTitleDescBinding = itemTitleDescBinding; + } + } }); } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserProfileFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserProfileFragment.java index 222af39a16..4b58989ff3 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserProfileFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/UserProfileFragment.java @@ -24,6 +24,10 @@ import com.squareup.picasso.Picasso; import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentAchievementBinding; +import org.ole.planet.myplanet.databinding.FragmentUserProfileBinding; +import org.ole.planet.myplanet.databinding.ItemTitleDescBinding; +import org.ole.planet.myplanet.databinding.RowStatBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmUserModel; import org.ole.planet.myplanet.service.UserProfileDbHandler; @@ -39,15 +43,13 @@ import io.realm.Realm; public class UserProfileFragment extends Fragment { - + private FragmentUserProfileBinding fragmentUserProfileBinding; + private RowStatBinding rowStatBinding; UserProfileDbHandler handler; DatabaseService realmService; Realm mRealm; - RecyclerView rvStat; - Button addPicture; RealmUserModel model; File output; - ImageView imageView; static final int IMAGE_TO_USE = 100; static String imageUrl = ""; @@ -65,19 +67,78 @@ public void onDestroy() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_user_profile, container, false); + fragmentUserProfileBinding = FragmentUserProfileBinding.inflate(inflater, container, false); handler = new UserProfileDbHandler(getActivity()); realmService = new DatabaseService(getActivity()); mRealm = realmService.getRealmInstance(); - rvStat = v.findViewById(R.id.rv_stat); - rvStat.setLayoutManager(new LinearLayoutManager(getActivity())); - rvStat.setNestedScrollingEnabled(false); - addPicture = (Button) v.findViewById(R.id.bt_profile_pic); - imageView = (ImageView) v.findViewById(R.id.image); - - addPicture.setOnClickListener(v1 -> searchForPhoto()); - populateUserData(v); - return v; + fragmentUserProfileBinding.rvStat.setLayoutManager(new LinearLayoutManager(getActivity())); + fragmentUserProfileBinding.rvStat.setNestedScrollingEnabled(false); + + fragmentUserProfileBinding.btProfilePic.setOnClickListener(v1 -> searchForPhoto()); + model = handler.getUserModel(); + fragmentUserProfileBinding.txtName.setText(String.format("%s %s %s", model.getFirstName(), model.getMiddleName(), model.getLastName())); + fragmentUserProfileBinding.txtEmail.setText(getString(R.string.email_colon) + + Utilities.checkNA(model.getEmail())); + String dob = TextUtils.isEmpty(model.getDob()) ? "N/A" : TimeUtils.getFormatedDate(model.getDob(), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + fragmentUserProfileBinding.txtDob.setText(getString(R.string.date_of_birth) + dob); + if (!TextUtils.isEmpty(model.getUserImage())) + Picasso.get().load(model.getUserImage()).placeholder(R.drawable.profile).into(fragmentUserProfileBinding.image, new Callback() { + @Override + public void onSuccess() { + } + + @Override + public void onError(Exception e) { + Picasso.get().load(new File(model.getUserImage())).placeholder(R.drawable.profile).error(R.drawable.profile).into(fragmentUserProfileBinding.image); + } + }); + else { + fragmentUserProfileBinding.image.setImageResource(R.drawable.profile); + } + final LinkedHashMap map = new LinkedHashMap(); + map.put("Community Name", Utilities.checkNA(model.getPlanetCode())); + map.put("Last Login : ", Utilities.getRelativeTime(handler.getLastVisit())); + map.put("Total Visits : ", handler.getOfflineVisits() + ""); + map.put("Most Opened Resource : ", Utilities.checkNA(handler.getMaxOpenedResource())); + map.put("Number of Resources Opened : ", Utilities.checkNA(handler.getNumberOfResourceOpen())); + + final LinkedList keys = new LinkedList<>(map.keySet()); + fragmentUserProfileBinding.rvStat.setAdapter(new RecyclerView.Adapter() { + @NonNull + @Override + public ViewHolderRowStat onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowStatBinding = RowStatBinding.inflate(LayoutInflater.from(getActivity()), parent, false); + return new ViewHolderRowStat(rowStatBinding); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof ViewHolderRowStat) { + rowStatBinding.tvTitle.setText(keys.get(position)); + rowStatBinding.tvTitle.setVisibility(View.VISIBLE); + rowStatBinding.tvDescription.setText(map.get(keys.get(position))); + if (position % 2 == 0) { + rowStatBinding.getRoot().setBackgroundColor(getResources().getColor(R.color.bg_white)); + rowStatBinding.getRoot().setBackgroundColor(getResources().getColor(R.color.md_grey_300)); + } + } + } + + @Override + public int getItemCount() { + return keys.size(); + } + + class ViewHolderRowStat extends RecyclerView.ViewHolder { + public RowStatBinding rowStatBinding; + + public ViewHolderRowStat(RowStatBinding rowStatBinding) { + super(rowStatBinding.getRoot()); + this.rowStatBinding = rowStatBinding; + } + } + }); + return fragmentUserProfileBinding.getRoot(); } public void searchForPhoto() { @@ -101,7 +162,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } model.setUserImage(path); mRealm.commitTransaction(); - imageView.setImageURI(url); + fragmentUserProfileBinding.image.setImageURI(url); Utilities.log("Image Url = " + imageUrl); } /* getRealm().executeTransactionAsync(new Realm.Transaction() { @@ -120,18 +181,18 @@ private void populateUserData(View v) { String dob = TextUtils.isEmpty(model.getDob()) ? "N/A" : TimeUtils.getFormatedDate(model.getDob(), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); ((TextView) v.findViewById(R.id.txt_dob)).setText(getString(R.string.date_of_birth) + dob); if (!TextUtils.isEmpty(model.getUserImage())) - Picasso.get().load(model.getUserImage()).placeholder(R.drawable.profile).into(imageView, new Callback() { + Picasso.get().load(model.getUserImage()).placeholder(R.drawable.profile).into(fragmentUserProfileBinding.image, new Callback() { @Override public void onSuccess() { } @Override public void onError(Exception e) { - Picasso.get().load(new File(model.getUserImage())).placeholder(R.drawable.profile).error(R.drawable.profile).into(imageView); + Picasso.get().load(new File(model.getUserImage())).placeholder(R.drawable.profile).error(R.drawable.profile).into(fragmentUserProfileBinding.image); } }); else { - imageView.setImageResource(R.drawable.profile); + fragmentUserProfileBinding.image.setImageResource(R.drawable.profile); } final LinkedHashMap map = new LinkedHashMap(); map.put("Community Name", Utilities.checkNA(model.getPlanetCode())); @@ -139,28 +200,25 @@ public void onError(Exception e) { map.put("Total Visits : ", handler.getOfflineVisits() + ""); map.put("Most Opened Resource : ", Utilities.checkNA(handler.getMaxOpenedResource())); map.put("Number of Resources Opened : ", Utilities.checkNA(handler.getNumberOfResourceOpen())); - setUpRecyclerView(map, v); - } - public void setUpRecyclerView(final HashMap map, View v) { final LinkedList keys = new LinkedList<>(map.keySet()); - rvStat.setAdapter(new RecyclerView.Adapter() { + fragmentUserProfileBinding.rvStat.setAdapter(new RecyclerView.Adapter() { @NonNull @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = getLayoutInflater().inflate(R.layout.row_stat, parent, false); - return new AdapterOtherInfo.ViewHolderOtherInfo(v); + public ViewHolderRowStat onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + rowStatBinding = RowStatBinding.inflate(LayoutInflater.from(getActivity()), parent, false); + return new ViewHolderRowStat(rowStatBinding); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof AdapterOtherInfo.ViewHolderOtherInfo) { - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvTitle.setText(keys.get(position)); - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvTitle.setVisibility(View.VISIBLE); - ((AdapterOtherInfo.ViewHolderOtherInfo) holder).tvDescription.setText(map.get(keys.get(position))); + if (holder instanceof ViewHolderRowStat) { + rowStatBinding.tvTitle.setText(keys.get(position)); + rowStatBinding.tvTitle.setVisibility(View.VISIBLE); + rowStatBinding.tvDescription.setText(map.get(keys.get(position))); if (position % 2 == 0) { - holder.itemView.setBackgroundColor(getResources().getColor(R.color.bg_white)); - holder.itemView.setBackgroundColor(getResources().getColor(R.color.md_grey_300)); + rowStatBinding.getRoot().setBackgroundColor(getResources().getColor(R.color.bg_white)); + rowStatBinding.getRoot().setBackgroundColor(getResources().getColor(R.color.md_grey_300)); } } } @@ -169,6 +227,15 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi public int getItemCount() { return keys.size(); } + + class ViewHolderRowStat extends RecyclerView.ViewHolder { + public RowStatBinding rowStatBinding; + + public ViewHolderRowStat(RowStatBinding rowStatBinding) { + super(rowStatBinding.getRoot()); + this.rowStatBinding = rowStatBinding; + } + } }); } } From 7a50782dfc7ff10b9d8ea5481132ad57c0ab60da Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Fri, 22 Sep 2023 20:10:43 +0300 Subject: [PATCH 52/80] courses: add select all button (fixes #2355) (#2356) Co-authored-by: dogi --- app/build.gradle | 4 +- .../myplanet/ui/course/AdapterCourses.java | 25 +++++ .../myplanet/ui/course/CourseFragment.java | 49 +++++++++- .../main/res/layout/fragment_my_course.xml | 93 +++++++++++-------- app/src/main/res/layout/layout_search.xml | 54 ++++++----- app/src/main/res/values-ar/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-ne/strings.xml | 2 + app/src/main/res/values-so/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 11 files changed, 167 insertions(+), 70 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7a566c1f37..ddad3ebe3f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1052 - versionName "0.10.52" + versionCode 1053 + versionName "0.10.53" 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 550631c4c0..ac0d27b4dd 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 @@ -56,6 +56,8 @@ public class AdapterCourses extends RecyclerView.Adapter courseList, HashMap map) { this.map = map; this.context = context; @@ -178,6 +180,29 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int } } + public boolean areAllSelected(){ + if (selectedItems.size() != courseList.size()) { + areAllSelected = false; + } + return areAllSelected; + } + + public void selectAllItems(boolean selectAll) { + if (selectAll) { + selectedItems.clear(); + selectedItems.addAll(courseList); + } else { + selectedItems.clear(); + } + + notifyDataSetChanged(); + + if (listener != null) { + listener.onSelectedListChange(selectedItems); + } + } + + private void displayTagCloud(FlexboxLayout flexboxDrawable, int position) { flexboxDrawable.removeAllViews(); final ChipCloud chipCloud = new ChipCloud(context, flexboxDrawable, config); diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java index 2ed0e5f7da..197f2ff38a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/course/CourseFragment.java @@ -7,6 +7,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.Button; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.Spinner; @@ -47,10 +48,12 @@ public class CourseFragment extends BaseRecyclerFragment implemen ImageView imgSearch; AdapterCourses adapterCourses; Button btnRemove, orderByDate, orderByTitle; + CheckBox selectAll; Spinner spnGrade, spnSubject; List searchTags; Spinner spn; AlertDialog confirmation; + private boolean allItemsSelected = false; public CourseFragment() { } @@ -88,9 +91,22 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { KeyboardUtils.hideSoftKeyboard(getActivity()); }); - btnRemove.setOnClickListener(V -> new AlertDialog.Builder(this.getContext()).setMessage(R.string.are_you_sure_you_want_to_delete_these_courses).setPositiveButton(R.string.yes, (dialogInterface, i) -> { - deleteSelected(true); - }).setNegativeButton(R.string.no, null).show()); + btnRemove.setOnClickListener(V -> new AlertDialog.Builder(this.getContext()) + .setMessage(R.string.are_you_sure_you_want_to_delete_these_courses) + .setPositiveButton(R.string.yes, (dialogInterface, i) -> { + deleteSelected(true); + if (adapterCourses.getCourseList().size() == 0) { + selectAll.setVisibility(View.GONE); + etSearch.setVisibility(View.GONE); + imgSearch.setVisibility(View.GONE); + tvAddToLib.setVisibility(View.GONE); + getView().findViewById(R.id.filter).setVisibility(View.GONE); + spn.setVisibility(View.GONE); + btnRemove.setVisibility(View.GONE); + tvSelected.setVisibility(View.GONE); + } + }) + .setNegativeButton(R.string.no, null).show()); getView().findViewById(R.id.btn_collections).setOnClickListener(view -> { CollectionsFragment f = CollectionsFragment.getInstance(searchTags, "courses"); f.setListener(this); @@ -140,6 +156,16 @@ private void initializeView() { addToMyList(); selectedItems.clear(); tvAddToLib.setEnabled(false); // selectedItems will always have a size of 0 + if (adapterCourses.getCourseList().size() == 0) { + selectAll.setVisibility(View.GONE); + etSearch.setVisibility(View.GONE); + imgSearch.setVisibility(View.GONE); + tvAddToLib.setVisibility(View.GONE); + getView().findViewById(R.id.filter).setVisibility(View.GONE); + spn.setVisibility(View.GONE); + btnRemove.setVisibility(View.GONE); + tvSelected.setVisibility(View.GONE); + } } }); etSearch = getView().findViewById(R.id.et_search); @@ -153,6 +179,22 @@ private void initializeView() { tvFragmentInfo = getView().findViewById(R.id.tv_fragment_info); spnGrade.setOnItemSelectedListener(itemSelectedListener); spnSubject.setOnItemSelectedListener(itemSelectedListener); + selectAll = getView().findViewById(R.id.selectAll); + if (adapterCourses.getCourseList().size() == 0) { + selectAll.setVisibility(View.GONE); + etSearch.setVisibility(View.GONE); + imgSearch.setVisibility(View.GONE); + tvAddToLib.setVisibility(View.GONE); + getView().findViewById(R.id.filter).setVisibility(View.GONE); + spn.setVisibility(View.GONE); + btnRemove.setVisibility(View.GONE); + tvSelected.setVisibility(View.GONE); + } + selectAll.setOnClickListener(view -> { + boolean allSelected = selectedItems.size() == adapterCourses.getCourseList().size(); + adapterCourses.selectAllItems(!allSelected); + selectAll.setText(allSelected ? getString(R.string.select_all) : getString(R.string.unselect_all)); + }); } private AdapterView.OnItemSelectedListener itemSelectedListener = new AdapterView.OnItemSelectedListener() { @@ -218,6 +260,7 @@ public void onTagClicked(RealmTag tag) { private void changeButtonStatus() { tvAddToLib.setEnabled(selectedItems.size() > 0); + selectAll.setText(adapterCourses.areAllSelected() ? getString(R.string.unselect_all) : getString(R.string.select_all)); } @Override diff --git a/app/src/main/res/layout/fragment_my_course.xml b/app/src/main/res/layout/fragment_my_course.xml index 8cf47f1f3a..770dc0d73b 100644 --- a/app/src/main/res/layout/fragment_my_course.xml +++ b/app/src/main/res/layout/fragment_my_course.xml @@ -1,3 +1,4 @@ + - - - - -