Merge branch 'master' of github.com:SimpleMobileTools/Simple-Calendar

This commit is contained in:
tibbi 2021-07-19 17:01:09 +02:00
commit 33ab342851
12 changed files with 271 additions and 16 deletions

View file

@ -21,6 +21,7 @@ import androidx.core.view.MenuItemCompat
import com.simplemobiletools.calendar.pro.BuildConfig
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.adapters.EventListAdapter
import com.simplemobiletools.calendar.pro.adapters.QuickFilterEventTypeAdapter
import com.simplemobiletools.calendar.pro.databases.EventsDatabase
import com.simplemobiletools.calendar.pro.dialogs.ExportEventsDialog
import com.simplemobiletools.calendar.pro.dialogs.FilterEventTypesDialog
@ -155,6 +156,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
if (!mIsSearchOpen) {
invalidateOptionsMenu()
}
setupQuickFilter()
}
override fun onPause() {
@ -295,6 +298,17 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
})
}
private fun setupQuickFilter() {
eventsHelper.getEventTypes(this, false) {
val quickFilterEventTypes = config.quickFilterEventTypes
quick_event_type_filter.adapter = QuickFilterEventTypeAdapter(this, it, quickFilterEventTypes) {
refreshViewPager()
updateWidgets()
}
}
}
private fun closeSearch() {
mSearchMenuItem?.collapseActionView()
}
@ -448,6 +462,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun showFilterDialog() {
FilterEventTypesDialog(this) {
refreshViewPager()
setupQuickFilter()
updateWidgets()
}
}

View file

