Skip to content

Commit

Permalink
Merge branch 'master' into 4920-alert-input
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Jan 3, 2025
2 parents 6dddfbe + a4cd17d commit d8eba42
Show file tree
Hide file tree
Showing 24 changed files with 426 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
AdapterCourses.showRating(`object`, rating, timesRated, ratingBar)
}
}
fun getUrlsAndStartDownload(
lib: List<RealmMyLibrary?>, urls: ArrayList<String>
) {
fun getUrlsAndStartDownload(lib: List<RealmMyLibrary?>, urls: ArrayList<String>) {
for (library in lib) {
val url = Utilities.getUrl(library)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) {
urls.add(url)
}
}
if (urls.isNotEmpty()) {
startDownload(urls)
}
if (urls.isNotEmpty()) startDownload(urls)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down Expand Up @@ -123,23 +125,53 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}

fun openResource(items: RealmMyLibrary) {
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline()}
openFileType(offlineItem, "offline")
if (items.openWith == "HTML") {
if (items.resourceOffline) {
val intent = Intent(activity, WebViewActivity::class.java)
intent.putExtra("RESOURCE_ID", items.id)
intent.putExtra("LOCAL_ADDRESS", items.resourceLocalAddress)
intent.putExtra("title", items.title)
startActivity(intent)
} else {
val resource = mRealm.where(RealmMyLibrary::class.java).equalTo("_id", items.resourceId).findFirst()
val downloadUrls = ArrayList<String>()
resource?.attachments?.forEach { attachment ->
attachment.name?.let { name ->
val url = Utilities.getUrl("${items.resourceId}", name)
downloadUrls.add(url)

val baseDir = File(context?.getExternalFilesDir(null), "ole/${items.resourceId}")
val lastSlashIndex = name.lastIndexOf('/')
if (lastSlashIndex > 0) {
val dirPath = name.substring(0, lastSlashIndex)
File(baseDir, dirPath).mkdirs()
}
}
}

if (downloadUrls.isNotEmpty()) {
startDownload(downloadUrls)
}
}
} else {
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline() }
openFileType(offlineItem, "offline")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
AdapterCourses.showRating(`object`, rating, timesRated, ratingBar)
}
}
fun getUrlsAndStartDownload(
lib: List<RealmMyLibrary?>, urls: ArrayList<String>
) {
fun getUrlsAndStartDownload(lib: List<RealmMyLibrary?>, urls: ArrayList<String>) {
for (library in lib) {
val url = Utilities.getUrl(library)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) urls.add(url)
if (!FileUtils.checkFileExist(url) && !TextUtils.isEmpty(url)) {
urls.add(url)
}
}
if (urls.isNotEmpty()) {
startDownload(urls)
}
if (urls.isNotEmpty()) startDownload(urls)
}
fun initRatingView(type: String?, id: String?, title: String?, listener: OnRatingChangeListener?) {
timesRated = requireView().findViewById(R.id.times_rated)
Expand Down Expand Up @@ -123,23 +125,53 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}

fun openResource(items: RealmMyLibrary) {
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline()}
openFileType(offlineItem, "offline")
if (items.openWith == "HTML") {
if (items.resourceOffline) {
val intent = Intent(activity, WebViewActivity::class.java)
intent.putExtra("RESOURCE_ID", items.id)
intent.putExtra("LOCAL_ADDRESS", items.resourceLocalAddress)
intent.putExtra("title", items.title)
startActivity(intent)
} else {
val resource = mRealm.where(RealmMyLibrary::class.java).equalTo("_id", items.resourceId).findFirst()
val downloadUrls = ArrayList<String>()
resource?.attachments?.forEach { attachment ->
attachment.name?.let { name ->
val url = Utilities.getUrl("${items.resourceId}", name)
downloadUrls.add(url)

val baseDir = File(context?.getExternalFilesDir(null), "ole/${items.resourceId}")
val lastSlashIndex = name.lastIndexOf('/')
if (lastSlashIndex > 0) {
val dirPath = name.substring(0, lastSlashIndex)
File(baseDir, dirPath).mkdirs()
}
}
}

if (downloadUrls.isNotEmpty()) {
startDownload(downloadUrls)
}
}
} else {
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
val matchingItems = mRealm.where(RealmMyLibrary::class.java)
.equalTo("resourceLocalAddress", items.resourceLocalAddress)
.findAll()
val anyOffline = matchingItems.any { it.isResourceOffline() }
if (anyOffline) {
val offlineItem = matchingItems.first { it.isResourceOffline() }
openFileType(offlineItem, "offline")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
if (items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
} else {
val arrayList = ArrayList<String>()
arrayList.add(Utilities.getUrl(items))
startDownload(arrayList)
profileDbHandler.setResourceOpenCount(items, KEY_RESOURCE_DOWNLOAD)
}
}
}
}
Expand Down
36 changes: 34 additions & 2 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmMyLibrary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.io.FileWriter
import java.io.IOException
import java.util.Calendar
import java.util.Date
import java.util.UUID

