diff --git a/app/build.gradle b/app/build.gradle index 9bc127db1..b4cd45e7b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,7 +33,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.5.7' + compile 'com.simplemobiletools:commons:2.5.10' compile 'joda-time:joda-time:2.9.1' compile 'com.facebook.stetho:stetho:1.4.1' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index 8e5d15383..0e8e3411c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -26,10 +26,7 @@ import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.views.MyScrollView import com.simplemobiletools.commons.dialogs.FilePickerDialog -import com.simplemobiletools.commons.extensions.checkWhatsNew -import com.simplemobiletools.commons.extensions.hasReadStoragePermission -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.LICENSE_JODA import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN import com.simplemobiletools.commons.helpers.LICENSE_STETHO @@ -126,7 +123,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { } private fun updateView(view: Int) { - calendar_fab.visibility = if (view == YEARLY_VIEW) View.GONE else View.VISIBLE + calendar_fab.beGoneIf(view == YEARLY_VIEW) mIsMonthSelected = view == MONTHLY_VIEW config.storedView = view updateViewPager() @@ -191,8 +188,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { } private fun fillMonthlyViewPager(targetDay: String) { - main_weekly_scrollview.visibility = View.GONE - calendar_fab.visibility = View.VISIBLE + main_weekly_scrollview.beGone() + calendar_fab.beVisible() val codes = getMonths(targetDay) val monthlyAdapter = MyMonthPagerAdapter(supportFragmentManager, codes, this) @@ -200,9 +197,9 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { clearOnPageChangeListeners() adapter = monthlyAdapter currentItem = codes.size / 2 - visibility = View.VISIBLE + beVisible() } - calendar_event_list_holder.visibility = View.GONE + calendar_event_list_holder.beGone() } private fun getMonths(code: String): List { @@ -224,9 +221,9 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { mWeekScrollY = y } }) - main_view_pager.visibility = View.GONE - calendar_event_list_holder.visibility = View.GONE - main_weekly_scrollview.visibility = View.VISIBLE + main_view_pager.beGone() + calendar_event_list_holder.beGone() + main_weekly_scrollview.beVisible() week_view_hours_holder.removeAllViews() for (i in 1..23) { @@ -293,8 +290,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { } private fun fillYearlyViewPager() { - main_weekly_scrollview.visibility = View.GONE - calendar_fab.visibility = View.GONE + main_weekly_scrollview.beGone() + calendar_fab.beGone() val targetYear = DateTime().toString(Formatter.YEAR_PATTERN).toInt() val years = getYears(targetYear) val yearlyAdapter = MyYearPagerAdapter(supportFragmentManager, years, this) @@ -314,10 +311,10 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { title = "${getString(R.string.app_launcher_name)} - ${years[position]}" } }) - visibility = View.VISIBLE + beVisible() } title = "${getString(R.string.app_launcher_name)} - ${years[years.size / 2]}" - calendar_event_list_holder.visibility = View.GONE + calendar_event_list_holder.beGone() } private fun getYears(targetYear: Int): List { @@ -350,9 +347,9 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { private fun fillEventsList() { main_view_pager.adapter = null - main_view_pager.visibility = View.GONE - main_weekly_scrollview.visibility = View.GONE - calendar_event_list_holder.visibility = View.VISIBLE + main_view_pager.beGone() + main_weekly_scrollview.beGone() + calendar_event_list_holder.beVisible() if (mEventListFragment == null) mEventListFragment = EventListFragment() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 96ddb729a..0fea0b14a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -179,12 +179,11 @@ class SettingsActivity : SimpleActivity() { settings_default_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(p0: AdapterView<*>?, p1: View?, itemIndex: Int, p3: Long) { + settings_custom_reminder_holder.beVisibleIf(itemIndex == 2) if (itemIndex == 2) { - settings_custom_reminder_holder.visibility = View.VISIBLE showKeyboard(custom_reminder_value) } else { hideKeyboard() - settings_custom_reminder_holder.visibility = View.GONE } config.defaultReminderType = getDefaultReminderValue(itemIndex) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt index f38a9f720..d507711ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetMonthlyConfigureActivity.kt @@ -9,12 +9,10 @@ import android.graphics.Paint import android.graphics.PorterDuff import android.os.Bundle import android.support.v7.app.AppCompatActivity -import android.view.View import android.widget.SeekBar import android.widget.TextView import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.extensions.config -import com.simplemobiletools.calendar.extensions.removeFlag import com.simplemobiletools.calendar.helpers.LOW_ALPHA import com.simplemobiletools.calendar.helpers.MonthlyCalendarImpl import com.simplemobiletools.calendar.helpers.MyWidgetMonthlyProvider @@ -22,6 +20,8 @@ import com.simplemobiletools.calendar.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.models.Day import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.extensions.adjustAlpha +import com.simplemobiletools.commons.extensions.beVisible +import com.simplemobiletools.commons.extensions.removeFlag import kotlinx.android.synthetic.main.first_row.* import kotlinx.android.synthetic.main.top_navigation.* import kotlinx.android.synthetic.main.widget_config_monthly.* @@ -145,13 +145,13 @@ class WidgetMonthlyConfigureActivity : AppCompatActivity(), MonthlyCalendar { if (applicationContext.config.displayWeekNumbers) { week_num.setTextColor(mTextColor) - week_num.visibility = View.VISIBLE + week_num.beVisible() for (i in 0..5) { (findViewById(mRes.getIdentifier("week_num_$i", "id", mPackageName)) as TextView).apply { text = "${mDays!![i * 7 + 3].weekOfYear}:" setTextColor(mTextColor) - visibility = View.VISIBLE + beVisible() } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt index a7fff34bb..57c25a4e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.commons.dialogs.ConfirmationDialog +import com.simplemobiletools.commons.extensions.beInvisibleIf import kotlinx.android.synthetic.main.event_item_day_view.view.* import java.util.* @@ -105,14 +106,12 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List, va event_item_start.setTextColor(textColor) toggleItemSelection(this, markedItems.contains(pos), pos) + event_item_end.beInvisibleIf(event.startTS == event.endTS) - if (event.startTS == event.endTS) { - event_item_end.visibility = View.INVISIBLE - } else { + if (event.startTS != event.endTS) { event_item_end.apply { text = Formatter.getTimeFromTS(context, event.endTS) setTextColor(textColor) - visibility = View.VISIBLE } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt index 00ceae170..02e997e14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListAdapter.kt @@ -15,6 +15,7 @@ import com.simplemobiletools.calendar.models.ListEvent import com.simplemobiletools.calendar.models.ListItem import com.simplemobiletools.calendar.models.ListSection import com.simplemobiletools.commons.dialogs.ConfirmationDialog +import com.simplemobiletools.commons.extensions.beInvisibleIf import kotlinx.android.synthetic.main.event_item_day_view.view.* import java.util.* @@ -122,13 +123,11 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List, event_item_title.text = item.title event_item_description.text = item.description event_item_start.text = Formatter.getTimeFromTS(context, item.startTS) + event_item_end.beInvisibleIf(item.startTS == item.endTS) toggleItemSelection(this, markedItems.contains(pos), pos) - if (item.startTS == item.endTS) { - event_item_end.visibility = View.INVISIBLE - } else { + if (item.startTS != item.endTS) { event_item_end.text = Formatter.getTimeFromTS(context, item.endTS) - event_item_end.visibility = View.VISIBLE val startCode = Formatter.getDayCodeFromTS(item.startTS) val endCode = Formatter.getDayCodeFromTS(item.endTS) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapterOld.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapterOld.kt index 7a21d6da3..f58bdac5e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapterOld.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapterOld.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.models.ListEvent import com.simplemobiletools.calendar.models.ListItem import com.simplemobiletools.calendar.models.ListSection +import com.simplemobiletools.commons.extensions.beInvisibleIf import kotlinx.android.synthetic.main.event_item_day_view.view.* class EventListWidgetAdapterOld(val context: Context, val mEvents: List) : BaseAdapter() { @@ -50,12 +51,10 @@ class EventListWidgetAdapterOld(val context: Context, val mEvents: List?, p1: View?, itemIndex: Int, p3: Long) { + import_events_custom_reminder_holder.beVisibleIf(itemIndex == 2) if (itemIndex == 2) { - import_events_custom_reminder_holder.visibility = View.VISIBLE activity.showKeyboard(import_events_custom_reminder_value) - } else { - import_events_custom_reminder_holder.visibility = View.GONE } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Int.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Int.kt deleted file mode 100644 index dbfc8db27..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Int.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.simplemobiletools.calendar.extensions - -// TODO: how to do "flags & ~flag" in kotlin? -fun Int.removeFlag(flag: Int) = this or flag - flag diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt index b9a74abaf..7c4a11f3b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt @@ -17,14 +17,11 @@ import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.DayActivity import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.getAppropriateTheme -import com.simplemobiletools.calendar.extensions.removeFlag import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.interfaces.NavigationListener import com.simplemobiletools.calendar.models.Day -import com.simplemobiletools.commons.extensions.adjustAlpha -import com.simplemobiletools.commons.extensions.beVisibleIf -import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.first_row.* import kotlinx.android.synthetic.main.fragment_month.view.* import kotlinx.android.synthetic.main.top_navigation.view.* @@ -118,7 +115,7 @@ class MonthFragment : Fragment(), MonthlyCalendar { activity.setTheme(context.getAppropriateTheme()) val view = getLayoutInflater(arguments).inflate(R.layout.date_picker, null) val datePicker = view.findViewById(R.id.date_picker) as DatePicker - datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).visibility = View.GONE + datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).beGone() val dateTime = DateTime(mCalendar.mTargetDate.toString()) datePicker.init(dateTime.year, dateTime.monthOfYear - 1, 1, null)