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 25, 2024
2 parents f8796ad + aa2d236 commit 9a56b02
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 114 deletions.
4 changes: 2 additions & 2 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 2099
versionName "0.20.99"
versionCode 2107
versionName "0.21.7"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
69 changes: 35 additions & 34 deletions app/src/main/java/org/ole/planet/myplanet/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.base.BaseResourceFragment.Companion.backgroundDownload
import org.ole.planet.myplanet.base.BaseResourceFragment.Companion.getAllLibraryList
import org.ole.planet.myplanet.callback.TeamPageListener
Expand Down Expand Up @@ -139,6 +140,40 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks {
false
}
}

fun handleUncaughtException(e: Throwable) {
e.printStackTrace()
applicationScope.launch(Dispatchers.IO) {
try {
val realm = Realm.getDefaultInstance()
try {
realm.executeTransaction { r ->
val log = r.createObject(RealmApkLog::class.java, "${UUID.randomUUID()}")
val model = UserProfileDbHandler(context).userModel
if (model != null) {
log.parentCode = model.parentCode
log.createdOn = model.planetCode
log.userId = model.id
}
log.time = "${Date().time}"
log.page = ""
log.version = getVersionName(context)
log.type = RealmApkLog.ERROR_TYPE_CRASH
log.setError(e)
}
} finally {
realm.close()
}
} catch (ex: Exception) {
ex.printStackTrace()
}
}

val homeIntent = Intent(Intent.ACTION_MAIN)
homeIntent.addCategory(Intent.CATEGORY_HOME)
homeIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(homeIntent)
}
}

