Skip to content

Commit

Permalink
all: san pablo november challenge (fixes #4752) (#4684)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
Okuro3499 and dogi committed Nov 6, 2024
1 parent 68ffc54 commit c01f5fa
Show file tree
Hide file tree
Showing 29 changed files with 864 additions and 192 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 2085
versionName "0.20.85"
versionCode 2086
versionName "0.20.86"
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
@@ -0,0 +1,29 @@
package org.ole.planet.myplanet.model

import io.realm.Realm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import java.util.UUID

open class RealmUserChallengeActions : RealmObject() {
@PrimaryKey
var id: String = UUID.randomUUID().toString()
var userId: String? = null
var actionType: String? = null
var resourceId: String? = null
var time: Long = 0

companion object {
fun createAction(realm: Realm, userId: String, resourceId: String?, actionType: String) {
realm.executeTransaction { transactionRealm ->
val action = transactionRealm.createObject(
RealmUserChallengeActions::class.java, UUID.randomUUID().toString()
)
action.userId = userId
action.actionType = actionType
action.resourceId = resourceId
action.time = System.currentTimeMillis()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ class UserProfileDbHandler(context: Context) {
}
}

val userModel: RealmUserModel?
get() {
if (mRealm.isClosed) {
mRealm = realmService.realmInstance
}
return mRealm.where(RealmUserModel::class.java)
.equalTo("id", settings.getString("userId", ""))
.findFirst()
val userModel: RealmUserModel? get() {
if (mRealm.isClosed) {
mRealm = realmService.realmInstance
}
return mRealm.where(RealmUserModel::class.java)
.equalTo("id", settings.getString("userId", ""))
.findFirst()
}

fun onLogin() {
if (!mRealm.isInTransaction) {
Expand Down Expand Up @@ -89,10 +88,8 @@ class UserProfileDbHandler(context: Context) {
return offlineActivities
}

val lastVisit: Long?
get() = mRealm.where(RealmOfflineActivity::class.java).max("loginTime") as Long?
val offlineVisits: Int
get() = getOfflineVisits(userModel)
val lastVisit: Long? get() = mRealm.where(RealmOfflineActivity::class.java).max("loginTime") as Long?
val offlineVisits: Int get() = getOfflineVisits(userModel)

fun getOfflineVisits(m: RealmUserModel?): Int { val dbUsers = mRealm.where(RealmOfflineActivity::class.java).equalTo("userName", m?.name).equalTo("type", KEY_LOGIN).findAll()
return if (!dbUsers.isEmpty()) {
Expand Down Expand Up @@ -126,6 +123,7 @@ class UserProfileDbHandler(context: Context) {
if (model?.id?.startsWith("guest") == true) {
return
}

if (!mRealm.isInTransaction) mRealm.beginTransaction()
val offlineActivities = mRealm.copyToRealm(createResourceUser(model))
offlineActivities.type = type
Expand All @@ -143,33 +141,31 @@ class UserProfileDbHandler(context: Context) {
return offlineActivities
}

val numberOfResourceOpen: String
get() {
val count = mRealm.where(RealmResourceActivity::class.java).equalTo("user", fullName)
.equalTo("type", KEY_RESOURCE_OPEN).count()
return if (count == 0L) "" else "Resource opened $count times."
}
val numberOfResourceOpen: String get() {
val count = mRealm.where(RealmResourceActivity::class.java).equalTo("user", fullName)
.equalTo("type", KEY_RESOURCE_OPEN).count()
return if (count == 0L) "" else "Resource opened $count times."
}

val maxOpenedResource: String
get() {
val result = mRealm.where(RealmResourceActivity::class.java)
.equalTo("user", fullName).equalTo("type", KEY_RESOURCE_OPEN)
.findAll().where().distinct("resourceId").findAll()
var maxCount = 0L
var maxOpenedResource = ""
for (realmResourceActivities in result) {
val count = mRealm.where(RealmResourceActivity::class.java)
.equalTo("user", fullName)
.equalTo("type", KEY_RESOURCE_OPEN)
.equalTo("resourceId", realmResourceActivities.resourceId).count()

if (count > maxCount) {
maxCount = count
maxOpenedResource = "${realmResourceActivities.title}"
}
val maxOpenedResource: String get() {
val result = mRealm.where(RealmResourceActivity::class.java)
.equalTo("user", fullName).equalTo("type", KEY_RESOURCE_OPEN)
.findAll().where().distinct("resourceId").findAll()
var maxCount = 0L
var maxOpenedResource = ""
for (realmResourceActivities in result) {
val count = mRealm.where(RealmResourceActivity::class.java)
.equalTo("user", fullName)
.equalTo("type", KEY_RESOURCE_OPEN)
.equalTo("resourceId", realmResourceActivities.resourceId).count()

if (count > maxCount) {
maxCount = count
maxOpenedResource = "${realmResourceActivities.title}"
}
return if (maxCount == 0L) "" else "$maxOpenedResource opened $maxCount times"
}
return if (maxCount == 0L) "" else "$maxOpenedResource opened $maxCount times"
}

companion object {
const val KEY_LOGIN = "login"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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
Expand Down Expand Up @@ -341,6 +342,8 @@ 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"){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.ole.planet.myplanet.model.RealmChatHistory
import org.ole.planet.myplanet.model.RealmMyTeam
import org.ole.planet.myplanet.model.RealmNews
import org.ole.planet.myplanet.model.RealmNews.Companion.createNews
import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.news.ExpandableListAdapter
Expand Down Expand Up @@ -213,7 +214,10 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List
map["chat"] = "true"
map["news"] = Gson().toJson(serializedMap)

createNews(map, mRealm, user, null)
val n = user?.let { it1 -> createNews(map, mRealm, it1, null) }
if (section== "community") {
createAction(mRealm, "${n?.userId}", n?.id, "voice")
}
fragment.refreshChatHistoryList()
dialog.dismiss()
}
Expand Down
Loading

0 comments on commit c01f5fa

Please sign in to comment.