open class RealmMyLibrary : RealmObject() {
@PrimaryKey
Expand Down Expand Up @@ -63,6 +64,8 @@ open class RealmMyLibrary : RealmObject() {
var courseId: String? = null
var stepId: String? = null
var isPrivate: Boolean = false
var attachments: RealmList<RealmAttachment>? = null

fun serializeResource(): JsonObject {
return JsonObject().apply {
addProperty("_id", _id)
Expand Down Expand Up @@ -279,7 +282,25 @@ open class RealmMyLibrary : RealmObject() {
description = JsonUtils.getString("description", doc)
if (doc.has("_attachments")) {
val attachments = doc["_attachments"].asJsonObject
attachments.entrySet().forEach { (key, _) ->
if (this.attachments == null) {
this.attachments = RealmList()
}

attachments.entrySet().forEach { (key, attachmentValue) ->
val attachmentObj = attachmentValue.asJsonObject

val realmAttachment = mRealm.createObject(RealmAttachment::class.java, UUID.randomUUID().toString())
realmAttachment.apply {
name = key
contentType = attachmentObj.get("content_type")?.asString
length = attachmentObj.get("length")?.asLong ?: 0
digest = attachmentObj.get("digest")?.asString
isStub = attachmentObj.get("stub")?.asBoolean == true
revpos = attachmentObj.get("revpos")?.asInt ?: 0
}

this.attachments?.add(realmAttachment)

if (key.indexOf("/") < 0) {
resourceRemoteAddress = "${settings.getString("couchdbURL", "http://")}/resources/$resourceId/$key"
resourceLocalAddress = key
Expand Down Expand Up @@ -410,4 +431,15 @@ open class RealmMyLibrary : RealmObject() {
return libraries.flatMap { it.subject ?: emptyList() }.toSet()
}
}
}
}

open class RealmAttachment : RealmObject() {
@PrimaryKey
var id: String? = null
var name: String? = null
var contentType: String? = null
var length: Long = 0
var digest: String? = null
var isStub: Boolean = false
var revpos: Int = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
val itemLibraryHomeBinding = ItemLibraryHomeBinding.inflate(LayoutInflater.from(activity))
val v = itemLibraryHomeBinding.root
setTextColor(itemLibraryHomeBinding.title, itemCnt)
val colorResId = if (itemCnt % 2 == 0) R.color.dashboard_item else R.color.dashboard_item_alternative
val colorResId = if (itemCnt % 2 == 0) R.color.card_bg else R.color.dashboard_item_alternative
val color = context?.let { ContextCompat.getColor(it, colorResId) }
if (color != null) {
v.setBackgroundColor(color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ open class BaseDashboardFragmentPlugin : BaseContainerFragment() {
}

fun setTextColor(textView: TextView, itemCnt: Int) {
textView.setTextColor(ContextCompat.getColor(requireContext(), R.color.md_black_1000))
textView.setTextColor(ContextCompat.getColor(requireContext(), R.color.daynight_textColor))
setBackgroundColor(textView, itemCnt)
}

Expand Down Expand Up @@ -166,7 +166,7 @@ open class BaseDashboardFragmentPlugin : BaseContainerFragment() {
if (count % 2 == 0) {
v.setBackgroundResource(R.drawable.light_rect)
} else {
v.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.dashboard_item_alternative))
v.setBackgroundResource(R.color.dashboard_item_alternative)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
val max = progress.get("max").asInt
val current = progress.get("current").asInt
val courseStatus = if (current == max) {
"$courseName terminado!"
getString(R.string.course_completed, courseName)
} else {
"Ingresa al curso $courseName completalo ($current de $max hecho)"
getString(R.string.course_in_progress, courseName, current, max)
}
challengeDialog(uniqueDates.size, courseStatus, allUniqueDates.size, hasUnfinishedSurvey)
} else {
challengeDialog(uniqueDates.size, "$courseName no iniciado", allUniqueDates.size, hasUnfinishedSurvey)
challengeDialog(uniqueDates.size, getString(R.string.course_not_started, courseName), allUniqueDates.size, hasUnfinishedSurvey)
}
}
}
Expand Down Expand Up @@ -376,27 +376,25 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
if (isCompleted && !hasShownCongrats) {
editor.putBoolean("has_shown_congrats", true).apply()
val markdownContent = """
Ingresos totales de la comunidad: **$${calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey)}** /$500
Tus ganancias totales: **$${calculateIndividualProgress(voiceCount, hasUnfinishedSurvey)}** /$11
### ¡Felicidades! Reto Completado <br/>
""".trimIndent()
${getString(R.string.community_earnings, calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey))}
${getString(R.string.your_earnings, calculateIndividualProgress(voiceCount, hasUnfinishedSurvey))}
### ${getString(R.string.congratulations)} <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount, hasUnfinishedSurvey).show(supportFragmentManager, "markdown_dialog")
} else {
val cappedVoiceCount = minOf(voiceCount, 5)
val voicesText = if (cappedVoiceCount > 0) {
"$cappedVoiceCount de 5 Voces diarias"
"$cappedVoiceCount ${getString(R.string.daily_voices)}"
} else {
""
}
val markdownContent = """
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()
${getString(R.string.community_earnings, calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey))}
${getString(R.string.your_earnings, calculateIndividualProgress(voiceCount, hasUnfinishedSurvey))}
### ${getString(R.string.per_survey, courseTaskDone)} <br/>
### ${getString(R.string.share_opinion)} $voicesText <br/>
### ${getString(R.string.remember_sync)} <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount, hasUnfinishedSurvey)
.show(supportFragmentManager, "markdown_dialog")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
val max = progress.get("max").asInt
val current = progress.get("current").asInt
val courseStatus = if (current == max) {
"$courseName terminado!"
getString(R.string.course_completed, courseName)
} else {
"Ingresa al curso $courseName completalo ($current de $max hecho)"
getString(R.string.course_in_progress, courseName, current, max)
}
challengeDialog(uniqueDates.size, courseStatus, allUniqueDates.size, hasUnfinishedSurvey)
} else {
challengeDialog(uniqueDates.size, "$courseName no iniciado", allUniqueDates.size, hasUnfinishedSurvey)
challengeDialog(uniqueDates.size, getString(R.string.course_not_started, courseName), allUniqueDates.size, hasUnfinishedSurvey)
}
}
}
Expand Down Expand Up @@ -376,27 +376,25 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
if (isCompleted && !hasShownCongrats) {
editor.putBoolean("has_shown_congrats", true).apply()
val markdownContent = """
Ingresos totales de la comunidad: **$${calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey)}** /$500

Tus ganancias totales: **$${calculateIndividualProgress(voiceCount, hasUnfinishedSurvey)}** /$11
### ¡Felicidades! Reto Completado <br/>
""".trimIndent()
${getString(R.string.community_earnings, calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey))}
${getString(R.string.your_earnings, calculateIndividualProgress(voiceCount, hasUnfinishedSurvey))}
### ${getString(R.string.congratulations)} <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount, hasUnfinishedSurvey).show(supportFragmentManager, "markdown_dialog")
} else {
val cappedVoiceCount = minOf(voiceCount, 5)
val voicesText = if (cappedVoiceCount > 0) {
"$cappedVoiceCount de 5 Voces diarias"
"$cappedVoiceCount ${getString(R.string.daily_voices)}"
} else {
""
}
val markdownContent = """
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()
${getString(R.string.community_earnings, calculateCommunityProgress(allVoiceCount, hasUnfinishedSurvey))}
${getString(R.string.your_earnings, calculateIndividualProgress(voiceCount, hasUnfinishedSurvey))}
### ${getString(R.string.per_survey, courseTaskDone)} <br/>
### ${getString(R.string.share_opinion)} $voicesText <br/>
### ${getString(R.string.remember_sync)} <br/>
""".trimIndent()
MarkdownDialog.newInstance(markdownContent, courseStatus, voiceCount, allVoiceCount, hasUnfinishedSurvey)
.show(supportFragmentManager, "markdown_dialog")
}
Expand Down
Loading

0 comments on commit d8eba42

Please sign in to comment.