Skip to content

Commit

Permalink
Merge branch 'master' into teamSurvey
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Jan 5, 2025
2 parents ad88fe5 + 8e36415 commit 23b37a0
Show file tree
Hide file tree
Showing 53 changed files with 816 additions and 292 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2140
versionName "0.21.40"
versionCode 2162
versionName "0.21.62"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -208,7 +208,7 @@ dependencies {
implementation "androidx.camera:camera-lifecycle:$camera_version"
implementation "androidx.camera:camera-view:$camera_version"

def dagger_hilt_version = "2.53.1"
def dagger_hilt_version = "2.54"
implementation "com.google.dagger:hilt-android:$dagger_hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$dagger_hilt_version"

Expand All @@ -220,7 +220,7 @@ dependencies {
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"

def media3_version = "1.5.0"
def media3_version = "1.5.1"
implementation "androidx.media3:media3-exoplayer:$media3_version"
implementation "androidx.media3:media3-ui:$media3_version"
implementation "androidx.media3:media3-common:$media3_version"
Expand Down
33 changes: 23 additions & 10 deletions app/src/main/java/org/ole/planet/myplanet/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -320,7 +333,7 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks {
}
}
}

private fun onAppBackgrounded() {}

private fun onAppStarted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
AdapterCourses.showRating(`object`, rating, timesRated, ratingBar)
}
}
fun getUrlsAndStartDownload(
lib: List<RealmMyLibrary?>, urls: ArrayList<String>
) {
fun getUrlsAndStartDownload(lib: List<RealmMyLibrary?>, urls: ArrayList<String>) {
for (library in lib) {
val url = Utilities.getUrl(library)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) {
urls.add(url)
}
}
if (urls.isNotEmpty()) {
startDownload(urls)
}
if (urls.isNotEmpty()) startDownload(urls)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down Expand Up @@ -123,23 +125,53 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}

fun openResource(items: RealmMyLibrary) {
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline()}
openFileType(offlineItem, "offline")
if (items.openWith == "HTML") {
if (items.resourceOffline) {
val intent = Intent(activity, WebViewActivity::class.java)
intent.putExtra("RESOURCE_ID", items.id)
intent.putExtra("LOCAL_ADDRESS", items.resourceLocalAddress)
intent.putExtra("title", items.title)
startActivity(intent)
} else {
val resource = mRealm.where(RealmMyLibrary::class.java).equalTo("_id", items.resourceId).findFirst()
val downloadUrls = ArrayList<String>()
resource?.attachments?.forEach { attachment ->
attachment.name?.let { name ->
val url = Utilities.getUrl("${items.resourceId}", name)
downloadUrls.add(url)

val baseDir = File(context?.getExternalFilesDir(null), "ole/${items.resourceId}")
val lastSlashIndex = name.lastIndexOf('/')
if (lastSlashIndex > 0) {
val dirPath = name.substring(0, lastSlashIndex)
File(baseDir, dirPath).mkdirs()
}
}
}

if (downloadUrls.isNotEmpty()) {
startDownload(downloadUrls)
}
}
} else {
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline() }
openFileType(offlineItem, "offline")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
AdapterCourses.showRating(`object`, rating, timesRated, ratingBar)
}
}
fun getUrlsAndStartDownload(
lib: List<RealmMyLibrary?>, urls: ArrayList<String>
) {
fun getUrlsAndStartDownload(lib: List<RealmMyLibrary?>, urls: ArrayList<String>) {
for (library in lib) {
val url = Utilities.getUrl(library)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) {
urls.add(url)
}
}
if (urls.isNotEmpty()) {
startDownload(urls)
}
if (urls.isNotEmpty()) startDownload(urls)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down Expand Up @@ -123,23 +125,53 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}

