Skip to content

Commit

Permalink
cleanup challenge logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 committed Dec 11, 2024
1 parent 69bc403 commit e55def6
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 96 deletions.
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 @@ -152,65 +150,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,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 @@ -29,8 +29,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 @@ -152,65 +150,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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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 @@ -342,8 +341,6 @@ 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
21 changes: 0 additions & 21 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.graphics.drawable.AnimationDrawable
import android.os.Build
import android.os.Bundle
import android.text.*
import android.util.Log
import android.view.*
import android.webkit.URLUtil
import android.widget.*
Expand Down Expand Up @@ -38,7 +37,6 @@ import org.ole.planet.myplanet.datamanager.*
import org.ole.planet.myplanet.datamanager.ApiClient.client
import org.ole.planet.myplanet.datamanager.Service.*
import org.ole.planet.myplanet.model.*
import org.ole.planet.myplanet.model.RealmUserChallengeActions.Companion.createAction
import org.ole.planet.myplanet.service.*
import org.ole.planet.myplanet.ui.dashboard.DashboardActivity
import org.ole.planet.myplanet.ui.team.AdapterTeam.OnUserSelectedListener
Expand Down Expand Up @@ -413,25 +411,6 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers

fun onLogin() {
val handler = UserProfileDbHandler(this)

val userId = handler.userModel?.id
if (userId != null && userId.startsWith("guest") == false) {
Log.d("okuro", "called")
val latestAction = mRealm.where(RealmUserChallengeActions::class.java)
.equalTo("userId", userId).sort("time", Sort.DESCENDING).findFirst()

val currentTime = System.currentTimeMillis()
val thresholdTime = 24 * 60 * 60 * 1000

if (latestAction == null) {
createAction(mRealm, userId, null, "login")
} else {
if (currentTime - latestAction.time >= thresholdTime) {
createAction(mRealm, userId, null, "login")
}
}
}

handler.onLogin()
handler.onDestroy()
editor.putBoolean(Constants.KEY_LOGIN, true).commit()
Expand Down

0 comments on commit e55def6

Please sign in to comment.