use some visibility extensions

This commit is contained in:
tibbi 2017-02-05 11:00:41 +01:00
parent 2b4e4e90e6
commit 13e871b5ef
10 changed files with 39 additions and 53 deletions

View File

@ -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'

View File

@ -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<String> {
@ -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<Int> {
@ -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()

View File

@ -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)

View File

@ -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()
}
}
}

View File

@ -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<Event>, 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
}
}

View File

@ -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<ListItem>,
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)

View File

@ -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<ListItem>) : BaseAdapter() {
@ -50,12 +51,10 @@ class EventListWidgetAdapterOld(val context: Context, val mEvents: List<ListItem
title.text = item.title
description?.text = item.description
start?.text = Formatter.getTimeFromTS(context, item.startTS)
end?.beInvisibleIf(item.startTS == item.endTS)
if (item.startTS == item.endTS) {
end?.visibility = View.INVISIBLE
} else {
if (item.startTS != item.endTS) {
end?.text = Formatter.getTimeFromTS(context, item.endTS)
end?.visibility = View.VISIBLE
val startCode = Formatter.getDayCodeFromTS(item.startTS)
val endCode = Formatter.getDayCodeFromTS(item.endTS)
@ -71,9 +70,11 @@ class EventListWidgetAdapterOld(val context: Context, val mEvents: List<ListItem
}
} else {
val item = mEvents[position] as ListSection
viewHolder.title.text = item.title
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
viewHolder.title.setTextColor(mTextColor)
viewHolder.title.apply {
text = item.title
setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
setTextColor(mTextColor)
}
}
return view

View File

@ -22,11 +22,9 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback:
import_events_reminder.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, 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
}
}

View File

@ -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

View File

@ -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)