diff --git a/.gitignore b/.gitignore index 72882161a7..f94cbdc52a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,9 +40,6 @@ proguard # Log files *.log -# Raw folder -assets - # Android Studio Navigation editor temp folder .navigation diff --git a/app/src/main/assets/images/github-filter-issues.png b/app/src/main/assets/images/github-filter-issues.png new file mode 100644 index 0000000000..fcdd042f70 Binary files /dev/null and b/app/src/main/assets/images/github-filter-issues.png differ diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt index b295f33bd1..5e32b61ca8 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt @@ -37,6 +37,7 @@ import io.realm.Case import io.realm.RealmChangeListener import io.realm.RealmObject import io.realm.RealmResults +import org.ole.planet.myplanet.BuildConfig import org.ole.planet.myplanet.MainApplication.Companion.context import org.ole.planet.myplanet.R import org.ole.planet.myplanet.base.BaseContainerFragment @@ -72,9 +73,13 @@ import org.ole.planet.myplanet.utilities.DialogUtils.guestDialog import org.ole.planet.myplanet.utilities.FileUtils.totalAvailableMemoryRatio import org.ole.planet.myplanet.utilities.KeyboardUtils.setupUI import org.ole.planet.myplanet.utilities.LocaleHelper +import org.ole.planet.myplanet.utilities.MarkdownDialog import org.ole.planet.myplanet.utilities.TimeUtils.formatDate import org.ole.planet.myplanet.utilities.Utilities import org.ole.planet.myplanet.utilities.Utilities.toast +import java.time.LocalDate +import java.time.temporal.ChronoUnit +import java.util.Calendar import java.util.Date import java.util.UUID import kotlin.math.ceil @@ -230,6 +235,41 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N } } }) + + val calendar = Calendar.getInstance() + val currentMonth = calendar.get(Calendar.MONTH) + + if (currentMonth == Calendar.OCTOBER) { + if (settings.getString("serverURL", "") == "https://${BuildConfig.PLANET_LEARNING_URL}") { + val today = LocalDate.now() + val endOfMonth = today.withDayOfMonth(today.lengthOfMonth()) + val remainingDays = ChronoUnit.DAYS.between(today, endOfMonth).toInt() + + challengeDialog(remainingDays) + } + } + } + + private fun challengeDialog(remainingDays: Int) { + val markdownContent = """ + ## myPlanet issues challenge + + ![issues challenge](file:///android_asset/images/github-filter-issues.png) + + get ready for virtual intern github issues challenge! + + **duration:** $remainingDays days remaining + + ## steps to participate: + - Find an issue on myPlanet + - Take a screenshot/record a video + - create an issue on our github repository using link below + + [new myPlanet issue](https://github.com/open-learning-exchange/myplanet/issues/new) + """.trimIndent() + + MarkdownDialog.newInstance(markdownContent) + .show(supportFragmentManager, "markdown_dialog") } private fun setupRealmListeners() { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite index 92a586ba7c..e087e77348 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite @@ -37,6 +37,7 @@ import io.realm.Case import io.realm.RealmChangeListener import io.realm.RealmObject import io.realm.RealmResults +import org.ole.planet.myplanet.BuildConfig import org.ole.planet.myplanet.MainApplication.Companion.context import org.ole.planet.myplanet.R //import org.ole.planet.myplanet.base.BaseContainerFragment @@ -72,9 +73,13 @@ import org.ole.planet.myplanet.utilities.DialogUtils.guestDialog import org.ole.planet.myplanet.utilities.FileUtils.totalAvailableMemoryRatio import org.ole.planet.myplanet.utilities.KeyboardUtils.setupUI import org.ole.planet.myplanet.utilities.LocaleHelper +import org.ole.planet.myplanet.utilities.MarkdownDialog import org.ole.planet.myplanet.utilities.TimeUtils.formatDate import org.ole.planet.myplanet.utilities.Utilities import org.ole.planet.myplanet.utilities.Utilities.toast +import java.time.LocalDate +import java.time.temporal.ChronoUnit +import java.util.Calendar import java.util.Date import java.util.UUID import kotlin.math.ceil @@ -230,6 +235,41 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N } } }) + + val calendar = Calendar.getInstance() + val currentMonth = calendar.get(Calendar.MONTH) + + if (currentMonth == Calendar.OCTOBER) { + if (settings.getString("serverURL", "") == "https://${BuildConfig.PLANET_LEARNING_URL}") { + val today = LocalDate.now() + val endOfMonth = today.withDayOfMonth(today.lengthOfMonth()) + val remainingDays = ChronoUnit.DAYS.between(today, endOfMonth).toInt() + + challengeDialog(remainingDays) + } + } + } + + private fun challengeDialog(remainingDays: Int) { + val markdownContent = """ + ## myPlanet issues challenge + + ![issues challenge](file:///android_asset/images/github-filter-issues.png) + + get ready for virtual intern github issues challenge! + + **duration:** $remainingDays days remaining + + ## steps to participate: + - Find an issue on myPlanet + - Take a screenshot/record a video + - create an issue on our github repository using link below + + [new myPlanet issue](https://github.com/open-learning-exchange/myplanet/issues/new) + """.trimIndent() + + MarkdownDialog.newInstance(markdownContent) + .show(supportFragmentManager, "markdown_dialog") } private fun setupRealmListeners() { diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/Markdown.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/Markdown.kt index ff9e1a60d9..d250657cb9 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/Markdown.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/Markdown.kt @@ -48,7 +48,7 @@ object Markdown { .usePlugin(object : AbstractMarkwonPlugin() { override fun configure(registry: MarkwonPlugin.Registry) { registry.require(ImagesPlugin::class.java) { imagesPlugin -> - imagesPlugin.addSchemeHandler(FileSchemeHandler.create()) + imagesPlugin.addSchemeHandler(FileSchemeHandler.createWithAssets(context.assets)) imagesPlugin.addSchemeHandler(NetworkSchemeHandler.create()) imagesPlugin.addSchemeHandler(OkHttpNetworkSchemeHandler.create()) } diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/MarkdownDialog.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/MarkdownDialog.kt new file mode 100644 index 0000000000..41ad4d53fd --- /dev/null +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/MarkdownDialog.kt @@ -0,0 +1,69 @@ +package org.ole.planet.myplanet.utilities + +import android.os.Bundle +import android.text.Spannable +import android.text.method.LinkMovementMethod +import android.text.style.URLSpan +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import org.ole.planet.myplanet.databinding.DialogCampaignChallengeBinding +import org.ole.planet.myplanet.utilities.Markdown.setMarkdownText + +class MarkdownDialog : DialogFragment() { + private lateinit var dialogCampaignChallengeBinding: DialogCampaignChallengeBinding + private var markdownContent: String = "" + + companion object { + private const val ARG_MARKDOWN_CONTENT = "markdown_content" + + fun newInstance(markdownContent: String): MarkdownDialog { + val fragment = MarkdownDialog() + val args = Bundle().apply { + putString(ARG_MARKDOWN_CONTENT, markdownContent) + } + fragment.arguments = args + return fragment + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + markdownContent = arguments?.getString(ARG_MARKDOWN_CONTENT) ?: "" + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + dialogCampaignChallengeBinding = DialogCampaignChallengeBinding.inflate(inflater, container, false) + return dialogCampaignChallengeBinding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + setupMarkdown() + dialogCampaignChallengeBinding.markdownTextView.movementMethod = LinkMovementMethod.getInstance() + val textWithSpans = dialogCampaignChallengeBinding.markdownTextView.text + if (textWithSpans is Spannable) { + val urlSpans = textWithSpans.getSpans(0, textWithSpans.length, URLSpan::class.java) + for (urlSpan in urlSpans) { + val start = textWithSpans.getSpanStart(urlSpan) + val end = textWithSpans.getSpanEnd(urlSpan) + val dynamicTitle = textWithSpans.subSequence(start, end).toString() + textWithSpans.setSpan(CustomClickableSpan(urlSpan.url, dynamicTitle, requireActivity()), start, end, textWithSpans.getSpanFlags(urlSpan)) + textWithSpans.removeSpan(urlSpan) + } + } + setupCloseButton() + } + + private fun setupMarkdown() { + setMarkdownText(dialogCampaignChallengeBinding.markdownTextView, markdownContent) + } + + private fun setupCloseButton() { + dialogCampaignChallengeBinding.closeButton.setOnClickListener { + dismiss() + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_close_24.xml b/app/src/main/res/drawable/baseline_close_24.xml new file mode 100644 index 0000000000..f8ca0c64b9 --- /dev/null +++ b/app/src/main/res/drawable/baseline_close_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/dialog_campaign_challenge.xml b/app/src/main/res/layout/dialog_campaign_challenge.xml new file mode 100644 index 0000000000..3da46c9b03 --- /dev/null +++ b/app/src/main/res/layout/dialog_campaign_challenge.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file