Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.graphics.Paint;
import android.graphics.Typeface;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,109 +15,104 @@

import ch.liip.timeforcoffee.R;
import ch.liip.timeforcoffee.api.models.Departure;
import ch.liip.timeforcoffee.api.models.Station;
import ch.liip.timeforcoffee.common.Typefaces;

import java.util.Arrays;
import java.util.List;

public class DepartureListAdapter extends ArrayAdapter<Departure> {
public class DepartureListAdapter extends RecyclerView.Adapter<DepartureListAdapter.ViewHolder> {

private List<Departure> mDepartures;
private Context mContext;
private final List<Departure> mDepartures;

private static final String[] linesWithSymbol = {"ICN", "EN", "ICN", "TGV", "RX", "EC", "IC", "SC", "CNL", "ICE", "IR"};

private static class DepartureViewHolder {
TextView lineNameTextView;
TextView toTextView;
TextView departureTextView;
TextView scheduledTimeTextView;
TextView realtimeTextView;
TextView platformTextView;
public DepartureListAdapter(List<Departure> departures) {
mDepartures = departures;
}

public DepartureListAdapter(Context context, List<Departure> departures) {
super(context, R.layout.departure_list_row, departures);
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.departure_list_row, viewGroup, false);
return new ViewHolder(view);
}

mDepartures = departures;
mContext = context;
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
viewHolder.bind(mDepartures.get(position));
}

@NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
Departure departure = this.mDepartures.get(position);
DepartureViewHolder viewHolder;
@Override
public int getItemCount() {
return mDepartures.size();
}

if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.departure_list_row, parent, false);
public void setDepartures(List<Departure> departures) {
mDepartures.clear();
mDepartures.addAll(departures);
notifyDataSetChanged();
}

viewHolder = new DepartureViewHolder();
viewHolder.lineNameTextView = convertView.findViewById(R.id.name);
viewHolder.toTextView = convertView.findViewById(R.id.to);
viewHolder.departureTextView = convertView.findViewById(R.id.departure);
viewHolder.scheduledTimeTextView = convertView.findViewById(R.id.scheduledtime);
viewHolder.realtimeTextView = convertView.findViewById(R.id.realtime);
viewHolder.platformTextView = convertView.findViewById(R.id.platform);
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView lineNameTextView;
TextView toTextView;
TextView departureTextView;
TextView scheduledTimeTextView;
TextView realtimeTextView;
TextView platformTextView;