@ -10,6 +10,7 @@ import android.view.Menu
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.dialogs.SelectCalendarsDialog
import com.simplemobiletools.calendar.pro.dialogs.SelectEventTypeDialog
import com.simplemobiletools.calendar.pro.dialogs.SelectQuickFilterEventTypesDialog
import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.models.EventType
@ -46,6 +47,7 @@ class SettingsActivity : SimpleActivity() {
setupCustomizeNotifications()
setupUseEnglish()
setupManageEventTypes()
setupManageQuickFilterEventTypes()
setupHourFormat()
setupSundayFirst()
setupHighlightWeekends()
@ -164,6 +166,12 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupManageQuickFilterEventTypes() {
settings_manage_quick_filter_event_types_holder.setOnClickListener {
showQuickFilterPicker()
}
}
private fun setupHourFormat() {
settings_hour_format.isChecked = config.use24HourFormat
settings_hour_format_holder.setOnClickListener {
@ -278,6 +286,10 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun showQuickFilterPicker() {
SelectQuickFilterEventTypesDialog(this) {}
}
private fun setupSundayFirst() {
settings_sunday_first.isChecked = config.isSundayFirst
settings_sunday_first_holder.setOnClickListener {

View file

@ -0,0 +1,97 @@
package com.simplemobiletools.calendar.pro.adapters
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.models.EventType
import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA
import kotlinx.android.synthetic.main.quick_filter_event_type_view.view.*
import java.util.*
class QuickFilterEventTypeAdapter(val activity: SimpleActivity, val allEventTypes: List<EventType>, private val quickFilterEventTypeIds: Set<String>, val filterChanged: () -> Unit) :
RecyclerView.Adapter<QuickFilterEventTypeAdapter.ViewHolder>() {
private val activeKeys = HashSet<Long>()
private val quickFilterEventTypes = ArrayList<EventType>()
private val displayEventTypes = activity.config.displayEventTypes
private val textColorActive = activity.config.textColor
private val textColorInactive = textColorActive.adjustAlpha(MEDIUM_ALPHA)
private val minItemWidth = activity.resources.getDimensionPixelSize(R.dimen.quick_filter_min_width)
init {
quickFilterEventTypeIds.forEach { quickFilterEventType ->
// Find the associated eventType, return if none found
val eventType = allEventTypes.find { eventType -> eventType.id.toString() == quickFilterEventType }
?: return@forEach
quickFilterEventTypes.add(eventType)
// Check if it is currently active
if (displayEventTypes.contains(eventType.id.toString())) {
activeKeys.add(eventType.id!!)
}
}
}
private fun toggleItemSelection(select: Boolean, eventType: EventType, pos: Int) {
if (select) {
activeKeys.add(eventType.id!!)
} else {
activeKeys.remove(eventType.id)
}
notifyItemChanged(pos)
}
fun getSelectedItemsList() = activeKeys.asSequence().map { it }.toMutableList() as ArrayList<Long>
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val parentWidth = parent.measuredWidth
val nrOfItems = quickFilterEventTypes.size
val view = activity.layoutInflater.inflate(R.layout.quick_filter_event_type_view, parent, false)
if (nrOfItems * minItemWidth > parentWidth) view.layoutParams.width = minItemWidth
else view.layoutParams.width = parentWidth / nrOfItems
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val eventType = quickFilterEventTypes[position]
holder.bindView(eventType)
}
override fun getItemCount() = quickFilterEventTypes.size
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(eventType: EventType): View {
val isSelected = activeKeys.contains(eventType.id)
itemView.apply {
quick_filter_event_type.text = eventType.title
val textColor = if (isSelected) textColorActive else textColorInactive
quick_filter_event_type.setTextColor(textColor)
val indicatorHeight =
if (isSelected) resources.getDimensionPixelSize(R.dimen.quick_filter_active_line_size)
else resources.getDimensionPixelSize(R.dimen.quick_filter_inactive_line_size)
quick_filter_event_type_color.layoutParams.height = indicatorHeight
quick_filter_event_type_color.setBackgroundColor(eventType.color)
quick_filter_event_type.setOnClickListener {
viewClicked(!isSelected, eventType)
filterChanged()
}
}
return itemView
}
private fun viewClicked(select: Boolean, eventType: EventType) {
if (select)
activity.config.displayEventTypes = activity.config.displayEventTypes.plus(eventType.id.toString())
else
activity.config.displayEventTypes = activity.config.displayEventTypes.minus(eventType.id.toString())
toggleItemSelection(select, eventType, adapterPosition)
}
}
}

View file

@ -0,0 +1,38 @@
package com.simplemobiletools.calendar.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.dialog_filter_event_types.view.*
class SelectQuickFilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> Unit) {
private lateinit var dialog: AlertDialog
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null)
init {
activity.eventsHelper.getEventTypes(activity, false) {
val quickFilterEventTypes = activity.config.quickFilterEventTypes
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, quickFilterEventTypes)
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok) { dialogInterface, i -> confirmEventTypes() }
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this)
}
}
}
private fun confirmEventTypes() {
val selectedItems = (view.filter_event_types_list.adapter as FilterEventTypeAdapter).getSelectedItemsList().map { it.toString() }.toHashSet()
if (activity.config.quickFilterEventTypes != selectedItems) {
activity.config.quickFilterEventTypes = selectedItems
callback()
}
dialog.dismiss()
}
}

View file

@ -71,6 +71,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getStringSet(DISPLAY_EVENT_TYPES, HashSet<String>())!!
set(displayEventTypes) = prefs.edit().remove(DISPLAY_EVENT_TYPES).putStringSet(DISPLAY_EVENT_TYPES, displayEventTypes).apply()
var quickFilterEventTypes: Set<String>
get() = prefs.getStringSet(QUICK_FILTER_EVENT_TYPES, HashSet<String>())!!
set(quickFilterEventTypes) = prefs.edit().remove(QUICK_FILTER_EVENT_TYPES).putStringSet(QUICK_FILTER_EVENT_TYPES, quickFilterEventTypes).apply()
var listWidgetViewToOpen: Int
get() = prefs.getInt(LIST_WIDGET_VIEW_TO_OPEN, DAILY_VIEW)
set(viewToOpenFromListWidget) = prefs.edit().putInt(LIST_WIDGET_VIEW_TO_OPEN, viewToOpenFromListWidget).apply()

View file

