add the scrolling views

This commit is contained in:
tibbi 2017-01-15 18:37:51 +01:00
parent f9cf4e8b80
commit ff4b7374c2
7 changed files with 201 additions and 17 deletions

View File

@ -18,8 +18,10 @@ import com.simplemobiletools.calendar.dialogs.ChangeViewDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.updateWidgets
import com.simplemobiletools.calendar.fragments.EventListFragment
import com.simplemobiletools.calendar.fragments.WeekFragment
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.views.MyScrollView
import com.simplemobiletools.commons.extensions.checkWhatsNew
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.LICENSE_JODA
@ -40,6 +42,10 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
private var mEventListFragment: EventListFragment? = null
private var mStoredTextColor = 0
companion object {
var mWeekScrollY = 0
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@ -116,6 +122,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
val targetDay = DateTime().toString(Formatter.DAYCODE_PATTERN)
fillMonthlyViewPager(targetDay)
}
mWeekScrollY = 0
}
private fun launchSettings() {
@ -161,7 +169,12 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
}
private fun fillWeeklyViewPager() {
val weeklyAdapter = MyWeekPagerAdapter(supportFragmentManager)
val weeklyAdapter = MyWeekPagerAdapter(supportFragmentManager, object : WeekFragment.WeekScrollListener {
override fun scrollTo(y: Int) {
week_view_hours_scrollview.scrollY = y
mWeekScrollY = y
}
})
main_view_pager.visibility = View.GONE
calendar_event_list_holder.visibility = View.GONE
main_weekly_scrollview.visibility = View.VISIBLE
@ -173,6 +186,15 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
view.text = if (value.length == 2) value else "0$value"
week_view_hours_holder.addView(view)
}
week_view_view_pager.adapter = weeklyAdapter
week_view_hours_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
mWeekScrollY = y
weeklyAdapter.updateScrollY(week_view_view_pager.currentItem, y)
}
})
}
private fun fillYearlyViewPager() {

View File

@ -4,16 +4,26 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.util.SparseArray
import com.simplemobiletools.calendar.fragments.WeekFragment
class MyWeekPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
class MyWeekPagerAdapter(fm: FragmentManager, private val mListener: WeekFragment.WeekScrollListener) : FragmentStatePagerAdapter(fm) {
private val mFragments = SparseArray<WeekFragment>()
override fun getCount() = 1
override fun getCount() = 3
override fun getItem(position: Int): Fragment {
val bundle = Bundle()
val fragment = WeekFragment()
fragment.arguments = bundle
fragment.setListener(mListener)
mFragments.put(position, fragment)
return fragment
}
fun updateScrollY(pos: Int, y: Int) {
(-1..1).map { mFragments[pos + it] }
.forEach { it?.updateScrollY(y) }
}
}

View File

@ -5,17 +5,36 @@ import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.MainActivity
import com.simplemobiletools.calendar.helpers.DBHelper
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.views.MyScrollView
import kotlinx.android.synthetic.main.fragment_week.view.*
import java.util.*
import kotlin.comparisons.compareBy
class WeekFragment : Fragment(), DBHelper.GetEventsListener {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_week, container, false)
private var mListener: WeekScrollListener? = null
lateinit var mView: View
return view
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater.inflate(R.layout.fragment_week, container, false)
mView.week_events_scrollview.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
mListener?.scrollTo(y)
}
})
mView.week_events_scrollview.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
updateScrollY(MainActivity.mWeekScrollY)
mView.week_events_scrollview.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
return mView
}
override fun gotEvents(events: MutableList<Event>) {
@ -24,4 +43,16 @@ class WeekFragment : Fragment(), DBHelper.GetEventsListener {
}
}
fun setListener(listener: WeekScrollListener) {
mListener = listener
}
fun updateScrollY(y: Int) {
mView.week_events_scrollview.scrollY = y
}
interface WeekScrollListener {
fun scrollTo(y: Int)
}
}

View File

@ -0,0 +1,28 @@
package com.simplemobiletools.calendar.views
import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
class MyScrollView : ScrollView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
var scrollViewListener: ScrollViewListener? = null
fun setOnScrollviewListener(scrollViewListener: ScrollViewListener) {
this.scrollViewListener = scrollViewListener
}
override fun onScrollChanged(x: Int, y: Int, oldx: Int, oldy: Int) {
super.onScrollChanged(x, y, oldx, oldy)
scrollViewListener?.onScrollChanged(this, x, y, oldx, oldy)
}
interface ScrollViewListener {
fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int)
}
}

View File

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
<LinearLayout
android:id="@+id/main_weekly_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -19,17 +19,29 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/week_view_hours_holder"
android:layout_width="match_parent"
<com.simplemobiletools.calendar.views.MyScrollView
android:id="@+id/week_view_hours_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/weekly_view_row_height">
android:layout_marginTop="@dimen/weekly_view_day_letters_height"
android:overScrollMode="never"
android:scrollbars="none">
</LinearLayout>
<LinearLayout
android:id="@+id/week_view_hours_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/weekly_view_row_height"/>
</com.simplemobiletools.calendar.views.MyScrollView>
<com.simplemobiletools.commons.views.MyViewPager
android:id="@+id/week_view_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
<com.simplemobiletools.commons.views.MyViewPager
android:id="@+id/main_view_pager"

View File

@ -1,8 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/week_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
</RelativeLayout>
<LinearLayout
android:id="@+id/week_letters_holder"
android:layout_width="match_parent"
android:layout_height="@dimen/weekly_view_day_letters_height"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/monday_letter"/>
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/tuesday_letter"/>
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/wednesday_letter"/>
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/thursday_letter"/>
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/friday_letter"/>
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/saturday_letter"/>
<com.simplemobiletools.commons.views.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/sunday_letter"/>
</LinearLayout>
<com.simplemobiletools.calendar.views.MyScrollView
android:id="@+id/week_events_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none">
<LinearLayout
android:id="@+id/week_events_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v4.widget.Space
android:layout_width="wrap_content"
android:layout_height="@dimen/weekly_view_events_height"/>
</LinearLayout>
</com.simplemobiletools.calendar.views.MyScrollView>
</LinearLayout>

View File

@ -4,6 +4,8 @@
<dimen name="yearly_padding_full">6dp</dimen>
<dimen name="weekly_view_row_height">60dp</dimen>
<dimen name="weekly_view_events_height">1440dp</dimen> <!-- weekly_view_row_height * 24 hours -->
<dimen name="weekly_view_day_letters_height">24dp</dimen>
<dimen name="min_widget_width">250dp</dimen>
<dimen name="min_widget_height">250dp</dimen>