From 916f941e941efbc9e324e115f3f635ab053001fd Mon Sep 17 00:00:00 2001 From: Ezerous Date: Tue, 11 Jul 2017 14:36:32 +0300 Subject: [PATCH] ForumFragment can be refreshed manually --- .../activities/main/forum/ForumFragment.java | 21 ++++++++++++++-- app/src/main/res/layout/fragment_forum.xml | 25 +++++++++++-------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index b8e3c140..83f7d748 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java @@ -2,9 +2,9 @@ package gr.thmmy.mthmmy.activities.main.forum; import android.os.AsyncTask; import android.os.Bundle; +import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,6 +26,7 @@ import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.Board; import gr.thmmy.mthmmy.model.Category; import gr.thmmy.mthmmy.session.SessionManager; +import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.ParseTask; import gr.thmmy.mthmmy.utils.exceptions.ParseException; import me.zhanghai.android.materialprogressbar.MaterialProgressBar; @@ -47,6 +48,7 @@ public class ForumFragment extends BaseFragment // Fragment initialization parameters, e.g. ARG_SECTION_NUMBER private MaterialProgressBar progressBar; + private SwipeRefreshLayout swipeRefreshLayout; private ForumAdapter forumAdapter; private List categories; @@ -124,7 +126,7 @@ public class ForumFragment extends BaseFragment } }); - RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.list); + CustomRecyclerView recyclerView = (CustomRecyclerView) rootView.findViewById(R.id.list); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(rootView.findViewById(R.id.list).getContext()); recyclerView.setLayoutManager(linearLayoutManager); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), @@ -132,6 +134,20 @@ public class ForumFragment extends BaseFragment recyclerView.addItemDecoration(dividerItemDecoration); recyclerView.setAdapter(forumAdapter); + swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swiperefresh); + swipeRefreshLayout.setOnRefreshListener( + new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + if (forumTask != null && forumTask.getStatus() != AsyncTask.Status.RUNNING) { + forumTask = new ForumTask(); + forumTask.execute(SessionManager.indexUrl.toString()); + } + } + + } + ); + } return rootView; } @@ -209,6 +225,7 @@ public class ForumFragment extends BaseFragment forumAdapter.notifyParentDataSetChanged(false); progressBar.setVisibility(ProgressBar.INVISIBLE); + swipeRefreshLayout.setRefreshing(false); } public void setUrl(String string) //TODO delete and simplify e.g. in prepareRequest possible? diff --git a/app/src/main/res/layout/fragment_forum.xml b/app/src/main/res/layout/fragment_forum.xml index 49bf6061..04c4ec4e 100644 --- a/app/src/main/res/layout/fragment_forum.xml +++ b/app/src/main/res/layout/fragment_forum.xml @@ -6,17 +6,22 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"> + + +