Skip to content

Commit 4d28968

Browse files
author
Luca Sardonini
committed
Lock map sliding layout while loading the map
1 parent 6f7b59e commit 4d28968

File tree

8 files changed

+129
-121
lines changed

8 files changed

+129
-121
lines changed

mobile/src/main/java/ch/liip/timeforcoffee/activity/ConnectionsActivity.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import ch.liip.timeforcoffee.fragment.StationMapFragment;
2525
import ch.liip.timeforcoffee.presenter.ConnectionsPresenter;
2626

27-
public class ConnectionsActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, ConnectionListFragment.Callbacks {
27+
public class ConnectionsActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, StationMapFragment.Callbacks, ConnectionListFragment.Callbacks {
2828

2929
private SlidingUpPanelLayout mSlidingLayout;
3030
private StationMapFragment mStationMapFragment;
@@ -105,10 +105,11 @@ protected void onCreate(Bundle savedInstanceState) {
105105

106106
// View
107107
mStationMapFragment = (StationMapFragment) getFragmentManager().findFragmentById(R.id.station_map);
108-
mProgressLayout = findViewById(R.id.progressLayout);
109108

109+
mProgressLayout = findViewById(R.id.progressLayout);
110110
mSlidingLayout = findViewById(R.id.sliding_layout);
111111
mSlidingLayout.setPanelSlideListener(this);
112+
mSlidingLayout.setTouchEnabled(false);
112113
}
113114

114115
@Override
@@ -193,7 +194,9 @@ public void onPanelAnchored(View panel) { }
193194
public void onPanelHidden(View panel) { }
194195

195196
@Override
196-
public void onConnectionSelected(Connection connection) { }
197+
public void onMapLoaded() {
198+
mSlidingLayout.setTouchEnabled(true);
199+
}
197200

198201
public void performConnectionsUpdate() {
199202
mPresenter.updateConnections();

mobile/src/main/java/ch/liip/timeforcoffee/activity/DeparturesActivity.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import ch.liip.timeforcoffee.fragment.StationMapFragment;
2929
import ch.liip.timeforcoffee.presenter.DeparturesPresenter;
3030

31-
public class DeparturesActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, FavoritesListFragment.Callbacks, DepartureListFragment.Callbacks {
31+
public class DeparturesActivity extends AppCompatActivity implements SlidingUpPanelLayout.PanelSlideListener, StationMapFragment.Callbacks, FavoritesListFragment.Callbacks, DepartureListFragment.Callbacks {
3232

3333
private SlidingUpPanelLayout mSlidingLayout;
3434
private StationMapFragment mStationMapFragment;
@@ -74,12 +74,6 @@ protected void onCreate(Bundle savedInstanceState) {
7474
ActionBar actionBar = getSupportActionBar();
7575
actionBar.setDisplayHomeAsUpEnabled(true);
7676

77-
mStationMapFragment = (StationMapFragment) getFragmentManager().findFragmentById(R.id.station_map);
78-
mStationMapFragment.setup(station);
79-
80-
mSlidingLayout = findViewById(R.id.sliding_layout);
81-
mSlidingLayout.setPanelSlideListener(this);
82-
8377
// Fragments
8478
Bundle favoritesFragmentArgs = new Bundle();
8579
favoritesFragmentArgs.putInt(FavoritesListFragment.ARG_MODE, FavoritesListFragment.ARG_MODE_DEPARTURES);
@@ -97,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
9791
fragments.add(mDepartureListFragment);
9892
fragments.add(mFavoriteListFragment);
9993

100-
// Initialize the ViewPager and bind to tabs
94+
// View
10195
mTabsViewPager = super.findViewById(R.id.viewpager);
10296
mTabsViewPager.setAdapter(new TabsAdapter(
10397
this,
@@ -114,6 +108,13 @@ public void onPageSelected(int position) {
114108
mPresenter.updateFavorites();
115109
}
116110
});
111+
112+
mStationMapFragment = (StationMapFragment) getFragmentManager().findFragmentById(R.id.station_map);
113+
mStationMapFragment.setup(station);
114+
115+
mSlidingLayout = findViewById(R.id.sliding_layout);
116+
mSlidingLayout.setPanelSlideListener(this);
117+
mSlidingLayout.setTouchEnabled(false);
117118
}
118119

119120
@Override
@@ -199,6 +200,11 @@ public void onPanelAnchored(View panel) { }
199200
@Override
200201
public void onPanelHidden(View panel) { }
201202

203+
@Override
204+
public void onMapLoaded() {
205+
mSlidingLayout.setTouchEnabled(true);
206+
}
207+
202208
@Override
203209
public void onDepartureSelected(Departure departure) {
204210
selectDeparture(departure);

mobile/src/main/java/ch/liip/timeforcoffee/adapter/ConnectionListAdapter.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,29 @@ public ConnectionListAdapter(Context context, List<Connection> connexions) {
3333
}
3434

3535
public View getView(int position, View convertView, ViewGroup parent) {
36-
3736
ConnectionListAdapter.ConnexionViewHolder viewHolder;
37+
String departureLabel = mContext.getResources().getString(R.string.connection_departure);
38+
String arrivalLabel = mContext.getResources().getString(R.string.connection_arrival);
3839

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

4344
viewHolder = new ConnectionListAdapter.ConnexionViewHolder();
44-
viewHolder.stationTextView = (TextView) convertView.findViewById(R.id.station);
45-
viewHolder.timeLabelTextView = (TextView) convertView.findViewById(R.id.time_label);
46-
viewHolder.timeTextView = (TextView) convertView.findViewById(R.id.time);
47-
viewHolder.realtimeDepartureTextView = (TextView) convertView.findViewById(R.id.realtime);
48-
viewHolder.departureTextView = (TextView) convertView.findViewById(R.id.departure);
45+
viewHolder.stationTextView = convertView.findViewById(R.id.station);
46+
viewHolder.timeLabelTextView = convertView.findViewById(R.id.time_label);
47+
viewHolder.timeTextView = convertView.findViewById(R.id.time);
48+
viewHolder.realtimeDepartureTextView = convertView.findViewById(R.id.realtime);
49+
viewHolder.departureTextView = convertView.findViewById(R.id.departure);
4950

5051

5152
convertView.setTag(viewHolder);
5253

53-
} else {
54+
}
55+
else {
5456
viewHolder = (ConnectionListAdapter.ConnexionViewHolder) convertView.getTag();
5557
}
5658

57-
String departureLabel = mContext.getResources().getString(R.string.connection_departure);
58-
String arrivalLabel = mContext.getResources().getString(R.string.connection_arrival);
59-
6059
Connection connection = this.mConnexions.get(position);
6160
viewHolder.stationTextView.setText(connection.getName());
6261
viewHolder.timeLabelTextView.setText(connection.getTimeLabel(departureLabel, arrivalLabel));
@@ -67,18 +66,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
6766
viewHolder.realtimeDepartureTextView.setVisibility(View.VISIBLE);
6867
viewHolder.realtimeDepartureTextView.setText(connection.getRealtimeDepartureStr());
6968
viewHolder.timeTextView.setPaintFlags(viewHolder.timeTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
70-
} else {
69+
}
70+
else {
7171
viewHolder.realtimeDepartureTextView.setVisibility(View.GONE);
7272
viewHolder.timeTextView.setPaintFlags(viewHolder.timeTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
7373
}
7474

7575
return convertView;
7676
}
7777

78-
public Connection getConnexion(int position) {
79-
return this.mConnexions.get(position);
80-
}
81-
8278
public void setConnexions(List<Connection> connexions) {
8379
this.mConnexions.clear();
8480
this.mConnexions.addAll(connexions);

mobile/src/main/java/ch/liip/timeforcoffee/fragment/ConnectionListFragment.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ch.liip.timeforcoffee.fragment;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.os.Bundle;
56
import android.os.Handler;
@@ -9,7 +10,6 @@
910
import android.view.LayoutInflater;
1011
import android.view.View;
1112
import android.view.ViewGroup;
12-
import android.widget.ListView;
1313

1414
import java.util.ArrayList;
1515
import java.util.List;
@@ -25,23 +25,12 @@ public class ConnectionListFragment extends ListFragment implements SwipeRefresh
2525
private ConnectionListAdapter mConnectionListAdapter;
2626
private SwipeRefreshLayout mSwipeRefreshLayout;
2727

28-
private ConnectionListFragment.Callbacks mCallbacks = sDummyCallbacks;
28+
private Callbacks mCallbacks;
2929

3030
public interface Callbacks {
31-
void onConnectionSelected(Connection connection);
3231
void onRefresh();
3332
}
3433

35-
private static ConnectionListFragment.Callbacks sDummyCallbacks = new ConnectionListFragment.Callbacks() {
36-
@Override
37-
public void onConnectionSelected(Connection connection) {
38-
}
39-
40-
@Override
41-
public void onRefresh() {
42-
}
43-
};
44-
4534
/**
4635
* Mandatory empty constructor for the fragment manager to instantiate the
4736
* fragment (e.g. upon screen orientation changes).
@@ -81,24 +70,28 @@ public void onRefresh() {
8170
new Handler().postDelayed(new Runnable() {
8271
@Override
8372
public void run() {
84-
mCallbacks.onRefresh();
8573
mSwipeRefreshLayout.setRefreshing(false);
74+
if(mCallbacks != null) {
75+
mCallbacks.onRefresh();
76+
}
8677
}
8778
}, 100);
8879
}
8980

9081
@Override
91-
public void onAttach(Context context) {
92-
super.onAttach(context);
93-
if (!(context instanceof ConnectionListFragment.Callbacks)) {
82+
public void onAttach(Activity activity) {
83+
super.onAttach(activity);
84+
if (!(activity instanceof ConnectionListFragment.Callbacks)) {
9485
throw new IllegalStateException("Activity must implement fragment's callbacks.");
9586
}
96-
mCallbacks = (ConnectionListFragment.Callbacks) context;
87+
88+
mCallbacks = (ConnectionListFragment.Callbacks) activity;
9789
}
9890

99-
public void onListItemClick(ListView listView, View view, int position, long id) {
100-
super.onListItemClick(listView, view, position, id);
101-
mCallbacks.onConnectionSelected(mConnectionListAdapter.getConnexion(position));
91+
@Override
92+
public void onDetach() {
93+
super.onDetach();
94+
mCallbacks = null;
10295
}
10396

10497
public void setConnections(List<Connection> connections) {

mobile/src/main/java/ch/liip/timeforcoffee/fragment/DepartureListFragment.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ch.liip.timeforcoffee.fragment;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.os.Bundle;
56
import android.os.Handler;
@@ -31,29 +32,18 @@ public class DepartureListFragment extends ListFragment implements SwipeRefreshL
3132

3233
private FragmentActivity mActivity;
3334
private DepartureListAdapter mDepartureListAdapter;
34-
private RelativeLayout mNoDesparturesLayout;
35+
private RelativeLayout mNoDeparturesLayout;
3536
private ProgressBar mLoadingDeparturesProgressBar;
3637
private SwipeRefreshLayout mSwipeRefreshLayout;
3738

38-
private Callbacks mCallbacks = sDummyCallbacks;
39+
private Callbacks mCallbacks;
3940

4041
public interface Callbacks {
4142
void onRefresh();
4243
void onDepartureSelected(Departure departure);
4344
void onDepartureFavoriteToggled(Departure departure, boolean isFavorite);
4445
}
4546

46-
private static Callbacks sDummyCallbacks = new Callbacks() {
47-
@Override
48-
public void onDepartureSelected(Departure departure) { }
49-
50-
@Override
51-
public void onRefresh() { }
52-
53-
@Override
54-
public void onDepartureFavoriteToggled(Departure departure, boolean isFavorite) { }
55-
};
56-
5747
/**
5848
* Mandatory empty constructor for the fragment manager to instantiate the
5949
* fragment (e.g. upon screen orientation changes).
@@ -77,12 +67,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
7767
View rootView = inflater.inflate(R.layout.fragment_departure_list, container, false);
7868

7969
mLoadingDeparturesProgressBar = rootView.findViewById(R.id.loadingDeparturesSpinner);
80-
mNoDesparturesLayout = rootView.findViewById(R.id.noDeparturesLayout);
70+
mNoDeparturesLayout = rootView.findViewById(R.id.noDeparturesLayout);
8171
mSwipeRefreshLayout = rootView.findViewById(R.id.swipe_container);
8272
mSwipeRefreshLayout.setOnRefreshListener(this);
8373

8474
mLoadingDeparturesProgressBar.setVisibility(View.GONE);
85-
mNoDesparturesLayout.setVisibility(View.GONE);
75+
mNoDeparturesLayout.setVisibility(View.GONE);
8676

8777
return rootView;
8878
}
@@ -100,37 +90,43 @@ public void onRefresh() {
10090
new Handler().postDelayed(new Runnable() {
10191
@Override
10292
public void run() {
103-
mCallbacks.onRefresh();
10493
mSwipeRefreshLayout.setRefreshing(false);
94+
if(mCallbacks != null) {
95+
mCallbacks.onRefresh();
96+
}
10597
}
10698
}, 100);
10799
}
108100

109101
@Override
110-
public void onAttach(Context context) {
111-
super.onAttach(context);
112-
if (!(context instanceof Callbacks)) {
102+
public void onAttach(Activity activity) {
103+
super.onAttach(activity);
104+
if (!(activity instanceof Callbacks)) {
113105
throw new IllegalStateException("Activity must implement fragment's callbacks.");
114106
}
115-
mCallbacks = (Callbacks) context;
107+
108+
mCallbacks = (Callbacks) activity;
116109
}
117110

118111
@Override
119112
public void onDetach() {
120113
super.onDetach();
121-
// Reset the active callbacks interface to the dummy implementation.
122-
mCallbacks = sDummyCallbacks;
114+
mCallbacks = null;
123115
}
124116

125117
@Override
126118
public void onListItemClick(ListView listView, View view, int position, long id) {
127119
super.onListItemClick(listView, view, position, id);
128-
mCallbacks.onDepartureSelected(mDepartureListAdapter.getDeparture(position));
120+
if(mCallbacks != null) {
121+
mCallbacks.onDepartureSelected(mDepartureListAdapter.getDeparture(position));
122+
}
129123
}
130124

131125
@Override
132126
public void onDepartureFavoriteToggled(Departure departure, boolean isFavorite) {
133-
mCallbacks.onDepartureFavoriteToggled(departure, isFavorite);
127+
if(mCallbacks != null) {
128+
mCallbacks.onDepartureFavoriteToggled(departure, isFavorite);
129+
}
134130
}
135131

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

152148
public void showNoDeparturesLayout(boolean show) {
153-
if(mNoDesparturesLayout != null) {
154-
mNoDesparturesLayout.setVisibility(View.GONE);
149+
if(mNoDeparturesLayout != null) {
150+
mNoDeparturesLayout.setVisibility(View.GONE);
155151
if (show) {
156-
mNoDesparturesLayout.setVisibility(View.VISIBLE);
152+
mNoDeparturesLayout.setVisibility(View.VISIBLE);
157153
} else {
158-
mNoDesparturesLayout.setVisibility(View.GONE);
154+
mNoDeparturesLayout.setVisibility(View.GONE);
159155
}
160156
}
161157
}

0 commit comments

Comments
 (0)