Commit 942f7c23 authored by Robert Hitt's avatar Robert Hitt
Browse files

Made the app more offline-friendly

- Also made the dialog fragment a bit nicer looking
parent 0922d8ad
Pipeline #752 failed with stages
in 4 minutes and 51 seconds
......@@ -11,6 +11,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".views.activities.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
......
......@@ -22,7 +22,6 @@ public class MyApplication extends Application {
// Default Realm config. Might want to change this later
Realm.init(this);
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
Realm.deleteRealm(realmConfig);
Realm.setDefaultConfiguration(realmConfig);
}
}
......@@ -4,6 +4,7 @@ package srct.whatsopen.presenters;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -65,8 +66,8 @@ public class MainPresenter {
public void onError(Throwable e) {
if(mMainView != null)
mMainView.dismissProgressBar();
Log.d("Network bad", e.getMessage());
// should probably show some error message
Toast.makeText(mMainView.getContext(), "Error establishing connection, " +
"schedules may be inaccurate.", Toast.LENGTH_LONG).show();
}
@Override
public void onNext(List<Facility> facilities) {
......
......@@ -9,6 +9,7 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import com.astuetz.PagerSlidingTabStrip;
......@@ -26,6 +27,7 @@ import srct.whatsopen.views.adapters.FacilityListFragmentPagerAdapter;
public class MainActivity extends AppCompatActivity implements MainView {
@BindView(R.id.progress_bar) CircularProgressBar mProgressBar;
@BindView(R.id.view_pager) ViewPager mViewPager;
private MainPresenter mPresenter;
......@@ -41,24 +43,22 @@ public class MainActivity extends AppCompatActivity implements MainView {
mPresenter = new MainPresenter();
mPresenter.attachView(this);
// Get facility data if necessary
if(Realm.getDefaultInstance().isEmpty())
mPresenter.loadFacilities();
// Reload facility data
mPresenter.loadFacilities();
// Configure toolbar
Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
setSupportActionBar(toolbar);
// Get the ViewPager and set its PagerAdapter
ViewPager viewPager = ButterKnife.findById(this, R.id.view_pager);
viewPager.setAdapter(new FacilityListFragmentPagerAdapter(getSupportFragmentManager()));
mViewPager.setAdapter(new FacilityListFragmentPagerAdapter(getSupportFragmentManager()));
// Now give the TabStrip the ViewPager
PagerSlidingTabStrip tabStrip = ButterKnife.findById(this, R.id.tabs);
tabStrip.setTabPaddingLeftRight(0);
tabStrip.setViewPager(viewPager);
tabStrip.setViewPager(mViewPager);
viewPager.setCurrentItem(1);
mViewPager.setCurrentItem(1);
}
@Override
......@@ -91,12 +91,14 @@ public class MainActivity extends AppCompatActivity implements MainView {
@Override
public void showProgressBar() {
mViewPager.setVisibility(View.INVISIBLE);
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void dismissProgressBar() {
mProgressBar.setVisibility(View.GONE);
mViewPager.setVisibility(View.VISIBLE);
}
@Override
......
......@@ -3,15 +3,17 @@ package srct.whatsopen.views.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import srct.whatsopen.R;
......@@ -49,6 +51,18 @@ public class NotificationDialogFragment extends DialogFragment {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(view);
ButterKnife.bind(this, view);
}
@OnClick(R.id.save_button)
public void onSave() {
Toast.makeText(getContext(), "Notifications set.", Toast.LENGTH_SHORT).show();
dismiss();
}
@OnClick(R.id.cancel_button)
public void onCancel() {
Toast.makeText(getContext(), "Canceled.", Toast.LENGTH_SHORT).show();
dismiss();
}
}
......@@ -58,15 +58,19 @@
<Button
android:id="@+id/save_button"
android:layout_gravity="center_horizontal"
android:text="Save"
android:textColor="@color/colorPrimary"
android:layout_gravity="center_horizontal"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/cancel_button"
android:layout_gravity="center_horizontal"
android:text="Cancel"
android:textColor="@color/colorPrimary"
android:layout_gravity="center_horizontal"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
......
......@@ -7,7 +7,6 @@
tools:context="srct.whatsopen.views.activities.MainActivity">
<LinearLayout
android:id="@+id/list_view"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
......@@ -25,9 +26,15 @@
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#9e9e9e" />
<CheckBox
android:id="@+id/type_opening_check"
android:text="Opening"
......@@ -62,9 +69,15 @@
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#9e9e9e" />
<CheckBox
android:id="@+id/interval_on_check"
android:text="On opening/closing"
......@@ -93,8 +106,7 @@
</android.support.v7.widget.CardView>
<LinearLayout
android:orientation="horizontal"
<RelativeLayout
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
......@@ -102,16 +114,21 @@
<Button
android:id="@+id/save_button"
android:text="Save"
android:textColor="@color/colorPrimary"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/cancel_button"
android:text="Cancel"
android:textColor="@color/colorPrimary"
android:layout_alignParentRight="true"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
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