fun openResource(items: RealmMyLibrary) {
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline()}
openFileType(offlineItem, "offline")
if (items.openWith == "HTML") {
if (items.resourceOffline) {
val intent = Intent(activity, WebViewActivity::class.java)
intent.putExtra("RESOURCE_ID", items.id)
intent.putExtra("LOCAL_ADDRESS", items.resourceLocalAddress)
intent.putExtra("title", items.title)
startActivity(intent)
} else {
val resource = mRealm.where(RealmMyLibrary::class.java).equalTo("_id", items.resourceId).findFirst()
val downloadUrls = ArrayList<String>()
resource?.attachments?.forEach { attachment ->
attachment.name?.let { name ->
val url = Utilities.getUrl("${items.resourceId}", name)
downloadUrls.add(url)

val baseDir = File(context?.getExternalFilesDir(null), "ole/${items.resourceId}")
val lastSlashIndex = name.lastIndexOf('/')
if (lastSlashIndex > 0) {
val dirPath = name.substring(0, lastSlashIndex)
File(baseDir, dirPath).mkdirs()
}
}
}

if (downloadUrls.isNotEmpty()) {
startDownload(downloadUrls)
}
}
} else {
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline() }
openFileType(offlineItem, "offline")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ abstract class BaseRecyclerFragment<LI> : BaseRecyclerParentFragment<Any?>(), 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.ole.planet.myplanet.MainApplication.Companion.context
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.datamanager.DatabaseService
import org.ole.planet.myplanet.datamanager.MyDownloadService
import org.ole.planet.myplanet.datamanager.Service
import org.ole.planet.myplanet.datamanager.Service.PlanetAvailableListener
import org.ole.planet.myplanet.model.Download
Expand Down Expand Up @@ -89,6 +90,7 @@ abstract class BaseResourceFragment : Fragment() {
if (!download?.failed!!) {
setProgress(download)
} else {
prgDialog.dismiss()
download.message?.let { showError(prgDialog, it) }
}
}
Expand Down Expand Up @@ -168,6 +170,27 @@ abstract class BaseResourceFragment : Fragment() {
}.setPositiveButton(R.string.dismiss, null).show()
}

private val resourceNotFoundReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
showResourceNotFoundDialog()
}
}

private fun showResourceNotFoundDialog() {
if (isAdded) {
if (prgDialog.isShowing()) {
prgDialog.dismiss()
}
AlertDialog.Builder(requireContext())
.setTitle(R.string.resource_not_found)
.setMessage(R.string.resource_not_found_message)
.setNegativeButton(R.string.close) { dialog, _ ->
dialog.dismiss()
}
.show()
}
}

fun startDownload(urls: ArrayList<String>) {
if (isAdded) {
Service(requireActivity()).isPlanetAvailable(object : PlanetAvailableListener {
Expand Down Expand Up @@ -221,17 +244,21 @@ abstract class BaseResourceFragment : Fragment() {

private fun registerReceiver() {
val bManager = LocalBroadcastManager.getInstance(requireActivity())

val intentFilter = IntentFilter()
intentFilter.addAction(DashboardActivity.MESSAGE_PROGRESS)
bManager.registerReceiver(broadcastReceiver, intentFilter)

val intentFilter2 = IntentFilter()
intentFilter2.addAction("ACTION_NETWORK_CHANGED")
LocalBroadcastManager.getInstance(MainApplication.context).registerReceiver(receiver, intentFilter2)
bManager.registerReceiver(receiver, intentFilter2)

val intentFilter3 = IntentFilter()
intentFilter3.addAction("SHOW_WIFI_ALERT")
LocalBroadcastManager.getInstance(MainApplication.context).registerReceiver(stateReceiver, intentFilter3)
bManager.registerReceiver(stateReceiver, intentFilter3)

val resourceNotFoundFilter = IntentFilter(MyDownloadService.RESOURCE_NOT_FOUND_ACTION)
bManager.registerReceiver(resourceNotFoundReceiver, resourceNotFoundFilter)
}

fun getLibraryList(mRealm: Realm): List<RealmMyLibrary> {
Expand All @@ -248,9 +275,11 @@ abstract class BaseResourceFragment : Fragment() {

override fun onPause() {
super.onPause()
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receiver)
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(broadcastReceiver)
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(stateReceiver)
val bManager = LocalBroadcastManager.getInstance(requireActivity())
bManager.unregisterReceiver(receiver)
bManager.unregisterReceiver(broadcastReceiver)
bManager.unregisterReceiver(stateReceiver)
bManager.unregisterReceiver(resourceNotFoundReceiver)
}

fun removeFromShelf(`object`: RealmObject) {
Expand Down
Loading

0 comments on commit 23b37a0

Please sign in to comment.