update commons to 2.12.9

This commit is contained in:
tibbi 2017-03-18 19:48:03 +01:00
parent fc1fd0f505
commit b1a20f51e0
8 changed files with 5 additions and 161 deletions

View file

@ -32,7 +32,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.12.7'
compile 'com.simplemobiletools:commons:2.12.9'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile 'com.google.code.gson:gson:2.8.0'

View file

@ -1,124 +0,0 @@
package com.simplemobiletools.gallery.views
import android.content.Context
import android.graphics.PorterDuff
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.widget.LinearLayout
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.config
import kotlinx.android.synthetic.main.fastscroller.view.*
// based on https://blog.stylingandroid.com/recyclerview-fastscroll-part-1
class FastScroller : LinearLayout {
private val handle: View
private var currHeight = 0
private val HANDLE_HIDE_DELAY = 1000L
private var recyclerView: RecyclerView? = null
private var swipeRefreshLayout: SwipeRefreshLayout? = null
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
fun setViews(recyclerView: RecyclerView, swipeRefreshLayout: SwipeRefreshLayout) {
this.recyclerView = recyclerView
this.swipeRefreshLayout = swipeRefreshLayout
handle.background.setColorFilter(context.config.primaryColor, PorterDuff.Mode.SRC_IN)
recyclerView.setOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(rv: RecyclerView, dx: Int, dy: Int) {
updateHandlePosition()
}
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
showHandle()
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
hideHandle()
}
}
})
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
currHeight = h
updateHandlePosition()
}
private fun updateHandlePosition() {
if (handle.isSelected || recyclerView == null)
return
val verticalScrollOffset = recyclerView!!.computeVerticalScrollOffset()
val verticalScrollRange = recyclerView!!.computeVerticalScrollRange()
val proportion = verticalScrollOffset.toFloat() / (verticalScrollRange.toFloat() - currHeight)
setPosition(currHeight * proportion)
}
override fun onTouchEvent(event: MotionEvent): Boolean {
return when (event.action) {
MotionEvent.ACTION_DOWN -> {
showHandle()
handle.isSelected = true
swipeRefreshLayout?.isEnabled = false
true
}
MotionEvent.ACTION_MOVE -> {
setPosition(event.y)
setRecyclerViewPosition(event.y)
true
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
hideHandle()
handle.isSelected = false
swipeRefreshLayout?.isEnabled = true
true
}
else -> super.onTouchEvent(event)
}
}
private fun setRecyclerViewPosition(y: Float) {
if (recyclerView != null) {
val itemCount = recyclerView!!.adapter.itemCount
val proportion = y / currHeight
val targetPos = getValueInRange(0f, (itemCount - 1).toFloat(), proportion * itemCount).toInt()
(recyclerView!!.layoutManager as GridLayoutManager).scrollToPositionWithOffset(targetPos, 0)
}
}
init {
orientation = LinearLayout.HORIZONTAL
clipChildren = false
val inflater = LayoutInflater.from(context)
inflater.inflate(R.layout.fastscroller, this)
handle = fastscroller_handle
}
private fun showHandle() {
handle.animate().alpha(1f).startDelay = 0L
}
private fun hideHandle() {
handle.animate().alpha(0f).startDelay = HANDLE_HIDE_DELAY
}
private fun setPosition(y: Float) {
val position = y / currHeight
val handleHeight = handle.height
handle.y = getValueInRange(0f, (currHeight - handleHeight).toFloat(), (currHeight - handleHeight) * position)
}
private fun getValueInRange(min: Float, max: Float, value: Float) = Math.min(Math.max(min, value), max)
}

View file

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="@dimen/normal_margin"
android:bottomLeftRadius="@dimen/normal_margin"/>
<solid android:color="@color/color_primary"/>
<size
android:width="@dimen/fastscroll_width"
android:height="@dimen/fastscroll_height"/>
</shape>

View file

@ -19,7 +19,7 @@
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="@integer/directory_columns"/>
<com.simplemobiletools.gallery.views.FastScroller
<com.simplemobiletools.commons.views.FastScroller
android:id="@+id/directories_fastscroller"
android:layout_width="wrap_content"
android:layout_height="match_parent"

View file

@ -19,7 +19,7 @@
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="@integer/media_columns"/>
<com.simplemobiletools.gallery.views.FastScroller
<com.simplemobiletools.commons.views.FastScroller
android:id="@+id/media_fastscroller"
android:layout_width="wrap_content"
android:layout_height="match_parent"

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="@+id/fastscroller_handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:background="@drawable/fastscroller_handle"/>
</merge>

View file

@ -19,8 +19,8 @@
<ImageView
android:id="@+id/managed_folders_icon"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="@dimen/exclude_folder_img_size"
android:layout_height="@dimen/exclude_folder_img_size"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="@dimen/medium_margin"

View file

@ -7,7 +7,4 @@
<dimen name="play_outline_size_big">160dp</dimen>
<dimen name="timer_padding">24dp</dimen>
<dimen name="tmb_shadow_height">50dp</dimen>
<dimen name="exclude_folder_img_size">48dp</dimen>
<dimen name="fastscroll_width">6dp</dimen>
<dimen name="fastscroll_height">40dp</dimen>
</resources>