Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/CommonScrollListener.java
Show All 11 Lines | BusTO - Fragments components | ||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
GNU General Public License for more details. | GNU General Public License for more details. | ||||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
package it.reyboz.bustorino.fragments; | package it.reyboz.bustorino.fragments; | ||||
import androidx.annotation.NonNull; | |||||
import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||
import android.util.Log; | import android.util.Log; | ||||
import android.widget.AbsListView; | import android.widget.AbsListView; | ||||
import java.lang.ref.WeakReference; | import java.lang.ref.WeakReference; | ||||
public class CommonScrollListener extends RecyclerView.OnScrollListener implements AbsListView.OnScrollListener{ | public class CommonScrollListener extends RecyclerView.OnScrollListener implements AbsListView.OnScrollListener{ | ||||
WeakReference<FragmentListenerMain> listenerWeakReference; | WeakReference<FragmentListenerMain> listenerWeakReference; | ||||
//enable swipeRefreshLayout when scrolling down or not | //enable swipeRefreshLayout when scrolling down or not | ||||
boolean enableRefreshLayout; | boolean enableRefreshLayout; | ||||
int lastvisibleitem; | int lastvisibleitem; | ||||
public CommonScrollListener(FragmentListenerMain lis, boolean enableRefreshLayout){ | public CommonScrollListener(FragmentListenerMain lis, boolean enableRefreshLayout){ | ||||
listenerWeakReference = new WeakReference<>(lis); | listenerWeakReference = new WeakReference<>(lis); | ||||
this.enableRefreshLayout = enableRefreshLayout; | this.enableRefreshLayout = enableRefreshLayout; | ||||
} | } | ||||
@Override | @Override | ||||
public void onScrollStateChanged(AbsListView view, int scrollState) { | public void onScrollStateChanged(AbsListView absListView, int i) { | ||||
/* | |||||
* This seems to be a totally useless method | |||||
*/ | |||||
} | } | ||||
@Override | @Override | ||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | ||||
FragmentListenerMain listener = listenerWeakReference.get(); | FragmentListenerMain listener = listenerWeakReference.get(); | ||||
if(listener==null){ | if(listener==null){ | ||||
//can't do anything, sorry | //can't do anything, sorry | ||||
Log.i(this.getClass().getName(),"called onScroll but FragmentListener is null"); | Log.i(this.getClass().getName(),"called onScroll but FragmentListener is null"); | ||||
Show All 21 Lines | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | ||||
// enabling or disabling the refresh layout | // enabling or disabling the refresh layout | ||||
enable = firstItemVisible && topOfFirstItemVisible; | enable = firstItemVisible && topOfFirstItemVisible; | ||||
} | } | ||||
listener.enableRefreshLayout(enable); | listener.enableRefreshLayout(enable); | ||||
//Log.d(getString(R.string.list_fragment_debug),"onScroll active, first item visible: "+firstVisibleItem+", refreshlayout enabled: "+enable); | //Log.d(getString(R.string.list_fragment_debug),"onScroll active, first item visible: "+firstVisibleItem+", refreshlayout enabled: "+enable); | ||||
}} | }} | ||||
@Override | @Override | ||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { | ||||
FragmentListenerMain listener = listenerWeakReference.get(); | FragmentListenerMain listener = listenerWeakReference.get(); | ||||
if(newState!=SCROLL_STATE_IDLE) listener.showFloatingActionButton(false); | if(newState!=SCROLL_STATE_IDLE) listener.showFloatingActionButton(false); | ||||
else listener.showFloatingActionButton(true); | else listener.showFloatingActionButton(true); | ||||
} | } | ||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register