Skip to content

Commit

Permalink
Merge branch 'master' into sync-investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Nov 20, 2024
2 parents 9584c30 + b3c2953 commit f8796ad
Show file tree
Hide file tree
Showing 92 changed files with 1,170 additions and 772 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ proguard
# Log files
*.log

# Raw folder
assets

# Android Studio Navigation editor temp folder
.navigation

Expand Down
32 changes: 16 additions & 16 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 2075
versionName "0.20.75"
versionCode 2099
versionName "0.20.99"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -85,8 +85,8 @@ android {
def planetViPin = project.findProperty('PLANET_VI_PIN') ?: ""
def planetXelaUrl = project.findProperty('PLANET_XELA_URL') ?: ""
def planetXelaPin = project.findProperty('PLANET_XELA_PIN') ?: ""
//def planetUriurUrl = project.findProperty('PLANET_URIUR_URL') ?: ""
//def planetUriurPin = project.findProperty('PLANET_URIUR_PIN') ?: ""
def planetUriurUrl = project.findProperty('PLANET_URIUR_URL') ?: ""
def planetUriurPin = project.findProperty('PLANET_URIUR_PIN') ?: ""
def planetRuiruUrl = project.findProperty('PLANET_RUIRU_URL') ?: ""
def planetRuiruPin = project.findProperty('PLANET_RUIRU_PIN') ?: ""
def planetEmbakasiUrl = project.findProperty('PLANET_EMBAKASI_URL') ?: ""
Expand Down Expand Up @@ -114,18 +114,18 @@ android {
it.buildConfigField 'String', 'PLANET_VI_PIN', "\"${planetViPin}\""
it.buildConfigField 'String', 'PLANET_XELA_URL', "\"${planetXelaUrl}\""
it.buildConfigField 'String', 'PLANET_XELA_PIN', "\"${planetXelaPin}\""
//it.buildConfigField('String', 'PLANET_URIUR_URL', "\"${planetUriurUrl}\"")
//it.buildConfigField('String', 'PLANET_URIUR_PIN', "\"${planetUriurPin}\"")
it.buildConfigField('String', 'PLANET_RUIRU_URL', "\"${planetRuiruUrl}\"")
it.buildConfigField('String', 'PLANET_RUIRU_PIN', "\"${planetRuiruPin}\"")
it.buildConfigField('String', 'PLANET_EMBAKASI_URL', "\"${planetEmbakasiUrl}\"")
it.buildConfigField('String', 'PLANET_EMBAKASI_PIN', "\"${planetEmbakasiPin}\"")
it.buildConfigField('String', 'PLANET_CAMBRIDGE_URL', "\"${planetCambridgeUrl}\"")
it.buildConfigField('String', 'PLANET_CAMBRIDGE_PIN', "\"${planetCambridgePin}\"")
//it.buildConfigField('String', 'PLANET_EGDIRBMAC_URL', "\"${planetEgdirbmacUrl}\"")
//it.buildConfigField('String', 'PLANET_EGDIRBMAC_PIN', "\"${planetEgdirbmacPin}\"")
it.buildConfigField('String', 'PLANET_PALMBAY_URL', "\"${planetPalmBayUrl}\"")
it.buildConfigField('String', 'PLANET_PALMBAY_PIN', "\"${planetPalmBayPin}\"")
it.buildConfigField 'String', 'PLANET_URIUR_URL', "\"${planetUriurUrl}\""
it.buildConfigField 'String', 'PLANET_URIUR_PIN', "\"${planetUriurPin}\""
it.buildConfigField 'String', 'PLANET_RUIRU_URL', "\"${planetRuiruUrl}\""
it.buildConfigField 'String', 'PLANET_RUIRU_PIN', "\"${planetRuiruPin}\""
it.buildConfigField 'String', 'PLANET_EMBAKASI_URL', "\"${planetEmbakasiUrl}\""
it.buildConfigField 'String', 'PLANET_EMBAKASI_PIN', "\"${planetEmbakasiPin}\""
it.buildConfigField 'String', 'PLANET_CAMBRIDGE_URL', "\"${planetCambridgeUrl}\""
it.buildConfigField 'String', 'PLANET_CAMBRIDGE_PIN', "\"${planetCambridgePin}\""
//it.buildConfigField 'String', 'PLANET_EGDIRBMAC_URL', "\"${planetEgdirbmacUrl}\""
//it.buildConfigField 'String', 'PLANET_EGDIRBMAC_PIN', "\"${planetEgdirbmacPin}\""
it.buildConfigField 'String', 'PLANET_PALMBAY_URL', "\"${planetPalmBayUrl}\""
it.buildConfigField 'String', 'PLANET_PALMBAY_PIN', "\"${planetPalmBayPin}\""
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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 @@ -150,28 +152,68 @@ 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" -> openIntent(items, TextFileViewerActivity::class.java)
"md" -> openIntent(items, MarkdownViewerActivity::class.java)
"csv" -> openIntent(items, CSVViewerActivity::class.java)
"apk" -> installApk(items)
else -> Toast.makeText(
activity, getString(R.string.this_file_type_is_currently_unsupported), Toast.LENGTH_LONG
).show()
"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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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 @@ -150,28 +152,68 @@ 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" -> openIntent(items, TextFileViewerActivity::class.java)
"md" -> openIntent(items, MarkdownViewerActivity::class.java)
"csv" -> openIntent(items, CSVViewerActivity::class.java)
// "apk" -> installApk(items)
else -> Toast.makeText(
activity, getString(R.string.this_file_type_is_currently_unsupported), Toast.LENGTH_LONG
).show()
"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
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,36 @@ abstract class BaseRecyclerParentFragment<LI> : BaseResourceFragment() {
RealmMyLibrary.getOurLibrary(model?.id, mRealm.where(c).equalTo("isPrivate", false).findAll().toList()) as List<LI>
}
else -> {
val results: List<RealmMyCourse> = mRealm.where(RealmMyCourse::class.java).isNotEmpty("courseTitle").findAll().toList()
val filteredResults = RealmMyCourse.getOurCourse(model?.id, results)
filteredResults as List<LI>
val myLibItems = getMyLibItems(c as Class<out RealmModel>)
val results: List<RealmMyCourse> = mRealm.where(RealmMyCourse::class.java)
.isNotEmpty("courseTitle")
.findAll()
.toList()
val ourCourseItems = RealmMyCourse.getOurCourse(model?.id, results)

when (c) {
RealmMyCourse::class.java -> {
val combinedList = mutableListOf<RealmMyCourse>()
(myLibItems as List<RealmMyCourse>).forEach { course ->
course.isMyCourse = true
combinedList.add(course)
}
ourCourseItems.forEach { course ->
if (!combinedList.any { it.id == course.id }) {
course.isMyCourse = false
combinedList.add(course)
}
}
combinedList as List<LI>
}
else -> {
throw IllegalArgumentException("Unsupported class: ${c.simpleName}")
}
}
}
}
}

