Commit 5b721131 authored by Robert Hitt's avatar Robert Hitt

Status display is now updated on settings change

parent 718ee0d9
Pipeline #865 passed with stages
in 4 minutes and 56 seconds
......@@ -2,9 +2,11 @@ package srct.whatsopen.views.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
......@@ -51,15 +53,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
setSupportActionBar(toolbar);
// Get the ViewPager and set its PagerAdapter
mViewPager.setAdapter(new FacilityListFragmentPagerAdapter(getSupportFragmentManager()));
// Now give the TabStrip the ViewPager
PagerSlidingTabStrip tabStrip = ButterKnife.findById(this, R.id.tabs);
tabStrip.setTabPaddingLeftRight(0);
tabStrip.setViewPager(mViewPager);
mViewPager.setCurrentItem(1);
setUpTabStrip();
}
@Override
......@@ -97,6 +91,19 @@ public class MainActivity extends AppCompatActivity implements MainView {
}
}
private void setUpTabStrip() {
// Get the ViewPager and set its PagerAdapter
mViewPager.setAdapter(new FacilityListFragmentPagerAdapter(getSupportFragmentManager()));
// Now give the TabStrip the ViewPager
PagerSlidingTabStrip tabStrip = ButterKnife.findById(this, R.id.tabs);
tabStrip.setTabPaddingLeftRight(0);
tabStrip.setViewPager(mViewPager);
// Set the default tab to 'All'
mViewPager.setCurrentItem(1);
}
@Override
public void showProgressBar() {
mViewPager.setVisibility(View.INVISIBLE);
......
package srct.whatsopen.views.fragments;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
......@@ -32,6 +34,7 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
private MainPresenter mPresenter;
private RecyclerView mRecyclerView;
private SwipeRefreshLayout mSwipeContainer;
private SharedPreferences.OnSharedPreferenceChangeListener mListener;
public static FacilityListFragment newInstance(String mode) {
Bundle args = new Bundle();
......@@ -50,6 +53,8 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
mRealm = Realm.getDefaultInstance();
mPresenter = new MainPresenter();
mPresenter.attachView(this);
setPreferenceChangeListener();
}
@Override
......@@ -134,4 +139,19 @@ public class FacilityListFragment extends android.support.v4.app.Fragment implem
public Context getContext() {
return getActivity();
}
// Redraws RecyclerView if the settings have changed for it
private void setPreferenceChangeListener() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("list_view_information_preference")) {
mRecyclerView.getAdapter().notifyDataSetChanged();
}
}
};
preferences.registerOnSharedPreferenceChangeListener(mListener);
}
}
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