private var activityReferences = 0
Expand Down Expand Up @@ -288,40 +323,6 @@ class MainApplication : Application(), Application.ActivityLifecycleCallbacks {

private fun onAppClosed() {}

private fun handleUncaughtException(e: Throwable) {
e.printStackTrace()
applicationScope.launch(Dispatchers.IO) {
try {
val realm = Realm.getDefaultInstance()
try {
realm.executeTransaction { r ->
val log = r.createObject(RealmApkLog::class.java, "${UUID.randomUUID()}")
val model = UserProfileDbHandler(this@MainApplication).userModel
if (model != null) {
log.parentCode = model.parentCode
log.createdOn = model.planetCode
log.userId = model.id
}
log.time = "${Date().time}"
log.page = ""
log.version = getVersionName(this@MainApplication)
log.type = RealmApkLog.ERROR_TYPE_CRASH
log.setError(e)
}
} finally {
realm.close()
}
} catch (ex: Exception) {
ex.printStackTrace()
}
}

val homeIntent = Intent(Intent.ACTION_MAIN)
homeIntent.addCategory(Intent.CATEGORY_HOME)
homeIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(homeIntent)
}

override fun onTerminate() {
super.onTerminate()
onAppClosed()
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmMyCourse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ open class RealmMyCourse : RealmObject() {
} else {
mutableListOf()
}

val linksToProcess: List<String>
synchronized(concatenatedLinks) {
for (link in concatenatedLinks) {
if (!existingConcatenatedLinks.contains(link)) {
existingConcatenatedLinks.add(link)
}
linksToProcess = concatenatedLinks.toList()
}
for (link in linksToProcess) {
if (!existingConcatenatedLinks.contains(link)) {
existingConcatenatedLinks.add(link)
}
}

val jsonConcatenatedLinks = gson.toJson(existingConcatenatedLinks)
settings.edit().putString("concatenated_links", jsonConcatenatedLinks).apply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.media.MediaRecorder
import android.os.Build
import android.os.Environment
import androidx.annotation.RequiresApi
import org.ole.planet.myplanet.MainApplication
import org.ole.planet.myplanet.MainApplication.Companion.context
import java.io.File
import java.util.UUID
Expand Down Expand Up @@ -73,11 +74,18 @@ class AudioRecorderService {
}

fun stopRecording() {
if (myAudioRecorder != null) {
myAudioRecorder?.stop()
myAudioRecorder?.release()
myAudioRecorder = null
audioRecordListener?.onRecordStopped(outputFile)
myAudioRecorder?.let { recorder ->
try {
if (isRecording()) {
recorder.stop()
recorder.release()
}
} catch (e: RuntimeException) {
MainApplication.handleUncaughtException(e)
} finally {
myAudioRecorder = null
audioRecordListener?.onRecordStopped(outputFile)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,23 @@ class AdapterCourses(private val context: Context, private var courseList: List<
}

holder.rowCourseBinding.title.text = course.courseTitle
holder.rowCourseBinding.description.text = course.description
val markdownContentWithLocalPaths = prependBaseUrlToImages(
course.description, "file://" + MainApplication.context.getExternalFilesDir(null) + "/ole/"
)
setMarkdownText(holder.rowCourseBinding.description, markdownContentWithLocalPaths)
holder.rowCourseBinding.description.apply {
text = course.description
val markdownContentWithLocalPaths = AdapterCourses.prependBaseUrlToImages(
course.description, "file://" + MainApplication.context.getExternalFilesDir(null) + "/ole/"
)
setMarkdownText(this, markdownContentWithLocalPaths)

setOnClickListener {
homeItemClickListener?.openCallFragment(TakeCourseFragment().apply {
arguments = Bundle().apply {
putString("id", course.courseId)
putInt("position", position)
}
})
}
}

if (course.gradeLevel.isNullOrEmpty() && course.subjectLevel.isNullOrEmpty()) {
holder.rowCourseBinding.holder.visibility = View.VISIBLE
holder.rowCourseBinding.tvDate2.visibility = View.VISIBLE
Expand Down Expand Up @@ -182,12 +194,18 @@ class AdapterCourses(private val context: Context, private var courseList: List<
holder.rowCourseBinding.checkbox.setOnClickListener { view: View ->
holder.rowCourseBinding.checkbox.contentDescription = context.getString(R.string.select_res_course, course.courseTitle)
Utilities.handleCheck((view as CheckBox).isChecked, position, selectedItems, courseList)
if (listener != null) listener!!.onSelectedListChange(selectedItems)
listener?.onSelectedListChange(selectedItems)
}
} else {
holder.rowCourseBinding.checkbox.visibility = View.GONE
}
showProgressAndRating(position, holder)

holder.rowCourseBinding.root.setOnClickListener {
if (position != RecyclerView.NO_POSITION) {
openCourse(courseList[position], 0)
}
}
}
}
}
Expand Down Expand Up @@ -350,4 +368,4 @@ class AdapterCourses(private val context: Context, private var courseList: List<
return result.toString()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl

currentStep = getCourseProgress()

position = when {
position > 0 -> position - 1
currentStep > 0 -> currentStep - 1
else -> 0
}

position = if (currentStep > 0) currentStep - 1 else 0
fragmentTakeCourseBinding.viewPager2.currentItem = position
updateStepDisplay(position)

Expand All @@ -93,6 +88,9 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
setListeners()
fragmentTakeCourseBinding.viewPager2.currentItem = position
checkSurveyCompletion()
fragmentTakeCourseBinding.backButton.setOnClickListener {
requireActivity().supportFragmentManager.popBackStack()
}
}

private fun setListeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
false
}

val allCommVoiceResults = mRealm.where(RealmNews::class.java)
.greaterThanOrEqualTo("time", startTime)
.findAll()

val allCommVoice = allCommVoiceResults.filter { realmNews ->
realmNews.viewIn?.let { viewInStr ->
try {
val viewInArray = JSONArray(viewInStr)
for (i in 0 until viewInArray.length()) {
val viewInObj = viewInArray.getJSONObject(i)
if (viewInObj.optString("section") == "community") {
return@filter true
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
false
}

fun getDateFromTimestamp(timestamp: Long): String {
val dateFormat = SimpleDateFormat("yyyy-MM-dd")
return dateFormat.format(Date(timestamp))
Expand All @@ -282,6 +303,10 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
.map { getDateFromTimestamp(it.time) }
.distinct()

val allUniqueDates = allCommVoice
.map { getDateFromTimestamp(it.time) }
.distinct()

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

val courseId = "9517e3b45a5bb63e69bb8f269216974d"
Expand Down Expand Up @@ -314,16 +339,16 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
} else {
"Ingresa al curso $courseName completalo ($current de $max hecho)"
}
challengeDialog(uniqueDates.size, courseStatus)
challengeDialog(uniqueDates.size, courseStatus, allUniqueDates.size)
} else {
challengeDialog(uniqueDates.size, "$courseName no iniciado")
challengeDialog(uniqueDates.size, "$courseName no iniciado", allUniqueDates.size)
}
}
}
}
}

fun challengeDialog(voiceCount: Int, courseStatus: String) {
fun challengeDialog(voiceCount: Int, courseStatus: String, allVoiceCount: Int) {
val voiceTaskDone = if (voiceCount >= 5) "" else "[ ]"
val prereqsMet = courseStatus.contains("terminado", ignoreCase = true) && voiceCount >= 5
val syncTaskDone = if (prereqsMet) {
Expand All @@ -345,10 +370,10 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
if (isCompleted && !hasShownCongrats) {
editor.putBoolean("has_shown_congrats", true).apply()
val markdownContent = """
![issues challenge](file:///android_asset/images/november_challenge.jpeg) <br/>
### ¡Felicidades Reto Completado!
Ganancias totales: **$${calculateProgress(allVoiceCount)}**
### ¡Felicidades! Reto Completado <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount)
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount)
.show(supportFragmentManager, "markdown_dialog")
} else {
val voicesText = if (voiceCount > 0) {
Expand All @@ -357,16 +382,20 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
""
}
val markdownContent = """
![issues challenge](file:///android_asset/images/november_challenge.jpeg) <br/>
Ganancias totales: **$${calculateProgress(allVoiceCount)}**
### $courseTaskDone <br/>
### $voiceTaskDone Comparte tu opinión en Nuestras Voces. $voicesText <br/>
### $syncTaskDone Recuerda sincronizar la aplicacion movil.
### $syncTaskDone Recuerda sincronizar la aplicación móvil. <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount)
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount)
.show(supportFragmentManager, "markdown_dialog")
}
}

private fun calculateProgress(allVoiceCount: Int): Int {
return (allVoiceCount) * 5
}

private fun setupRealmListeners() {
setupListener {
mRealm.where(RealmMyLibrary::class.java).findAllAsync()
Expand Down
Loading

0 comments on commit 9a56b02

Please sign in to comment.