Commit 48d39478 authored by Robert Hitt's avatar Robert Hitt
Browse files

Added on click listeners to facility views

- Also added pretty ripple animations
- Accidentally made the favorite buttons a bit
more forgiving as well
parent 1b9b464b
......@@ -2,7 +2,6 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/WhatsOpen.iml" filepath="$PROJECT_DIR$/WhatsOpen.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/whats-open-android.iml" filepath="$PROJECT_DIR$/whats-open-android.iml" />
</modules>
......
......@@ -33,7 +33,6 @@ import srct.whatsopen.ui.adapters.FacilityListFragmentPagerAdapter;
public class MainActivity extends AppCompatActivity {
private Realm mRealm;
private RecyclerView mRecyclerView;
@Override
......@@ -41,8 +40,6 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get Realm singleton
mRealm = Realm.getDefaultInstance();
// Get WhatsOpenClient singleton
WhatsOpenService service = WhatsOpenClient.getInstance();
......@@ -63,7 +60,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
mRealm.close();
}
// does not work currently
......@@ -82,7 +79,10 @@ public class MainActivity extends AppCompatActivity {
// Gets a Call from the given Retrofit service, then asynchronously executes it
// On success, copies the resulting facility list to the Realm DB
private void callWhatsOpenAPI(WhatsOpenService service) {
// Get Realm and SharedPreference instances
final Realm realm = Realm.getDefaultInstance();
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
Call<List<Facility>> call = service.facilityList();
call.enqueue(new Callback<List<Facility>>() {
......@@ -90,20 +90,23 @@ public class MainActivity extends AppCompatActivity {
public void onResponse(Call<List<Facility>> call, Response<List<Facility>> response) {
List<Facility> facilities = response.body();
// Query SharedReferences for each Facility's favorite status. defaults to false
for(Facility facility : facilities) {
facility.setOpen(getOpenStatus(facility));
// Query SharedReferences for each Facility's favorite status. defaults to false
facility.setFavorited(pref.getBoolean(facility.getName(), false));
facility.setOpen(getOpenStatus(facility));
}
mRealm.beginTransaction();
mRealm.copyToRealmOrUpdate(facilities);
mRealm.commitTransaction();
realm.beginTransaction();
realm.copyToRealmOrUpdate(facilities);
realm.commitTransaction();
realm.close();
}
@Override
public void onFailure(Call<List<Facility>> call, Throwable t) {
// do some stuff
realm.close();
}
});
}
......@@ -114,8 +117,7 @@ public class MainActivity extends AppCompatActivity {
RealmList<OpenTimes> openTimesList = facility.getMainSchedule().getOpenTimesList();
// have to mess with the current day value, as Calender.DAY_OF_WEEK
// starts with Saturday as 1 and the Whats Open Api starts with Monday
// at 0, for some reason.
// starts with Sunday as 1 and the Whats Open Api starts with Monday at 0
int currentDay = (5 + now.get(Calendar.DAY_OF_WEEK)) % 7;
OpenTimes currentOpenTimes = null;
......
......@@ -11,6 +11,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
......@@ -79,7 +80,7 @@ public class FacilityListAdapter extends
public Facility data;
public ViewHolder(View itemView) {
public ViewHolder(final View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
......@@ -87,6 +88,8 @@ public class FacilityListAdapter extends
// should expand to the facility's detail view
@OnClick(R.id.text_layout)
public void expandFacilityView() {
String name = data.getName();
Toast.makeText(context, name + " clicked", Toast.LENGTH_SHORT).show();
}
// toggles favorite status
......
......@@ -14,7 +14,7 @@
app:pstsShouldExpand="true"
app:pstsIndicatorColor="@color/colorPrimary"
app:pstsIndicatorHeight="6dp"
app:pstsTabBackground="@drawable/tab_button_bg"
app:pstsTabBackground="@drawable/button_bg"
android:layout_width="match_parent"
android:layout_height="48dp"/>
......
......@@ -3,15 +3,15 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="@color/facilityClosed"
android:elevation="2dp">
<RelativeLayout android:id="@+id/text_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:layout_weight="1">
<TextView android:id="@+id/facility_name"
android:layout_width="wrap_content"
......
......@@ -6,6 +6,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorControlHighlight">@color/tabButtonPressed</item>
</style>
</resources>
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