Skip to content

Commit

Permalink
Merge branch 'master' into htmlGames
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Dec 19, 2024
2 parents d558e4f + 626dd23 commit 44a89c6
Show file tree
Hide file tree
Showing 37 changed files with 279 additions and 218 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 2127
versionName "0.21.27"
versionCode 2143
versionName "0.21.43"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -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"

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 @@ -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
Expand Down Expand Up @@ -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?) {
Expand Down Expand Up @@ -159,81 +155,38 @@ 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)
}
}
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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?) {
Expand Down Expand Up @@ -154,81 +150,38 @@ 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)
}
}
}

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()
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 @@ -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<String>()
ActivityCompat.requestPermissions(this, permissionsArray, PERMISSION_REQUEST_CODE_FILE)
} else {
Toast.makeText(this, R.string.permissions_granted, Toast.LENGTH_SHORT).show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()
ActivityCompat.requestPermissions(this, permissionsArray, PERMISSION_REQUEST_CODE_FILE)
} else {
Toast.makeText(this, R.string.permissions_granted, Toast.LENGTH_SHORT).show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,13 @@ class Service(private val context: Context) {
}) { error: Throwable ->
realm.close()
error.printStackTrace()
callback.onSuccess("Unable to connect to planet earth")
}
}
}
}

override fun onFailure(call: Call<JsonObject?>, t: Throwable) {
realm.close()
callback.onSuccess("Unable to connect to planet earth")
}
})
}
Expand Down
Loading

0 comments on commit 44a89c6

Please sign in to comment.