Created ScrollListView

This commit is contained in:
Pierre 2018-04-28 11:08:42 +02:00
parent fc9dabf238
commit 71a58ed337
4 changed files with 123 additions and 2 deletions

View File

@ -55,7 +55,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -0,0 +1,19 @@
package org.communiquons.android.comunic.client.ui.listeners;
/**
* On Scroll change listener
*
* This listener works with {@link org.communiquons.android.comunic.client.ui.views.ScrollListView}
*
* @author Pierre HUBERT
* Created by pierre on 4/28/18.
*/
public interface OnScrollChangeDetectListener {
/**
* This method is triggered when the user reach the top (first item) of the list view
*/
void onReachTop();
}

View File

@ -0,0 +1,102 @@
package org.communiquons.android.comunic.client.ui.views;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.AbsListView;
import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener;
/**
* Custom ListView with extended functions
*
* This class use some concepts from maXp StackOverFlow answer
* on question "Detect Scroll Up & Scroll down in ListView"
*
* @author Pierre HUBERT
* Created by pierre on 4/28/18.
*/
public class ScrollListView extends android.widget.ListView {
/**
* Debug tag
*/
private static final String TAG = "ScrollListView";
/**
* Optional additional scroll listener
*/
private OnScrollListener onScrollListener;
/**
* Scroll change detection listener
*/
private OnScrollChangeDetectListener onScrollChangeDetectListener;
public ScrollListView(Context context) {
super(context);
init();
}
public ScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ScrollListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public ScrollListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
/**
* Initialize this view
*/
private void init(){
super.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
//Call additional listener (if any)
if(onScrollListener != null)
onScrollListener.onScrollStateChanged(view, scrollState);
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
//Call additional listener (if any)
if(onScrollListener != null)
onScrollListener.onScroll(view, firstVisibleItem,
visibleItemCount, totalItemCount);
if(onScrollChangeDetectListener != null && firstVisibleItem == 0
&& visibleItemCount > 0)
onScrollChangeDetectListener.onReachTop();
}
});
}
@Override
public void setOnScrollListener(OnScrollListener onScrollListener) {
this.onScrollListener = onScrollListener;
}
public void setOnScrollChangeDetectListener(OnScrollChangeDetectListener onScrollChangeDetectListener) {
this.onScrollChangeDetectListener = onScrollChangeDetectListener;
}
public OnScrollListener getOnScrollListener() {
return onScrollListener;
}
}

View File

@ -21,7 +21,7 @@
android:layout_marginTop="10dp"/>
<!-- Messages -->
<ListView
<org.communiquons.android.comunic.client.ui.views.ScrollListView
android:id="@+id/fragment_conversation_messageslist"
android:layout_width="match_parent"
android:layout_height="0dp"