Hiding FABs on scroll.
This commit is contained in:
parent
3bdfef9f8b
commit
9e6602f114
@ -1,3 +1,7 @@
|
|||||||
|
**master**
|
||||||
|
|
||||||
|
- Hiding FABs on scroll.
|
||||||
|
|
||||||
**1.5.4.10**
|
**1.5.4.10**
|
||||||
|
|
||||||
- Displaying a loader when "reading more" in the article viewer.
|
- Displaying a loader when "reading more" in the article viewer.
|
||||||
|
@ -124,6 +124,14 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
image.visibility = View.GONE
|
image.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nestedScrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||||
|
if (scrollY > oldScrollY) {
|
||||||
|
fab.hide()
|
||||||
|
} else {
|
||||||
|
fab.show()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent, prefs: SharedPreferences) {
|
private fun getContentFromMercury(customTabsIntent: CustomTabsIntent, prefs: SharedPreferences) {
|
||||||
|
@ -8,6 +8,7 @@ import android.support.v7.app.AppCompatActivity
|
|||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.support.v7.widget.Toolbar
|
import android.support.v7.widget.Toolbar
|
||||||
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter
|
import apps.amine.bou.readerforselfoss.adapters.SourcesListAdapter
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||||
@ -20,6 +21,8 @@ import retrofit2.Response
|
|||||||
|
|
||||||
class SourcesActivity : AppCompatActivity() {
|
class SourcesActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var mRecyclerView: RecyclerView
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
Scoop.getInstance().apply(this)
|
Scoop.getInstance().apply(this)
|
||||||
@ -30,10 +33,15 @@ class SourcesActivity : AppCompatActivity() {
|
|||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
mRecyclerView.clearOnScrollListeners()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
val mFab: FloatingActionButton = findViewById(R.id.fab)
|
val mFab: FloatingActionButton = findViewById(R.id.fab)
|
||||||
val mRecyclerView: RecyclerView = findViewById(R.id.activity_sources)
|
mRecyclerView = findViewById(R.id.activity_sources)
|
||||||
val mLayoutManager = LinearLayoutManager(this)
|
val mLayoutManager = LinearLayoutManager(this)
|
||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package apps.amine.bou.readerforselfoss.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.support.design.widget.CoordinatorLayout
|
||||||
|
import android.support.design.widget.FloatingActionButton
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
|
||||||
|
class ScrollAwareFABBehavior(context: Context, attrs: AttributeSet) : CoordinatorLayout.Behavior<FloatingActionButton>() {
|
||||||
|
|
||||||
|
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: FloatingActionButton,
|
||||||
|
directTargetChild: View, target: View, nestedScrollAxes: Int): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNestedScroll(coordinatorLayout: CoordinatorLayout,
|
||||||
|
child: FloatingActionButton,
|
||||||
|
target: View, dxConsumed: Int, dyConsumed: Int,
|
||||||
|
dxUnconsumed: Int, dyUnconsumed: Int) {
|
||||||
|
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
|
||||||
|
if (dyConsumed > 0 && child.visibility == View.VISIBLE) {
|
||||||
|
child.hide(object : FloatingActionButton.OnVisibilityChangedListener() {
|
||||||
|
override fun onHidden(fab: FloatingActionButton?) {
|
||||||
|
super.onHidden(fab)
|
||||||
|
fab!!.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} else if (dyConsumed < 0 && child.visibility != View.VISIBLE) {
|
||||||
|
child.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -43,5 +43,6 @@
|
|||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginRight="16dp" />
|
android:layout_marginRight="16dp"
|
||||||
|
app:layout_behavior="apps.amine.bou.readerforselfoss.utils.ScrollAwareFABBehavior" />
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user