update the bg and text color properly in widget config
This commit is contained in:
parent
2691ac7f41
commit
4f0f909d07
|
@ -10,10 +10,14 @@ import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
|
import com.simplemobiletools.calendar.adapters.EventListWidgetAdapter
|
||||||
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
||||||
import com.simplemobiletools.calendar.helpers.*
|
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 kotlinx.android.synthetic.main.widget_config_list.*
|
||||||
import yuku.ambilwarna.AmbilWarnaDialog
|
import yuku.ambilwarna.AmbilWarnaDialog
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class WidgetListConfigureActivity : AppCompatActivity() {
|
class WidgetListConfigureActivity : AppCompatActivity() {
|
||||||
lateinit var mRes: Resources
|
lateinit var mRes: Resources
|
||||||
|
@ -26,6 +30,8 @@ class WidgetListConfigureActivity : AppCompatActivity() {
|
||||||
private var mTextColorWithoutTransparency = 0
|
private var mTextColorWithoutTransparency = 0
|
||||||
private var mTextColor = 0
|
private var mTextColor = 0
|
||||||
|
|
||||||
|
private var mEventsAdapter: EventListWidgetAdapter? = null
|
||||||
|
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setResult(Activity.RESULT_CANCELED)
|
setResult(Activity.RESULT_CANCELED)
|
||||||
|
@ -40,6 +46,14 @@ class WidgetListConfigureActivity : AppCompatActivity() {
|
||||||
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||||
finish()
|
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_save.setOnClickListener { saveConfig() }
|
||||||
config_bg_color.setOnClickListener { pickBackgroundColor() }
|
config_bg_color.setOnClickListener { pickBackgroundColor() }
|
||||||
config_text_color.setOnClickListener { pickTextColor() }
|
config_text_color.setOnClickListener { pickTextColor() }
|
||||||
|
@ -122,13 +136,14 @@ class WidgetListConfigureActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private fun updateTextColors() {
|
private fun updateTextColors() {
|
||||||
mTextColor = mTextColorWithoutTransparency.adjustAlpha(HIGH_ALPHA)
|
mTextColor = mTextColorWithoutTransparency.adjustAlpha(HIGH_ALPHA)
|
||||||
|
mEventsAdapter?.setTextColor(mTextColor)
|
||||||
config_text_color.setBackgroundColor(mTextColor)
|
config_text_color.setBackgroundColor(mTextColor)
|
||||||
config_save.setTextColor(mTextColor)
|
config_save.setTextColor(mTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateBgColor() {
|
private fun updateBgColor() {
|
||||||
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
|
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
|
||||||
|
config_events_list.setBackgroundColor(mBgColor)
|
||||||
config_bg_color.setBackgroundColor(mBgColor)
|
config_bg_color.setBackgroundColor(mBgColor)
|
||||||
config_save.setBackgroundColor(mBgColor)
|
config_save.setBackgroundColor(mBgColor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,11 @@ class EventListWidgetAdapter(val context: Context, val mEvents: List<ListItem>)
|
||||||
|
|
||||||
private val mInflater: LayoutInflater
|
private val mInflater: LayoutInflater
|
||||||
private var mTopDivider: Drawable? = null
|
private var mTopDivider: Drawable? = null
|
||||||
private var mNow = (System.currentTimeMillis() / 1000).toInt()
|
private var mTextColor = 0
|
||||||
private var mOrangeColor = 0
|
|
||||||
private var mGreyColor = 0
|
|
||||||
private var mTodayDate = ""
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
mTopDivider = context.resources.getDrawable(R.drawable.divider)
|
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 {
|
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(mTextColor)
|
||||||
start?.setTextColor(currTextColor)
|
end?.setTextColor(mTextColor)
|
||||||
end?.setTextColor(currTextColor)
|
title.setTextColor(mTextColor)
|
||||||
title.setTextColor(currTextColor)
|
description?.setTextColor(mTextColor)
|
||||||
description?.setTextColor(currTextColor)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val item = mEvents[position] as ListSection
|
val item = mEvents[position] as ListSection
|
||||||
viewHolder.title.text = item.title
|
viewHolder.title.text = item.title
|
||||||
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
|
viewHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
|
||||||
|
viewHolder.title.setTextColor(mTextColor)
|
||||||
if (mGreyColor == 0)
|
|
||||||
mGreyColor = viewHolder.title.currentTextColor
|
|
||||||
|
|
||||||
viewHolder.title.setTextColor(if (item.title == mTodayDate) mOrangeColor else mGreyColor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
fun setTextColor(color: Int) {
|
||||||
return if (mEvents[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
|
mTextColor = color
|
||||||
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getViewTypeCount(): Int {
|
override fun getItemViewType(position: Int) = if (mEvents[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
|
||||||
return 2
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCount(): Int {
|
override fun getViewTypeCount() = 2
|
||||||
return mEvents.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItem(position: Int): Any {
|
override fun getCount() = mEvents.size
|
||||||
return mEvents[position]
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItem(position: Int) = mEvents[position]
|
||||||
return 0
|
|
||||||
}
|
override fun getItemId(position: Int) = 0L
|
||||||
|
|
||||||
internal class ViewHolder(view: View) {
|
internal class ViewHolder(view: View) {
|
||||||
val title = view.event_item_title
|
val title = view.event_item_title
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingTop="@dimen/medium_padding"
|
android:paddingTop="@dimen/medium_padding"/>
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
@ -5,11 +5,19 @@
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_margin="@dimen/activity_margin">
|
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
|
<Button
|
||||||
android:id="@+id/config_bg_color"
|
android:id="@+id/config_bg_color"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_above="@+id/config_text_color" />
|
android:layout_above="@+id/config_text_color"/>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/config_bg_seekbar_holder"
|
android:id="@+id/config_bg_seekbar_holder"
|
||||||
|
@ -26,14 +34,14 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingRight="@dimen/activity_margin" />
|
android:paddingRight="@dimen/activity_margin"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/config_text_color"
|
android:id="@+id/config_text_color"
|
||||||
android:layout_width="50dp"
|
android:layout_width="50dp"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_alignParentBottom="true" />
|
android:layout_alignParentBottom="true"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/config_save"
|
android:id="@+id/config_save"
|
||||||
|
@ -46,5 +54,5 @@
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
android:text="@android:string/ok"
|
android:text="@android:string/ok"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="@dimen/config_text_size" />
|
android:textSize="@dimen/config_text_size"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in New Issue