Skip to content

Commit

Permalink
Fleshed out rest of route detail screens.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvora committed Feb 3, 2018
1 parent 5a7ed0f commit 7fd45b8
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

import com.andrewvora.apps.rideatlanta.R;
import com.andrewvora.apps.rideatlanta.data.contracts.FavoriteRouteDataObject;
import com.andrewvora.apps.rideatlanta.data.repos.TrainsRepo;
import com.google.gson.annotations.SerializedName;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
* Created by faytx on 10/23/2016.
* @author Andrew Vorakrajangthiti
*/
public class Train extends BaseModel implements FavoriteRouteDataObject, Cloneable, Parcelable {

private static final String TRAIN_ARRIVAL_DATE_FORMAT = "M/dd/yyyy H:mm:ss a"; // 12/10/2017 12:58:44 AM
private static final String DISPLAYABLE_EVENT_TIME_12H = "H:mm a";

private static final String RED_LINE = "RED";
private static final String BLUE_LINE = "BLUE";
private static final String GOLD_LINE = "GOLD";
Expand Down Expand Up @@ -202,6 +208,16 @@ public static String combineArrivalTimes(@NonNull List<Train> trainList) {
return sb.toString();
}

public String getDisplayableEventTime() {
final DateFormat df = new SimpleDateFormat(TRAIN_ARRIVAL_DATE_FORMAT, Locale.getDefault());
try {
final Date date = df.parse(eventTime);
return new SimpleDateFormat(DISPLAYABLE_EVENT_TIME_12H, Locale.getDefault()).format(date);
} catch (Exception e) {
return "";
}
}

/*------------------------------------*
* Generated Parcelable Code
*------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void onBindViewHolder(BusViewHolder holder, int position) {
final Context context = holder.itemView.getContext();
final String status = Bus.getFormattedAdherence(context, bus.getAdherence());
holder.timeTilArrivalTextView.setText(status);

final String vehicleId = context.getString(R.string.bus_vehicle_id_template, bus.getVehicleNumber());
holder.vehicleIdTextView.setText(vehicleId);
}

@Override
Expand All @@ -64,6 +67,7 @@ static class BusViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.route_destination) TextView destinationTextView;
@BindView(R.id.route_direction) TextView directionTextView;
@BindView(R.id.route_time_until_arrival) TextView timeTilArrivalTextView;
@BindView(R.id.route_vehicle_id) TextView vehicleIdTextView;

BusViewHolder(View view) {
super(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.andrewvora.apps.rideatlanta.R;
import com.andrewvora.apps.rideatlanta.data.models.Bus;
import com.andrewvora.apps.rideatlanta.views.SimpleDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -61,6 +62,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
ButterKnife.bind(this, view);

busRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
busRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));
busRecyclerView.setAdapter(recyclerViewAdapter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.andrewvora.apps.rideatlanta.routedetails.train;

import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -9,6 +10,7 @@

import com.andrewvora.apps.rideatlanta.R;
import com.andrewvora.apps.rideatlanta.data.models.Train;
import com.andrewvora.apps.rideatlanta.utils.WordUtils;

import java.util.List;

Expand All @@ -17,7 +19,6 @@

/**
* Created on 12/10/2017.
*
* @author Andrew Vorakrajangthiti
*/
public class TrainRouteDetailsAdapter extends RecyclerView.Adapter<TrainRouteDetailsAdapter.RouteDetailsViewHolder> {
Expand All @@ -42,9 +43,22 @@ public RouteDetailsViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
public void onBindViewHolder(RouteDetailsViewHolder holder, int position) {
final Train train = trains.get(position);

holder.routeNameTextView.setText(train.getName());
holder.directionTextView.setText(train.getDirection());
holder.adherenceTextView.setText(train.getTimeTilArrival());
final int colorResId = Train.getColorRes(train.getLine());
final int color = ContextCompat.getColor(holder.itemView.getContext(), colorResId);
holder.routeNameTextView.setBackgroundColor(color);
holder.routeNameTextView.setText(train.getLine());

final String destinationText = WordUtils.capitalizeWords(train.getStation());
holder.destinationTextView.setText(destinationText);

final int directionResId = WordUtils.getFullDirectionString(train.getDirection());
holder.directionTextView.setText(directionResId);

holder.timeTilTextView.setText(train.getWaitingTime());
holder.trainIdTextView.setText(String.valueOf(train.getTrainId()));

final String arrivalTime = train.getDisplayableEventTime();
holder.arrivalTimeTextView.setText(arrivalTime);
}

@Override
Expand All @@ -54,8 +68,11 @@ public int getItemCount() {

static class RouteDetailsViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.route_name) TextView routeNameTextView;
@BindView(R.id.route_destination) TextView destinationTextView;
@BindView(R.id.direction_text_view) TextView directionTextView;
@BindView(R.id.time_text_view) TextView adherenceTextView;
@BindView(R.id.time_til_text_view) TextView timeTilTextView;
@BindView(R.id.arrival_time_text_view) TextView arrivalTimeTextView;
@BindView(R.id.train_id) TextView trainIdTextView;

RouteDetailsViewHolder(@NonNull View view) {
super(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.andrewvora.apps.rideatlanta.R;
import com.andrewvora.apps.rideatlanta.data.models.Train;
import com.andrewvora.apps.rideatlanta.views.SimpleDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -63,6 +64,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);

trainRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));
trainRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
trainRecyclerView.setAdapter(recyclerViewAdapter);
}
Expand Down
33 changes: 28 additions & 5 deletions app/src/main/res/layout/element_bus_route_detail.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<RelativeLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:padding="16dp">

