Skip to content

Commit

Permalink
Merge branch 'master' into 1859-username-length
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Jan 10, 2025
2 parents d38e33a + 08e4079 commit 0dd14d6
Show file tree
Hide file tree
Showing 94 changed files with 1,623 additions and 754 deletions.
14 changes: 7 additions & 7 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 2107
versionName "0.21.7"
versionCode 2181
versionName "0.21.81"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -191,7 +191,7 @@ dependencies {
implementation 'org.osmdroid:osmdroid-android:6.1.20'
implementation 'org.jetbrains:annotations:26.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0"
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.29'

implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar'
Expand All @@ -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.52"
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.4.1"
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 All @@ -230,7 +230,7 @@ dependencies {
implementation "io.noties.markwon:image:$markwon_version"
implementation "io.noties.markwon:html:$markwon_version"
implementation "io.noties.markwon:ext-tables:$markwon_version"
implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.0.21"))
implementation(platform("org.jetbrains.kotlin:kotlin-bom:2.1.0"))

implementation 'com.github.chrisbanes:PhotoView:2.3.0'
}
Expand Down
Binary file removed app/src/main/assets/images/november_challenge.jpeg
Binary file not shown.
43 changes: 32 additions & 11 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,17 +112,25 @@ 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)
}

suspend fun isServerReachable(urlString: String): Boolean {
return try {
val url = URL(urlString)
if (urlString.isBlank()) return false

val formattedUrl = if (!urlString.startsWith("http://") && !urlString.startsWith("https://")) {
"http://$urlString"
} else {
urlString
}

val url = URL(formattedUrl)
val connection = withContext(Dispatchers.IO) {
url.openConnection()
} as HttpURLConnection
Expand Down Expand Up @@ -210,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 @@ -266,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 @@ -278,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 @@ -312,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 @@ -29,8 +29,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
Expand Down Expand Up @@ -72,16 +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) else Utilities.toast(
activity, getString(R.string.no_images_to_download)
)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down Expand Up @@ -127,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 All @@ -152,65 +180,32 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
val filenameArray = items.resourceLocalAddress?.split("\\.".toRegex())?.toTypedArray()
val extension = filenameArray?.get(filenameArray.size - 1)
val mimetype = Utilities.getMimeType(items.resourceLocalAddress)
val userId = "${model?.id}"

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)
}
}
}

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)
}
"md" -> {
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()
Expand Down
Loading

0 comments on commit 0dd14d6

Please sign in to comment.