mark the pressed empty grid in weekly view on click

This commit is contained in:
tibbi
2017-01-22 11:19:09 +01:00
parent e72f6bae2a
commit 6ad9819ef3
2 changed files with 23 additions and 4 deletions

View File

@ -1,23 +1,41 @@
package com.simplemobiletools.calendar.adapters package com.simplemobiletools.calendar.adapters
import android.content.Context import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.BaseAdapter import android.widget.BaseAdapter
import android.widget.ImageView
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.config
class WeekEventsAdapter(val context: Context) : BaseAdapter() { class WeekEventsAdapter(val context: Context) : BaseAdapter() {
private val mInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater private val mInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
private val defaultBackground = context.config.backgroundColor
private val coloredBackground = context.config.primaryColor
private var selectedGrid: ImageView? = null
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var view = convertView var view = convertView
if (view == null) { if (view == null) {
view = mInflater.inflate(R.layout.week_grid_item, parent, false) view = mInflater.inflate(R.layout.week_grid_item, parent, false) as ImageView
view.background = ColorDrawable(defaultBackground)
} }
return view!! view.setOnClickListener {
selectedGrid?.background = ColorDrawable(defaultBackground)
if (selectedGrid == view) {
selectedGrid = null
} else {
view!!.background = ColorDrawable(coloredBackground)
(view as ImageView).setImageResource(R.drawable.ic_plus)
selectedGrid = view as ImageView
}
}
return view
} }
override fun getItem(position: Int) = null override fun getItem(position: Int) = null

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <ImageView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/week_holder" android:id="@+id/week_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/weekly_view_row_minus_one_height" android:layout_height="@dimen/weekly_view_row_minus_one_height"
android:background="@android:color/white"/> android:background="@android:color/transparent"
android:scaleType="centerInside"/>