removing some redundant code

This commit is contained in:
tibbi 2018-09-21 14:45:23 +02:00
parent ebc26dc6e0
commit 3ab7b0ab2a
8 changed files with 10 additions and 12 deletions

View File

@ -106,7 +106,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onResume() {
super.onResume()
if (mStoredTextColor != config.textColor || mStoredBackgroundColor != config.backgroundColor || mStoredPrimaryColor != config.primaryColor
|| mStoredDayCode != Formatter.getTodayCode(applicationContext) || mStoredDimPastEvents != config.dimPastEvents) {
|| mStoredDayCode != Formatter.getTodayCode() || mStoredDimPastEvents != config.dimPastEvents) {
updateViewPager()
}
@ -206,7 +206,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
mStoredUse24HourFormat = use24HourFormat
mStoredDimPastEvents = dimPastEvents
}
mStoredDayCode = Formatter.getTodayCode(applicationContext)
mStoredDayCode = Formatter.getTodayCode()
}
private fun setupSearch(menu: Menu) {
@ -534,7 +534,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
}
private fun updateViewPager(dayCode: String? = Formatter.getTodayCode(applicationContext)) {
private fun updateViewPager(dayCode: String? = Formatter.getTodayCode()) {
val fragment = getFragmentsHolder()
currentFragments.forEach {
supportFragmentManager.beginTransaction().remove(it).commitNow()

View File

@ -288,7 +288,7 @@ fun Context.rescheduleReminder(event: Event?, minutes: Int) {
}
}
fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode(this)) {
fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode()) {
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(dayCode))
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

View File

@ -31,7 +31,7 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
currentDayCode = arguments?.getString(DAY_CODE) ?: ""
todayDayCode = Formatter.getTodayCode(context!!)
todayDayCode = Formatter.getTodayCode()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

View File

@ -182,5 +182,5 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
(activity as? MainActivity)?.updateActionBarTitle(getString(R.string.app_launcher_name))
}
override fun getNewEventDayCode() = Formatter.getTodayCode(context!!)
override fun getNewEventDayCode() = Formatter.getTodayCode()
}

View File

@ -31,7 +31,7 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
currentDayCode = arguments?.getString(DAY_CODE) ?: ""
todayDayCode = Formatter.getTodayCode(context!!)
todayDayCode = Formatter.getTodayCode()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

View File

@ -93,5 +93,5 @@ class YearFragmentsHolder : MyFragmentHolder() {
(activity as? MainActivity)?.updateActionBarTitle("${getString(R.string.app_launcher_name)} - $currentYear")
}
override fun getNewEventDayCode() = Formatter.getTodayCode(context!!)
override fun getNewEventDayCode() = Formatter.getTodayCode()
}

View File

@ -58,7 +58,7 @@ object Formatter {
return "$month $day $year"
}
fun getTodayCode(context: Context) = Formatter.getDayCodeFromTS(getNowSeconds())
fun getTodayCode() = Formatter.getDayCodeFromTS(getNowSeconds())
fun getHours(context: Context, dateTime: DateTime) = dateTime.toString(getHourPattern(context))
@ -85,8 +85,6 @@ object Formatter {
// use manually translated month names, as DateFormat and Joda have issues with a lot of languages
fun getMonthName(context: Context, id: Int) = context.resources.getStringArray(R.array.months)[id - 1]
fun getYear(dateTime: DateTime) = dateTime.toString(YEAR_PATTERN)
fun getHourPattern(context: Context) = if (context.config.use24HourFormat) PATTERN_HOURS_24 else PATTERN_HOURS_12
fun getTimePattern(context: Context) = if (context.config.use24HourFormat) PATTERN_TIME_24 else PATTERN_TIME_12

View File

@ -195,7 +195,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
setupIntent(context, views, GO_TO_TODAY, R.id.top_go_to_today)
setupIntent(context, views, NEW_EVENT, R.id.top_new_event)
val monthCode = days.firstOrNull { it.code.substring(6) == "01" }?.code ?: Formatter.getTodayCode(context)
val monthCode = days.firstOrNull { it.code.substring(6) == "01" }?.code ?: Formatter.getTodayCode()
setupAppOpenIntent(context, views, R.id.top_value, monthCode)
try {