@ -54,6 +54,7 @@ const val LAST_EVENT_REMINDER_MINUTES = "reminder_minutes"
const val LAST_EVENT_REMINDER_MINUTES_2 = "reminder_minutes_2"
const val LAST_EVENT_REMINDER_MINUTES_3 = "reminder_minutes_3"
const val DISPLAY_EVENT_TYPES = "display_event_types"
const val QUICK_FILTER_EVENT_TYPES = "quick_filter_event_types"
const val LIST_WIDGET_VIEW_TO_OPEN = "list_widget_view_to_open"
const val CALDAV_SYNC = "caldav_sync"
const val CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids"

View file

@ -5,28 +5,54 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragments_holder"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/quick_event_type_filter"
app:layout_constraintTop_toTopOf="parent">
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<FrameLayout
android:id="@+id/fragments_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simplemobiletools.commons.views.MyFloatingActionButton
android:id="@+id/calendar_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/activity_margin"
android:contentDescription="@string/new_event"
android:src="@drawable/ic_plus_vector"
app:backgroundTint="@color/color_primary"
app:rippleColor="@color/pressed_item_foreground" />
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.simplemobiletools.commons.views.MyFloatingActionButton
android:id="@+id/calendar_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/activity_margin"
android:layout_marginBottom="@dimen/activity_margin"
android:contentDescription="@string/new_event"
android:src="@drawable/ic_plus_vector"
app:backgroundTint="@color/color_primary"
app:layout_constraintBottom_toTopOf="@+id/quick_event_type_filter"
app:layout_constraintEnd_toEndOf="parent"
app:rippleColor="@color/pressed_item_foreground" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/quick_event_type_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:overScrollMode="never"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:rippleColor="@color/pressed_item_foreground" />
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:id="@+id/search_holder"

View file

@ -141,6 +141,27 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_manage_quick_filter_event_types_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/normal_margin"
android:paddingTop="@dimen/bigger_margin"
android:paddingEnd="@dimen/normal_margin"
android:paddingBottom="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_manage_quick_filter_event_types"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingStart="@dimen/medium_margin"
android:paddingEnd="@dimen/medium_margin"
android:text="@string/manage_quick_filter_event_types" />
</RelativeLayout>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/reminders_label"
android:layout_width="wrap_content"

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/quick_filter_event_type_holder"
android:layout_width="match_parent"
android:minWidth="@dimen/quick_filter_min_width"
android:layout_height="@dimen/quick_filter_height">
<Button
android:id="@+id/quick_filter_event_type"
android:layout_width="match_parent"
android:layout_height="@dimen/quick_filter_height"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="?attr/selectableItemBackground"
android:checked="false"
android:ellipsize="end"
android:maxLines="2"
android:paddingStart="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"
android:text=""
android:textAllCaps="false" />
<ImageView
android:id="@+id/quick_filter_event_type_color"
android:layout_width="match_parent"
android:layout_height="@dimen/quick_filter_inactive_line_size"
android:layout_above="@id/quick_filter_event_type"
android:layout_alignParentBottom="true"
android:clickable="false"
android:background="@color/color_primary" />
</RelativeLayout>

View file

@ -200,6 +200,7 @@
<string name="other_time">Andere Zeit</string>
<string name="highlight_weekends">Wochenenden in einigen Ansichten hervorheben</string>
<string name="allow_changing_time_zones">Zeitzone kann geändert werden</string>
<string name="manage_quick_filter_event_types">Termintypen zur schnellen Filterung verwalten</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>

View file

@ -32,4 +32,9 @@
<dimen name="avatar_size">40dp</dimen>
<dimen name="avatar_status_size">16dp</dimen>
<dimen name="quick_filter_height">48dp</dimen>
<dimen name="quick_filter_min_width">88dp</dimen>
<dimen name="quick_filter_active_line_size">4dp</dimen>
<dimen name="quick_filter_inactive_line_size">1dp</dimen>
</resources>

View file

@ -200,6 +200,7 @@
<string name="other_time">Other time</string>
<string name="highlight_weekends">Highlight weekends on some views</string>
<string name="allow_changing_time_zones">Allow changing event time zones</string>
<string name="manage_quick_filter_event_types">Manage quick filter event types</string>
<!-- CalDAV sync -->
<string name="caldav">CalDAV</string>