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

Detail view now fully fleshed out

parent 15cf9bc5
......@@ -32,6 +32,7 @@ dependencies {
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'io.reactivex:rxandroid:1.2.0'
......
package srct.whatsopen.ui.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.realm.Realm;
import io.realm.RealmList;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.ui.adapters.FacilityListAdapter;
public class DetailActivity extends AppCompatActivity {
@BindView(R.id.facility_name) TextView nameTextView;
@BindView(R.id.open_status) TextView openStatusTextView;
@BindView(R.id.open_duration) TextView openDurationTextView;
@BindView(R.id.location_text) TextView locationTextView;
@BindView(R.id.schedule_text) TextView scheduleTextView;
MenuItem mFavoriteMenuItem;
......@@ -39,6 +45,7 @@ public class DetailActivity extends AppCompatActivity {
// Set up layout
ButterKnife.bind(this);
configureToolbar();
fillTextViews();
}
@Override
......@@ -100,4 +107,125 @@ public class DetailActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Display the content to the text views
private void fillTextViews() {
String statusText = mFacility.isOpen() ? "Open" : "Closed";
openStatusTextView.setText(statusText);
openDurationTextView.setText(getStatusDuration());
locationTextView.setText(mFacility.getLocation());
scheduleTextView.setText(Html.fromHtml(getSchedule()));
}
// Finds the next time the facility closes or opens and returns it
private String getStatusDuration() {
Calendar now = Calendar.getInstance();
RealmList<OpenTimes> openTimesList = mFacility.getMainSchedule().getOpenTimesList();
if(openTimesList.size() == 0)
return "No open time on schedule";
int currentDay = (5 + now.get(Calendar.DAY_OF_WEEK)) % 7;
String durationMessage;
if(mFacility.isOpen()) {
String closingTime = openTimesList.get(currentDay).getEndTime();
closingTime = parseTo12HourTime(closingTime);
durationMessage = "Closes at " + closingTime;
return durationMessage;
}
// Check if the facility opens later today
if(currentDay < openTimesList.size()) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try {
Date currentTime = sdf.parse(sdf.format(now.getTime()));
Date startTime = sdf.parse(openTimesList.get(currentDay).getStartTime());
if(currentTime.compareTo(startTime) < 0) {
String openingTime = openTimesList.get(currentDay).getStartTime();
openingTime = parseTo12HourTime(openingTime);
return "Opens today at " + openingTime;
}
} catch (ParseException pe) {
pe.printStackTrace();
return "";
}
}
// Else return the opening time of the next day
int nextDay = (currentDay + 1) % openTimesList.size();
String nextDayStr = parseIntToDay(nextDay);
String openingTime = openTimesList.get(nextDay).getStartTime();
openingTime = parseTo12HourTime(openingTime);
durationMessage = "Opens on " + nextDayStr + " at " + openingTime;
return durationMessage;
}
// Parses 24 hour formatted time String to 12 hour formatted time String
private String parseTo12HourTime(String time) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
final Date date = sdf.parse(time);
return new SimpleDateFormat("h:mm a").format(date);
} catch (ParseException pe) {
pe.printStackTrace();
return "";
}
}
// Parses an integer to a String of the day of the week
private String parseIntToDay(int day) {
switch(day) {
case 0:
return "Monday";
case 1:
return "Tuesday";
case 2:
return "Wednesday";
case 3:
return "Thursday";
case 4:
return "Friday";
case 5:
return "Saturday";
case 6:
return "Sunday";
default:
return "";
}
}
// Parses the schedule into an HTML string
private String getSchedule() {
RealmList<OpenTimes> openTimesList = mFacility.getMainSchedule().getOpenTimesList();
if(openTimesList.size() == 0)
return "No schedule available";
StringBuilder scheduleString = new StringBuilder();
boolean first = true;
for(OpenTimes o : openTimesList) {
if(first)
first = false;
else
scheduleString.append("<br/>");
scheduleString.append("<b>" + parseIntToDay(o.getStartDay()) + "</b>: ");
scheduleString.append(parseTo12HourTime(o.getStartTime()));
scheduleString.append(" - ");
scheduleString.append(parseTo12HourTime(o.getEndTime()));
}
return scheduleString.toString();
}
}
......@@ -149,6 +149,7 @@ public class MainActivity extends AppCompatActivity {
else
return false;
} catch (ParseException pe) {
pe.printStackTrace();
return false;
}
}
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
......@@ -11,9 +11,119 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<TextView
android:text="TextView"
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/facility_name"/>
android:elevation="1dp"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:paddingTop="4dp"
android:paddingLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:text="Status: "
android:textSize="30sp"
/>
<TextView
android:id="@+id/open_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="TextView"
android:textSize="26sp"
/>
</LinearLayout>
<TextView
android:id="@+id/open_duration"
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingBottom="12dp"
android:textSize="16sp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="1dp"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location: "
android:textColor="@color/colorPrimary"
android:textSize="26sp"/>
<TextView
android:id="@+id/location_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:textSize="20sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="1dp"
android:layout_margin="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingBottom="12dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule: "
android:textColor="@color/colorPrimary"
android:textSize="26sp"/>
<TextView
android:id="@+id/schedule_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
\ No newline at end of file
......@@ -2,6 +2,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/miRefresh"
android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="ifRoom"
android:title="Refresh"/>
<item
android:id="@+id/miOptions"
android:icon="@drawable/ic_options_24dp"
......
......@@ -4,11 +4,6 @@ import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
......
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