<TextView
style="@style/BusLabelTextStyle"
android:id="@+id/route_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:textSize="18sp"
android:padding="6dp"
tools:text="125"/>

<TextView
style="@style/RouteTitleTextStyle"
android:id="@+id/route_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Clackamas Towne Center"/>
android:layout_toEndOf="@+id/route_name"
android:layout_marginStart="12dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="12dp"
android:maxLines="2"
android:textSize="20sp"
tools:text="Clackamas Towne Center on the Intersection of 6th and main"/>

<TextView
style="@style/RouteSubtitleTextStyle"
android:id="@+id/route_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/route_destination"
android:textSize="14sp"
tools:text="Northwest"/>

<TextView
style="@style/RouteLabelTextStyle"
android:id="@+id/route_time_until_arrival"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/route_destination"
android:layout_alignParentEnd="true"
android:textSize="16sp"
tools:text="12 mins"/>

</LinearLayout>
<TextView
android:id="@+id/route_vehicle_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/route_direction"
tools:text="Vehicle ID: 1452"/>
</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/element_home_info_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginBottom="12dp"
android:background="@color/md_white_1000"
app:contentPadding="12dp">

Expand Down
41 changes: 37 additions & 4 deletions app/src/main/res/layout/element_train_route_detail.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<RelativeLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -15,20 +15,53 @@
android:id="@+id/route_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="500"/>
android:padding="8dp"
tools:backgroundTint="@color/md_blue_500"
tools:text="BLUE"/>

<TextView
style="@style/RouteTitleTextStyle"
android:id="@+id/route_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/route_name"
android:layout_marginStart="12dp"
android:layout_marginEnd="16dp"
android:lines="2"
android:textSize="18sp"
tools:text="Clackamas Town Center Town Hall"/>

<TextView
style="@style/RouteSubtitleTextStyle"
android:id="@+id/direction_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/route_destination"
android:layout_marginTop="8dp"
tools:text="Southwest"/>

<TextView
style="@style/RouteLabelTextStyle"
android:id="@+id/time_text_view"
android:id="@+id/time_til_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/route_destination"
android:layout_marginTop="4dp"
android:layout_alignParentEnd="true"
tools:text="5 minutes"/>

</LinearLayout>
<TextView
android:id="@+id/train_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/direction_text_view"
tools:text="Vehicle ID: 7456"/>

<TextView
android:id="@+id/arrival_time_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/time_til_text_view"
android:layout_alignParentEnd="true"
tools:text="\@ 12:58 AM"/>
</RelativeLayout>
12 changes: 6 additions & 6 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
android:layout_height="match_parent"
android:background="@color/md_grey_100">

<android.support.v7.widget.RecyclerView
xmlns:android="https://schemas.android.com/apk/res/android"
android:id="@+id/home_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<ProgressBar
android:id="@+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center"/>

<android.support.v7.widget.RecyclerView
xmlns:android="https://schemas.android.com/apk/res/android"
android:id="@+id/home_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</FrameLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@
<string name="label_destination">Next destination</string>
<string name="label_arrival_in">Arrives in</string>
<string name="label_status">Status</string>

<string name="bus_vehicle_id_template">Vehicle ID: %1$d</string>
<string name="train_arrival_time_template">\@ %1$s</string>
</resources>

0 comments on commit 7fd45b8

Please sign in to comment.