adding a slider at the weekly view for changing days count

This commit is contained in:
tibbi
2020-06-08 12:14:11 +02:00
parent dfeee92598
commit 783890bf46
5 changed files with 79 additions and 11 deletions

View File

@@ -82,7 +82,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
appLaunched(BuildConfig.APPLICATION_ID) appLaunched(BuildConfig.APPLICATION_ID)
checkWhatsNewDialog() checkWhatsNewDialog()
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW) calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW && config.storedView != WEEKLY_VIEW)
calendar_fab.setOnClickListener { calendar_fab.setOnClickListener {
launchNewEventIntent(currentFragments.last().getNewEventDayCode()) launchNewEventIntent(currentFragments.last().getNewEventDayCode())
} }
@@ -279,7 +279,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
mIsSearchOpen = false mIsSearchOpen = false
search_holder.beGone() search_holder.beGone()
calendar_fab.beVisibleIf(currentFragments.last() !is YearFragmentsHolder) calendar_fab.beVisibleIf(currentFragments.last() !is YearFragmentsHolder && currentFragments.last() !is WeekFragmentsHolder)
invalidateOptionsMenu() invalidateOptionsMenu()
return true return true
} }
@@ -410,10 +410,9 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
RadioItem(EVENTS_LIST_VIEW, getString(R.string.simple_event_list))) RadioItem(EVENTS_LIST_VIEW, getString(R.string.simple_event_list)))
RadioGroupDialog(this, items, config.storedView) { RadioGroupDialog(this, items, config.storedView) {
calendar_fab.beVisibleIf(it as Int != YEARLY_VIEW)
resetActionBarTitle() resetActionBarTitle()
closeSearch() closeSearch()
updateView(it) updateView(it as Int)
shouldGoToTodayBeVisible = false shouldGoToTodayBeVisible = false
invalidateOptionsMenu() invalidateOptionsMenu()
} }
@@ -643,7 +642,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
private fun updateView(view: Int) { private fun updateView(view: Int) {
calendar_fab.beVisibleIf(view != YEARLY_VIEW) calendar_fab.beVisibleIf(view != YEARLY_VIEW && view != WEEKLY_VIEW)
config.storedView = view config.storedView = view
checkSwipeRefreshAvailability() checkSwipeRefreshAvailability()
updateViewPager() updateViewPager()

View File

@@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.DatePicker import android.widget.DatePicker
import android.widget.RelativeLayout
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@@ -28,6 +29,8 @@ import org.joda.time.DateTime
class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener { class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
private val PREFILLED_WEEKS = 151 private val PREFILLED_WEEKS = 151
private val MIN_SEEKBAR_VALUE = 1
private val MAX_SEEKBAR_VALUE = 14
private var viewPager: MyViewPager? = null private var viewPager: MyViewPager? = null
private var weekHolder: ViewGroup? = null private var weekHolder: ViewGroup? = null
@@ -104,6 +107,27 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
} }
}) })
weekHolder!!.week_view_hours_scrollview.setOnTouchListener { view, motionEvent -> true } weekHolder!!.week_view_hours_scrollview.setOnTouchListener { view, motionEvent -> true }
weekHolder!!.week_view_seekbar.apply {
progress = context?.config?.weeklyViewDays ?: 7
max = MAX_SEEKBAR_VALUE
onSeekBarChangeListener {
if (it == 0) {
progress = 1
}
updateWeeklyViewDays(progress)
}
}
// avoid seekbar width changing if the days count changes to 1, 10 etc
weekHolder!!.week_view_days_count.onGlobalLayout {
weekHolder!!.week_view_seekbar.layoutParams.width = weekHolder!!.week_view_seekbar.width
(weekHolder!!.week_view_seekbar.layoutParams as RelativeLayout.LayoutParams).removeRule(RelativeLayout.START_OF)
}
updateDaysCount(context?.config?.weeklyViewDays ?: 7)
updateActionBarTitle() updateActionBarTitle()
} }
@@ -149,11 +173,11 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, dateTime.dayOfMonth, null) datePicker.init(dateTime.year, dateTime.monthOfYear - 1, dateTime.dayOfMonth, null)
AlertDialog.Builder(context!!) AlertDialog.Builder(context!!)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok) { dialog, which -> dateSelected(dateTime, datePicker) } .setPositiveButton(R.string.ok) { dialog, which -> dateSelected(dateTime, datePicker) }
.create().apply { .create().apply {
activity?.setupDialogStuff(view, this) activity?.setupDialogStuff(view, this)
} }
} }
private fun dateSelected(dateTime: DateTime, datePicker: DatePicker) { private fun dateSelected(dateTime: DateTime, datePicker: DatePicker) {
@@ -176,6 +200,15 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
setupFragment() setupFragment()
} }
private fun updateWeeklyViewDays(days: Int) {
context!!.config.weeklyViewDays = days
updateDaysCount(days)
}
private fun updateDaysCount(cnt: Int) {
weekHolder!!.week_view_days_count.text = context!!.resources.getQuantityString(R.plurals.days, cnt, cnt)
}
override fun refreshEvents() { override fun refreshEvents() {
(viewPager?.adapter as? MyWeekPagerAdapter)?.updateCalendars(viewPager!!.currentItem) (viewPager?.adapter as? MyWeekPagerAdapter)?.updateCalendars(viewPager!!.currentItem)
} }

