diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetListConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetListConfigureActivity.kt index eebad05e7..5824eb4bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetListConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/WidgetListConfigureActivity.kt @@ -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(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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt index b6266bbb2..a3e83bc49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt @@ -20,17 +20,11 @@ class EventListWidgetAdapter(val context: Context, val mEvents: List) 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) } } - 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 diff --git a/app/src/main/res/layout/event_list_widget.xml b/app/src/main/res/layout/event_list_widget.xml index 9a71ddab6..20e546246 100644 --- a/app/src/main/res/layout/event_list_widget.xml +++ b/app/src/main/res/layout/event_list_widget.xml @@ -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"/> diff --git a/app/src/main/res/layout/widget_config_list.xml b/app/src/main/res/layout/widget_config_list.xml index 21ba17b03..474e2c1e8 100644 --- a/app/src/main/res/layout/widget_config_list.xml +++ b/app/src/main/res/layout/widget_config_list.xml @@ -1,15 +1,23 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_centerHorizontal="true" + android:layout_margin="@dimen/activity_margin"> + +