Skip to content

Commit

Permalink
Merge branch 'master' into 2776-migrate-realmfeedback-to-kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Dec 5, 2023
2 parents b6eb01d + 954abfb commit f152dbe
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 78 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ dependencies {

implementation 'com.github.jeancsanchez:jcplayer:2.7.2'

implementation "com.google.dagger:hilt-android:2.48.1"
kapt "com.google.dagger:hilt-android-compiler:2.48.1"
implementation "com.google.dagger:hilt-android:2.49"
kapt "com.google.dagger:hilt-android-compiler:2.49"

implementation 'com.mikepenz:crossfader:1.6.0@aar'
implementation 'com.mikepenz:crossfadedrawerlayout:1.1.0@aar'
Expand Down Expand Up @@ -132,6 +132,8 @@ dependencies {
implementation 'com.github.kizitonwose:CalendarView:1.1.0'
implementation "io.noties.markwon:editor:4.6.2"
implementation "io.noties.markwon:image:4.6.2"
implementation "io.noties.markwon:html:4.6.2"
implementation 'com.caverock:androidsvg-aar:1.4'
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'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<!-- <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>-->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

<application
android:name=".MainApplication"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.ole.planet.myplanet.base

import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
Expand All @@ -16,27 +19,23 @@ import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatRatingBar
import androidx.core.content.FileProvider
import com.google.gson.JsonObject
import io.realm.RealmResults
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.base.PermissionActivity.hasInstallPermission
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.callback.OnRatingChangeListener
import org.ole.planet.myplanet.model.RealmMyLibrary
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.service.UserProfileDbHandler.KEY_RESOURCE_DOWNLOAD
import org.ole.planet.myplanet.service.UserProfileDbHandler.KEY_RESOURCE_OPEN
import org.ole.planet.myplanet.ui.course.AdapterCourses
import org.ole.planet.myplanet.ui.viewer.AudioPlayerActivity
import org.ole.planet.myplanet.ui.viewer.CSVViewerActivity
import org.ole.planet.myplanet.ui.viewer.ImageViewerActivity
import org.ole.planet.myplanet.ui.viewer.MarkdownViewerActivity
import org.ole.planet.myplanet.ui.viewer.PDFReaderActivity
import org.ole.planet.myplanet.ui.viewer.TextFileViewerActivity
import org.ole.planet.myplanet.ui.viewer.VideoPlayerActivity
import org.ole.planet.myplanet.ui.viewer.*
import org.ole.planet.myplanet.utilities.FileUtils
import org.ole.planet.myplanet.utilities.Utilities
import java.io.File
Expand All @@ -46,9 +45,9 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
var rating: TextView? = null
var ratingBar: AppCompatRatingBar? = null
lateinit var profileDbHandler: UserProfileDbHandler
// private val INSTALL_UNKNOWN_SOURCES_REQUEST_CODE = 112
// var hasInstallPermission = hasInstallPermission(MainApplication.context)
// private var currentLibrary: RealmMyLibrary? = null
private val INSTALL_UNKNOWN_SOURCES_REQUEST_CODE = 112
var hasInstallPermission = hasInstallPermission(MainApplication.context)
private var currentLibrary: RealmMyLibrary? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -146,6 +145,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
fun checkMoreFileExtensions(extension: String?, items: RealmMyLibrary) {
when (extension) {
"txt" -> openIntent(items, TextFileViewerActivity::class.java)
Expand All @@ -158,8 +158,9 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun installApk(items: RealmMyLibrary) {
// currentLibrary = items
currentLibrary = items
val directory = File(MainApplication.context.getExternalFilesDir(null).toString() + "/ole" + "/" + items.id)
if (!directory.exists()) {
if (!directory.mkdirs()) {
Expand All @@ -183,22 +184,22 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK

if (intent.resolveActivity(requireActivity().packageManager) != null) {
// if (hasInstallPermission(MainApplication.context)) {
if (hasInstallPermission(MainApplication.context)) {
startActivity(intent)
// } else {
// requestInstallPermission()
// }
} else {
requestInstallPermission()
}
} else {
Utilities.toast(activity,"No app to handle the installation")
}
}

// @RequiresApi(Build.VERSION_CODES.O)
// private fun requestInstallPermission() {
// val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
// intent.data = Uri.parse("package:" + MainApplication.context.packageName)
// startActivityForResult(intent, INSTALL_UNKNOWN_SOURCES_REQUEST_CODE)
// }
@RequiresApi(Build.VERSION_CODES.O)
private fun requestInstallPermission() {
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
intent.data = Uri.parse("package:" + MainApplication.context.packageName)
startActivityForResult(intent, INSTALL_UNKNOWN_SOURCES_REQUEST_CODE)
}

fun openFileType(items: RealmMyLibrary, videotype: String) {
val mimetype = Utilities.getMimeType(items.resourceLocalAddress)
Expand Down Expand Up @@ -298,22 +299,22 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}
}

// @RequiresApi(Build.VERSION_CODES.O)
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// super.onActivityResult(requestCode, resultCode, data)
// if (requestCode == INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) {
// if (resultCode == Activity.RESULT_OK) {
// if (currentLibrary != null) {
// installApk(currentLibrary!!)
// currentLibrary = null
// }
// } else {
// Utilities.toast(requireActivity(), getString(R.string.permissions_denied))
// }
// }
// }
@RequiresApi(Build.VERSION_CODES.O)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == INSTALL_UNKNOWN_SOURCES_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
if (currentLibrary != null) {
installApk(currentLibrary!!)
currentLibrary = null
}
} else {
Utilities.toast(requireActivity(), getString(R.string.permissions_denied))
}
}
}

// open fun handleBackPressed() {
// requireActivity().onBackPressed()
// }
open fun handleBackPressed() {
requireActivity().onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ protected void showDownloadDialog(final List<RealmMyLibrary> db_myLibrary) {
@Override
public void isAvailable() {
if (!db_myLibrary.isEmpty()) {
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.my_library_alertdialog, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setView(convertView).setTitle(R.string.download_suggestion);
alertDialogBuilder.setPositiveButton(R.string.download_selected, (dialogInterface, i) -> startDownload(DownloadUtils.downloadFiles(db_myLibrary, lv.getSelectedItemsList(), settings))).setNeutralButton(R.string.download_all, (dialogInterface, i) -> startDownload(DownloadUtils.downloadAllFiles(db_myLibrary, settings))).setNegativeButton(R.string.txt_cancel, null);
AlertDialog alertDialog = alertDialogBuilder.create();
createListView(db_myLibrary, alertDialog);
alertDialog.show();
(alertDialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(lv.getSelectedItemsList().size() > 0);
if (isAdded() && getActivity() != null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
convertView = inflater.inflate(R.layout.my_library_alertdialog, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setView(convertView).setTitle(R.string.download_suggestion);
alertDialogBuilder.setPositiveButton(R.string.download_selected, (dialogInterface, i) -> startDownload(DownloadUtils.downloadFiles(db_myLibrary, lv.getSelectedItemsList(), settings))).setNeutralButton(R.string.download_all, (dialogInterface, i) -> startDownload(DownloadUtils.downloadAllFiles(db_myLibrary, settings))).setNegativeButton(R.string.txt_cancel, null);
AlertDialog alertDialog = alertDialogBuilder.create();
createListView(db_myLibrary, alertDialog);
alertDialog.show();
(alertDialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(lv.getSelectedItemsList().size() > 0);
}
} else {
Utilities.toast(requireContext(), getString(R.string.no_resources_to_download));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public boolean checkPermission(String strPermission) {
return result == PackageManager.PERMISSION_GRANTED;
}

// public static boolean hasInstallPermission(android.content.Context context) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// return context.getPackageManager().canRequestPackageInstalls();
// }
// return true;
// }
public static boolean hasInstallPermission(android.content.Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return context.getPackageManager().canRequestPackageInstalls();
}
return true;
}

public void checkUsagesPermission() {
if (!getUsagesPermission(this)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.UUID

open class RealmCourseActivity : RealmObject() {
@PrimaryKey
private var id: String? = null
private var _id: String? = null
@JvmField
var createdOn: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int
viewHolder.rowCourseBinding.title.setText(courseList.get(position).getCourseTitle());
viewHolder.rowCourseBinding.description.setText(courseList.get(position).getDescription());
markwon.setMarkdown(viewHolder.rowCourseBinding.description, courseList.get(position).getDescription());

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

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

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

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -32,8 +33,11 @@
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.file.FileSchemeHandler;
import io.noties.markwon.image.network.NetworkSchemeHandler;
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler;
import io.noties.markwon.movement.MovementMethodPlugin;
import io.realm.Realm;
import io.realm.RealmResults;
Expand All @@ -57,13 +61,17 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
id = getArguments().getString("courseId");
}
markwon = Markwon.builder(context)
.usePlugin(HtmlPlugin.create())
.usePlugin(ImagesPlugin.create())
.usePlugin(MovementMethodPlugin.none())
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configure(@NonNull MarkwonPlugin.Registry registry) {
registry.require(ImagesPlugin.class, imagesPlugin ->
imagesPlugin.addSchemeHandler(FileSchemeHandler.create())
registry.require(ImagesPlugin.class, imagesPlugin -> {
imagesPlugin.addSchemeHandler(FileSchemeHandler.create());
imagesPlugin.addSchemeHandler(NetworkSchemeHandler.create());
imagesPlugin.addSchemeHandler(OkHttpNetworkSchemeHandler.create());
}
);
}
})
Expand Down Expand Up @@ -93,10 +101,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}

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

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

private void setStepsList() {
List<RealmCourseStep> steps = RealmCourseStep.getSteps(mRealm, courses.getCourseId());
fragmentCourseDetailBinding.stepsList.setLayoutManager(new LinearLayoutManager(getActivity()));
Expand Down
Loading

0 comments on commit f152dbe

Please sign in to comment.