View File

@@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.pro.helpers
import android.content.Context import android.content.Context
import android.media.AudioManager import android.media.AudioManager
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.extensions.scheduleCalDAVSync import com.simplemobiletools.calendar.pro.extensions.scheduleCalDAVSync
import com.simplemobiletools.commons.extensions.getDefaultAlarmTitle import com.simplemobiletools.commons.extensions.getDefaultAlarmTitle
@@ -183,4 +182,8 @@ class Config(context: Context) : BaseConfig(context) {
var weeklyViewItemHeightMultiplier: Float var weeklyViewItemHeightMultiplier: Float
get() = prefs.getFloat(WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER, 1f) get() = prefs.getFloat(WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER, 1f)
set(weeklyViewItemHeightMultiplier) = prefs.edit().putFloat(WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER, weeklyViewItemHeightMultiplier).apply() set(weeklyViewItemHeightMultiplier) = prefs.edit().putFloat(WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER, weeklyViewItemHeightMultiplier).apply()
var weeklyViewDays: Int
get() = prefs.getInt(WEEKLY_VIEW_DAYS, 7)
set(weeklyViewDays) = prefs.edit().putInt(WEEKLY_VIEW_DAYS, weeklyViewDays).apply()
} }

View File

@@ -75,6 +75,7 @@ const val ALLOW_CHANGING_TIME_ZONES = "allow_changing_time_zones"
const val LAST_EXPORT_PATH = "last_export_path" const val LAST_EXPORT_PATH = "last_export_path"
const val EXPORT_PAST_EVENTS = "export_past_events" const val EXPORT_PAST_EVENTS = "export_past_events"
const val WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER = "weekly_view_item_height_multiplier" const val WEEKLY_VIEW_ITEM_HEIGHT_MULTIPLIER = "weekly_view_item_height_multiplier"
const val WEEKLY_VIEW_DAYS = "weekly_view_days"
// repeat_rule for monthly and yearly repetition // repeat_rule for monthly and yearly repetition
const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition) const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/week_view_holder" android:id="@+id/week_view_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -17,6 +18,7 @@
android:id="@+id/week_view_hours_scrollview" android:id="@+id/week_view_hours_scrollview"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_above="@+id/week_view_seekbar"
android:layout_below="@+id/week_view_hours_divider" android:layout_below="@+id/week_view_hours_divider"
android:background="@drawable/stroke_right" android:background="@drawable/stroke_right"
android:overScrollMode="never" android:overScrollMode="never"
@@ -35,6 +37,36 @@
android:id="@+id/week_view_view_pager" android:id="@+id/week_view_view_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@+id/week_view_seekbar"
android:layout_toEndOf="@+id/week_view_hours_scrollview" /> android:layout_toEndOf="@+id/week_view_hours_scrollview" />
<include
android:id="@+id/week_view_days_count_divider"
layout="@layout/divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_above="@+id/week_view_seekbar" />
<com.simplemobiletools.commons.views.MySeekBar
android:id="@+id/week_view_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="@dimen/activity_margin"
android:layout_toStartOf="@+id/week_view_days_count"
android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/week_view_days_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignTop="@+id/week_view_seekbar"
android:layout_alignBottom="@+id/week_view_seekbar"
android:layout_alignParentEnd="true"
android:layout_marginStart="@dimen/activity_margin"
android:layout_marginEnd="@dimen/activity_margin"
android:gravity="center_vertical"
tools:text="7 days" />
</RelativeLayout> </RelativeLayout>