implement Pull to refresh
This commit is contained in:
parent
97e0d3301f
commit
9c40031300
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -27,8 +28,10 @@ import java.util.List;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class ItemsFragment extends android.support.v4.app.Fragment implements AdapterView.OnItemClickListener {
|
public class ItemsFragment extends android.support.v4.app.Fragment
|
||||||
|
implements AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {
|
||||||
@BindView(R.id.items_list) ListView mListView;
|
@BindView(R.id.items_list) ListView mListView;
|
||||||
|
@BindView(R.id.items_swipe_refresh) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
|
|
||||||
private List<FileDirItem> mItems;
|
private List<FileDirItem> mItems;
|
||||||
private ItemInteractionListener mListener;
|
private ItemInteractionListener mListener;
|
||||||
|
@ -46,7 +49,9 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
mShowHidden = Config.newInstance(getContext()).getShowHidden();
|
mShowHidden = Config.newInstance(getContext()).getShowHidden();
|
||||||
|
mItems = new ArrayList<>();
|
||||||
fillItems();
|
fillItems();
|
||||||
|
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,8 +65,13 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad
|
||||||
|
|
||||||
private void fillItems() {
|
private void fillItems() {
|
||||||
final String path = getArguments().getString(Constants.PATH);
|
final String path = getArguments().getString(Constants.PATH);
|
||||||
mItems = getItems(path);
|
final List<FileDirItem> newItems = getItems(path);
|
||||||
Collections.sort(mItems);
|
Collections.sort(newItems);
|
||||||
|
if (mItems != null && newItems.toString().equals(mItems.toString())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mItems = newItems;
|
||||||
|
|
||||||
final ItemsAdapter adapter = new ItemsAdapter(getContext(), mItems);
|
final ItemsAdapter adapter = new ItemsAdapter(getContext(), mItems);
|
||||||
mListView.setAdapter(adapter);
|
mListView.setAdapter(adapter);
|
||||||
|
@ -108,6 +118,12 @@ public class ItemsFragment extends android.support.v4.app.Fragment implements Ad
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
fillItems();
|
||||||
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
|
}
|
||||||
|
|
||||||
public interface ItemInteractionListener {
|
public interface ItemInteractionListener {
|
||||||
void itemClicked(String path);
|
void itemClicked(String path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,16 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<android.support.v4.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/items_swipe_refresh"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/items_list"
|
android:id="@+id/items_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:paddingLeft="@dimen/activity_margin"/>
|
android:paddingLeft="@dimen/activity_margin"/>
|
||||||
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Loading…
Reference in New Issue