From 93156e99aa50728315c17475af6b1375fe71937c Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 11 Nov 2017 20:57:29 -0800 Subject: [PATCH] Updated build dependencies, and also switched to a new fastscroller library for RecyclerView that seems to work more smoothly on older devices. Also, the implementation of it seems pretty simple, and should be relatively easy to debug if problems arise. --- src/musikdroid/app/build.gradle | 8 ++-- .../remote/ui/activity/AlbumBrowseActivity.kt | 7 ++-- .../ui/activity/CategoryBrowseActivity.kt | 7 ++-- .../remote/ui/activity/PlayQueueActivity.kt | 9 ++--- .../remote/ui/activity/TrackListActivity.kt | 10 ++--- .../remote/ui/extension/Extensions.kt | 5 +-- .../remote/ui/model/TrackListSlidingWindow.kt | 38 ++++++++----------- .../remote/websocket/WebSocketService.kt | 6 ++- .../res/layout/recycler_view_activity.xml | 26 ++++--------- src/musikdroid/build.gradle | 2 +- 10 files changed, 47 insertions(+), 71 deletions(-) diff --git a/src/musikdroid/app/build.gradle b/src/musikdroid/app/build.gradle index c6a918ff7..923277f69 100644 --- a/src/musikdroid/app/build.gradle +++ b/src/musikdroid/app/build.gradle @@ -69,9 +69,9 @@ dependencies { implementation(name:'videocache-2.8.0-pre', ext:'aar') implementation 'org.slf4j:slf4j-android:1.7.21' - implementation "android.arch.persistence.room:runtime:1.0.0-alpha9-1" - annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha9-1" - kapt "android.arch.persistence.room:compiler:1.0.0-alpha9-1" + implementation "android.arch.persistence.room:runtime:1.0.0" + annotationProcessor "android.arch.persistence.room:compiler:1.0.0" + kapt "android.arch.persistence.room:compiler:1.0.0" compileOnly 'org.glassfish:javax.annotation:10.0-b28' implementation 'com.google.dagger:dagger:2.11' @@ -85,7 +85,7 @@ dependencies { implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'com.google.android.exoplayer:exoplayer:r2.4.2' implementation 'com.google.android.exoplayer:extension-okhttp:r2.4.2' - implementation 'com.github.pluscubed:recycler-fast-scroll:0.3.2@aar' + implementation 'com.simplecityapps:recyclerview-fastscroll:1.0.16' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support:appcompat-v7:26.1.0' diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/AlbumBrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/AlbumBrowseActivity.kt index baf0a5c17..a74c9fae1 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/AlbumBrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/AlbumBrowseActivity.kt @@ -9,7 +9,7 @@ import android.view.Menu import android.view.View import android.view.ViewGroup import android.widget.TextView -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller +import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import io.casey.musikcube.remote.R import io.casey.musikcube.remote.data.IAlbum import io.casey.musikcube.remote.data.ICategoryValue @@ -43,9 +43,8 @@ class AlbumBrowseActivity : BaseActivity(), Filterable { setTitleFromIntent(R.string.albums_title) enableUpNavigation() - val fastScroller = findViewById(R.id.fast_scroller) - val recyclerView = findViewById(R.id.recycler_view) - setupDefaultRecyclerView(recyclerView, fastScroller, adapter) + val recyclerView = findViewById(R.id.recycler_view) + setupDefaultRecyclerView(recyclerView, adapter) emptyView = findViewById(R.id.empty_list_view) emptyView.capability = EmptyListView.Capability.OnlineOnly diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/CategoryBrowseActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/CategoryBrowseActivity.kt index fa43ee1e2..912bfa475 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/CategoryBrowseActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/CategoryBrowseActivity.kt @@ -9,7 +9,7 @@ import android.view.Menu import android.view.View import android.view.ViewGroup import android.widget.TextView -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller +import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import io.casey.musikcube.remote.R import io.casey.musikcube.remote.data.ICategoryValue import io.casey.musikcube.remote.data.IDataProvider @@ -48,9 +48,8 @@ class CategoryBrowseActivity : BaseActivity(), Filterable { setContentView(R.layout.recycler_view_activity) setTitle(categoryTitleStringId) - val fastScroller = findViewById(R.id.fast_scroller) - val recyclerView = findViewById(R.id.recycler_view) - setupDefaultRecyclerView(recyclerView, fastScroller, adapter) + val recyclerView = findViewById(R.id.recycler_view) + setupDefaultRecyclerView(recyclerView, adapter) emptyView = findViewById(R.id.empty_list_view) emptyView.capability = EmptyListView.Capability.OnlineOnly diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/PlayQueueActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/PlayQueueActivity.kt index 2d60705e1..f189bf449 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/PlayQueueActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/PlayQueueActivity.kt @@ -8,7 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller +import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import io.casey.musikcube.remote.R import io.casey.musikcube.remote.data.IDataProvider import io.casey.musikcube.remote.data.ITrack @@ -33,9 +33,8 @@ class PlayQueueActivity : BaseActivity() { setContentView(R.layout.recycler_view_activity) - val fastScroller = findViewById(R.id.fast_scroller) - val recyclerView = findViewById(R.id.recycler_view) - setupDefaultRecyclerView(recyclerView, fastScroller, adapter) + val recyclerView = findViewById(R.id.recycler_view) + setupDefaultRecyclerView(recyclerView, adapter) emptyView = findViewById(R.id.empty_list_view) emptyView.capability = EmptyListView.Capability.OfflineOk @@ -45,7 +44,7 @@ class PlayQueueActivity : BaseActivity() { val queryFactory = playback!!.playlistQueryFactory offlineQueue = playback!!.playlistQueryFactory.offline() - tracks = TrackListSlidingWindow(recyclerView, fastScroller, dataProvider, queryFactory) + tracks = TrackListSlidingWindow(recyclerView, dataProvider, queryFactory) tracks.setInitialPosition(intent.getIntExtra(EXTRA_PLAYING_INDEX, -1)) tracks.setOnMetadataLoadedListener(slidingWindowListener) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/TrackListActivity.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/TrackListActivity.kt index 7bf672edc..638a81787 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/TrackListActivity.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/activity/TrackListActivity.kt @@ -9,7 +9,7 @@ import android.view.Menu import android.view.View import android.view.ViewGroup import android.widget.TextView -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller +import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import io.casey.musikcube.remote.R import io.casey.musikcube.remote.data.IDataProvider import io.casey.musikcube.remote.data.ITrack @@ -51,9 +51,8 @@ class TrackListActivity : BaseActivity(), Filterable { val queryFactory = createCategoryQueryFactory(categoryType, categoryId) - val fastScroller = findViewById(R.id.fast_scroller) - val recyclerView = findViewById(R.id.recycler_view) - setupDefaultRecyclerView(recyclerView, fastScroller, adapter) + val recyclerView = findViewById(R.id.recycler_view) + setupDefaultRecyclerView(recyclerView, adapter) emptyView = findViewById(R.id.empty_list_view) emptyView.let { @@ -62,8 +61,7 @@ class TrackListActivity : BaseActivity(), Filterable { it.alternateView = recyclerView } - tracks = TrackListSlidingWindow( - recyclerView, fastScroller, dataProvider, queryFactory) + tracks = TrackListSlidingWindow(recyclerView, dataProvider, queryFactory) tracks.setOnMetadataLoadedListener(slidingWindowListener) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/extension/Extensions.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/extension/Extensions.kt index be7709f92..6a82353f6 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/extension/Extensions.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/extension/Extensions.kt @@ -19,23 +19,20 @@ import android.widget.CheckBox import android.widget.CompoundButton import android.widget.EditText import android.widget.TextView -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller import io.casey.musikcube.remote.R import io.casey.musikcube.remote.ui.activity.Filterable import io.casey.musikcube.remote.ui.fragment.TransportFragment import io.casey.musikcube.remote.util.Strings -var EXTRA_ACTIVITY_TITLE = "extra_title" +val EXTRA_ACTIVITY_TITLE = "extra_title" fun AppCompatActivity.setupDefaultRecyclerView( recyclerView: RecyclerView, - fastScroller: RecyclerFastScroller, adapter: RecyclerView.Adapter<*>) { val layoutManager = LinearLayoutManager(this) recyclerView.layoutManager = LinearLayoutManager(this) recyclerView.adapter = adapter - fastScroller.attachRecyclerView(recyclerView) val dividerItemDecoration = DividerItemDecoration(this, layoutManager.orientation) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/model/TrackListSlidingWindow.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/model/TrackListSlidingWindow.kt index fb1fbde6e..ddb34a0a9 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/model/TrackListSlidingWindow.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/ui/model/TrackListSlidingWindow.kt @@ -2,16 +2,14 @@ package io.casey.musikcube.remote.ui.model import android.support.v7.widget.RecyclerView import android.util.Log -import android.view.MotionEvent -import android.view.View -import com.pluscubed.recyclerfastscroll.RecyclerFastScroller +import com.simplecityapps.recyclerview_fastscroll.interfaces.OnFastScrollStateChangeListener +import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView import io.casey.musikcube.remote.data.IDataProvider import io.casey.musikcube.remote.data.ITrack import io.reactivex.Observable import io.reactivex.disposables.CompositeDisposable -class TrackListSlidingWindow(private val recyclerView: RecyclerView, - private val fastScroller: RecyclerFastScroller, +class TrackListSlidingWindow(private val recyclerView: FastScrollRecyclerView, val dataProvider: IDataProvider, private val queryFactory: TrackListSlidingWindow.QueryFactory) { @@ -57,19 +55,14 @@ class TrackListSlidingWindow(private val recyclerView: RecyclerView, notifyMetadataLoaded(0, 0) } - private val fastScrollerTouch by lazy { - View.OnTouchListener { _, event -> - if (event != null) { - val type = event.actionMasked - if (type == MotionEvent.ACTION_DOWN) { - fastScrollerActive = true - } - else if (type == MotionEvent.ACTION_UP) { - fastScrollerActive = false - requery() - } - } - false + private val fastScrollStateChangeListener = object: OnFastScrollStateChangeListener { + override fun onFastScrollStop() { + fastScrollerActive = false + requery() + } + + override fun onFastScrollStart() { + fastScrollerActive = true } } @@ -108,8 +101,7 @@ class TrackListSlidingWindow(private val recyclerView: RecyclerView, fun pause() { connected = false - recyclerView.removeOnScrollListener(_scrollListener) - fastScroller.setOnHandleTouchListener(null) + recyclerView.removeOnScrollListener(recyclerViewScrollListener) disposables.dispose() disposables = CompositeDisposable() } @@ -118,8 +110,8 @@ class TrackListSlidingWindow(private val recyclerView: RecyclerView, disposables.add(dataProvider.observePlayQueue() .subscribe({ requery() }, { /* error */ })) - recyclerView.addOnScrollListener(_scrollListener) - fastScroller.setOnHandleTouchListener(fastScrollerTouch) + recyclerView.setStateChangeListener(fastScrollStateChangeListener) + recyclerView.addOnScrollListener(recyclerViewScrollListener) connected = true fastScrollerActive = false } @@ -209,7 +201,7 @@ class TrackListSlidingWindow(private val recyclerView: RecyclerView, return scrollState != RecyclerView.SCROLL_STATE_IDLE || fastScrollerActive } - private val _scrollListener = object : RecyclerView.OnScrollListener() { + private val recyclerViewScrollListener = object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) { scrollState = newState if (!scrolling()) { diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/websocket/WebSocketService.kt b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/websocket/WebSocketService.kt index daebad624..24cce2e00 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/websocket/WebSocketService.kt +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/websocket/WebSocketService.kt @@ -12,6 +12,8 @@ import io.casey.musikcube.remote.util.NetworkUtil import io.casey.musikcube.remote.util.Preconditions import io.reactivex.Observable import io.reactivex.subjects.PublishSubject +import io.reactivex.subjects.ReplaySubject +import io.reactivex.subjects.Subject import java.util.* import java.util.concurrent.atomic.AtomicLong @@ -293,7 +295,9 @@ class WebSocketService constructor(private val context: Context) { throw Exception("socket disconnected") } else if (socket == null) { - throw Exception("socket not connected") + val replay = ReplaySubject.create() + replay.onError(Exception("socket not connected")) + return replay } } diff --git a/src/musikdroid/app/src/main/res/layout/recycler_view_activity.xml b/src/musikdroid/app/src/main/res/layout/recycler_view_activity.xml index 3b6f00462..c30a03f7a 100644 --- a/src/musikdroid/app/src/main/res/layout/recycler_view_activity.xml +++ b/src/musikdroid/app/src/main/res/layout/recycler_view_activity.xml @@ -1,6 +1,5 @@ - - - - - - - - + android:layout_height="match_parent" + app:fastScrollAutoHide="true" + app:fastScrollAutoHideDelay="1500" + app:fastScrollThumbColor="@color/color_accent" />