Skip to content

Commit

Permalink
Lock map sliding layout while loading the map
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Sardonini committed Mar 19, 2018
1 parent 6f7b59e commit 4d28968
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import ch.liip.timeforcoffee.fragment.StationMapFragment;
import ch.liip.timeforcoffee.presenter.ConnectionsPresenter;

public class ConnectionsActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, ConnectionListFragment.Callbacks {
public class ConnectionsActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, StationMapFragment.Callbacks, ConnectionListFragment.Callbacks {

private SlidingUpPanelLayout mSlidingLayout;
private StationMapFragment mStationMapFragment;
Expand Down Expand Up @@ -105,10 +105,11 @@ protected void onCreate(Bundle savedInstanceState) {

// View
mStationMapFragment = (StationMapFragment) getFragmentManager().findFragmentById(R.id.station_map);
mProgressLayout = findViewById(R.id.progressLayout);

mProgressLayout = findViewById(R.id.progressLayout);
mSlidingLayout = findViewById(R.id.sliding_layout);
mSlidingLayout.setPanelSlideListener(this);
mSlidingLayout.setTouchEnabled(false);
}

@Override
Expand Down Expand Up @@ -193,7 +194,9 @@ public void onPanelAnchored(View panel) { }
public void onPanelHidden(View panel) { }

@Override
public void onConnectionSelected(Connection connection) { }
public void onMapLoaded() {
mSlidingLayout.setTouchEnabled(true);
}

public void performConnectionsUpdate() {
mPresenter.updateConnections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import ch.liip.timeforcoffee.fragment.StationMapFragment;
import ch.liip.timeforcoffee.presenter.DeparturesPresenter;

public class DeparturesActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, FavoritesListFragment.Callbacks, DepartureListFragment.Callbacks {
public class DeparturesActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, StationMapFragment.Callbacks, FavoritesListFragment.Callbacks, DepartureListFragment.Callbacks {

private SlidingUpPanelLayout mSlidingLayout;
private StationMapFragment mStationMapFragment;
Expand Down Expand Up @@ -74,12 +74,6 @@ protected void onCreate(Bundle savedInstanceState) {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

mStationMapFragment = (StationMapFragment) getFragmentManager().findFragmentById(R.id.station_map);
mStationMapFragment.setup(station);

mSlidingLayout = findViewById(R.id.sliding_layout);
mSlidingLayout.setPanelSlideListener(this);

// Fragments
Bundle favoritesFragmentArgs = new Bundle();
favoritesFragmentArgs.putInt(FavoritesListFragment.ARG_MODE, FavoritesListFragment.ARG_MODE_DEPARTURES);
Expand All @@ -97,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
fragments.add(mDepartureListFragment);
fragments.add(mFavoriteListFragment);

// Initialize the ViewPager and bind to tabs
// View
mTabsViewPager = super.findViewById(R.id.viewpager);
mTabsViewPager.setAdapter(new TabsAdapter(
this,
Expand All @@ -114,6 +108,13 @@ public void onPageSelected(int position) {
mPresenter.updateFavorites();
}
});

mStationMapFragment = (StationMapFragment) getFragmentManager().findFragmentById(R.id.station_map);
mStationMapFragment.setup(station);

mSlidingLayout = findViewById(R.id.sliding_layout);
mSlidingLayout.setPanelSlideListener(this);
mSlidingLayout.setTouchEnabled(false);
}

@Override
Expand Down Expand Up @@ -199,6 +200,11 @@ public void onPanelAnchored(View panel) { }
@Override
public void onPanelHidden(View panel) { }

@Override
public void onMapLoaded() {
mSlidingLayout.setTouchEnabled(true);
}

@Override
public void onDepartureSelected(Departure departure) {
selectDeparture(departure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,29 @@ public ConnectionListAdapter(Context context, List<Connection> connexions) {
}

public View getView(int position, View convertView, ViewGroup parent) {

ConnectionListAdapter.ConnexionViewHolder viewHolder;
String departureLabel = mContext.getResources().getString(R.string.connection_departure);
String arrivalLabel = mContext.getResources().getString(R.string.connection_arrival);

if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fragment_connection_list_row, parent, false);

viewHolder = new ConnectionListAdapter.ConnexionViewHolder();
viewHolder.stationTextView = (TextView) convertView.findViewById(R.id.station);
viewHolder.timeLabelTextView = (TextView) convertView.findViewById(R.id.time_label);
viewHolder.timeTextView = (TextView) convertView.findViewById(R.id.time);
viewHolder.realtimeDepartureTextView = (TextView) convertView.findViewById(R.id.realtime);
viewHolder.departureTextView = (TextView) convertView.findViewById(R.id.departure);
viewHolder.stationTextView = convertView.findViewById(R.id.station);
viewHolder.timeLabelTextView = convertView.findViewById(R.id.time_label);
viewHolder.timeTextView = convertView.findViewById(R.id.time);
viewHolder.realtimeDepartureTextView = convertView.findViewById(R.id.realtime);
viewHolder.departureTextView = convertView.findViewById(R.id.departure);


convertView.setTag(viewHolder);

} else {
}
else {
viewHolder = (ConnectionListAdapter.ConnexionViewHolder) convertView.getTag();
}

String departureLabel = mContext.getResources().getString(R.string.connection_departure);
String arrivalLabel = mContext.getResources().getString(R.string.connection_arrival);

Connection connection = this.mConnexions.get(position);
viewHolder.stationTextView.setText(connection.getName());
viewHolder.timeLabelTextView.setText(connection.getTimeLabel(departureLabel, arrivalLabel));
Expand All @@ -67,18 +66,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
viewHolder.realtimeDepartureTextView.setVisibility(View.VISIBLE);
viewHolder.realtimeDepartureTextView.setText(connection.getRealtimeDepartureStr());
viewHolder.timeTextView.setPaintFlags(viewHolder.timeTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
}
else {
viewHolder.realtimeDepartureTextView.setVisibility(View.GONE);
viewHolder.timeTextView.setPaintFlags(viewHolder.timeTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}

return convertView;
}

public Connection getConnexion(int position) {
return this.mConnexions.get(position);
}

public void setConnexions(List<Connection> connexions) {
this.mConnexions.clear();
this.mConnexions.addAll(connexions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.liip.timeforcoffee.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -9,7 +10,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -25,23 +25,12 @@ public class ConnectionListFragment extends ListFragment implements SwipeRefresh
private ConnectionListAdapter mConnectionListAdapter;
private SwipeRefreshLayout mSwipeRefreshLayout;

private ConnectionListFragment.Callbacks mCallbacks = sDummyCallbacks;
private Callbacks mCallbacks;

public interface Callbacks {
void onConnectionSelected(Connection connection);
void onRefresh();
}

private static ConnectionListFragment.Callbacks sDummyCallbacks = new ConnectionListFragment.Callbacks() {
@Override
public void onConnectionSelected(Connection connection) {
}

@Override
public void onRefresh() {
}
};

/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
Expand Down Expand Up @@ -81,24 +70,28 @@ public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mCallbacks.onRefresh();
mSwipeRefreshLayout.setRefreshing(false);
if(mCallbacks != null) {
mCallbacks.onRefresh();
}
}
}, 100);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (!(context instanceof ConnectionListFragment.Callbacks)) {
public void onAttach(Activity activity) {
super.onAttach(activity);
if (!(activity instanceof ConnectionListFragment.Callbacks)) {
throw new IllegalStateException("Activity must implement fragment's callbacks.");
}
mCallbacks = (ConnectionListFragment.Callbacks) context;

mCallbacks = (ConnectionListFragment.Callbacks) activity;
}

public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
mCallbacks.onConnectionSelected(mConnectionListAdapter.getConnexion(position));
@Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}

public void setConnections(List<Connection> connections) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.liip.timeforcoffee.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -31,29 +32,18 @@ public class DepartureListFragment extends ListFragment implements SwipeRefreshL

private FragmentActivity mActivity;
private DepartureListAdapter mDepartureListAdapter;
private RelativeLayout mNoDesparturesLayout;
private RelativeLayout mNoDeparturesLayout;
private ProgressBar mLoadingDeparturesProgressBar;
private SwipeRefreshLayout mSwipeRefreshLayout;

private Callbacks mCallbacks = sDummyCallbacks;
private Callbacks mCallbacks;

public interface Callbacks {
void onRefresh();
void onDepartureSelected(Departure departure);
void onDepartureFavoriteToggled(Departure departure, boolean isFavorite);
}

private static Callbacks sDummyCallbacks = new Callbacks() {
@Override
public void onDepartureSelected(Departure departure) { }

@Override
public void onRefresh() { }

@Override
public void onDepartureFavoriteToggled(Departure departure, boolean isFavorite) { }
};

/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
Expand All @@ -77,12 +67,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View rootView = inflater.inflate(R.layout.fragment_departure_list, container, false);

mLoadingDeparturesProgressBar = rootView.findViewById(R.id.loadingDeparturesSpinner);
mNoDesparturesLayout = rootView.findViewById(R.id.noDeparturesLayout);
mNoDeparturesLayout = rootView.findViewById(R.id.noDeparturesLayout);
mSwipeRefreshLayout = rootView.findViewById(R.id.swipe_container);
mSwipeRefreshLayout.setOnRefreshListener(this);

mLoadingDeparturesProgressBar.setVisibility(View.GONE);
mNoDesparturesLayout.setVisibility(View.GONE);
mNoDeparturesLayout.setVisibility(View.GONE);

return rootView;
}
Expand All @@ -100,37 +90,43 @@ public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mCallbacks.onRefresh();
mSwipeRefreshLayout.setRefreshing(false);
if(mCallbacks != null) {
mCallbacks.onRefresh();
}
}
}, 100);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (!(context instanceof Callbacks)) {
public void onAttach(Activity activity) {
super.onAttach(activity);
if (!(activity instanceof Callbacks)) {
throw new IllegalStateException("Activity must implement fragment's callbacks.");
}
mCallbacks = (Callbacks) context;

mCallbacks = (Callbacks) activity;
}

@Override
public void onDetach() {
super.onDetach();
// Reset the active callbacks interface to the dummy implementation.
mCallbacks = sDummyCallbacks;
mCallbacks = null;
}

@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
mCallbacks.onDepartureSelected(mDepartureListAdapter.getDeparture(position));
if(mCallbacks != null) {
mCallbacks.onDepartureSelected(mDepartureListAdapter.getDeparture(position));
}
}

@Override
public void onDepartureFavoriteToggled(Departure departure, boolean isFavorite) {
mCallbacks.onDepartureFavoriteToggled(departure, isFavorite);
if(mCallbacks != null) {
mCallbacks.onDepartureFavoriteToggled(departure, isFavorite);
}
}

public void setDepartures(List<Departure> departures) {
Expand All @@ -150,12 +146,12 @@ public void showLoadingDeparturesProgressBar(boolean show) {
}

public void showNoDeparturesLayout(boolean show) {
if(mNoDesparturesLayout != null) {
mNoDesparturesLayout.setVisibility(View.GONE);
if(mNoDeparturesLayout != null) {
mNoDeparturesLayout.setVisibility(View.GONE);
if (show) {
mNoDesparturesLayout.setVisibility(View.VISIBLE);
mNoDeparturesLayout.setVisibility(View.VISIBLE);
} else {
mNoDesparturesLayout.setVisibility(View.GONE);
mNoDeparturesLayout.setVisibility(View.GONE);
}
}
}
Expand Down
Loading

0 comments on commit 4d28968

Please sign in to comment.