fun getList(c: Class<*>, orderBy: String): List<LI> = getList(c, orderBy, Sort.ASCENDING)

@Suppress("UNCHECKED_CAST")
fun getList(c: Class<*>, orderBy: String? = null, sort: Sort = Sort.ASCENDING): List<LI> {
return when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ abstract class PermissionActivity : AppCompatActivity() {
return result == PackageManager.PERMISSION_GRANTED
}

@RequiresApi(Build.VERSION_CODES.M)
fun checkUsagesPermission() {
if (!getUsagesPermission(this)) {
Utilities.toast(this, getString(R.string.please_allow_usages_permission_to_myplanet_app))
Expand All @@ -36,9 +35,8 @@ abstract class PermissionActivity : AppCompatActivity() {
}
}

@RequiresApi(Build.VERSION_CODES.M)
fun getUsagesPermission(context: Context): Boolean {
val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
val appOps = context.getSystemService(APP_OPS_SERVICE) as AppOpsManager
var mode = -1
try {
val method = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Expand Down Expand Up @@ -106,9 +104,7 @@ abstract class PermissionActivity : AppCompatActivity() {
const val PERMISSION_REQUEST_CODE_FILE = 111
@JvmStatic
fun hasInstallPermission(context: Context): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.packageManager.canRequestPackageInstalls()
} else true
return context.packageManager.canRequestPackageInstalls()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ abstract class PermissionActivity : AppCompatActivity() {
return result == PackageManager.PERMISSION_GRANTED
}

@RequiresApi(Build.VERSION_CODES.M)
fun checkUsagesPermission() {
if (!getUsagesPermission(this)) {
Utilities.toast(this, getString(R.string.please_allow_usages_permission_to_myplanet_app))
Expand All @@ -36,9 +35,8 @@ abstract class PermissionActivity : AppCompatActivity() {
}
}

@RequiresApi(Build.VERSION_CODES.M)
fun getUsagesPermission(context: Context): Boolean {
val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
val appOps = context.getSystemService(APP_OPS_SERVICE) as AppOpsManager
var mode = -1
try {
val method = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Expand Down Expand Up @@ -106,9 +104,7 @@ abstract class PermissionActivity : AppCompatActivity() {
const val PERMISSION_REQUEST_CODE_FILE = 111
// @JvmStatic
// fun hasInstallPermission(context: Context): Boolean {
// return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// context.packageManager.canRequestPackageInstalls()
// } else true
// return context.packageManager.canRequestPackageInstalls()
// }
}
}
Loading

0 comments on commit f8796ad

Please sign in to comment.