diff --git a/app/build.gradle b/app/build.gradle index 04da2d8270..e489f37262 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 26 targetSdkVersion 34 - versionCode 2127 - versionName "0.21.27" + versionCode 2143 + versionName "0.21.43" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true @@ -202,13 +202,13 @@ dependencies { implementation 'com.mikepenz:crossfadedrawerlayout:1.1.0@aar' implementation('com.mikepenz:materialdrawer:6.1.1@aar') { transitive = true} - def camera_version = "1.4.0" + def camera_version = "1.4.1" implementation "androidx.camera:camera-core:$camera_version" implementation "androidx.camera:camera-camera2:$camera_version" implementation "androidx.camera:camera-lifecycle:$camera_version" implementation "androidx.camera:camera-view:$camera_version" - def dagger_hilt_version = "2.53" + def dagger_hilt_version = "2.53.1" implementation "com.google.dagger:hilt-android:$dagger_hilt_version" kapt "com.google.dagger:hilt-android-compiler:$dagger_hilt_version" diff --git a/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt b/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt index a14ce8359e..70c0049d1f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt +++ b/app/src/main/java/org/ole/planet/myplanet/MainApplication.kt @@ -5,6 +5,7 @@ import android.app.Application import android.content.Context import android.content.Intent import android.content.SharedPreferences +import android.content.res.Configuration import android.os.Bundle import android.os.StrictMode import android.os.StrictMode.VmPolicy @@ -55,7 +56,7 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks { private const val AUTO_SYNC_WORK_TAG = "autoSyncWork" private const val STAY_ONLINE_WORK_TAG = "stayOnlineWork" private const val TASK_NOTIFICATION_WORK_TAG = "taskNotificationWork" - lateinit var context: Context + lateinit var context: Context lateinit var mRealm: Realm lateinit var service: DatabaseService var preferences: SharedPreferences? = null @@ -111,10 +112,10 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks { } fun setThemeMode(themeMode: String) { - val sharedPreferences = context.getSharedPreferences("app_preferences", MODE_PRIVATE) + val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE) with(sharedPreferences.edit()) { putString("theme_mode", themeMode) - apply() + commit() } applyThemeMode(themeMode) } @@ -218,10 +219,8 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks { registerActivityLifecycleCallbacks(this) onAppStarted() - val sharedPreferences = getSharedPreferences("app_preferences", MODE_PRIVATE) - val themeMode = sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) - - applyThemeMode(themeMode) + val savedThemeMode = getCurrentThemeMode() + applyThemeMode(savedThemeMode) isNetworkConnectedFlow.onEach { isConnected -> if (isConnected) { @@ -274,8 +273,17 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks { override fun onConfigurationChanged(newConfig: android.content.res.Configuration) { super.onConfigurationChanged(newConfig) - LocaleHelper.onAttach(this) - val currentNightMode = newConfig.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK + val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + val isSystemNight= when (currentNightMode) { + Configuration.UI_MODE_NIGHT_YES -> true + Configuration.UI_MODE_NIGHT_NO -> false + else -> false + } + val savedThemeMode = getCurrentThemeMode() + if (savedThemeMode != ThemeMode.FOLLOW_SYSTEM) { + return + } + when (currentNightMode) { android.content.res.Configuration.UI_MODE_NIGHT_NO -> { applyThemeMode(ThemeMode.LIGHT) @@ -286,6 +294,11 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks { } } + private fun getCurrentThemeMode(): String { + val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE) + return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM + } + override fun onActivityCreated(activity: Activity, bundle: Bundle?) {} override fun onActivityStarted(activity: Activity) { @@ -320,7 +333,7 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks { } } } - + private fun onAppBackgrounded() {} private fun onAppStarted() { diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt b/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt index ce5b816888..000a8aa2e0 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt @@ -30,8 +30,6 @@ import org.ole.planet.myplanet.base.PermissionActivity.Companion.hasInstallPermi 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.model.RealmUserChallengeActions -import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction import org.ole.planet.myplanet.service.UserProfileDbHandler import org.ole.planet.myplanet.service.UserProfileDbHandler.Companion.KEY_RESOURCE_DOWNLOAD import org.ole.planet.myplanet.service.UserProfileDbHandler.Companion.KEY_RESOURCE_OPEN @@ -79,9 +77,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() { val url = Utilities.getUrl(library) if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url) } - if (urls.isNotEmpty()) startDownload(urls) else Utilities.toast( - activity, getString(R.string.no_images_to_download) - ) + if (urls.isNotEmpty()) startDownload(urls) } fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) { @@ -159,34 +155,17 @@ abstract class BaseContainerFragment : BaseResourceFragment() { private fun checkFileExtension(items: RealmMyLibrary) { val mimetype = Utilities.getMimeType(items.resourceLocalAddress) - val userId = "${model?.id}" - Log.d("FileExtension", "Mimetype: ${items.resourceLocalAddress}") - val extension = items.resourceLocalAddress ?.substringAfterLast('.', "") ?.lowercase() - val existingAction = mRealm.where(RealmUserChallengeActions::class.java) - .equalTo("userId", userId) - .equalTo("resourceId", items.resourceId) - .findFirst() - if (mimetype != null) { if (mimetype.contains("image")) { openIntent(items, ImageViewerActivity::class.java) - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } } else if (mimetype.contains("pdf")) { openPdf(items) - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } } else if (mimetype.contains("audio")) { openIntent(items, AudioPlayerActivity::class.java) - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } } else { checkMoreFileExtensions(extension, items) } @@ -194,46 +173,20 @@ abstract class BaseContainerFragment : BaseResourceFragment() { } private fun checkMoreFileExtensions(extension: String?, items: RealmMyLibrary) { - val userId = "${model?.id}" - val existingAction = mRealm.where(RealmUserChallengeActions::class.java) - .equalTo("userId", userId) - .equalTo("resourceId", items.resourceId) - .findFirst() - when (extension) { "txt" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openIntent(items, TextFileViewerActivity::class.java) } "html", "htm" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openHtmlResource(items) } "md" -> { - if (items.resourceLocalAddress?.contains("README.md", ignoreCase = true) == true) { - Log.d("FileExtension", "Detected README.md file") - return - } - - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openIntent(items, MarkdownViewerActivity::class.java) } "csv" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openIntent(items, CSVViewerActivity::class.java) } "apk" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } installApk(items) } else -> Toast.makeText(activity, getString(R.string.this_file_type_is_currently_unsupported), Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt.lite b/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt.lite index a127e39f4d..db66984e4c 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt.lite +++ b/app/src/main/java/org/ole/planet/myplanet/base/BaseContainerFragment.kt.lite @@ -17,8 +17,8 @@ import android.widget.ArrayAdapter import android.widget.Button import android.widget.TextView import android.widget.Toast -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts +//import androidx.activity.result.ActivityResultLauncher +//import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AlertDialog import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.widget.AppCompatRatingBar @@ -30,8 +30,6 @@ import org.ole.planet.myplanet.R 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.model.RealmUserChallengeActions -import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction import org.ole.planet.myplanet.service.UserProfileDbHandler import org.ole.planet.myplanet.service.UserProfileDbHandler.Companion.KEY_RESOURCE_DOWNLOAD import org.ole.planet.myplanet.service.UserProfileDbHandler.Companion.KEY_RESOURCE_OPEN @@ -79,9 +77,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() { val url = Utilities.getUrl(library) if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url) } - if (urls.isNotEmpty()) startDownload(urls) else Utilities.toast( - activity, getString(R.string.no_images_to_download) - ) + if (urls.isNotEmpty()) startDownload(urls) } fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) { @@ -154,34 +150,17 @@ abstract class BaseContainerFragment : BaseResourceFragment() { private fun checkFileExtension(items: RealmMyLibrary) { val mimetype = Utilities.getMimeType(items.resourceLocalAddress) - val userId = "${model?.id}" - Log.d("FileExtension", "Mimetype: ${items.resourceLocalAddress}") - val extension = items.resourceLocalAddress ?.substringAfterLast('.', "") ?.lowercase() - val existingAction = mRealm.where(RealmUserChallengeActions::class.java) - .equalTo("userId", userId) - .equalTo("resourceId", items.resourceId) - .findFirst() - if (mimetype != null) { if (mimetype.contains("image")) { openIntent(items, ImageViewerActivity::class.java) - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } } else if (mimetype.contains("pdf")) { openPdf(items) - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } } else if (mimetype.contains("audio")) { openIntent(items, AudioPlayerActivity::class.java) - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } } else { checkMoreFileExtensions(extension, items) } @@ -189,46 +168,20 @@ abstract class BaseContainerFragment : BaseResourceFragment() { } private fun checkMoreFileExtensions(extension: String?, items: RealmMyLibrary) { - val userId = "${model?.id}" - val existingAction = mRealm.where(RealmUserChallengeActions::class.java) - .equalTo("userId", userId) - .equalTo("resourceId", items.resourceId) - .findFirst() - when (extension) { "txt" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openIntent(items, TextFileViewerActivity::class.java) } "html", "htm" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openHtmlResource(items) } "md" -> { - if (items.resourceLocalAddress?.contains("README.md", ignoreCase = true) == true) { - Log.d("FileExtension", "Detected README.md file") - return - } - - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openIntent(items, MarkdownViewerActivity::class.java) } "csv" -> { - if (existingAction == null) { - createAction(mRealm, userId, items.resourceId, "resourceOpen") - } openIntent(items, CSVViewerActivity::class.java) } // "apk" -> { -// if (existingAction == null) { -// createAction(mRealm, userId, items.resourceId, "resourceOpen") -// } // installApk(items) // } else -> Toast.makeText(activity, getString(R.string.this_file_type_is_currently_unsupported), Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt b/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt index 35746787be..25da0f5919 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/base/BaseRecyclerFragment.kt @@ -302,7 +302,8 @@ abstract class BaseRecyclerFragment
  • : BaseRecyclerParentFragment(), On "discussions" -> (v as TextView).setText(R.string.no_news) "survey" -> (v as TextView).setText(R.string.no_surveys) "submission" -> (v as TextView).setText(R.string.no_submissions) - "teams" -> (v as TextView).setText(R.string.no_teams) + "team" -> (v as TextView).setText(R.string.no_teams) + "enterprise" -> (v as TextView).setText(R.string.no_enterprise) "chatHistory" -> (v as TextView).setText(R.string.no_chats) "feedback" -> (v as TextView).setText(R.string.no_feedback) else -> (v as TextView).setText(R.string.no_data_available_please_check_and_try_again) diff --git a/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt b/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt index 5d516fd5b8..f623c37051 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt @@ -83,11 +83,9 @@ abstract class PermissionActivity : AppCompatActivity() { permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE) } } - if (permissions.isNotEmpty()) { + if (permissions.isNotEmpty() && !checkPermission(Manifest.permission.RECORD_AUDIO) &&!checkPermission(Manifest.permission.CAMERA)) { val permissionsArray = permissions.toTypedArray() ActivityCompat.requestPermissions(this, permissionsArray, PERMISSION_REQUEST_CODE_FILE) - } else { - Toast.makeText(this, R.string.permissions_granted, Toast.LENGTH_SHORT).show() } } diff --git a/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt.lite b/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt.lite index 4229f08651..97ccedad8d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt.lite +++ b/app/src/main/java/org/ole/planet/myplanet/base/PermissionActivity.kt.lite @@ -83,11 +83,9 @@ abstract class PermissionActivity : AppCompatActivity() { permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE) } } - if (permissions.isNotEmpty()) { + if (permissions.isNotEmpty() && !checkPermission(Manifest.permission.RECORD_AUDIO) &&!checkPermission(Manifest.permission.CAMERA)) { val permissionsArray = permissions.toTypedArray() ActivityCompat.requestPermissions(this, permissionsArray, PERMISSION_REQUEST_CODE_FILE) - } else { - Toast.makeText(this, R.string.permissions_granted, Toast.LENGTH_SHORT).show() } } diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt index de64caf55d..18a2b916af 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt @@ -307,7 +307,6 @@ class Service(private val context: Context) { }) { error: Throwable -> realm.close() error.printStackTrace() - callback.onSuccess("Unable to connect to planet earth") } } } @@ -315,7 +314,6 @@ class Service(private val context: Context) { override fun onFailure(call: Call, t: Throwable) { realm.close() - callback.onSuccess("Unable to connect to planet earth") } }) } diff --git a/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt b/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt index ba34e3b34b..f36ec0262c 100644 --- a/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt +++ b/app/src/main/java/org/ole/planet/myplanet/model/RealmSubmission.kt @@ -204,12 +204,25 @@ open class RealmSubmission : RealmObject() { } } + fun generateParentId(courseId: String?, examId: String?): String? { + return if (!examId.isNullOrEmpty()) { + if (!courseId.isNullOrEmpty()) { + "$examId@$courseId" + } else { + examId + } + } else { + null + } + } + @JvmStatic - fun getNoOfSubmissionByUser(id: String?, userId: String?, mRealm: Realm): String { + fun getNoOfSubmissionByUser(id: String?, courseId:String?, userId: String?, mRealm: Realm): String { if (id == null || userId == null) return "No Submissions Found" - + val submissionParentId= generateParentId(courseId, id) + if(submissionParentId.isNullOrEmpty()) return "No Submissions Found" val submissionCount = mRealm.where(RealmSubmission::class.java) - .equalTo("parentId", id) + .equalTo("parentId", submissionParentId) .equalTo("userId", userId) .equalTo("status", "complete") .count().toInt() @@ -230,15 +243,15 @@ open class RealmSubmission : RealmObject() { } @JvmStatic - fun getRecentSubmissionDate(id: String?, userId: String?, mRealm: Realm): String { + fun getRecentSubmissionDate(id: String?, courseId:String?, userId: String?, mRealm: Realm): String { if (id == null || userId == null) return "" - + val submissionParentId= generateParentId(courseId, id) + if(submissionParentId.isNullOrEmpty()) return "" val recentSubmission = mRealm.where(RealmSubmission::class.java) - .equalTo("parentId", id) + .equalTo("parentId", submissionParentId) .equalTo("userId", userId) .sort("startTime", Sort.DESCENDING) .findFirst() - return recentSubmission?.startTime?.let { TimeUtils.getFormatedDateWithTime(it) } ?: "" } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt index 5a7f192220..68e8ac05f1 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/SettingActivity.kt @@ -10,8 +10,10 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter +import android.widget.ListView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.ContextCompat import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceChangeListener @@ -23,6 +25,7 @@ import io.realm.Realm import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.ole.planet.myplanet.MainApplication.Companion.context import org.ole.planet.myplanet.MainApplication.Companion.mRealm import org.ole.planet.myplanet.MainApplication.Companion.setThemeMode import org.ole.planet.myplanet.R @@ -107,7 +110,7 @@ class SettingActivity : AppCompatActivity() { val darkMode = findPreference("dark_mode") darkMode?.setOnPreferenceClickListener { - darkMode() + darkMode(requireActivity()) true } @@ -267,36 +270,56 @@ class SettingActivity : AppCompatActivity() { dialog.show() } - private fun darkMode() { - val options = arrayOf(getString(R.string.dark_mode_off), getString(R.string.dark_mode_on), getString(R.string.dark_mode_follow_system)) - val currentMode = getCurrentThemeMode() - val checkedItem = when (currentMode) { - ThemeMode.LIGHT -> 0 - ThemeMode.DARK -> 1 - else -> 2 - } + companion object { + fun darkMode(context: Context) { + val options = arrayOf(context.getString(R.string.dark_mode_off), context.getString(R.string.dark_mode_on),context.getString(R.string.dark_mode_follow_system)) + val currentMode = getCurrentThemeMode(context) + val checkedItem = when (currentMode) { + ThemeMode.LIGHT -> 0 + ThemeMode.DARK -> 1 + else -> 2 + } - val builder = AlertDialog.Builder(requireContext()) - .setTitle(getString(R.string.select_theme_mode)) - .setSingleChoiceItems(ArrayAdapter(requireContext(), R.layout.checked_list_item, options), checkedItem) { dialog, which -> - val selectedMode = when (which) { - 0 -> ThemeMode.LIGHT - 1 -> ThemeMode.DARK - 2 -> ThemeMode.FOLLOW_SYSTEM - else -> ThemeMode.FOLLOW_SYSTEM + val builder = AlertDialog.Builder(context, R.style.CustomAlertDialogStyle) + .setTitle(context.getString(R.string.select_theme_mode)) + .setSingleChoiceItems(ArrayAdapter(context, R.layout.checked_list_item, options), checkedItem) { dialog, which -> + val selectedMode = when (which) { + 0 -> ThemeMode.LIGHT + 1 -> ThemeMode.DARK + 2 -> ThemeMode.FOLLOW_SYSTEM + else -> ThemeMode.FOLLOW_SYSTEM + } + setThemeMode(context, selectedMode) + dialog.dismiss() } - setThemeMode(selectedMode) - dialog.dismiss() - } - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, null) - val dialog = builder.create() - dialog.show() - } + val dialog = builder.create() + dialog.show() - private fun getCurrentThemeMode(): String { - val sharedPreferences = requireContext().getSharedPreferences(PREFS_NAME, MODE_PRIVATE) - return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM + val window = dialog.window + window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + } + + private fun getCurrentThemeMode(context: Context): String { + val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE) + return sharedPreferences.getString("theme_mode", ThemeMode.FOLLOW_SYSTEM) ?: ThemeMode.FOLLOW_SYSTEM + } + + private fun setThemeMode(context: Context, themeMode: String) { + val sharedPreferences = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE) + with(sharedPreferences.edit()) { + putString("theme_mode", themeMode) + apply() + } + AppCompatDelegate.setDefaultNightMode( + when (themeMode) { + ThemeMode.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO + ThemeMode.DARK -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + } + ) + } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt index a1b1696a1b..98e5ba502d 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatDetailFragment.kt @@ -15,7 +15,6 @@ import org.ole.planet.myplanet.databinding.FragmentChatDetailBinding import org.ole.planet.myplanet.datamanager.* import org.ole.planet.myplanet.model.* import org.ole.planet.myplanet.model.RealmChatHistory.Companion.addConversationToChatHistory -import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction import org.ole.planet.myplanet.service.UserProfileDbHandler import org.ole.planet.myplanet.ui.dashboard.DashboardActivity import org.ole.planet.myplanet.utilities.Utilities @@ -342,8 +341,6 @@ class ChatDetailFragment : Fragment() { } (requireActivity() as? DashboardActivity)?.refreshChatHistoryList() } - - createAction(mRealm, "${user?.id}", "${response.body()?.couchDBResponse?.id}", "ai research") } else { fragmentChatDetailBinding.textGchatIndicator.visibility = View.VISIBLE fragmentChatDetailBinding.textGchatIndicator.text = if (response.message() == "null"){ diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt index e86345f025..0aa57b9938 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt @@ -126,7 +126,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List chatShareDialogBinding.listView.setAdapter(expandableListAdapter) chatShareDialogBinding.listView.setOnChildClickListener { _, _, groupPosition, childPosition, _ -> - if (expandableTitleList[groupPosition] == "share with team/enterprise") { + if (expandableTitleList[groupPosition] == context.getString(R.string.share_with_team_enterprise)) { val teamList = mRealm.where(RealmMyTeam::class.java) .isEmpty("teamId").notEqualTo("status", "archived") .equalTo("type", "team").findAll() @@ -135,10 +135,10 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List .isEmpty("teamId").notEqualTo("status", "archived") .equalTo("type", "enterprise").findAll() - if (expandableDetailList[expandableTitleList[groupPosition]]?.get(childPosition) == "teams") { - showGrandChildRecyclerView(teamList, "teams", filteredChatHistory[position]) + if (expandableDetailList[expandableTitleList[groupPosition]]?.get(childPosition) == context.getString(R.string.teams)) { + showGrandChildRecyclerView(teamList, context.getString(R.string.teams), filteredChatHistory[position]) } else { - showGrandChildRecyclerView(enterpriseList, "enterprises", filteredChatHistory[position]) + showGrandChildRecyclerView(enterpriseList, context.getString(R.string.enterprises), filteredChatHistory[position]) } } else { settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) @@ -146,7 +146,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List val communityName = settings?.getString("communityName", "") val teamId = "$communityName@$sParentcode" val community = mRealm.where(RealmMyTeam::class.java).equalTo("_id", teamId).findFirst() - showEditTextAndShareButton(community, "community", filteredChatHistory[position]) + showEditTextAndShareButton(community, context.getString(R.string.community), filteredChatHistory[position]) } dialog?.dismiss() false @@ -167,13 +167,13 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List val grandChildDialogBinding = GrandChildRecyclerviewDialogBinding.inflate(LayoutInflater.from(context)) var dialog: AlertDialog? = null - if (section == "teams") { + if (section == context.getString(R.string.teams)) { grandChildDialogBinding.title.text = context.getString(R.string.team) } else { grandChildDialogBinding.title.text = context.getString(R.string.enterprises) } val grandChildAdapter = GrandChildAdapter(items) { selectedItem -> - showEditTextAndShareButton(selectedItem, "teams", realmChatHistory) + showEditTextAndShareButton(selectedItem, context.getString(R.string.teams), realmChatHistory) dialog?.dismiss() } grandChildDialogBinding.recyclerView.layoutManager = LinearLayoutManager(context) @@ -181,7 +181,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List val builder = AlertDialog.Builder(context) builder.setView(grandChildDialogBinding.root) - builder.setPositiveButton("close") { _, _ -> + builder.setPositiveButton(context.getString(R.string.close)) { _, _ -> dialog?.dismiss() } dialog = builder.create() @@ -235,14 +235,14 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List private fun getData(): Map> { val expandableListDetail: MutableMap> = HashMap() val community: MutableList = ArrayList() - community.add("community") + community.add(context.getString(R.string.community)) val teams: MutableList = ArrayList() - teams.add("teams") - teams.add("enterprises") + teams.add(context.getString(R.string.teams)) + teams.add(context.getString(R.string.enterprises)) - expandableListDetail["share with community"] = community - expandableListDetail["share with team/enterprise"] = teams + expandableListDetail[context.getString(R.string.share_with_community)] = community + expandableListDetail[context.getString(R.string.share_with_team_enterprise)] = teams return expandableListDetail } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/resources/AdapterResource.kt b/app/src/main/java/org/ole/planet/myplanet/ui/resources/AdapterResource.kt index ff523d7846..c0c8a59d48 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/resources/AdapterResource.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/resources/AdapterResource.kt @@ -74,6 +74,10 @@ class AdapterResource(private val context: Context, private var libraryList: Lis holder.bind() holder.rowLibraryBinding.title.text = libraryList[position]?.title setMarkdownText(holder.rowLibraryBinding.description, libraryList[position]?.description!!) + holder.rowLibraryBinding.description.setOnClickListener { + val library = libraryList[position] + openLibrary(library) + } holder.rowLibraryBinding.timesRated.text = context.getString(R.string.num_total, libraryList[position]?.timesRated) holder.rowLibraryBinding.checkbox.isChecked = selectedItems.contains(libraryList[position]) holder.rowLibraryBinding.checkbox.contentDescription = "${context.getString(R.string.selected)} ${libraryList[position]?.title}" diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt b/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt index e4551d0ae7..b618711e36 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/survey/AdapterSurvey.kt @@ -85,8 +85,8 @@ class AdapterSurvey(private val context: Context, private val mRealm: Realm, pri startSurvey.visibility = View.GONE } - tvNoSubmissions.text = getNoOfSubmissionByUser(exam.id, user?.id, mRealm) - tvDateCompleted.text = getRecentSubmissionDate(exam.id, user?.id, mRealm) + tvNoSubmissions.text = getNoOfSubmissionByUser(exam.id, exam.courseId, user?.id, mRealm) + tvDateCompleted.text = getRecentSubmissionDate(exam.id, exam.courseId, user?.id, mRealm) tvDate.text = formatDate(RealmStepExam.getSurveyCreationTime(exam.id!!, mRealm)!!, "MMM dd, yyyy") } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt index f4e213c23d..3198454964 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt @@ -20,9 +20,12 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.lifecycleScope import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.google.android.material.bottomnavigation.BottomNavigationView +import io.realm.Realm import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.ole.planet.myplanet.R import org.ole.planet.myplanet.callback.OnRatingChangeListener import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction @@ -61,11 +64,7 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack 4 -> openEnterpriseFragment() 3 -> openCallFragment(TeamFragment(), "survey") 5 -> { - if (profileDbHandler.userModel?.isGuest() == true) { - showGuestUserDialog() - } else { - openCallFragment(CommunityTabFragment(), "community") - } + openCallFragment(CommunityTabFragment(), "community") } } } @@ -121,10 +120,24 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack } fun logSyncInSharedPrefs() { - lifecycleScope.launch { - if (isServerReachable(Utilities.getUrl())) { - startUpload("dashboard") - createAction(mRealm, "${profileDbHandler.userModel?.id}", null, "sync") + lifecycleScope.launch(Dispatchers.IO + SupervisorJob()) { + try { + val isReachable = isServerReachable(Utilities.getUrl()) + if (isReachable) { + withContext(Dispatchers.Main) { + startUpload("dashboard") + } + + withContext(Dispatchers.IO) { + Realm.getDefaultInstance().use { realm -> + realm.executeTransaction { + createAction(realm, "${profileDbHandler.userModel?.id}", null, "sync") + } + } + } + } + } catch (e: Exception) { + e.printStackTrace() } } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt index 1432276248..d0eed59e4f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt @@ -19,6 +19,7 @@ import org.ole.planet.myplanet.callback.SyncListener import org.ole.planet.myplanet.databinding.* import org.ole.planet.myplanet.datamanager.* import org.ole.planet.myplanet.model.* +import org.ole.planet.myplanet.ui.SettingActivity import org.ole.planet.myplanet.ui.community.HomeCommunityDialogFragment import org.ole.planet.myplanet.ui.feedback.FeedbackFragment import org.ole.planet.myplanet.ui.userprofile.* @@ -110,6 +111,10 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener { } } }) + val selectDarkModeButton = findViewById(R.id.themeToggleButton) + selectDarkModeButton?.setOnClickListener{ + SettingActivity.SettingFragment.darkMode(this) + } } private fun declareElements() { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt index 10b8f3f4db..6f6efc9145 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt @@ -6,7 +6,6 @@ import android.graphics.drawable.AnimationDrawable import android.os.Build import android.os.Bundle import android.text.* -import android.util.Log import android.view.* import android.webkit.URLUtil import android.widget.* @@ -38,7 +37,6 @@ import org.ole.planet.myplanet.datamanager.* import org.ole.planet.myplanet.datamanager.ApiClient.client import org.ole.planet.myplanet.datamanager.Service.* import org.ole.planet.myplanet.model.* -import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction import org.ole.planet.myplanet.service.* import org.ole.planet.myplanet.ui.dashboard.DashboardActivity import org.ole.planet.myplanet.ui.team.AdapterTeam.OnUserSelectedListener @@ -413,25 +411,6 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers fun onLogin() { val handler = UserProfileDbHandler(this) - - val userId = handler.userModel?.id - if (userId != null && userId.startsWith("guest") == false) { - Log.d("okuro", "called") - val latestAction = mRealm.where(RealmUserChallengeActions::class.java) - .equalTo("userId", userId).sort("time", Sort.DESCENDING).findFirst() - - val currentTime = System.currentTimeMillis() - val thresholdTime = 24 * 60 * 60 * 1000 - - if (latestAction == null) { - createAction(mRealm, userId, null, "login") - } else { - if (currentTime - latestAction.time >= thresholdTime) { - createAction(mRealm, userId, null, "login") - } - } - } - handler.onLogin() handler.onDestroy() editor.putBoolean(Constants.KEY_LOGIN, true).commit() diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/team/TeamFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/team/TeamFragment.kt index 62bb743394..5cae9b86f5 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/team/TeamFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/team/TeamFragment.kt @@ -242,7 +242,7 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem { fragmentTeamBinding.rvTeamList.adapter = adapterTeamList listContentDescription(conditionApplied) val itemCount = adapterTeamList.itemCount - showNoData(fragmentTeamBinding.tvMessage, itemCount, "teams") + showNoData(fragmentTeamBinding.tvMessage, itemCount, "$type") if (itemCount == 0) { fragmentTeamBinding.etSearch.visibility = View.GONE fragmentTeamBinding.tableTitle.visibility = View.GONE diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt index 689468c50f..b9baf7fa7a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt @@ -34,7 +34,7 @@ object DialogUtils { fun guestDialog(context: Context) { val profileDbHandler = UserProfileDbHandler(context) - val builder = android.app.AlertDialog.Builder(context, R.style.AlertDialogTheme) + val builder = android.app.AlertDialog.Builder(context, R.style.CustomAlertDialog) builder.setTitle(context.getString(R.string.become_a_member)) builder.setMessage(context.getString(R.string.to_access_this_feature_become_a_member)) builder.setCancelable(false) @@ -75,7 +75,7 @@ object DialogUtils { private fun showDialog(context: Context) { if (MainApplication.syncFailedCount > 3) { - val pd = AlertDialog.Builder(context) + val pd = AlertDialog.Builder(context, R.style.CustomAlertDialog) var message = if (NetworkUtils.isBluetoothEnabled()) "Bluetooth " else "" message += if (NetworkUtils.isWifiEnabled()) "Wifi " else "" message += context.getString(R.string.is_on_please_turn_of_to_save_battery) @@ -101,7 +101,7 @@ object DialogUtils { @JvmStatic fun showAlert(context: Context?, title: String?, message: String?) { if (context is Activity && !context.isFinishing) { - AlertDialog.Builder(context, R.style.AlertDialogTheme) + AlertDialog.Builder(context, R.style.CustomAlertDialog) .setTitle(title) .setMessage(message) .setPositiveButton(R.string.finish, null) @@ -111,7 +111,7 @@ object DialogUtils { @JvmStatic fun getAlertDialog(context: Context, message: String, pos: String, listener: DialogInterface.OnClickListener?): AlertDialog { - return AlertDialog.Builder(ContextThemeWrapper(context, R.style.AlertDialogTheme)) + return AlertDialog.Builder(ContextThemeWrapper(context, R.style.CustomAlertDialog)) .setMessage(message) .setIcon(R.drawable.courses) .setPositiveButton(pos, listener) @@ -130,7 +130,7 @@ object DialogUtils { @JvmStatic fun getAlertDialog(context: Context, title: String, v: View): AlertDialog { - return AlertDialog.Builder(ContextThemeWrapper(context, R.style.AlertDialogTheme)) + return AlertDialog.Builder(ContextThemeWrapper(context, R.style.CustomAlertDialog)) .setTitle(title) .setIcon(R.drawable.ic_edit) .setView(v) diff --git a/app/src/main/res/drawable/moon_24dp.png b/app/src/main/res/drawable/moon_24dp.png new file mode 100644 index 0000000000..26ac0d8fa2 Binary files /dev/null and b/app/src/main/res/drawable/moon_24dp.png differ diff --git a/app/src/main/res/drawable/moon_35.png b/app/src/main/res/drawable/moon_35.png new file mode 100644 index 0000000000..4f748d24fa Binary files /dev/null and b/app/src/main/res/drawable/moon_35.png differ diff --git a/app/src/main/res/drawable/sun_24dp.png b/app/src/main/res/drawable/sun_24dp.png new file mode 100644 index 0000000000..7272d70af8 Binary files /dev/null and b/app/src/main/res/drawable/sun_24dp.png differ diff --git a/app/src/main/res/drawable/sun_35.png b/app/src/main/res/drawable/sun_35.png new file mode 100644 index 0000000000..1599faeff8 Binary files /dev/null and b/app/src/main/res/drawable/sun_35.png differ diff --git a/app/src/main/res/drawable/white_moon_24dp.png b/app/src/main/res/drawable/white_moon_24dp.png new file mode 100644 index 0000000000..56bca0d0e9 Binary files /dev/null and b/app/src/main/res/drawable/white_moon_24dp.png differ diff --git a/app/src/main/res/layout-large-land/activity_login.xml b/app/src/main/res/layout-large-land/activity_login.xml index a058ffce53..54904c34a7 100644 --- a/app/src/main/res/layout-large-land/activity_login.xml +++ b/app/src/main/res/layout-large-land/activity_login.xml @@ -211,12 +211,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + android:layout_height="match_parent"> + + + + android:layout_height="match_parent"> + + + + + + + + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 47eb0743ca..405073d31a 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -30,6 +30,7 @@ تسجيل الخروج ملاحظات myPlanet + يختار مكتبتي دوراتي تجمعاتي @@ -1207,5 +1208,9 @@ تم إلغاء التصدير. فشل في حفظ ملف CSV. تم حفظ ملف CSV بنجاح. + مشاركة مع الفريق/المؤسسة + فرق + مجتمع + المؤسسات غير متوفرة diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 3727d2c1a6..23c877cb17 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -30,6 +30,7 @@ Cerrar sesión Retroalimentación myPlanet + Seleccionar miBiblioteca misCursos misEncuentros @@ -1207,5 +1208,9 @@ exportación cancelada. error al guardar el archivo CSV. archivo CSV guardado con éxito. + compartir con el equipo/empresa + equipos + comunidad + empresas no disponibles diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5656636e18..045d857083 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -30,6 +30,7 @@ Déconnexion Retour d\'information myPlanet + Sélectionner maBibliothèque mesCours mesRencontres @@ -1207,5 +1208,9 @@ exportation annulée. échec de l\'enregistrement du fichier CSV. fichier CSV enregistré avec succès. + partager avec l\'équipe/l\'entreprise + équipes + communauté + entreprises non disponibles diff --git a/app/src/main/res/values-ne/strings.xml b/app/src/main/res/values-ne/strings.xml index 0b1baa8537..d9920520c4 100644 --- a/app/src/main/res/values-ne/strings.xml +++ b/app/src/main/res/values-ne/strings.xml @@ -30,6 +30,7 @@ लगआउट प्रतिक्रिया myPlanet + चयन गर्नुहोस् मेरो पुस्तकालय मेरो पाठ्यक्रमहरू मेरो मिठिङहरू @@ -1207,5 +1208,9 @@ निर्यात रद्द गरियो। CSV फाइल सुरक्षित गर्न असफल। CSV फाइल सफलतापूर्वक सुरक्षित गरियो। + टोली/उद्यमसँग साझा गर्नुहोस् + टोलीहरू + समुदाय + उद्यमहरू उपलब्ध छैनन् diff --git a/app/src/main/res/values-so/strings.xml b/app/src/main/res/values-so/strings.xml index 20d504d033..2f87ff661c 100644 --- a/app/src/main/res/values-so/strings.xml +++ b/app/src/main/res/values-so/strings.xml @@ -30,6 +30,7 @@ ka bax jawaab celin myPlanet + Dooro maktabadayda coursyadayda myMeetups @@ -1207,5 +1208,9 @@ dhoofinta waa la joojiyay. waa lagu guuldareystay in la badbaadiyo faylka CSV. faylka CSV si guul leh ayaa loo keydiyay. + la wadaag kooxda/ganacsiga + kooxo + bulsho + ganacsiyo lama heli karo diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bdc706d8c1..c23eed13c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1207,5 +1207,9 @@ export cancelled. failed to save CSV file. CSV file saved successfully. + share with team/enterprise + teams + community + enteprises not available diff --git a/build.gradle b/build.gradle index 757ea1c9ba..b4bfa63b58 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:8.7.3' classpath "io.realm:realm-gradle-plugin:10.19.0" - classpath "com.google.dagger:hilt-android-gradle-plugin:2.53" + classpath "com.google.dagger:hilt-android-gradle-plugin:2.53.1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" // NOTE: Do not place your application dependencies here