mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Monument utils converted to kotlin
This commit is contained in:
parent
f8f0a94500
commit
eca14b8ffe
6 changed files with 56 additions and 68 deletions
|
|
@ -60,10 +60,12 @@ import fr.free.nrw.commons.utils.ConfigUtils.isBetaFlavour
|
|||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||
import fr.free.nrw.commons.utils.LengthUtils.computeBearing
|
||||
import fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween
|
||||
import fr.free.nrw.commons.utils.Monuments
|
||||
import fr.free.nrw.commons.utils.NetworkUtils.isInternetConnectionEstablished
|
||||
import fr.free.nrw.commons.utils.PermissionUtils.hasPermission
|
||||
import fr.free.nrw.commons.utils.ViewUtil.showLongToast
|
||||
import fr.free.nrw.commons.utils.isMonumentsEnabled
|
||||
import fr.free.nrw.commons.utils.wLMEndDate
|
||||
import fr.free.nrw.commons.utils.wLMStartDate
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
|
|
@ -242,8 +244,8 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
|
|||
private fun initWLMCampaign() {
|
||||
wlmCampaign = Campaign(
|
||||
getString(R.string.wlm_campaign_title),
|
||||
getString(R.string.wlm_campaign_description), Monuments.getWLMStartDate().toString(),
|
||||
Monuments.getWLMEndDate().toString(), NearbyParentFragment.WLM_URL, true
|
||||
getString(R.string.wlm_campaign_description), wLMStartDate,
|
||||
wLMEndDate, NearbyParentFragment.WLM_URL, true
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -729,7 +731,7 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
|
|||
* of campaigns on the campaigns card
|
||||
*/
|
||||
private fun fetchCampaigns() {
|
||||
if (Monuments.isMonumentsEnabled(Date())) {
|
||||
if (isMonumentsEnabled) {
|
||||
if (binding != null) {
|
||||
binding!!.campaignsView.setCampaign(wlmCampaign)
|
||||
binding!!.campaignsView.visibility = View.VISIBLE
|
||||
|
|
|
|||
|
|
@ -91,13 +91,11 @@ import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract
|
|||
import fr.free.nrw.commons.nearby.model.BottomSheetItem
|
||||
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter
|
||||
import fr.free.nrw.commons.upload.FileUtils
|
||||
import fr.free.nrw.commons.utils.ClipboardUtils
|
||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||
import fr.free.nrw.commons.utils.ExecutorUtils.get
|
||||
import fr.free.nrw.commons.utils.LayoutUtils.getScreenWidth
|
||||
import fr.free.nrw.commons.utils.LayoutUtils.setLayoutHeightAlignedToWidth
|
||||
import fr.free.nrw.commons.utils.MapUtils.defaultLatLng
|
||||
import fr.free.nrw.commons.utils.Monuments
|
||||
import fr.free.nrw.commons.utils.NearbyFABUtils.addAnchorToBigFABs
|
||||
import fr.free.nrw.commons.utils.NearbyFABUtils.addAnchorToSmallFABs
|
||||
import fr.free.nrw.commons.utils.NearbyFABUtils.removeAnchorFromFAB
|
||||
|
|
@ -107,6 +105,7 @@ import fr.free.nrw.commons.utils.UrlUtils
|
|||
import fr.free.nrw.commons.utils.ViewUtil.showLongToast
|
||||
import fr.free.nrw.commons.utils.copyToClipboard
|
||||
import fr.free.nrw.commons.utils.handleGeoCoordinates
|
||||
import fr.free.nrw.commons.utils.isMonumentsEnabled
|
||||
import fr.free.nrw.commons.wikidata.WikidataConstants
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener.WikidataP18EditListener
|
||||
|
|
@ -468,7 +467,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
}
|
||||
}
|
||||
_isDarkTheme = systemThemeUtils?.isDeviceInNightMode() == true
|
||||
if (Monuments.isMonumentsEnabled(Date())) {
|
||||
if (isMonumentsEnabled) {
|
||||
binding?.rlContainerWlmMonthMessage?.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding?.rlContainerWlmMonthMessage?.visibility = View.GONE
|
||||
|
|
@ -837,7 +836,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
loadAnimations()
|
||||
setBottomSheetCallbacks()
|
||||
addActionToTitle()
|
||||
if (!Monuments.isMonumentsEnabled(Date())) {
|
||||
if (!isMonumentsEnabled) {
|
||||
NearbyFilterState.setWlmSelected(false)
|
||||
}
|
||||
}
|
||||
|
|
@ -1580,7 +1579,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
searchLatLng,
|
||||
false,
|
||||
true,
|
||||
Monuments.isMonumentsEnabled(Date()),
|
||||
isMonumentsEnabled,
|
||||
customQuery
|
||||
)
|
||||
}
|
||||
|
|
@ -1633,7 +1632,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
|||
searchLatLng,
|
||||
false,
|
||||
true,
|
||||
Monuments.isMonumentsEnabled(Date()),
|
||||
isMonumentsEnabled,
|
||||
customQuery
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import fr.free.nrw.commons.contributions.Contribution
|
|||
import fr.free.nrw.commons.filepicker.UploadableFile.DateTimeWithSource
|
||||
import fr.free.nrw.commons.settings.Prefs.Licenses
|
||||
import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha
|
||||
import fr.free.nrw.commons.utils.Monuments
|
||||
import fr.free.nrw.commons.utils.getWikiLovesMonumentsYear
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
|
|
@ -49,7 +49,7 @@ class PageContentsCreator @Inject constructor(private val context: Context) {
|
|||
String.format(
|
||||
Locale.ENGLISH,
|
||||
"{{Wiki Loves Monuments %d|1= %s}}\n",
|
||||
Monuments.getWikiLovesMonumentsYear(Calendar.getInstance()),
|
||||
getWikiLovesMonumentsYear(Calendar.getInstance()),
|
||||
contribution.countryCode
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public final class Monuments {
|
||||
|
||||
/**
|
||||
* For now we are enabling the monuments only when the date lies between 1 Sept & 31 OCt
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static boolean isMonumentsEnabled(final Date date) {
|
||||
if (date.getMonth() == 8) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Util function to get the start date of wlm monument
|
||||
* For this release we are hardcoding it to be 1st September
|
||||
* @return
|
||||
*/
|
||||
public static String getWLMStartDate() {
|
||||
return "1 Sep";
|
||||
}
|
||||
|
||||
/***
|
||||
* Util function to get the end date of wlm monument
|
||||
* For this release we are hardcoding it to be 31st October
|
||||
* @return
|
||||
*/
|
||||
public static String getWLMEndDate() {
|
||||
return "30 Sep";
|
||||
}
|
||||
|
||||
/***
|
||||
* Function to get the current WLM year
|
||||
* It increments at the start of September in line with the other WLM functions
|
||||
* (No consideration of locales for now)
|
||||
* @param calendar
|
||||
* @return
|
||||
*/
|
||||
public static int getWikiLovesMonumentsYear(Calendar calendar) {
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
if (calendar.get(Calendar.MONTH) < Calendar.SEPTEMBER) {
|
||||
year -= 1;
|
||||
}
|
||||
return year;
|
||||
}
|
||||
}
|
||||
39
app/src/main/java/fr/free/nrw/commons/utils/Monuments.kt
Normal file
39
app/src/main/java/fr/free/nrw/commons/utils/Monuments.kt
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package fr.free.nrw.commons.utils
|
||||
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
* Get the start date of wlm monument
|
||||
* For this release we are hardcoding it to be 1st September
|
||||
* @return
|
||||
*/
|
||||
const val wLMStartDate: String = "1 Sep"
|
||||
|
||||
/***
|
||||
* Get the end date of wlm monument
|
||||
* For this release we are hardcoding it to be 31st October
|
||||
* @return
|
||||
*/
|
||||
const val wLMEndDate: String = "30 Sep"
|
||||
|
||||
/**
|
||||
* For now we are enabling the monuments only when the date lies between 1 Sept & 31 OCt
|
||||
*/
|
||||
val isMonumentsEnabled: Boolean
|
||||
get() = Date().month == 8
|
||||
|
||||
/***
|
||||
* Function to get the current WLM year
|
||||
* It increments at the start of September in line with the other WLM functions
|
||||
* (No consideration of locales for now)
|
||||
* @param calendar
|
||||
* @return
|
||||
*/
|
||||
fun getWikiLovesMonumentsYear(calendar: Calendar): Int {
|
||||
var year = calendar[Calendar.YEAR]
|
||||
if (calendar[Calendar.MONTH] < Calendar.SEPTEMBER) {
|
||||
year -= 1
|
||||
}
|
||||
return year
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import fr.free.nrw.commons.utils.Monuments
|
||||
import fr.free.nrw.commons.utils.getWikiLovesMonumentsYear
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import java.util.Calendar
|
||||
|
|
@ -10,20 +10,20 @@ class UtilsTest {
|
|||
fun wikiLovesMonumentsYearBeforeSeptember() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(2022, Calendar.FEBRUARY, 1)
|
||||
Assertions.assertEquals(2021, Monuments.getWikiLovesMonumentsYear(cal))
|
||||
Assertions.assertEquals(2021, getWikiLovesMonumentsYear(cal))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun wikiLovesMonumentsYearInSeptember() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(2022, Calendar.SEPTEMBER, 1)
|
||||
Assertions.assertEquals(2022, Monuments.getWikiLovesMonumentsYear(cal))
|
||||
Assertions.assertEquals(2022, getWikiLovesMonumentsYear(cal))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun wikiLovesMonumentsYearAfterSeptember() {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.set(2022, Calendar.DECEMBER, 1)
|
||||
Assertions.assertEquals(2022, Monuments.getWikiLovesMonumentsYear(cal))
|
||||
Assertions.assertEquals(2022, getWikiLovesMonumentsYear(cal))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue