updating colors on a couple places

This commit is contained in:
tibbi 2017-01-02 22:52:16 +01:00
parent b89f8a82e8
commit a4f98d8944
8 changed files with 56 additions and 47 deletions

View File

@ -8,20 +8,22 @@ import com.bignerdranch.android.multiselector.MultiSelector
import com.bignerdranch.android.multiselector.SwappingHolder
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import kotlinx.android.synthetic.main.event_item.view.*
import java.util.*
class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val listener: ItemOperationsListener?, val itemClick: (Event) -> Unit) :
RecyclerView.Adapter<EventsAdapter.ViewHolder>() {
class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val listener: ItemOperationsListener?, val itemClick: (Event) -> Unit) :
RecyclerView.Adapter<DayEventsAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
val views = ArrayList<View>()
companion object {
var actMode: ActionMode? = null
val markedItems = HashSet<Int>()
var textColor = 0
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
itemView.event_item_frame.isSelected = select
@ -35,15 +37,17 @@ class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val l
}
}
init {
textColor = Config.newInstance(activity).textColor
}
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return when (item.itemId) {
R.id.cab_delete -> {
askConfirmDelete()
true
}
else -> false
when (item.itemId) {
R.id.cab_delete -> askConfirmDelete()
else -> return false
}
return true
}
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
@ -92,15 +96,24 @@ class EventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, val l
itemView.apply {
event_item_title.text = event.title
event_item_title.setTextColor(textColor)
event_item_description.text = event.description
event_item_description.setTextColor(textColor)
event_item_start.text = Formatter.getTimeFromTS(context, event.startTS)
event_item_start.setTextColor(textColor)
toggleItemSelection(this, markedItems.contains(pos), pos)
if (event.startTS == event.endTS) {
event_item_end.visibility = View.INVISIBLE
} else {
event_item_end.text = Formatter.getTimeFromTS(context, event.endTS)
event_item_end.visibility = View.VISIBLE
event_item_end.apply {
text = Formatter.getTimeFromTS(context, event.endTS)
setTextColor(textColor)
visibility = View.VISIBLE
}
}
setOnClickListener { viewClicked(multiSelector, event, pos) }

View File

@ -9,6 +9,7 @@ import com.bignerdranch.android.multiselector.MultiSelector
import com.bignerdranch.android.multiselector.SwappingHolder
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem
@ -29,11 +30,11 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
var actMode: ActionMode? = null
val markedItems = HashSet<Int>()
var mTopDivider: Drawable? = null
var topDivider: Drawable? = null
var mNow = (System.currentTimeMillis() / 1000).toInt()
var mOrangeColor = 0
var mGreyColor = 0
var mTodayDate = ""
var primaryColor = 0
var textColor = 0
var todayDate = ""
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
itemView.event_item_frame.isSelected = select
@ -48,21 +49,20 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
}
init {
mTopDivider = activity.resources.getDrawable(R.drawable.divider)
mOrangeColor = activity.resources.getColor(R.color.color_primary)
textColor = Config.newInstance(activity).textColor
topDivider = activity.resources.getDrawable(R.drawable.divider)
primaryColor = activity.resources.getColor(R.color.color_primary)
val mTodayCode = Formatter.getDayCodeFromTS(mNow)
mTodayDate = Formatter.getDate(activity, mTodayCode)
todayDate = Formatter.getDate(activity, mTodayCode)
}
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return when (item.itemId) {
R.id.cab_delete -> {
askConfirmDelete()
true
}
else -> false
when (item.itemId) {
R.id.cab_delete -> askConfirmDelete()
else -> return false
}
return true
}
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
@ -137,7 +137,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
}
}
val currTextColor = if (item.startTS <= mNow) mOrangeColor else mGreyColor
val currTextColor = if (item.startTS <= mNow) primaryColor else textColor
event_item_start.setTextColor(currTextColor)
event_item_end.setTextColor(currTextColor)
event_item_title.setTextColor(currTextColor)
@ -181,14 +181,10 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
class SectionHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(listItem: ListItem): View {
val item = listItem as ListSection
itemView.apply {
event_item_title.text = item.title
event_item_title.setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
if (mGreyColor == 0)
mGreyColor = event_item_title.currentTextColor
event_item_title.setTextColor(if (item.title == mTodayDate) mOrangeColor else mGreyColor)
itemView.event_item_title.apply {
text = item.title
setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else topDivider, null, null)
setTextColor(if (item.title == todayDate) primaryColor else textColor)
}
return itemView

View File

@ -10,11 +10,7 @@ import com.simplemobiletools.calendar.helpers.DAY_CODE
class MyDayPagerAdapter(fm: FragmentManager, private val mCodes: List<String>, private val mListener: DayFragment.DeleteListener) :
FragmentStatePagerAdapter(fm) {
var fragments: SparseArray<DayFragment>
init {
fragments = SparseArray(10)
}
var fragments: SparseArray<DayFragment> = SparseArray(10)
override fun getCount() = mCodes.size

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.fragments
import android.content.Intent
import android.content.res.Resources
import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle
import android.support.v4.app.Fragment
@ -15,7 +14,7 @@ import android.widget.RelativeLayout
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.EventsAdapter
import com.simplemobiletools.calendar.adapters.DayEventsAdapter
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
@ -27,7 +26,7 @@ import kotlinx.android.synthetic.main.top_navigation.view.*
import java.util.*
import kotlin.comparisons.compareBy
class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, EventsAdapter.ItemOperationsListener {
class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEventsListener, DayEventsAdapter.ItemOperationsListener {
private var mTextColor = 0
private var mDayCode = ""
private var mEvents: MutableList<Event>? = null
@ -49,6 +48,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
val day = Formatter.getDayTitle(activity.applicationContext, mDayCode)
mHolder.top_value.text = day
mHolder.top_value.setOnClickListener { pickDay() }
mHolder.top_value.setTextColor(mConfig.textColor)
mToBeDeleted = ArrayList<Int>()
setupButtons()
@ -61,7 +61,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
}
private fun setupButtons() {
val baseColor = Color.BLACK
val baseColor = mConfig.textColor
mTextColor = baseColor.adjustAlpha(HIGH_ALPHA)
mHolder.apply {
@ -119,7 +119,7 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
if (activity == null)
return
val eventsAdapter = EventsAdapter(activity as SimpleActivity, eventsToShow, this) {
val eventsAdapter = DayEventsAdapter(activity as SimpleActivity, eventsToShow, this) {
editEvent(it.id)
}
mHolder.day_events.apply {

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.fragments
import android.content.Intent
import android.content.res.Resources
import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle
import android.support.v4.app.Fragment
@ -83,6 +82,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
override fun updateMonthlyCalendar(month: String, days: List<Day>) {
activity?.runOnUiThread {
mHolder.top_value.text = month
mHolder.top_value.setTextColor(mConfig.textColor)
updateDays(days)
}
}
@ -92,7 +92,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
}
private fun setupButtons() {
val baseColor = Color.BLACK
val baseColor = mConfig.textColor
mTextColor = baseColor.adjustAlpha(HIGH_ALPHA)
mTextColorWithEvent = mRes.getColor(R.color.color_primary).adjustAlpha(HIGH_ALPHA)
mWeakTextColor = baseColor.adjustAlpha(LOW_ALPHA)

View File

@ -17,6 +17,7 @@ import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.interfaces.YearlyCalendar
import com.simplemobiletools.calendar.views.SmallMonthView
import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.fragment_year.view.*
import org.joda.time.DateTime
import java.util.*
@ -32,6 +33,7 @@ class YearFragment : Fragment(), YearlyCalendar {
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater!!.inflate(R.layout.fragment_year, container, false)
mYear = arguments.getInt(YEAR_LABEL)
context.updateTextColors(mView.calendar_holder)
setupMonths()
mCalendar = YearlyCalendarImpl(this, context, mYear)

View File

@ -2,11 +2,11 @@ package com.simplemobiletools.calendar.views
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.Config
import com.simplemobiletools.calendar.helpers.MEDIUM_ALPHA
import com.simplemobiletools.commons.extensions.adjustAlpha
import java.util.*
@ -55,9 +55,10 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
a.recycle()
}
val baseColor = Color.BLACK
val config = Config.newInstance(context)
val baseColor = config.textColor
mTextColor = baseColor.adjustAlpha(MEDIUM_ALPHA)
mColoredTextColor = resources.getColor(R.color.color_primary).adjustAlpha(MEDIUM_ALPHA)
mColoredTextColor = config.primaryColor.adjustAlpha(MEDIUM_ALPHA)
mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = mTextColor

View File

@ -13,6 +13,7 @@
android:clipToPadding="false"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/medium_margin"
android:scrollbars="vertical"
android:visibility="gone"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>