mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
use the new event list adapter at the widget config screen
This commit is contained in:
@@ -8,7 +8,7 @@ import android.graphics.Color
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
import com.simplemobiletools.calendar.adapters.EventListWidgetAdapterOld
|
import com.simplemobiletools.calendar.adapters.EventListAdapter
|
||||||
import com.simplemobiletools.calendar.extensions.config
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
@@ -33,7 +33,7 @@ class WidgetListConfigureActivity : SimpleActivity() {
|
|||||||
private var mTextColorWithoutTransparency = 0
|
private var mTextColorWithoutTransparency = 0
|
||||||
private var mTextColor = 0
|
private var mTextColor = 0
|
||||||
|
|
||||||
private var mEventsAdapter: EventListWidgetAdapterOld? = null
|
private var mEventsAdapter: EventListAdapter? = null
|
||||||
|
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -49,8 +49,10 @@ class WidgetListConfigureActivity : SimpleActivity() {
|
|||||||
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
if (mWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||||
finish()
|
finish()
|
||||||
|
|
||||||
mEventsAdapter = EventListWidgetAdapterOld(this, getListItems())
|
mEventsAdapter = EventListAdapter(this, getListItems(), null) {
|
||||||
mEventsAdapter!!.setTextColor(mTextColor)
|
|
||||||
|
}
|
||||||
|
mEventsAdapter!!.updateTextColor(mTextColor)
|
||||||
config_events_list.adapter = mEventsAdapter
|
config_events_list.adapter = mEventsAdapter
|
||||||
|
|
||||||
config_save.setOnClickListener { saveConfig() }
|
config_save.setOnClickListener { saveConfig() }
|
||||||
@@ -127,7 +129,7 @@ class WidgetListConfigureActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun updateColors() {
|
private fun updateColors() {
|
||||||
mTextColor = mTextColorWithoutTransparency
|
mTextColor = mTextColorWithoutTransparency
|
||||||
mEventsAdapter?.setTextColor(mTextColor)
|
mEventsAdapter?.updateTextColor(mTextColor)
|
||||||
config_text_color.setBackgroundColor(mTextColor)
|
config_text_color.setBackgroundColor(mTextColor)
|
||||||
config_save.setTextColor(mTextColor)
|
config_save.setTextColor(mTextColor)
|
||||||
}
|
}
|
||||||
|
@@ -1,108 +0,0 @@
|
|||||||
package com.simplemobiletools.calendar.adapters
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.BaseAdapter
|
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.TextView
|
|
||||||
import com.simplemobiletools.calendar.R
|
|
||||||
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.applyColorFilter
|
|
||||||
import com.simplemobiletools.commons.extensions.beInvisibleIf
|
|
||||||
import kotlinx.android.synthetic.main.event_list_item_widget.view.*
|
|
||||||
|
|
||||||
class EventListWidgetAdapterOld(val context: Context, val mEvents: List<ListItem>) : BaseAdapter() {
|
|
||||||
val ITEM_EVENT = 0
|
|
||||||
val ITEM_HEADER = 1
|
|
||||||
|
|
||||||
private val mInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
||||||
private var mTopDivider: Drawable? = null
|
|
||||||
private var mTextColor = 0
|
|
||||||
|
|
||||||
init {
|
|
||||||
mTopDivider = context.resources.getDrawable(R.drawable.divider_width)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
|
||||||
var view = convertView
|
|
||||||
val viewHolder: ViewHolder
|
|
||||||
val type = getItemViewType(position)
|
|
||||||
|
|
||||||
if (view == null) {
|
|
||||||
if (type == ITEM_EVENT) {
|
|
||||||
view = mInflater.inflate(R.layout.event_list_item, parent, false)
|
|
||||||
} else {
|
|
||||||
view = mInflater.inflate(R.layout.event_list_section, parent, false)
|
|
||||||
view.setOnClickListener(null)
|
|
||||||
}
|
|
||||||
viewHolder = ViewHolder(view)
|
|
||||||
view!!.tag = viewHolder
|
|
||||||
} else {
|
|
||||||
viewHolder = view.tag as ViewHolder
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == ITEM_EVENT) {
|
|
||||||
val item = mEvents[position] as ListEvent
|
|
||||||
viewHolder.apply {
|
|
||||||
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?.text = Formatter.getTimeFromTS(context, item.endTS)
|
|
||||||
|
|
||||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
|
||||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
|
||||||
if (startCode != endCode) {
|
|
||||||
end?.append(" (${Formatter.getDateFromCode(context, endCode)})")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
start?.setTextColor(mTextColor)
|
|
||||||
end?.setTextColor(mTextColor)
|
|
||||||
title.setTextColor(mTextColor)
|
|
||||||
description?.setTextColor(mTextColor)
|
|
||||||
color?.applyColorFilter(mTextColor)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val item = mEvents[position] as ListSection
|
|
||||||
viewHolder.title.apply {
|
|
||||||
text = item.title
|
|
||||||
setCompoundDrawablesWithIntrinsicBounds(null, if (position == 0) null else mTopDivider, null, null)
|
|
||||||
setTextColor(mTextColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setTextColor(color: Int) {
|
|
||||||
mTextColor = color
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemViewType(position: Int) = if (mEvents[position] is ListEvent) ITEM_EVENT else ITEM_HEADER
|
|
||||||
|
|
||||||
override fun getViewTypeCount() = 2
|
|
||||||
|
|
||||||
override fun getCount() = mEvents.size
|
|
||||||
|
|
||||||
override fun getItem(position: Int) = mEvents[position]
|
|
||||||
|
|
||||||
override fun getItemId(position: Int) = 0L
|
|
||||||
|
|
||||||
internal class ViewHolder(view: View) {
|
|
||||||
val title = view.event_section_title
|
|
||||||
val description: TextView? = view.event_item_description
|
|
||||||
val start: TextView? = view.event_item_start
|
|
||||||
val end: TextView? = view.event_item_end
|
|
||||||
val color: ImageView? = view.event_item_color
|
|
||||||
}
|
|
||||||
}
|
|
@@ -117,6 +117,11 @@ abstract class MyAdapter(val activity: SimpleActivity, val itemClick: (Any) -> U
|
|||||||
actMode?.finish()
|
actMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateTextColor(textColor: Int) {
|
||||||
|
this.textColor = textColor
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
private val adapterListener = object : MyAdapterListener {
|
private val adapterListener = object : MyAdapterListener {
|
||||||
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
|
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
|
||||||
toggleItemSelection(select, position)
|
toggleItemSelection(select, position)
|
||||||
|
@@ -1,13 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/config_list_holder"
|
android:id="@+id/config_list_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_margin="@dimen/activity_margin">
|
android:layout_margin="@dimen/activity_margin">
|
||||||
|
|
||||||
<ListView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/config_events_list"
|
android:id="@+id/config_events_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -16,7 +17,8 @@
|
|||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:divider="@null"
|
android:divider="@null"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingTop="@dimen/medium_margin"/>
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/config_bg_color"
|
android:id="@+id/config_bg_color"
|
||||||
|
Reference in New Issue
Block a user