convertView.setTag(viewHolder);
}
else {
viewHolder = (DepartureViewHolder) convertView.getTag();
public ViewHolder(View view) {
super(view);
lineNameTextView = view.findViewById(R.id.name);
toTextView = view.findViewById(R.id.to);
departureTextView = view.findViewById(R.id.departure);
scheduledTimeTextView = view.findViewById(R.id.scheduledtime);
realtimeTextView = view.findViewById(R.id.realtime);
platformTextView = view.findViewById(R.id.platform);
}

setLineName(viewHolder.lineNameTextView, departure);
viewHolder.toTextView.setText(departure.getDestinationName());
viewHolder.departureTextView.setText(departure.departureInMinutes());

if (departure.isLate()) {
viewHolder.realtimeTextView.setVisibility(View.VISIBLE);
viewHolder.realtimeTextView.setText(departure.getDepartureRealtimeStr());
viewHolder.scheduledTimeTextView.setText(departure.getDepartureScheduledStr());
viewHolder.scheduledTimeTextView.setPaintFlags(viewHolder.scheduledTimeTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
else {
viewHolder.realtimeTextView.setVisibility(View.GONE);
viewHolder.scheduledTimeTextView.setText(departure.getDepartureScheduledStr());
viewHolder.scheduledTimeTextView.setPaintFlags(viewHolder.scheduledTimeTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
public void bind(Departure departure) {
setLineName(lineNameTextView, departure);
toTextView.setText(departure.getDestinationName());
departureTextView.setText(departure.departureInMinutes());

if (departure.isLate()) {
realtimeTextView.setVisibility(View.VISIBLE);
realtimeTextView.setText(departure.getDepartureRealtimeStr());
scheduledTimeTextView.setText(departure.getDepartureScheduledStr());
scheduledTimeTextView.setPaintFlags(scheduledTimeTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
realtimeTextView.setVisibility(View.GONE);
scheduledTimeTextView.setText(departure.getDepartureScheduledStr());
scheduledTimeTextView.setPaintFlags(scheduledTimeTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}

if (departure.getPlatform() != null) {
viewHolder.platformTextView.setVisibility(View.VISIBLE);
viewHolder.platformTextView.setText(String.format(getContext().getString(R.string.platform), departure.getPlatform()));
}
else {
viewHolder.platformTextView.setVisibility(View.GONE);
if (departure.getPlatform() != null) {
platformTextView.setVisibility(View.VISIBLE);
platformTextView.setText(String.format(platformTextView.getContext().getString(R.string.platform), departure.getPlatform()));
} else {
platformTextView.setVisibility(View.GONE);
}
}

return convertView;
}

private void setLineName(TextView textView, Departure departure) {
String name = departure.getLine();
textView.setText(name);

try {
if (Arrays.asList(linesWithSymbol).contains(name)) {
Typeface type = Typefaces.get(mContext, "trainsymbol");
textView.setTypeface(type);
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.RED);
}
else {
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setTextColor(name.equals("RE") ? Color.RED : departure.getColorFg());
textView.setBackgroundColor(departure.getColorBg() == Color.WHITE ? mContext.getResources().getColor(R.color.gray) : departure.getColorBg());
private void setLineName(TextView textView, Departure departure) {
String name = departure.getLine();
textView.setText(name);

try {
if (Arrays.asList(linesWithSymbol).contains(name)) {
Typeface type = Typefaces.get(textView.getContext(), "trainsymbol");
textView.setTypeface(type);
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.RED);
} else {
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setTextColor(name.equals("RE") ? Color.RED : departure.getColorFg());
textView.setBackgroundColor(departure.getColorBg() == Color.WHITE ? textView.getContext().getResources().getColor(R.color.gray) : departure.getColorBg());
}
} catch (Exception ex) {
// Do nothing
}
}
catch (Exception ex) {
// Do nothing
}
}

public void setDepartures(List<Departure> departures) {
mDepartures.clear();
mDepartures.addAll(departures);
notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
package ch.liip.timeforcoffee.adapter;

import android.content.Context;
import android.support.wearable.view.WearableListView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import ch.liip.timeforcoffee.R;
import ch.liip.timeforcoffee.api.models.Station;
import ch.liip.timeforcoffee.view.StationItemView;

import java.util.List;

/**
* Created by fsantschi on 08/03/15.
*/
public class StationListAdapter extends WearableListView.Adapter {

private List<Station> mStations;
private Context mContext;
public class StationListAdapter extends RecyclerView.Adapter<StationListAdapter.ViewHolder> {

private final List<Station> mStations;

public StationListAdapter(Context context, List<Station> stations) {
mStations = stations;
mContext = context;
}

@Override
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
return new WearableListView.ViewHolder(new StationItemView(mContext));
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.station_item, viewGroup, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(WearableListView.ViewHolder viewHolder, final int position) {
StationItemView view = (StationItemView) viewHolder.itemView;
final Station item = mStations.get(position);
TextView textView = (TextView) view.findViewById(R.id.name);
textView.setText(item.getName());
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
viewHolder.bind(mStations.get(position));
}

@Override
Expand All @@ -46,4 +43,18 @@ public void setStations(List<Station> stations) {
mStations.addAll(stations);
notifyDataSetChanged();
}

public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView mTextView;

public ViewHolder(View view) {
super(view);
mTextView = (TextView) view.findViewById(R.id.name);
}

public void bind(Station station) {
mTextView.setText(station.getName());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import android.app.Fragment;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.wear.widget.WearableLinearLayoutManager;
import androidx.wear.widget.WearableRecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import ch.liip.timeforcoffee.R;
import ch.liip.timeforcoffee.adapter.DepartureListAdapter;
import ch.liip.timeforcoffee.adapter.StationListAdapter;
import ch.liip.timeforcoffee.api.models.Departure;
import ch.liip.timeforcoffee.api.models.Station;

Expand All @@ -25,7 +28,8 @@ public class DepartureListFragment extends Fragment {
private ProgressBar mProgressBar;
private TextView mNoResultsTextView;
private TextView mTitleTextView;
private ListView mListView;
WearableLinearLayoutManager mLinearLayoutManager;
private WearableRecyclerView mListView;
private DepartureListAdapter mAdapter;

private List<Departure> mDepartures = new ArrayList<>();
Expand All @@ -44,7 +48,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mTitleTextView = view.findViewById(R.id.title);
mListView = view.findViewById(R.id.list_view);

mAdapter = new DepartureListAdapter(getActivity(), mDepartures);
mLinearLayoutManager = new WearableLinearLayoutManager(getActivity());
mListView.setLayoutManager(mLinearLayoutManager);
mListView.setEdgeItemsCenteringEnabled(true);

mAdapter = new DepartureListAdapter(mDepartures);
mListView.setAdapter(mAdapter);

return view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Fragment;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.wear.widget.WearableLinearLayoutManager;
import androidx.wear.widget.WearableRecyclerView;

import android.support.wearable.view.WearableListView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -24,7 +27,8 @@ public class StationListFragment extends Fragment implements WearableListView.Cl
private ProgressBar mProgressBar;
private TextView mTitleTextView;

private WearableListView mListView;
WearableLinearLayoutManager mLinearLayoutManager;
private WearableRecyclerView mListView;
private StationListAdapter mAdapter;

private List<Station> mStations = new ArrayList<>();
Expand All @@ -44,8 +48,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mListView = view.findViewById(R.id.list_view);

mAdapter = new StationListAdapter(getActivity(), mStations);

mLinearLayoutManager = new WearableLinearLayoutManager(getActivity());
mListView.setLayoutManager(mLinearLayoutManager);
mListView.setEdgeItemsCenteringEnabled(true);
mListView.setAdapter(mAdapter);
mListView.setClickListener(this);
//mListView.setClickListener(this);

return view;
}
Expand Down
8 changes: 4 additions & 4 deletions wear/src/main/res/layout/activity_wear.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.wear.widget.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
Expand All @@ -9,8 +10,7 @@

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_box="all">
android:layout_height="match_parent">

<ch.liip.timeforcoffee.view.FragmentViewPager
android:id="@+id/gridViewPager"
Expand All @@ -31,4 +31,4 @@
android:layout_height="match_parent"
android:layout_width="match_parent"/>

</android.support.wearable.view.BoxInsetLayout>
</androidx.wear.widget.BoxInsetLayout>
8 changes: 4 additions & 4 deletions wear/src/main/res/layout/fragment_departure_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
android:layout_gravity="center"
android:indeterminate="true"
android:indeterminateTint="@color/primary"
android:indeterminateTintMode="src_in" />
android:indeterminateTintMode="src_in"
tools:visibility="gone"/>

<TextView
android:id="@+id/noResults"
Expand All @@ -37,14 +38,13 @@
android:visibility="gone"
tools:text="Zürich, Albisrieden" />

<ListView
<androidx.wear.widget.WearableRecyclerView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="34dp"
android:dividerHeight="0dp"
android:listSelector="@android:color/transparent"
android:visibility="gone"
app:layout_box="left|bottom|right" />
android:visibility="gone" />

</FrameLayout>
Loading