mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fix #96, add a Daily View
This commit is contained in:
@@ -264,6 +264,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
private fun showViewDialog() {
|
private fun showViewDialog() {
|
||||||
val res = resources
|
val res = resources
|
||||||
val items = arrayListOf(
|
val items = arrayListOf(
|
||||||
|
RadioItem(DAILY_VIEW, res.getString(R.string.daily_view)),
|
||||||
RadioItem(WEEKLY_VIEW, res.getString(R.string.weekly_view)),
|
RadioItem(WEEKLY_VIEW, res.getString(R.string.weekly_view)),
|
||||||
RadioItem(MONTHLY_VIEW, res.getString(R.string.monthly_view)),
|
RadioItem(MONTHLY_VIEW, res.getString(R.string.monthly_view)),
|
||||||
RadioItem(YEARLY_VIEW, res.getString(R.string.yearly_view)),
|
RadioItem(YEARLY_VIEW, res.getString(R.string.yearly_view)),
|
||||||
@@ -497,7 +498,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
|
|
||||||
when (config.storedView) {
|
when (config.storedView) {
|
||||||
MONTHLY_VIEW -> bundle.putString(DAY_CODE, Formatter.getTodayCode(applicationContext))
|
DAILY_VIEW, MONTHLY_VIEW -> bundle.putString(DAY_CODE, Formatter.getTodayCode(applicationContext))
|
||||||
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, getThisWeekDateTime())
|
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, getThisWeekDateTime())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,6 +526,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFragmentsHolder() = when (config.storedView) {
|
private fun getFragmentsHolder() = when (config.storedView) {
|
||||||
|
DAILY_VIEW -> DayFragmentsHolder()
|
||||||
MONTHLY_VIEW -> MonthFragmentsHolder()
|
MONTHLY_VIEW -> MonthFragmentsHolder()
|
||||||
YEARLY_VIEW -> YearFragmentsHolder()
|
YEARLY_VIEW -> YearFragmentsHolder()
|
||||||
EVENTS_LIST_VIEW -> EventListFragment()
|
EVENTS_LIST_VIEW -> EventListFragment()
|
||||||
|
@@ -0,0 +1,107 @@
|
|||||||
|
package com.simplemobiletools.calendar.fragments
|
||||||
|
|
||||||
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v4.view.ViewPager
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.simplemobiletools.calendar.R
|
||||||
|
import com.simplemobiletools.calendar.activities.MainActivity
|
||||||
|
import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter
|
||||||
|
import com.simplemobiletools.calendar.extensions.config
|
||||||
|
import com.simplemobiletools.calendar.helpers.DAY_CODE
|
||||||
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
|
import com.simplemobiletools.calendar.interfaces.NavigationListener
|
||||||
|
import com.simplemobiletools.commons.views.MyViewPager
|
||||||
|
import kotlinx.android.synthetic.main.fragment_days_holder.view.*
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
||||||
|
private val PREFILLED_DAYS = 121
|
||||||
|
|
||||||
|
private var viewPager: MyViewPager? = null
|
||||||
|
private var defaultDaylyPage = 0
|
||||||
|
private var todayDayCode = ""
|
||||||
|
private var currentDayCode = ""
|
||||||
|
private var isGoToTodayVisible = false
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
currentDayCode = arguments?.getString(DAY_CODE) ?: ""
|
||||||
|
todayDayCode = Formatter.getTodayCode(context!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
val view = inflater.inflate(R.layout.fragment_days_holder, container, false)
|
||||||
|
view.background = ColorDrawable(context!!.config.backgroundColor)
|
||||||
|
viewPager = view.fragment_days_viewpager
|
||||||
|
setupFragment()
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupFragment() {
|
||||||
|
val codes = getDays(currentDayCode)
|
||||||
|
val dailyAdapter = MyDayPagerAdapter(activity!!.supportFragmentManager, codes, this)
|
||||||
|
defaultDaylyPage = codes.size / 2
|
||||||
|
|
||||||
|
viewPager!!.apply {
|
||||||
|
adapter = dailyAdapter
|
||||||
|
addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageSelected(position: Int) {
|
||||||
|
currentDayCode = codes[position]
|
||||||
|
val shouldGoToTodayBeVisible = shouldGoToTodayBeVisible()
|
||||||
|
if (isGoToTodayVisible != shouldGoToTodayBeVisible) {
|
||||||
|
(activity as? MainActivity)?.toggleGoToTodayVisibility(shouldGoToTodayBeVisible)
|
||||||
|
isGoToTodayVisible = shouldGoToTodayBeVisible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
currentItem = defaultDaylyPage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getDays(code: String): List<String> {
|
||||||
|
val days = ArrayList<String>(PREFILLED_DAYS)
|
||||||
|
val today = Formatter.getDateTimeFromCode(code)
|
||||||
|
for (i in -PREFILLED_DAYS / 2..PREFILLED_DAYS / 2) {
|
||||||
|
days.add(Formatter.getDayCodeFromDateTime(today.plusDays(i)))
|
||||||
|
}
|
||||||
|
return days
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun goLeft() {
|
||||||
|
viewPager!!.currentItem = viewPager!!.currentItem - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun goRight() {
|
||||||
|
viewPager!!.currentItem = viewPager!!.currentItem + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun goToDateTime(dateTime: DateTime) {
|
||||||
|
currentDayCode = Formatter.getDayCodeFromDateTime(dateTime)
|
||||||
|
setupFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun goToToday() {
|
||||||
|
currentDayCode = todayDayCode
|
||||||
|
setupFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun refreshEvents() {
|
||||||
|
setupFragment()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun shouldGoToTodayBeVisible() = currentDayCode != todayDayCode
|
||||||
|
|
||||||
|
override fun updateActionBarTitle() {
|
||||||
|
(activity as MainActivity).supportActionBar?.title = getString(R.string.app_launcher_name)
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,7 @@ val MONTHLY_VIEW = 1
|
|||||||
val YEARLY_VIEW = 2
|
val YEARLY_VIEW = 2
|
||||||
val EVENTS_LIST_VIEW = 3
|
val EVENTS_LIST_VIEW = 3
|
||||||
val WEEKLY_VIEW = 4
|
val WEEKLY_VIEW = 4
|
||||||
|
val DAILY_VIEW = 5
|
||||||
|
|
||||||
val REMINDER_OFF = -1
|
val REMINDER_OFF = -1
|
||||||
|
|
||||||
|
@@ -4,7 +4,8 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/day_holder"
|
android:id="@+id/day_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/medium_margin">
|
||||||
|
|
||||||
<include layout="@layout/top_navigation"/>
|
<include layout="@layout/top_navigation"/>
|
||||||
|
|
||||||
|
8
app/src/main/res/layout/fragment_days_holder.xml
Normal file
8
app/src/main/res/layout/fragment_days_holder.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.simplemobiletools.commons.views.MyViewPager
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/fragment_days_viewpager"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"/>
|
Reference in New Issue
Block a user