Skip to content

Commit

Permalink
Merge branch 'master' into multipleUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 authored Dec 4, 2024
2 parents b47845c + 6e539a4 commit 59e3114
Show file tree
Hide file tree
Showing 26 changed files with 348 additions and 172 deletions.
10 changes: 5 additions & 5 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 2124
versionName "0.21.24"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -208,7 +208,7 @@ dependencies {
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.53"
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.0"
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.
4 changes: 2 additions & 2 deletions app/src/main/java/org/ole/planet/myplanet/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks {

suspend fun isServerReachable(urlString: String?): Boolean {
return try {
if (urlString.isNullOrBlank()) return false

if (urlString.isBlank()) return false
val formattedUrl = if (!urlString.startsWith("http://") && !urlString.startsWith("https://")) {
"http://$urlString"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class AdapterCourses(private val context: Context, private var courseList: List<
holder.rowCourseBinding.title.text = course.courseTitle
holder.rowCourseBinding.description.apply {
text = course.description
val markdownContentWithLocalPaths = AdapterCourses.prependBaseUrlToImages(
course.description, "file://" + MainApplication.context.getExternalFilesDir(null) + "/ole/"
val markdownContentWithLocalPaths = prependBaseUrlToImages(
course.description, "file://${MainApplication.context.getExternalFilesDir(null)}/ole/"
)
setMarkdownText(this, markdownContentWithLocalPaths)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.ole.planet.myplanet.model.RealmExamQuestion
import org.ole.planet.myplanet.model.RealmMyCourse
import org.ole.planet.myplanet.model.RealmStepExam
import org.ole.planet.myplanet.model.RealmSubmission
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler

class MyProgressFragment : Fragment() {
Expand Down Expand Up @@ -111,5 +112,26 @@ class MyProgressFragment : Fragment() {
}
return null
}

fun countUsersWhoCompletedCourse(realm: Realm, courseId: String): Int {
var completedCount = 0
val allUsers = realm.where(RealmUserModel::class.java).findAll()

allUsers.forEach { user ->
val userId = user.id
val courses = RealmMyCourse.getMyCourseByUserId(userId, realm.where(RealmMyCourse::class.java).findAll())

val course = courses.find { it.courseId == courseId }
if (course != null) {
val steps = RealmMyCourse.getCourseSteps(realm, courseId)
val currentProgress = RealmCourseProgress.getCurrentProgress(steps, realm, userId, courseId)

if (currentProgress == steps.size) {
completedCount++
}
}
}
return completedCount
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.utilities.DialogUtils.getAlertDialog
import org.ole.planet.myplanet.utilities.Utilities
import java.util.Locale
import kotlin.collections.isNotEmpty

class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnClickListener {
private lateinit var fragmentTakeCourseBinding: FragmentTakeCourseBinding
lateinit var dbService: DatabaseService
lateinit var mRealm: Realm
var courseId: String? = null
private var currentCourse: RealmMyCourse? = null
lateinit var steps: List<RealmCourseStep?>
var userModel: RealmUserModel? = null
var position = 0
private var currentStep = 0

Expand Down Expand Up @@ -250,12 +249,10 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
.equalTo("stepId", step?.id)
.equalTo("type", "surveys")
.findAll()
stepSurvey.any { survey ->
!existsSubmission(survey.id, "survey")
}
stepSurvey.any { survey -> !existsSubmission(mRealm, survey.id, "survey") }
}

if (hasUnfinishedSurvey && courseId == "9517e3b45a5bb63e69bb8f269216974d") {
if (hasUnfinishedSurvey && courseId == "4e6b78800b6ad18b4e8b0e1e38a98cac") {
fragmentTakeCourseBinding.finishStep.setOnClickListener {
Toast.makeText(context, getString(R.string.please_complete_survey), Toast.LENGTH_SHORT).show() }
} else {
Expand All @@ -267,38 +264,39 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
}
}

private fun existsSubmission(firstStepId: String?, submissionType: String): Boolean {
val questions = mRealm.where(RealmExamQuestion::class.java)
.equalTo("examId", firstStepId)
.findAll()

var isPresent = false
if (questions != null && questions.isNotEmpty()) {
val examId = questions[0]?.examId
val isSubmitted = courseId?.let { courseId ->
val parentId = "$examId@$courseId"
mRealm.where(RealmSubmission::class.java)
.equalTo("userId", userModel?.id)
.equalTo("parentId", parentId)
.equalTo("type", submissionType)
.findFirst() != null
} == true
isPresent = isSubmitted
}
return isPresent
}

private val isValidClickRight: Boolean
get() = fragmentTakeCourseBinding.viewPager2.adapter != null && fragmentTakeCourseBinding.viewPager2.currentItem < fragmentTakeCourseBinding.viewPager2.adapter?.itemCount!!
private val isValidClickLeft: Boolean
get() = fragmentTakeCourseBinding.viewPager2.adapter != null && fragmentTakeCourseBinding.viewPager2.currentItem > 0
private val isValidClickRight: Boolean get() = fragmentTakeCourseBinding.viewPager2.adapter != null && fragmentTakeCourseBinding.viewPager2.currentItem < fragmentTakeCourseBinding.viewPager2.adapter?.itemCount!!
private val isValidClickLeft: Boolean get() = fragmentTakeCourseBinding.viewPager2.adapter != null && fragmentTakeCourseBinding.viewPager2.currentItem > 0

companion object {
var courseId: String? = null
var userModel: RealmUserModel? = null

@JvmStatic
fun newInstance(b: Bundle?): TakeCourseFragment {
val takeCourseFragment = TakeCourseFragment()
takeCourseFragment.arguments = b
return takeCourseFragment
}

fun existsSubmission(mRealm: Realm, firstStepId: String?, submissionType: String): Boolean {
val questions = mRealm.where(RealmExamQuestion::class.java)
.equalTo("examId", firstStepId)
.findAll()

var isPresent = false
if (questions != null && questions.isNotEmpty()) {
val examId = questions[0]?.examId
val isSubmitted = courseId?.let { courseId ->
val parentId = "$examId@$courseId"
mRealm.where(RealmSubmission::class.java)
.equalTo("userId", userModel?.id)
.equalTo("parentId", parentId)
.equalTo("type", submissionType)
.findFirst() != null
} == true
isPresent = isSubmitted
}
return isPresent
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import io.realm.RealmResults
import kotlinx.coroutines.launch
import org.json.JSONArray
import org.ole.planet.myplanet.BuildConfig
import org.ole.planet.myplanet.MainApplication.Companion.context
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.base.BaseContainerFragment
import org.ole.planet.myplanet.base.BaseResourceFragment.Companion.getLibraryList
import org.ole.planet.myplanet.base.BaseResourceFragment
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.databinding.ActivityDashboardBinding
import org.ole.planet.myplanet.databinding.CustomTabBinding
Expand All @@ -62,10 +62,10 @@ import org.ole.planet.myplanet.ui.SettingActivity
import org.ole.planet.myplanet.ui.chat.ChatHistoryListFragment
import org.ole.planet.myplanet.ui.community.CommunityTabFragment
import org.ole.planet.myplanet.ui.courses.CoursesFragment
import org.ole.planet.myplanet.ui.courses.MyProgressFragment.Companion.fetchCourseData
import org.ole.planet.myplanet.ui.courses.MyProgressFragment.Companion.getCourseProgress
import org.ole.planet.myplanet.ui.dashboard.notification.NotificationsFragment
import org.ole.planet.myplanet.ui.courses.MyProgressFragment
import org.ole.planet.myplanet.ui.courses.TakeCourseFragment
import org.ole.planet.myplanet.ui.dashboard.notification.NotificationListener
import org.ole.planet.myplanet.ui.dashboard.notification.NotificationsFragment
import org.ole.planet.myplanet.ui.feedback.FeedbackListFragment
import org.ole.planet.myplanet.ui.resources.ResourceDetailFragment
import org.ole.planet.myplanet.ui.resources.ResourcesFragment
Expand Down Expand Up @@ -231,7 +231,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
} else {
if (!doubleBackToExitPressedOnce) {
doubleBackToExitPressedOnce = true
toast(context, getString(R.string.press_back_again_to_exit))
toast(MainApplication.context, getString(R.string.press_back_again_to_exit))
Handler(Looper.getMainLooper()).postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
} else {
val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container)
Expand All @@ -245,12 +245,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
}
})

val voiceCount = mRealm.where(RealmUserChallengeActions::class.java)
.equalTo("userId", user?.id)
.equalTo("actionType", "voice")
.findAll().count()

val startTime = 1730408400
val startTime = 1733011200000
val commVoiceResults = mRealm.where(RealmNews::class.java)
.equalTo("userId", user?.id)
.greaterThanOrEqualTo("time", startTime)
Expand Down Expand Up @@ -307,10 +302,16 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
.map { getDateFromTimestamp(it.time) }
.distinct()

val courseData = fetchCourseData(mRealm, user?.id)
val courseData = MyProgressFragment.fetchCourseData(mRealm, user?.id)

val courseId = "4e6b78800b6ad18b4e8b0e1e38a98cac"
val progress = MyProgressFragment.getCourseProgress(courseData, courseId)

val courseId = "9517e3b45a5bb63e69bb8f269216974d"
val progress = getCourseProgress(courseData, courseId)
val hasUnfinishedSurvey = mRealm.where(RealmStepExam::class.java)
.equalTo("courseId", courseId)
.equalTo("type", "surveys")
.findAll()
.any { survey -> !TakeCourseFragment.existsSubmission(mRealm, survey.id, "survey") }

val validUrls = listOf(
"https://${BuildConfig.PLANET_GUATEMALA_URL}",
Expand All @@ -323,7 +324,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N

val today = LocalDate.now()
if (user?.id?.startsWith("guest") == false) {
val endDate = LocalDate.of(today.year, 12, 1)
val endDate = LocalDate.of(today.year, 12, 31)
if (today.isBefore(endDate)) {
if (settings.getString("serverURL", "") in validUrls) {
val course = mRealm.where(RealmMyCourse::class.java)
Expand All @@ -339,20 +340,21 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
} else {
"Ingresa al curso $courseName completalo ($current de $max hecho)"
}
challengeDialog(uniqueDates.size, courseStatus, allUniqueDates.size)
challengeDialog(uniqueDates.size, courseStatus, allUniqueDates.size, hasUnfinishedSurvey)
} else {
challengeDialog(uniqueDates.size, "$courseName no iniciado", allUniqueDates.size)
challengeDialog(uniqueDates.size, "$courseName no iniciado", allUniqueDates.size, hasUnfinishedSurvey)
}
}
}
}
}

fun challengeDialog(voiceCount: Int, courseStatus: String, allVoiceCount: Int) {
fun challengeDialog (voiceCount: Int, courseStatus: String, allVoiceCount: Int, hasUnfinishedSurvey: Boolean) {
val voiceTaskDone = if (voiceCount >= 5) "" else "[ ]"
val prereqsMet = courseStatus.contains("terminado", ignoreCase = true) && voiceCount >= 5
var hasValidSync = false
val syncTaskDone = if (prereqsMet) {
val hasValidSync = mRealm.where(RealmUserChallengeActions::class.java)
hasValidSync = mRealm.where(RealmUserChallengeActions::class.java)
.equalTo("userId", user?.id)
.equalTo("actionType", "sync")
.count() > 0
Expand All @@ -370,30 +372,44 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
if (isCompleted && !hasShownCongrats) {
editor.putBoolean("has_shown_congrats", true).apply()
val markdownContent = """
Ganancias totales: **$${calculateProgress(allVoiceCount)}**
Ingresos totales de la comunidad: **$${calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey)}** /$500
Tus ganancias totales: **$${calculateIndividualProgress(voiceCount, hasUnfinishedSurvey)}** /$11
### ¡Felicidades! Reto Completado <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount)
.show(supportFragmentManager, "markdown_dialog")
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount, hasUnfinishedSurvey).show(supportFragmentManager, "markdown_dialog")
} else {
val voicesText = if (voiceCount > 0) {
"$voiceCount de 5 Voces diarias"
val cappedVoiceCount = minOf(voiceCount, 5)
val voicesText = if (cappedVoiceCount > 0) {
"$cappedVoiceCount de 5 Voces diarias"
} else {
""
}
val markdownContent = """
Ganancias totales: **$${calculateProgress(allVoiceCount)}**
### $courseTaskDone <br/>
### $voiceTaskDone Comparte tu opinión en Nuestras Voces. $voicesText <br/>
Ingresos totales de la comunidad: **$${calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey)}** /$500
Tus ganancias totales: **$${calculateIndividualProgress(voiceCount, hasUnfinishedSurvey)}** /$11
### $courseTaskDone $1 por encuesta <br/>
### $voiceTaskDone Comparte tu opinión en Nuestras Voces.[$2/voz] $voicesText <br/>
### $syncTaskDone Recuerda sincronizar la aplicación móvil. <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount)
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount, hasUnfinishedSurvey)
.show(supportFragmentManager, "markdown_dialog")
}
}

private fun calculateProgress(allVoiceCount: Int): Int {
return (allVoiceCount) * 5
private fun calculateIndividualProgress(voiceCount: Int, hasUnfinishedSurvey: Boolean): Int {
val earnedDollarsVoice = minOf(voiceCount, 5) * 2
val earnedDollarsSurvey = if (!hasUnfinishedSurvey) 1 else 0
val total = earnedDollarsVoice + earnedDollarsSurvey
return total.coerceAtMost(500)
}

private fun calculateCommunityProgress (allVoiceCount: Int, hasUnfinishedSurvey: Boolean): Int {
val earnedDollarsVoice = minOf(allVoiceCount, 5) * 2
val earnedDollarsSurvey = if (!hasUnfinishedSurvey) 1 else 0
val total = earnedDollarsVoice + earnedDollarsSurvey
return total.coerceAtMost(11)
}

private fun setupRealmListeners() {
Expand Down Expand Up @@ -475,7 +491,7 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
}

private fun updateResourceNotification() {
val resourceCount = getLibraryList(mRealm, user?.id).size
val resourceCount = BaseResourceFragment.getLibraryList(mRealm, user?.id).size
if (resourceCount > 0) {
val existingNotification = mRealm.where(RealmNotification::class.java)
.equalTo("userId", user?.id)
Expand Down
Loading

0 comments on commit 59e3114

Please sign in to comment.