update the bg and text color properly in widget config

This commit is contained in:
tibbi 2016-11-27 22:25:47 +01:00
parent 2691ac7f41
commit 4f0f909d07
4 changed files with 48 additions and 42 deletions

View File

@ -10,10 +10,14 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.SeekBar
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.EventListWidgetAdapter
import com.simplemobiletools.calendar.extensions.adjustAlpha
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.ListEvent
import com.simplemobiletools.calendar.models.ListItem
import kotlinx.android.synthetic.main.widget_config_list.*
import yuku.ambilwarna.AmbilWarnaDialog
import java.util.*
class WidgetListConfigureActivity : AppCompatActivity() {
lateinit var mRes: Resources
@ -26,6 +30,8 @@ class WidgetListConfigureActivity : AppCompatActivity() {
private var mTextColorWithoutTransparency = 0
private var mTextColor = 0
private var mEventsAdapter: EventListWidgetAdapter? = null
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setResult(Activity.RESULT_CANCELED)
@ -40,6 +46,14 @@ class WidgetListConfigureActivity : AppCompatActivity() {
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
finish()
val listItems = ArrayList<ListItem>(10)
val event = ListEvent(1, 1, 2, "title", "desc")
listItems.add(event)
mEventsAdapter = EventListWidgetAdapter(this, listItems)
mEventsAdapter!!.setTextColor(mTextColor)
config_events_list.adapter = mEventsAdapter
config_save.setOnClickListener { saveConfig() }
config_bg_color.setOnClickListener { pickBackgroundColor() }
config_text_color.setOnClickListener { pickTextColor() }
@ -122,13 +136,14 @@ class WidgetListConfigureActivity : AppCompatActivity() {
private fun updateTextColors() {
mTextColor = mTextColorWithoutTransparency.adjustAlpha(HIGH_ALPHA)
mEventsAdapter?.setTextColor(mTextColor)
config_text_color.setBackgroundColor(mTextColor)
config_save.setTextColor(mTextColor)
}
private fun updateBgColor() {
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
config_events_list.setBackgroundColor(mBgColor)
config_bg_color.setBackgroundColor(mBgColor)
config_save.setBackgroundColor(mBgColor)
}

View File

@ -20,17 +20,11 @@ class EventListWidgetAdapter(val context: Context, val mEvents: List<ListItem>)
private val mInflater: LayoutInflater
private var mTopDivider: Drawable? = null
private var mNow = (System.currentTimeMillis() / 1000).toInt()
private var mOrangeColor = 0
private var mGreyColor = 0
private var mTodayDate = ""
private var mTextColor = 0
init {
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mTopDivider = context.resources.getDrawable(R.drawable.divider)
mOrangeColor = context.resources.getColor(R.color.colorPrimary)
val mTodayCode = Formatter.getDayCodeFromTS(mNow)
mTodayDate = Formatter.getEventDate(context, mTodayCode)
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
@ -71,45 +65,35 @@ class EventListWidgetAdapter(val context: Context, val mEvents: List<ListItem>)
}
}
val currTextColor = if (item.startTS <= mNow) mOrangeColor else mGreyColor
start?.setTextColor(currTextColor)
end?.setTextColor(currTextColor)
title.setTextColor(currTextColor)
description?.setTextColor(currTextColor)
start?.setTextColor(mTextColor)
end?.setTextColor(mTextColor)
title.setTextColor(mTextColor)
description?.setTextColor(mTextColor)
}
} else {
val item = mEvents[position] as ListSection
viewHolder.title.text = item.title
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
if (mGreyColor == 0)
mGreyColor = viewHolder.title.currentTextColor
viewHolder.title.setTextColor(if (item.title == mTodayDate) mOrangeColor else mGreyColor)
viewHolder.title.setTextColor(mTextColor)
}
return view
}
override fun getItemViewType(position: Int): Int {
return if (mEvents[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
fun setTextColor(color: Int) {
mTextColor = color
notifyDataSetChanged()
}
override fun getViewTypeCount(): Int {
return 2
}
override fun getItemViewType(position: Int) = if (mEvents[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
override fun getCount(): Int {
return mEvents.size
}
override fun getViewTypeCount() = 2
override fun getItem(position: Int): Any {
return mEvents[position]
}
override fun getCount() = mEvents.size
override fun getItemId(position: Int): Long {
return 0
}
override fun getItem(position: Int) = mEvents[position]
override fun getItemId(position: Int) = 0L
internal class ViewHolder(view: View) {
val title = view.event_item_title

View File

@ -11,7 +11,6 @@
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/medium_padding"
android:visibility="gone"/>
android:paddingTop="@dimen/medium_padding"/>
</RelativeLayout>

View File

@ -1,15 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/activity_margin">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/activity_margin">
<ListView
android:id="@+id/config_events_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/config_bg_color"
android:layout_marginBottom="@dimen/activity_margin"
android:clipToPadding="false"/>
<Button
android:id="@+id/config_bg_color"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="@+id/config_text_color" />
android:layout_above="@+id/config_text_color"/>
<RelativeLayout
android:id="@+id/config_bg_seekbar_holder"
@ -26,14 +34,14 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin" />
android:paddingRight="@dimen/activity_margin"/>
</RelativeLayout>
<Button
android:id="@+id/config_text_color"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true" />
android:layout_alignParentBottom="true"/>
<Button
android:id="@+id/config_save"
@ -46,5 +54,5 @@
android:paddingRight="@dimen/activity_margin"
android:text="@android:string/ok"
android:textColor="@android:color/white"
android:textSize="@dimen/config_text_size" />
android:textSize="@dimen/config_text_size"/>
</RelativeLayout>