mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Moved Monuments related utils into their own class
This commit is contained in:
parent
f1cf82ee34
commit
1fdc70cd9f
6 changed files with 67 additions and 60 deletions
|
|
@ -30,7 +30,6 @@ import androidx.work.WorkManager
|
||||||
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
||||||
import fr.free.nrw.commons.Media
|
import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.utils.Utils
|
|
||||||
import fr.free.nrw.commons.auth.SessionManager
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
import fr.free.nrw.commons.campaigns.CampaignView
|
import fr.free.nrw.commons.campaigns.CampaignView
|
||||||
import fr.free.nrw.commons.campaigns.CampaignsPresenter
|
import fr.free.nrw.commons.campaigns.CampaignsPresenter
|
||||||
|
|
@ -61,6 +60,7 @@ import fr.free.nrw.commons.utils.ConfigUtils.isBetaFlavour
|
||||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||||
import fr.free.nrw.commons.utils.LengthUtils.computeBearing
|
import fr.free.nrw.commons.utils.LengthUtils.computeBearing
|
||||||
import fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween
|
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.NetworkUtils.isInternetConnectionEstablished
|
||||||
import fr.free.nrw.commons.utils.PermissionUtils.hasPermission
|
import fr.free.nrw.commons.utils.PermissionUtils.hasPermission
|
||||||
import fr.free.nrw.commons.utils.ViewUtil.showLongToast
|
import fr.free.nrw.commons.utils.ViewUtil.showLongToast
|
||||||
|
|
@ -242,8 +242,8 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
|
||||||
private fun initWLMCampaign() {
|
private fun initWLMCampaign() {
|
||||||
wlmCampaign = Campaign(
|
wlmCampaign = Campaign(
|
||||||
getString(R.string.wlm_campaign_title),
|
getString(R.string.wlm_campaign_title),
|
||||||
getString(R.string.wlm_campaign_description), Utils.getWLMStartDate().toString(),
|
getString(R.string.wlm_campaign_description), Monuments.getWLMStartDate().toString(),
|
||||||
Utils.getWLMEndDate().toString(), NearbyParentFragment.WLM_URL, true
|
Monuments.getWLMEndDate().toString(), NearbyParentFragment.WLM_URL, true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -729,7 +729,7 @@ class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.On
|
||||||
* of campaigns on the campaigns card
|
* of campaigns on the campaigns card
|
||||||
*/
|
*/
|
||||||
private fun fetchCampaigns() {
|
private fun fetchCampaigns() {
|
||||||
if (Utils.isMonumentsEnabled(Date())) {
|
if (Monuments.isMonumentsEnabled(Date())) {
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
binding!!.campaignsView.setCampaign(wlmCampaign)
|
binding!!.campaignsView.setCampaign(wlmCampaign)
|
||||||
binding!!.campaignsView.visibility = View.VISIBLE
|
binding!!.campaignsView.visibility = View.VISIBLE
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ import fr.free.nrw.commons.utils.GeoCoordinates
|
||||||
import fr.free.nrw.commons.utils.LayoutUtils.getScreenWidth
|
import fr.free.nrw.commons.utils.LayoutUtils.getScreenWidth
|
||||||
import fr.free.nrw.commons.utils.LayoutUtils.setLayoutHeightAlignedToWidth
|
import fr.free.nrw.commons.utils.LayoutUtils.setLayoutHeightAlignedToWidth
|
||||||
import fr.free.nrw.commons.utils.MapUtils.defaultLatLng
|
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.addAnchorToBigFABs
|
||||||
import fr.free.nrw.commons.utils.NearbyFABUtils.addAnchorToSmallFABs
|
import fr.free.nrw.commons.utils.NearbyFABUtils.addAnchorToSmallFABs
|
||||||
import fr.free.nrw.commons.utils.NearbyFABUtils.removeAnchorFromFAB
|
import fr.free.nrw.commons.utils.NearbyFABUtils.removeAnchorFromFAB
|
||||||
|
|
@ -465,7 +466,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_isDarkTheme = systemThemeUtils?.isDeviceInNightMode() == true
|
_isDarkTheme = systemThemeUtils?.isDeviceInNightMode() == true
|
||||||
if (Utils.isMonumentsEnabled(Date())) {
|
if (Monuments.isMonumentsEnabled(Date())) {
|
||||||
binding?.rlContainerWlmMonthMessage?.visibility = View.VISIBLE
|
binding?.rlContainerWlmMonthMessage?.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
binding?.rlContainerWlmMonthMessage?.visibility = View.GONE
|
binding?.rlContainerWlmMonthMessage?.visibility = View.GONE
|
||||||
|
|
@ -834,7 +835,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
||||||
loadAnimations()
|
loadAnimations()
|
||||||
setBottomSheetCallbacks()
|
setBottomSheetCallbacks()
|
||||||
addActionToTitle()
|
addActionToTitle()
|
||||||
if (!Utils.isMonumentsEnabled(Date())) {
|
if (!Monuments.isMonumentsEnabled(Date())) {
|
||||||
NearbyFilterState.setWlmSelected(false)
|
NearbyFilterState.setWlmSelected(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1578,7 +1579,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
||||||
searchLatLng,
|
searchLatLng,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
Utils.isMonumentsEnabled(Date()),
|
Monuments.isMonumentsEnabled(Date()),
|
||||||
customQuery
|
customQuery
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1631,7 +1632,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
||||||
searchLatLng,
|
searchLatLng,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
Utils.isMonumentsEnabled(Date()),
|
Monuments.isMonumentsEnabled(Date()),
|
||||||
customQuery
|
customQuery
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package fr.free.nrw.commons.upload
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import fr.free.nrw.commons.utils.Utils
|
|
||||||
import fr.free.nrw.commons.contributions.Contribution
|
import fr.free.nrw.commons.contributions.Contribution
|
||||||
import fr.free.nrw.commons.filepicker.UploadableFile.DateTimeWithSource
|
import fr.free.nrw.commons.filepicker.UploadableFile.DateTimeWithSource
|
||||||
import fr.free.nrw.commons.settings.Prefs.Licenses
|
import fr.free.nrw.commons.settings.Prefs.Licenses
|
||||||
import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha
|
import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha
|
||||||
|
import fr.free.nrw.commons.utils.Monuments
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
|
@ -49,7 +49,7 @@ class PageContentsCreator @Inject constructor(private val context: Context) {
|
||||||
String.format(
|
String.format(
|
||||||
Locale.ENGLISH,
|
Locale.ENGLISH,
|
||||||
"{{Wiki Loves Monuments %d|1= %s}}\n",
|
"{{Wiki Loves Monuments %d|1= %s}}\n",
|
||||||
Utils.getWikiLovesMonumentsYear(Calendar.getInstance()),
|
Monuments.getWikiLovesMonumentsYear(Calendar.getInstance()),
|
||||||
contribution.countryCode
|
contribution.countryCode
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
52
app/src/main/java/fr/free/nrw/commons/utils/Monuments.java
Normal file
52
app/src/main/java/fr/free/nrw/commons/utils/Monuments.java
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,8 +16,6 @@ import androidx.browser.customtabs.CustomTabsIntent;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
@ -119,48 +117,4 @@ public class Utils {
|
||||||
textView.setText(content);
|
textView.setText(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package fr.free.nrw.commons
|
package fr.free.nrw.commons
|
||||||
|
|
||||||
import fr.free.nrw.commons.utils.Utils
|
import fr.free.nrw.commons.utils.Monuments
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
|
@ -10,20 +10,20 @@ class UtilsTest {
|
||||||
fun wikiLovesMonumentsYearBeforeSeptember() {
|
fun wikiLovesMonumentsYearBeforeSeptember() {
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
cal.set(2022, Calendar.FEBRUARY, 1)
|
cal.set(2022, Calendar.FEBRUARY, 1)
|
||||||
Assertions.assertEquals(2021, Utils.getWikiLovesMonumentsYear(cal))
|
Assertions.assertEquals(2021, Monuments.getWikiLovesMonumentsYear(cal))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun wikiLovesMonumentsYearInSeptember() {
|
fun wikiLovesMonumentsYearInSeptember() {
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
cal.set(2022, Calendar.SEPTEMBER, 1)
|
cal.set(2022, Calendar.SEPTEMBER, 1)
|
||||||
Assertions.assertEquals(2022, Utils.getWikiLovesMonumentsYear(cal))
|
Assertions.assertEquals(2022, Monuments.getWikiLovesMonumentsYear(cal))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun wikiLovesMonumentsYearAfterSeptember() {
|
fun wikiLovesMonumentsYearAfterSeptember() {
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
cal.set(2022, Calendar.DECEMBER, 1)
|
cal.set(2022, Calendar.DECEMBER, 1)
|
||||||
Assertions.assertEquals(2022, Utils.getWikiLovesMonumentsYear(cal))
|
Assertions.assertEquals(2022, Monuments.getWikiLovesMonumentsYear(cal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue