add a button for removing contact events
This commit is contained in:
parent
ff0f78eb09
commit
74064e57d5
|
@ -36,7 +36,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.4.13'
|
implementation 'com.simplemobiletools:commons:3.4.14'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
|
|
||||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.DataSource
|
import com.bumptech.glide.load.DataSource
|
||||||
|
@ -132,11 +133,13 @@ class ContactActivity : SimpleActivity() {
|
||||||
contact_email_image.applyColorFilter(textColor)
|
contact_email_image.applyColorFilter(textColor)
|
||||||
contact_event_image.applyColorFilter(textColor)
|
contact_event_image.applyColorFilter(textColor)
|
||||||
contact_source_image.applyColorFilter(textColor)
|
contact_source_image.applyColorFilter(textColor)
|
||||||
contact_number_add_new.applyColorFilter(getAdjustedPrimaryColor())
|
|
||||||
|
val adjustedPrimaryColor = getAdjustedPrimaryColor()
|
||||||
|
contact_number_add_new.applyColorFilter(adjustedPrimaryColor)
|
||||||
contact_number_add_new.background.applyColorFilter(textColor)
|
contact_number_add_new.background.applyColorFilter(textColor)
|
||||||
contact_email_add_new.applyColorFilter(getAdjustedPrimaryColor())
|
contact_email_add_new.applyColorFilter(adjustedPrimaryColor)
|
||||||
contact_email_add_new.background.applyColorFilter(textColor)
|
contact_email_add_new.background.applyColorFilter(textColor)
|
||||||
contact_event_add_new.applyColorFilter(getAdjustedPrimaryColor())
|
contact_event_add_new.applyColorFilter(adjustedPrimaryColor)
|
||||||
contact_event_add_new.background.applyColorFilter(textColor)
|
contact_event_add_new.background.applyColorFilter(textColor)
|
||||||
|
|
||||||
contact_photo.setOnClickListener { trySetPhoto() }
|
contact_photo.setOnClickListener { trySetPhoto() }
|
||||||
|
@ -239,10 +242,22 @@ class ContactActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
(eventHolder as? ViewGroup)?.apply {
|
(eventHolder as? ViewGroup)?.apply {
|
||||||
getDateTime(event.value, contact_event)
|
val contactEvent = contact_event.apply {
|
||||||
contact_event.tag = event.value
|
getDateTime(event.value, this)
|
||||||
contact_event.alpha = 1f
|
tag = event.value
|
||||||
setupEventTypePicker(contact_event_type, contact_event, event.type)
|
alpha = 1f
|
||||||
|
}
|
||||||
|
|
||||||
|
setupEventTypePicker(this, event.type)
|
||||||
|
|
||||||
|
contact_event_remove.apply {
|
||||||
|
beVisible()
|
||||||
|
applyColorFilter(getAdjustedPrimaryColor())
|
||||||
|
background.applyColorFilter(config.textColor)
|
||||||
|
setOnClickListener {
|
||||||
|
resetContactEvent(contactEvent, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,7 +319,7 @@ class ContactActivity : SimpleActivity() {
|
||||||
if (contact!!.events.isEmpty()) {
|
if (contact!!.events.isEmpty()) {
|
||||||
val eventHolder = contact_events_holder.getChildAt(0)
|
val eventHolder = contact_events_holder.getChildAt(0)
|
||||||
(eventHolder as? ViewGroup)?.apply {
|
(eventHolder as? ViewGroup)?.apply {
|
||||||
setupEventTypePicker(contact_event_type, contact_event)
|
setupEventTypePicker(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,26 +342,47 @@ class ContactActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEventTypePicker(eventTypeField: TextView, eventField: TextView, type: Int = DEFAULT_EVENT_TYPE) {
|
private fun setupEventTypePicker(eventHolder: ViewGroup, type: Int = DEFAULT_EVENT_TYPE) {
|
||||||
eventTypeField.apply {
|
eventHolder.contact_event_type.apply {
|
||||||
setText(getEventTextId(type))
|
setText(getEventTextId(type))
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
showEventTypePicker(it as TextView)
|
showEventTypePicker(it as TextView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val eventField = eventHolder.contact_event
|
||||||
eventField.setOnClickListener {
|
eventField.setOnClickListener {
|
||||||
val setDateListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
|
val setDateListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
|
||||||
|
eventHolder.contact_event_remove.beVisible()
|
||||||
val date = DateTime().withDate(year, monthOfYear + 1, dayOfMonth).withTimeAtStartOfDay()
|
val date = DateTime().withDate(year, monthOfYear + 1, dayOfMonth).withTimeAtStartOfDay()
|
||||||
val formatted = date.toString(DateTimeFormat.mediumDate())
|
val formatted = date.toString(DateTimeFormat.mediumDate())
|
||||||
eventField.text = formatted
|
eventField.apply {
|
||||||
eventField.tag = date.toString("yyyy-MM-dd")
|
text = formatted
|
||||||
eventField.alpha = 1f
|
tag = date.toString("yyyy-MM-dd")
|
||||||
|
alpha = 1f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val date = getDateTime(eventField.tag?.toString() ?: "")
|
val date = getDateTime(eventField.tag?.toString() ?: "")
|
||||||
DatePickerDialog(this, getDialogTheme(), setDateListener, date.year, date.monthOfYear - 1, date.dayOfMonth).show()
|
DatePickerDialog(this, getDialogTheme(), setDateListener, date.year, date.monthOfYear - 1, date.dayOfMonth).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventHolder.contact_event_remove.apply {
|
||||||
|
applyColorFilter(getAdjustedPrimaryColor())
|
||||||
|
background.applyColorFilter(config.textColor)
|
||||||
|
setOnClickListener {
|
||||||
|
resetContactEvent(eventField, this@apply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resetContactEvent(contactEvent: TextView, removeContactEventButton: ImageView) {
|
||||||
|
contactEvent.apply {
|
||||||
|
text = getString(R.string.unknown)
|
||||||
|
tag = ""
|
||||||
|
alpha = 0.5f
|
||||||
|
}
|
||||||
|
removeContactEventButton.beGone()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDateTime(dateString: String, viewToUpdate: TextView? = null): DateTime {
|
private fun getDateTime(dateString: String, viewToUpdate: TextView? = null): DateTime {
|
||||||
|
@ -551,7 +587,7 @@ class ContactActivity : SimpleActivity() {
|
||||||
private fun addNewEventField() {
|
private fun addNewEventField() {
|
||||||
layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply {
|
layoutInflater.inflate(R.layout.item_event, contact_events_holder, false).apply {
|
||||||
updateTextColors(this as ViewGroup)
|
updateTextColors(this as ViewGroup)
|
||||||
setupEventTypePicker(contact_event_type, contact_event)
|
setupEventTypePicker(this)
|
||||||
contact_events_holder.addView(this)
|
contact_events_holder.addView(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_toLeftOf="@+id/contact_event_type"
|
android:layout_toLeftOf="@+id/contact_event_remove"
|
||||||
android:layout_toStartOf="@+id/contact_event_type"
|
android:layout_toStartOf="@+id/contact_event_remove"
|
||||||
android:alpha="0.5"
|
android:alpha="0.5"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:paddingBottom="@dimen/normal_margin"
|
android:paddingBottom="@dimen/normal_margin"
|
||||||
|
@ -21,6 +21,23 @@
|
||||||
android:text="@string/unknown"
|
android:text="@string/unknown"
|
||||||
android:textSize="@dimen/bigger_text_size"/>
|
android:textSize="@dimen/bigger_text_size"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/contact_event_remove"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@+id/contact_event"
|
||||||
|
android:layout_alignTop="@+id/contact_event"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginBottom="@dimen/medium_margin"
|
||||||
|
android:layout_marginLeft="@dimen/small_margin"
|
||||||
|
android:layout_marginRight="@dimen/small_margin"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:layout_toLeftOf="@+id/contact_event_type"
|
||||||
|
android:background="@drawable/button_background"
|
||||||
|
android:padding="@dimen/medium_margin"
|
||||||
|
android:src="@drawable/ic_minus"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/contact_event_type"
|
android:id="@+id/contact_event_type"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue