Commit d38df244 authored by Robert Hitt's avatar Robert Hitt
Browse files

Added pull for refresh to facility list view

parent 790f73f5
...@@ -25,16 +25,17 @@ import srct.whatsopen.model.OpenTimes; ...@@ -25,16 +25,17 @@ import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.model.SpecialSchedule; import srct.whatsopen.model.SpecialSchedule;
import srct.whatsopen.service.WhatsOpenService; import srct.whatsopen.service.WhatsOpenService;
import srct.whatsopen.service.WhatsOpenApi; import srct.whatsopen.service.WhatsOpenApi;
import srct.whatsopen.views.MainView;
import srct.whatsopen.views.activities.MainActivity; import srct.whatsopen.views.activities.MainActivity;
public class MainPresenter { public class MainPresenter {
private MainActivity mMainView; private MainView mMainView;
private SharedPreferences pref; private SharedPreferences pref;
public void attachView(MainActivity view) { public void attachView(MainView view) {
this.mMainView = view; this.mMainView = view;
pref = PreferenceManager.getDefaultSharedPreferences(mMainView); pref = PreferenceManager.getDefaultSharedPreferences(mMainView.getContext());
} }
public void detachView() { public void detachView() {
......
package srct.whatsopen.views; package srct.whatsopen.views;
import android.content.Context;
public interface MainView { public interface MainView {
public void showProgressBar(); public void showProgressBar();
public void dismissProgressBar(); public void dismissProgressBar();
public Context getContext();
} }
package srct.whatsopen.views.activities; package srct.whatsopen.views.activities;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
...@@ -98,6 +99,11 @@ public class MainActivity extends AppCompatActivity implements MainView { ...@@ -98,6 +99,11 @@ public class MainActivity extends AppCompatActivity implements MainView {
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
} }
@Override
public Context getContext() {
return this;
}
// Opens the About page for the app // Opens the About page for the app
private void expandAboutActivity() { private void expandAboutActivity() {
Intent i = new Intent(this, AboutActivity.class); Intent i = new Intent(this, AboutActivity.class);
......
package srct.whatsopen.views.fragments; package srct.whatsopen.views.fragments;
import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import io.realm.Realm; import io.realm.Realm;
import io.realm.Sort; import io.realm.Sort;
import srct.whatsopen.R; import srct.whatsopen.R;
import srct.whatsopen.model.Facility; import srct.whatsopen.model.Facility;
import srct.whatsopen.presenters.MainPresenter;
import srct.whatsopen.views.MainView;
import srct.whatsopen.views.decorations.DividerItemDecoration; import srct.whatsopen.views.decorations.DividerItemDecoration;
import srct.whatsopen.views.adapters.FacilityListAdapter; import srct.whatsopen.views.adapters.FacilityListAdapter;
public class FacilityListFragment extends android.support.v4.app.Fragment { public class FacilityListFragment extends android.support.v4.app.Fragment implements MainView {
public static final String ARG_MODE = "ARG_MODE"; public static final String ARG_MODE = "ARG_MODE";
private String mMode; private String mMode;
private Realm mRealm; private Realm mRealm;
private MainPresenter mPresenter;
private RecyclerView mRecyclerView; private RecyclerView mRecyclerView;
private SwipeRefreshLayout mSwipeContainer;
public static FacilityListFragment newInstance(String mode) { public static FacilityListFragment newInstance(String mode) {
Bundle args = new Bundle(); Bundle args = new Bundle();
...@@ -41,25 +48,34 @@ public class FacilityListFragment extends android.support.v4.app.Fragment { ...@@ -41,25 +48,34 @@ public class FacilityListFragment extends android.support.v4.app.Fragment {
mMode = getArguments().getString(ARG_MODE); mMode = getArguments().getString(ARG_MODE);
mRealm = Realm.getDefaultInstance(); mRealm = Realm.getDefaultInstance();
mPresenter = new MainPresenter();
mPresenter.attachView(this);
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); mPresenter.detachView();
mRealm.close(); mRealm.close();
super.onDestroy();
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.fragment_facility, container, false); Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_facility_list, container, false);
} }
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
mRecyclerView = ButterKnife.findById(view, R.id.rvFacilities); mRecyclerView = ButterKnife.findById(view, R.id.rv_facilities);
mSwipeContainer = ButterKnife.findById(view, R.id.swipe_container);
setUpRecyclerView(view); setUpRecyclerView(view);
mSwipeContainer.setOnRefreshListener(() -> mPresenter.loadFacilities());
mSwipeContainer.setColorSchemeColors(getResources().getColor(R.color.colorPrimaryDark));
} }
// Handles set up for the Recycler View // Handles set up for the Recycler View
...@@ -103,4 +119,19 @@ public class FacilityListFragment extends android.support.v4.app.Fragment { ...@@ -103,4 +119,19 @@ public class FacilityListFragment extends android.support.v4.app.Fragment {
Drawable dividerDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.divider); Drawable dividerDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.divider);
mRecyclerView.addItemDecoration(new DividerItemDecoration(dividerDrawable)); mRecyclerView.addItemDecoration(new DividerItemDecoration(dividerDrawable));
} }
@Override
public void showProgressBar() {
// shouldn't do anything
}
@Override
public void dismissProgressBar() {
mSwipeContainer.setRefreshing(false);
}
@Override
public Context getContext() {
return getActivity();
}
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/fragment_facility"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
tools:context="srct.whatsopen.views.fragments.FacilityListFragment"> tools:context="srct.whatsopen.views.fragments.FacilityListFragment">
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/rvFacilities" android:id="@+id/rv_facilities"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
</RelativeLayout> </android.support.v4.widget.SwipeRefreshLayout>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment