mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 04:08:46 +00:00
Replace listeners and runnables with lambdas.
This commit is contained in:
parent
d08464cb7f
commit
34b1104020
35 changed files with 803 additions and 1340 deletions
|
@ -190,13 +190,11 @@ public class MyActionBar extends LinearLayout {
|
|||
public void startProgress() {
|
||||
if (progressCount++ == 0) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
progressView.setVisibility(View.VISIBLE);
|
||||
if (progressAnimation == null) {
|
||||
progressAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate);
|
||||
progressImage.startAnimation(progressAnimation);
|
||||
}
|
||||
handler.post(() -> {
|
||||
progressView.setVisibility(View.VISIBLE);
|
||||
if (progressAnimation == null) {
|
||||
progressAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate);
|
||||
progressImage.startAnimation(progressAnimation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -204,15 +202,13 @@ public class MyActionBar extends LinearLayout {
|
|||
|
||||
public void stopProgress() {
|
||||
if (--progressCount <= 0) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
if (progressAnimation != null) {
|
||||
progressImage.clearAnimation();
|
||||
progressAnimation = null;
|
||||
}
|
||||
if (!progressAlwaysVisible)
|
||||
progressView.setVisibility(View.GONE);
|
||||
handler.postDelayed(() -> {
|
||||
if (progressAnimation != null) {
|
||||
progressImage.clearAnimation();
|
||||
progressAnimation = null;
|
||||
}
|
||||
if (!progressAlwaysVisible)
|
||||
progressView.setVisibility(View.GONE);
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
|
@ -224,13 +220,11 @@ public class MyActionBar extends LinearLayout {
|
|||
public void overflow(final int menuResId, final PopupMenu.OnMenuItemClickListener menuItemClickListener) {
|
||||
final View overflowButton = findViewById(R.id.action_bar_overflow_button);
|
||||
overflowButton.setVisibility(View.VISIBLE);
|
||||
overflowButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu overflowMenu = new PopupMenu(context, v);
|
||||
overflowMenu.inflate(menuResId);
|
||||
overflowMenu.setOnMenuItemClickListener(menuItemClickListener);
|
||||
overflowMenu.show();
|
||||
}
|
||||
overflowButton.setOnClickListener(v -> {
|
||||
final PopupMenu overflowMenu = new PopupMenu(context, v);
|
||||
overflowMenu.inflate(menuResId);
|
||||
overflowMenu.setOnMenuItemClickListener(menuItemClickListener);
|
||||
overflowMenu.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,12 +187,10 @@ public abstract class OeffiMainActivity extends OeffiActivity {
|
|||
final MyActionBar actionBar = getMyActionBar();
|
||||
|
||||
final NavigationMenuAdapter menuAdapter = new NavigationMenuAdapter(this,
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
onOptionsItemSelected(item);
|
||||
navigationDrawerLayout.closeDrawers();
|
||||
return false;
|
||||
}
|
||||
item -> {
|
||||
onOptionsItemSelected(item);
|
||||
navigationDrawerLayout.closeDrawers();
|
||||
return false;
|
||||
});
|
||||
final Menu menu = menuAdapter.getMenu();
|
||||
onCreateOptionsMenu(menu);
|
||||
|
@ -206,11 +204,7 @@ public abstract class OeffiMainActivity extends OeffiActivity {
|
|||
navigationDrawerLayout.setDrawerShadow(R.drawable.view_shadow_right, Gravity.LEFT);
|
||||
navigationDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
|
||||
public void onDrawerOpened(final View drawerView) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
heartbeat.start();
|
||||
}
|
||||
}, 2000);
|
||||
handler.postDelayed(() -> heartbeat.start(), 2000);
|
||||
}
|
||||
|
||||
public void onDrawerClosed(final View drawerView) {
|
||||
|
@ -223,18 +217,12 @@ public abstract class OeffiMainActivity extends OeffiActivity {
|
|||
}
|
||||
});
|
||||
|
||||
navigationDrawerFooterView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
heartbeat.start();
|
||||
}
|
||||
navigationDrawerFooterView.setOnClickListener(v -> {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
heartbeat.start();
|
||||
});
|
||||
|
||||
actionBar.setDrawer(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
toggleNavigation();
|
||||
}
|
||||
});
|
||||
actionBar.setDrawer(v -> toggleNavigation());
|
||||
|
||||
updateNavigation();
|
||||
}
|
||||
|
@ -581,18 +569,16 @@ public abstract class OeffiMainActivity extends OeffiActivity {
|
|||
}
|
||||
}
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (isFinishing())
|
||||
return;
|
||||
runOnUiThread(() -> {
|
||||
if (isFinishing())
|
||||
return;
|
||||
|
||||
showDialog(DIALOG_MESSAGE, message);
|
||||
showDialog(DIALOG_MESSAGE, message);
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
messagesPrefs.edit().putLong(id, now).commit();
|
||||
if ("info".equals(action))
|
||||
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).commit();
|
||||
}
|
||||
final long now = System.currentTimeMillis();
|
||||
messagesPrefs.edit().putLong(id, now).commit();
|
||||
if ("info".equals(action))
|
||||
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).commit();
|
||||
});
|
||||
} else {
|
||||
log.info("Got '{}: {}' when fetching message from: '{}'", response.code(),
|
||||
|
|
|
@ -495,17 +495,13 @@ public class OeffiMapView extends MapView {
|
|||
|
||||
public void setZoomControls(final ZoomControls zoomControls) {
|
||||
this.zoomControls = zoomControls;
|
||||
zoomControls.setOnZoomInClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
showZoomControls();
|
||||
getController().zoomIn();
|
||||
}
|
||||
zoomControls.setOnZoomInClickListener(v -> {
|
||||
showZoomControls();
|
||||
getController().zoomIn();
|
||||
});
|
||||
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
showZoomControls();
|
||||
getController().zoomOut();
|
||||
}
|
||||
zoomControls.setOnZoomOutClickListener(v -> {
|
||||
showZoomControls();
|
||||
getController().zoomOut();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -272,61 +272,43 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
final MyActionBar actionBar = getMyActionBar();
|
||||
setPrimaryColor(R.color.action_bar_background_directions);
|
||||
actionBar.setPrimaryTitle(R.string.directions_activity_title);
|
||||
actionBar.setTitlesOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
NetworkPickerActivity.start(DirectionsActivity.this);
|
||||
}
|
||||
});
|
||||
actionBar.setTitlesOnClickListener(v -> NetworkPickerActivity.start(DirectionsActivity.this));
|
||||
buttonExpand = actionBar.addToggleButton(R.drawable.ic_expand_white_24dp,
|
||||
R.string.directions_action_expand_title);
|
||||
buttonExpand.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
|
||||
if (isChecked)
|
||||
expandForm();
|
||||
else
|
||||
collapseForm();
|
||||
buttonExpand.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked)
|
||||
expandForm();
|
||||
else
|
||||
collapseForm();
|
||||
|
||||
updateMap();
|
||||
}
|
||||
updateMap();
|
||||
});
|
||||
actionBar.addButton(R.drawable.ic_shuffle_white_24dp, R.string.directions_action_return_trip_title)
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
viewToLocation.exchangeWith(viewFromLocation);
|
||||
}
|
||||
});
|
||||
actionBar.overflow(R.menu.directions_options, new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.directions_options_clear_history) {
|
||||
if (network != null)
|
||||
showDialog(DIALOG_CLEAR_HISTORY);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
.setOnClickListener(v -> viewToLocation.exchangeWith(viewFromLocation));
|
||||
actionBar.overflow(R.menu.directions_options, item -> {
|
||||
if (item.getItemId() == R.id.directions_options_clear_history) {
|
||||
if (network != null)
|
||||
showDialog(DIALOG_CLEAR_HISTORY);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
initNavigation();
|
||||
|
||||
((Button) findViewById(R.id.directions_network_missing_capability_button))
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
NetworkPickerActivity.start(DirectionsActivity.this);
|
||||
}
|
||||
});
|
||||
.setOnClickListener((OnClickListener) v -> NetworkPickerActivity.start(DirectionsActivity.this));
|
||||
connectivityWarningView = (TextView) findViewById(R.id.directions_connectivity_warning_box);
|
||||
|
||||
initLayoutTransitions();
|
||||
|
||||
final AutoCompleteLocationAdapter autoCompleteAdapter = new AutoCompleteLocationAdapter();
|
||||
|
||||
final LocationView.Listener locationChangeListener = new LocationView.Listener() {
|
||||
public void changed() {
|
||||
updateMap();
|
||||
queryHistoryListAdapter.clearSelectedEntry();
|
||||
requestFocusFirst();
|
||||
}
|
||||
final LocationView.Listener locationChangeListener = () -> {
|
||||
updateMap();
|
||||
queryHistoryListAdapter.clearSelectedEntry();
|
||||
requestFocusFirst();
|
||||
};
|
||||
|
||||
viewFromLocation = (LocationView) findViewById(R.id.directions_from);
|
||||
|
@ -344,17 +326,15 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
viewToLocation = (LocationView) findViewById(R.id.directions_to);
|
||||
viewToLocation.setAdapter(autoCompleteAdapter);
|
||||
viewToLocation.setListener(locationChangeListener);
|
||||
viewToLocation.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_GO) {
|
||||
viewGo.performClick();
|
||||
return true;
|
||||
} else if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
requestFocusFirst();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
viewToLocation.setOnEditorActionListener((v, actionId, event) -> {
|
||||
if (actionId == EditorInfo.IME_ACTION_GO) {
|
||||
viewGo.performClick();
|
||||
return true;
|
||||
} else if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
requestFocusFirst();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
viewToLocation.setContextMenuItemClickListener(new LocationContextMenuItemClickListener(viewToLocation,
|
||||
|
@ -372,27 +352,23 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
viewProductToggles.add((ToggleImageButton) findViewById(R.id.directions_products_c));
|
||||
initProductToggles();
|
||||
|
||||
final OnLongClickListener productLongClickListener = new OnLongClickListener() {
|
||||
public boolean onLongClick(final View v) {
|
||||
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
|
||||
builder.setTitle(R.string.directions_products_prompt);
|
||||
builder.setItems(R.array.directions_products, new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
for (final ToggleImageButton view : viewProductToggles) {
|
||||
if (which == 0)
|
||||
view.setChecked(view.equals(v));
|
||||
if (which == 1)
|
||||
view.setChecked(!view.equals(v));
|
||||
if (which == 2)
|
||||
view.setChecked(true);
|
||||
if (which == 3)
|
||||
view.setChecked("SUTBP".contains((String) view.getTag()));
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
return true;
|
||||
}
|
||||
final OnLongClickListener productLongClickListener = v -> {
|
||||
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
|
||||
builder.setTitle(R.string.directions_products_prompt);
|
||||
builder.setItems(R.array.directions_products, (dialog, which) -> {
|
||||
for (final ToggleImageButton view : viewProductToggles) {
|
||||
if (which == 0)
|
||||
view.setChecked(view.equals(v));
|
||||
if (which == 1)
|
||||
view.setChecked(!view.equals(v));
|
||||
if (which == 2)
|
||||
view.setChecked(true);
|
||||
if (which == 3)
|
||||
view.setChecked("SUTBP".contains((String) view.getTag()));
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
return true;
|
||||
};
|
||||
for (final View view : viewProductToggles)
|
||||
view.setOnLongClickListener(productLongClickListener);
|
||||
|
@ -400,44 +376,36 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
viewBike = (CheckBox) findViewById(R.id.directions_option_bike);
|
||||
|
||||
viewTimeDepArr = (Button) findViewById(R.id.directions_time_dep_arr);
|
||||
viewTimeDepArr.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
|
||||
builder.setTitle(R.string.directions_set_time_prompt);
|
||||
builder.setItems(R.array.directions_set_time, new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
final String[] parts = getResources().getStringArray(R.array.directions_set_time_values)[which]
|
||||
.split("_");
|
||||
final DepArr depArr = DepArr.valueOf(parts[0]);
|
||||
if (parts[1].equals("AT")) {
|
||||
time = new TimeSpec.Absolute(depArr, time.timeInMillis());
|
||||
} else if (parts[1].equals("IN")) {
|
||||
if (parts.length > 2) {
|
||||
time = new TimeSpec.Relative(depArr,
|
||||
Long.parseLong(parts[2]) * DateUtils.MINUTE_IN_MILLIS);
|
||||
} else {
|
||||
time = new TimeSpec.Relative(depArr, 0);
|
||||
handleDiffClick();
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException(parts[1]);
|
||||
}
|
||||
updateGUI();
|
||||
viewTimeDepArr.setOnClickListener(v -> {
|
||||
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
|
||||
builder.setTitle(R.string.directions_set_time_prompt);
|
||||
builder.setItems(R.array.directions_set_time, (dialog, which) -> {
|
||||
final String[] parts = getResources().getStringArray(R.array.directions_set_time_values)[which]
|
||||
.split("_");
|
||||
final DepArr depArr = DepArr.valueOf(parts[0]);
|
||||
if (parts[1].equals("AT")) {
|
||||
time = new TimeSpec.Absolute(depArr, time.timeInMillis());
|
||||
} else if (parts[1].equals("IN")) {
|
||||
if (parts.length > 2) {
|
||||
time = new TimeSpec.Relative(depArr,
|
||||
Long.parseLong(parts[2]) * DateUtils.MINUTE_IN_MILLIS);
|
||||
} else {
|
||||
time = new TimeSpec.Relative(depArr, 0);
|
||||
handleDiffClick();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException(parts[1]);
|
||||
}
|
||||
updateGUI();
|
||||
});
|
||||
builder.show();
|
||||
});
|
||||
|
||||
viewTime1 = (Button) findViewById(R.id.directions_time_1);
|
||||
viewTime2 = (Button) findViewById(R.id.directions_time_2);
|
||||
|
||||
viewGo = (Button) findViewById(R.id.directions_go);
|
||||
viewGo.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
handleGo();
|
||||
}
|
||||
});
|
||||
viewGo.setOnClickListener(v -> handleGo());
|
||||
|
||||
viewQueryHistoryList = (RecyclerView) findViewById(android.R.id.list);
|
||||
viewQueryHistoryList.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
@ -453,18 +421,14 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
quickReturnView.getLayoutParams().width, quickReturnView.getLayoutParams().height);
|
||||
layoutParams.setBehavior(new QuickReturnBehavior());
|
||||
quickReturnView.setLayoutParams(layoutParams);
|
||||
quickReturnView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(final View v, final int left, final int top, final int right, final int bottom,
|
||||
final int oldLeft, final int oldTop, final int oldRight, final int oldBottom) {
|
||||
final int height = bottom - top;
|
||||
viewQueryHistoryList.setPadding(viewQueryHistoryList.getPaddingLeft(), height,
|
||||
viewQueryHistoryList.getPaddingRight(), viewQueryHistoryList.getPaddingBottom());
|
||||
viewQueryHistoryEmpty.setPadding(viewQueryHistoryEmpty.getPaddingLeft(), height,
|
||||
viewQueryHistoryEmpty.getPaddingRight(), viewQueryHistoryEmpty.getPaddingBottom());
|
||||
viewQueryMissingCapability.setPadding(viewQueryMissingCapability.getPaddingLeft(), height,
|
||||
viewQueryMissingCapability.getPaddingRight(), viewQueryMissingCapability.getPaddingBottom());
|
||||
}
|
||||
quickReturnView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
||||
final int height = bottom - top;
|
||||
viewQueryHistoryList.setPadding(viewQueryHistoryList.getPaddingLeft(), height,
|
||||
viewQueryHistoryList.getPaddingRight(), viewQueryHistoryList.getPaddingBottom());
|
||||
viewQueryHistoryEmpty.setPadding(viewQueryHistoryEmpty.getPaddingLeft(), height,
|
||||
viewQueryHistoryEmpty.getPaddingRight(), viewQueryHistoryEmpty.getPaddingBottom());
|
||||
viewQueryMissingCapability.setPadding(viewQueryMissingCapability.getPaddingLeft(), height,
|
||||
viewQueryMissingCapability.getPaddingRight(), viewQueryMissingCapability.getPaddingBottom());
|
||||
});
|
||||
|
||||
mapView = (OeffiMapView) findViewById(R.id.directions_map);
|
||||
|
@ -493,17 +457,13 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
final LocationTextView locationView = (LocationTextView) view
|
||||
.findViewById(R.id.directions_map_pin_location);
|
||||
final View buttonGroup = view.findViewById(R.id.directions_map_pin_buttons);
|
||||
buttonGroup.findViewById(R.id.directions_map_pin_button_from).setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
viewFromLocation.setLocation(pinLocation);
|
||||
mapView.removeAllViews();
|
||||
}
|
||||
buttonGroup.findViewById(R.id.directions_map_pin_button_from).setOnClickListener(v -> {
|
||||
viewFromLocation.setLocation(pinLocation);
|
||||
mapView.removeAllViews();
|
||||
});
|
||||
buttonGroup.findViewById(R.id.directions_map_pin_button_to).setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
viewToLocation.setLocation(pinLocation);
|
||||
mapView.removeAllViews();
|
||||
}
|
||||
buttonGroup.findViewById(R.id.directions_map_pin_button_to).setOnClickListener(v -> {
|
||||
viewToLocation.setLocation(pinLocation);
|
||||
mapView.removeAllViews();
|
||||
});
|
||||
locationView.setLocation(pinLocation);
|
||||
locationView.setShowLocationType(false);
|
||||
|
@ -744,49 +704,37 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
}
|
||||
}
|
||||
|
||||
private final OnClickListener dateClickListener = new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs);
|
||||
final int year = calendar.get(Calendar.YEAR);
|
||||
final int month = calendar.get(Calendar.MONTH);
|
||||
final int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
private final OnClickListener dateClickListener = v -> {
|
||||
final Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs);
|
||||
final int year = calendar.get(Calendar.YEAR);
|
||||
final int month = calendar.get(Calendar.MONTH);
|
||||
final int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
new DatePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, new OnDateSetListener() {
|
||||
public void onDateSet(final DatePicker view, final int year, final int month, final int day) {
|
||||
calendar.set(Calendar.YEAR, year);
|
||||
calendar.set(Calendar.MONTH, month);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, day);
|
||||
time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis());
|
||||
updateGUI();
|
||||
}
|
||||
}, year, month, day).show();
|
||||
}
|
||||
new DatePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, (view, year1, month1, day1) -> {
|
||||
calendar.set(Calendar.YEAR, year1);
|
||||
calendar.set(Calendar.MONTH, month1);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, day1);
|
||||
time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis());
|
||||
updateGUI();
|
||||
}, year, month, day).show();
|
||||
};
|
||||
|
||||
private final OnClickListener timeClickListener = new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs);
|
||||
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
final int minute = calendar.get(Calendar.MINUTE);
|
||||
private final OnClickListener timeClickListener = v -> {
|
||||
final Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeInMillis(((TimeSpec.Absolute) time).timeMs);
|
||||
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
final int minute = calendar.get(Calendar.MINUTE);
|
||||
|
||||
new TimePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, new OnTimeSetListener() {
|
||||
public void onTimeSet(final TimePicker view, final int hour, final int minute) {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis());
|
||||
updateGUI();
|
||||
}
|
||||
}, hour, minute, DateFormat.is24HourFormat(DirectionsActivity.this)).show();
|
||||
}
|
||||
new TimePickerDialog(DirectionsActivity.this, Constants.ALERT_DIALOG_THEME, (view, hour1, minute1) -> {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hour1);
|
||||
calendar.set(Calendar.MINUTE, minute1);
|
||||
time = new TimeSpec.Absolute(time.depArr, calendar.getTimeInMillis());
|
||||
updateGUI();
|
||||
}, hour, minute, DateFormat.is24HourFormat(DirectionsActivity.this)).show();
|
||||
};
|
||||
|
||||
private final OnClickListener diffClickListener = new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
handleDiffClick();
|
||||
}
|
||||
};
|
||||
private final OnClickListener diffClickListener = v -> handleDiffClick();
|
||||
|
||||
private void handleDiffClick() {
|
||||
final int[] relativeTimeValues = getResources().getIntArray(R.array.directions_set_time_relative);
|
||||
|
@ -801,16 +749,14 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
}
|
||||
final DialogBuilder builder = DialogBuilder.get(this);
|
||||
builder.setTitle(R.string.directions_set_time_relative_prompt);
|
||||
builder.setItems(relativeTimeStrings, new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
if (which < relativeTimeValues.length) {
|
||||
final int mins = relativeTimeValues[which];
|
||||
time = new TimeSpec.Relative(mins * DateUtils.MINUTE_IN_MILLIS);
|
||||
} else {
|
||||
time = new TimeSpec.Absolute(DepArr.DEPART, time.timeInMillis());
|
||||
}
|
||||
updateGUI();
|
||||
builder.setItems(relativeTimeStrings, (dialog, which) -> {
|
||||
if (which < relativeTimeValues.length) {
|
||||
final int mins = relativeTimeValues[which];
|
||||
time = new TimeSpec.Relative(mins * DateUtils.MINUTE_IN_MILLIS);
|
||||
} else {
|
||||
time = new TimeSpec.Absolute(DepArr.DEPART, time.timeInMillis());
|
||||
}
|
||||
updateGUI();
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
@ -1009,11 +955,9 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
}
|
||||
|
||||
final ProgressDialog progressDialog = ProgressDialog.show(DirectionsActivity.this, null,
|
||||
getString(R.string.directions_query_progress), true, true, new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
if (queryTripsRunnable != null)
|
||||
queryTripsRunnable.cancel();
|
||||
}
|
||||
getString(R.string.directions_query_progress), true, true, dialog -> {
|
||||
if (queryTripsRunnable != null)
|
||||
queryTripsRunnable.cancel();
|
||||
});
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
|
@ -1070,14 +1014,12 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
final DialogBuilder builder = DialogBuilder.get(DirectionsActivity.this);
|
||||
builder.setTitle(getString(R.string.ambiguous_address_title));
|
||||
builder.setAdapter(new AmbiguousLocationAdapter(DirectionsActivity.this, autocompletes),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
final LocationView locationView = result.ambiguousFrom != null
|
||||
? viewFromLocation
|
||||
: (result.ambiguousVia != null ? viewViaLocation : viewToLocation);
|
||||
locationView.setLocation(autocompletes.get(which));
|
||||
viewGo.performClick();
|
||||
}
|
||||
(dialog, which) -> {
|
||||
final LocationView locationView = result.ambiguousFrom != null
|
||||
? viewFromLocation
|
||||
: (result.ambiguousVia != null ? viewViaLocation : viewToLocation);
|
||||
locationView.setLocation(autocompletes.get(which));
|
||||
viewGo.performClick();
|
||||
});
|
||||
builder.create().show();
|
||||
} else {
|
||||
|
@ -1092,11 +1034,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
R.string.directions_alert_redirect_title);
|
||||
builder.setMessage(getString(R.string.directions_alert_redirect_message, url.host()));
|
||||
builder.setPositiveButton(R.string.directions_alert_redirect_button_follow,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
||||
}
|
||||
});
|
||||
(dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()))));
|
||||
builder.setNegativeButton(R.string.directions_alert_redirect_button_dismiss, null);
|
||||
builder.show();
|
||||
}
|
||||
|
@ -1107,11 +1045,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
R.string.directions_alert_blocked_title);
|
||||
builder.setMessage(getString(R.string.directions_alert_blocked_message, url.host()));
|
||||
builder.setPositiveButton(R.string.directions_alert_blocked_button_retry,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
viewGo.performClick();
|
||||
}
|
||||
});
|
||||
(dialog, which) -> viewGo.performClick());
|
||||
builder.setNegativeButton(R.string.directions_alert_blocked_button_dismiss, null);
|
||||
builder.show();
|
||||
}
|
||||
|
@ -1122,11 +1056,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
R.string.directions_alert_internal_error_title);
|
||||
builder.setMessage(getString(R.string.directions_alert_internal_error_message, url.host()));
|
||||
builder.setPositiveButton(R.string.directions_alert_internal_error_button_retry,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
viewGo.performClick();
|
||||
}
|
||||
});
|
||||
(dialog, which) -> viewGo.performClick());
|
||||
builder.setNegativeButton(R.string.directions_alert_internal_error_button_dismiss, null);
|
||||
builder.show();
|
||||
}
|
||||
|
@ -1145,17 +1075,11 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
final DialogBuilder builder = DialogBuilder.warn(DirectionsActivity.this,
|
||||
R.string.alert_network_problem_title);
|
||||
builder.setMessage(R.string.alert_network_problem_message);
|
||||
builder.setPositiveButton(R.string.alert_network_problem_retry, new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
dialog.dismiss();
|
||||
viewGo.performClick();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
builder.setPositiveButton(R.string.alert_network_problem_retry, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
viewGo.performClick();
|
||||
});
|
||||
builder.setOnCancelListener(dialog -> dialog.dismiss());
|
||||
builder.show();
|
||||
}
|
||||
};
|
||||
|
@ -1172,13 +1096,11 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
|
|||
final DialogBuilder builder = DialogBuilder.get(this);
|
||||
builder.setMessage(R.string.directions_query_history_clear_confirm_message);
|
||||
builder.setPositiveButton(R.string.directions_query_history_clear_confirm_button_clear,
|
||||
new Dialog.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
queryHistoryListAdapter.removeAllEntries();
|
||||
viewFromLocation.reset();
|
||||
viewViaLocation.reset();
|
||||
viewToLocation.reset();
|
||||
}
|
||||
(dialog, which) -> {
|
||||
queryHistoryListAdapter.removeAllEntries();
|
||||
viewFromLocation.reset();
|
||||
viewViaLocation.reset();
|
||||
viewToLocation.reset();
|
||||
});
|
||||
builder.setNegativeButton(R.string.directions_query_history_clear_confirm_button_dismiss, null);
|
||||
return builder.create();
|
||||
|
|
|
@ -143,15 +143,13 @@ public class DirectionsShortcutActivity extends OeffiActivity
|
|||
|
||||
public void onLocationStart(final String provider) {
|
||||
progressDialog = ProgressDialog.show(DirectionsShortcutActivity.this, null,
|
||||
getString(R.string.acquire_location_start, provider), true, true, new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
locationHelper.stop();
|
||||
getString(R.string.acquire_location_start, provider), true, true, dialog -> {
|
||||
locationHelper.stop();
|
||||
|
||||
if (queryTripsRunnable != null)
|
||||
queryTripsRunnable.cancel();
|
||||
if (queryTripsRunnable != null)
|
||||
queryTripsRunnable.cancel();
|
||||
|
||||
finish();
|
||||
}
|
||||
finish();
|
||||
});
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
@ -264,23 +262,13 @@ public class DirectionsShortcutActivity extends OeffiActivity
|
|||
R.string.directions_alert_redirect_title);
|
||||
builder.setMessage(getString(R.string.directions_alert_redirect_message, url.host()));
|
||||
builder.setPositiveButton(R.string.directions_alert_redirect_button_follow,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
||||
finish();
|
||||
}
|
||||
(dialog, which) -> {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString())));
|
||||
finish();
|
||||
});
|
||||
builder.setNegativeButton(R.string.directions_alert_redirect_button_dismiss,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
(dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
@ -290,16 +278,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
|
|||
R.string.directions_alert_blocked_title);
|
||||
builder.setMessage(getString(R.string.directions_alert_blocked_message, url.host()));
|
||||
builder.setNeutralButton(R.string.directions_alert_blocked_button_dismiss,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
(dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
@ -309,16 +289,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
|
|||
R.string.directions_alert_internal_error_title);
|
||||
builder.setMessage(getString(R.string.directions_alert_internal_error_message, url.host()));
|
||||
builder.setNeutralButton(R.string.directions_alert_internal_error_button_dismiss,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
(dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
@ -329,16 +301,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
|
|||
builder.setMessage(getString(R.string.directions_alert_ssl_exception_message,
|
||||
Throwables.getRootCause(x).toString()));
|
||||
builder.setNeutralButton(R.string.directions_alert_ssl_exception_button_dismiss,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
(dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
};
|
||||
|
@ -351,16 +315,8 @@ public class DirectionsShortcutActivity extends OeffiActivity
|
|||
private void errorDialog(final int resId) {
|
||||
final DialogBuilder builder = DialogBuilder.warn(this, R.string.directions_shortcut_error_title);
|
||||
builder.setMessage(resId);
|
||||
builder.setPositiveButton("Ok", new OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("Ok", (dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -144,11 +144,7 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback
|
|||
|
||||
@Override
|
||||
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
chooseView.requestLayout();
|
||||
}
|
||||
});
|
||||
handler.post(() -> chooseView.requestLayout());
|
||||
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
}
|
||||
|
@ -164,23 +160,21 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback
|
|||
final int paddingCram = res.getDimensionPixelSize(R.dimen.list_entry_padding_horizontal_cram);
|
||||
final int paddingLax = res.getDimensionPixelSize(R.dimen.list_entry_padding_horizontal_lax);
|
||||
textView.setPadding(paddingLax, paddingCram, paddingLax, paddingCram);
|
||||
textView.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
|
||||
// workaround for NPE
|
||||
if (parent == null)
|
||||
return;
|
||||
textView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
// workaround for NPE
|
||||
if (parent == null)
|
||||
return;
|
||||
|
||||
final Location location = (Location) parent.getItemAtPosition(position);
|
||||
final Location location = (Location) parent.getItemAtPosition(position);
|
||||
|
||||
// workaround for NPE
|
||||
if (location == null)
|
||||
return;
|
||||
// workaround for NPE
|
||||
if (location == null)
|
||||
return;
|
||||
|
||||
setLocation(location);
|
||||
setLocation(location);
|
||||
|
||||
afterLocationViewInput();
|
||||
fireChanged();
|
||||
}
|
||||
afterLocationViewInput();
|
||||
fireChanged();
|
||||
});
|
||||
|
||||
leftDrawable = new MultiDrawable(context);
|
||||
|
|
|
@ -157,54 +157,52 @@ public abstract class QueryTripsRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnPreExecute() {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
final boolean hasOptimize = options.optimize != null;
|
||||
final boolean hasWalkSpeed = options.walkSpeed != null && options.walkSpeed != WalkSpeed.NORMAL;
|
||||
final boolean hasAccessibility = options.accessibility != null
|
||||
&& options.accessibility != Accessibility.NEUTRAL;
|
||||
handler.post(() -> {
|
||||
final boolean hasOptimize = options.optimize != null;
|
||||
final boolean hasWalkSpeed = options.walkSpeed != null && options.walkSpeed != WalkSpeed.NORMAL;
|
||||
final boolean hasAccessibility = options.accessibility != null
|
||||
&& options.accessibility != Accessibility.NEUTRAL;
|
||||
|
||||
final SpannableStringBuilder progressMessage = new SpannableStringBuilder(
|
||||
res.getString(R.string.directions_query_progress));
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), 0, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (hasOptimize || hasWalkSpeed || hasAccessibility) {
|
||||
progressMessage.append('\n');
|
||||
if (hasOptimize) {
|
||||
progressMessage.append('\n')
|
||||
.append(res.getString(R.string.directions_preferences_optimize_trip_title))
|
||||
.append(": ");
|
||||
final int begin = progressMessage.length();
|
||||
progressMessage.append(
|
||||
res.getStringArray(R.array.directions_optimize_trip)[options.optimize.ordinal()]);
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), begin, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
if (hasWalkSpeed) {
|
||||
progressMessage.append('\n')
|
||||
.append(res.getString(R.string.directions_preferences_walk_speed_title)).append(": ");
|
||||
final int begin = progressMessage.length();
|
||||
progressMessage
|
||||
.append(res.getStringArray(R.array.directions_walk_speed)[options.walkSpeed.ordinal()]);
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), begin, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
if (hasAccessibility) {
|
||||
progressMessage.append('\n')
|
||||
.append(res.getString(R.string.directions_preferences_accessibility_title))
|
||||
.append(": ");
|
||||
final int begin = progressMessage.length();
|
||||
progressMessage.append(
|
||||
res.getStringArray(R.array.directions_accessibility)[options.accessibility.ordinal()]);
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), begin, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
final SpannableStringBuilder progressMessage = new SpannableStringBuilder(
|
||||
res.getString(R.string.directions_query_progress));
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), 0, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (hasOptimize || hasWalkSpeed || hasAccessibility) {
|
||||
progressMessage.append('\n');
|
||||
if (hasOptimize) {
|
||||
progressMessage.append('\n')
|
||||
.append(res.getString(R.string.directions_preferences_optimize_trip_title))
|
||||
.append(": ");
|
||||
final int begin = progressMessage.length();
|
||||
progressMessage.append(
|
||||
res.getStringArray(R.array.directions_optimize_trip)[options.optimize.ordinal()]);
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), begin, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
if (hasWalkSpeed) {
|
||||
progressMessage.append('\n')
|
||||
.append(res.getString(R.string.directions_preferences_walk_speed_title)).append(": ");
|
||||
final int begin = progressMessage.length();
|
||||
progressMessage
|
||||
.append(res.getStringArray(R.array.directions_walk_speed)[options.walkSpeed.ordinal()]);
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), begin, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
if (hasAccessibility) {
|
||||
progressMessage.append('\n')
|
||||
.append(res.getString(R.string.directions_preferences_accessibility_title))
|
||||
.append(": ");
|
||||
final int begin = progressMessage.length();
|
||||
progressMessage.append(
|
||||
res.getStringArray(R.array.directions_accessibility)[options.accessibility.ordinal()]);
|
||||
progressMessage.setSpan(new StyleSpan(Typeface.BOLD), begin, progressMessage.length(),
|
||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
dialog.setMessage(progressMessage);
|
||||
|
||||
onPreExecute();
|
||||
}
|
||||
|
||||
dialog.setMessage(progressMessage);
|
||||
|
||||
onPreExecute();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -212,65 +210,41 @@ public abstract class QueryTripsRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnPostExecute() {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onPostExecute();
|
||||
}
|
||||
});
|
||||
handler.post(() -> onPostExecute());
|
||||
}
|
||||
|
||||
protected void onPostExecute() {
|
||||
}
|
||||
|
||||
private void postOnResult(final QueryTripsResult result) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onResult(result);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onResult(result));
|
||||
}
|
||||
|
||||
protected abstract void onResult(QueryTripsResult result);
|
||||
|
||||
private void postOnRedirect(final HttpUrl url) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onRedirect(url);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onRedirect(url));
|
||||
}
|
||||
|
||||
protected void onRedirect(final HttpUrl url) {
|
||||
}
|
||||
|
||||
private void postOnBlocked(final HttpUrl url) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onBlocked(url);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onBlocked(url));
|
||||
}
|
||||
|
||||
protected void onBlocked(final HttpUrl url) {
|
||||
}
|
||||
|
||||
private void postOnInternalError(final HttpUrl url) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onInternalError(url);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onInternalError(url));
|
||||
}
|
||||
|
||||
protected void onInternalError(final HttpUrl url) {
|
||||
}
|
||||
|
||||
private void postOnSSLException(final SSLException x) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onSSLException(x);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onSSLException(x));
|
||||
}
|
||||
|
||||
protected void onSSLException(final SSLException x) {
|
||||
|
@ -279,11 +253,7 @@ public abstract class QueryTripsRunnable implements Runnable {
|
|||
public void cancel() {
|
||||
cancelled.set(true);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onCancelled();
|
||||
}
|
||||
});
|
||||
handler.post(() -> onCancelled());
|
||||
}
|
||||
|
||||
protected void onCancelled() {
|
||||
|
|
|
@ -198,11 +198,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
|
|||
final MyActionBar actionBar = getMyActionBar();
|
||||
setPrimaryColor(R.color.action_bar_background_directions);
|
||||
actionBar.setPrimaryTitle(getTitle());
|
||||
actionBar.setBack(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
actionBar.setBack(v -> finish());
|
||||
|
||||
// action bar secondary title
|
||||
final StringBuilder secondaryTitle = new StringBuilder();
|
||||
|
@ -223,60 +219,50 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
|
|||
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
trackButton = actionBar.addToggleButton(R.drawable.ic_location_white_24dp,
|
||||
R.string.directions_trip_details_action_track_title);
|
||||
trackButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
|
||||
if (isChecked) {
|
||||
final String provider = requestLocationUpdates();
|
||||
if (provider != null) {
|
||||
final android.location.Location lastKnownLocation = locationManager
|
||||
.getLastKnownLocation(provider);
|
||||
if (lastKnownLocation != null
|
||||
&& (lastKnownLocation.getLatitude() != 0 || lastKnownLocation.getLongitude() != 0))
|
||||
location = LocationHelper.locationToPoint(lastKnownLocation);
|
||||
else
|
||||
location = null;
|
||||
mapView.setLocationAware(TripDetailsActivity.this);
|
||||
}
|
||||
} else {
|
||||
locationManager.removeUpdates(TripDetailsActivity.this);
|
||||
location = null;
|
||||
|
||||
mapView.setLocationAware(null);
|
||||
trackButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked) {
|
||||
final String provider = requestLocationUpdates();
|
||||
if (provider != null) {
|
||||
final android.location.Location lastKnownLocation = locationManager
|
||||
.getLastKnownLocation(provider);
|
||||
if (lastKnownLocation != null
|
||||
&& (lastKnownLocation.getLatitude() != 0 || lastKnownLocation.getLongitude() != 0))
|
||||
location = LocationHelper.locationToPoint(lastKnownLocation);
|
||||
else
|
||||
location = null;
|
||||
mapView.setLocationAware(TripDetailsActivity.this);
|
||||
}
|
||||
} else {
|
||||
locationManager.removeUpdates(TripDetailsActivity.this);
|
||||
location = null;
|
||||
|
||||
mapView.zoomToAll();
|
||||
updateGUI();
|
||||
mapView.setLocationAware(null);
|
||||
}
|
||||
|
||||
mapView.zoomToAll();
|
||||
updateGUI();
|
||||
});
|
||||
}
|
||||
actionBar.addButton(R.drawable.ic_share_white_24dp, R.string.directions_trip_details_action_share_title)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu popupMenu = new PopupMenu(TripDetailsActivity.this, v);
|
||||
popupMenu.inflate(R.menu.directions_trip_details_action_share);
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.directions_trip_details_action_share_short) {
|
||||
shareTripShort();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.directions_trip_details_action_share_long) {
|
||||
shareTripLong();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
popupMenu.show();
|
||||
}
|
||||
.setOnClickListener(v -> {
|
||||
final PopupMenu popupMenu = new PopupMenu(TripDetailsActivity.this, v);
|
||||
popupMenu.inflate(R.menu.directions_trip_details_action_share);
|
||||
popupMenu.setOnMenuItemClickListener(item -> {
|
||||
if (item.getItemId() == R.id.directions_trip_details_action_share_short) {
|
||||
shareTripShort();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.directions_trip_details_action_share_long) {
|
||||
shareTripLong();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
popupMenu.show();
|
||||
});
|
||||
if (getPackageManager().resolveActivity(scheduleTripIntent, 0) != null) {
|
||||
actionBar.addButton(R.drawable.ic_today_white_24dp, R.string.directions_trip_details_action_calendar_title)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
startActivity(scheduleTripIntent);
|
||||
}
|
||||
});
|
||||
.setOnClickListener(v -> startActivity(scheduleTripIntent));
|
||||
}
|
||||
|
||||
legsGroup = (ViewGroup) findViewById(R.id.directions_trip_details_legs_group);
|
||||
|
@ -626,11 +612,9 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
|
|||
expandButton
|
||||
.setVisibility(intermediateStops != null && !intermediateStops.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
expandButton.setChecked(checked != null ? checked : false);
|
||||
expandButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
|
||||
legExpandStates.put(leg, isChecked);
|
||||
updateGUI();
|
||||
}
|
||||
expandButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
legExpandStates.put(leg, isChecked);
|
||||
updateGUI();
|
||||
});
|
||||
|
||||
final TableLayout stopsView = (TableLayout) row.findViewById(R.id.directions_trip_details_public_entry_stops);
|
||||
|
@ -664,11 +648,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
|
|||
final View collapsedIntermediateStopsRow = collapsedIntermediateStopsRow(numIntermediateStops,
|
||||
leg.line.style);
|
||||
stopsView.addView(collapsedIntermediateStopsRow);
|
||||
collapsedIntermediateStopsRow.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
expandButton.setChecked(true);
|
||||
}
|
||||
});
|
||||
collapsedIntermediateStopsRow.setOnClickListener(v -> expandButton.setChecked(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -898,14 +878,12 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
|
|||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new StationContextMenu(TripDetailsActivity.this, v, network, location, null,
|
||||
false, false, true, false, false);
|
||||
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.station_context_details) {
|
||||
StationDetailsActivity.start(TripDetailsActivity.this, network, location);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
contextMenu.setOnMenuItemClickListener(item -> {
|
||||
if (item.getItemId() == R.id.station_context_details) {
|
||||
StationDetailsActivity.start(TripDetailsActivity.this, network, location);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
|
@ -922,28 +900,26 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
|
|||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new StationContextMenu(TripDetailsActivity.this, v, network, stop.location,
|
||||
null, false, false, true, true, false);
|
||||
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.station_context_details) {
|
||||
StationDetailsActivity.start(TripDetailsActivity.this, network, stop.location);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.station_context_directions_from) {
|
||||
final Date arrivalTime = stop.getArrivalTime();
|
||||
final TimeSpec.Absolute time = new TimeSpec.Absolute(DepArr.DEPART,
|
||||
arrivalTime != null ? arrivalTime.getTime() : stop.getDepartureTime().getTime());
|
||||
DirectionsActivity.start(TripDetailsActivity.this, stop.location, trip.to, time,
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.station_context_directions_to) {
|
||||
final Date arrivalTime = stop.getArrivalTime();
|
||||
final TimeSpec.Absolute time = new TimeSpec.Absolute(DepArr.ARRIVE,
|
||||
arrivalTime != null ? arrivalTime.getTime() : stop.getDepartureTime().getTime());
|
||||
DirectionsActivity.start(TripDetailsActivity.this, trip.from, stop.location, time,
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
contextMenu.setOnMenuItemClickListener(item -> {
|
||||
if (item.getItemId() == R.id.station_context_details) {
|
||||
StationDetailsActivity.start(TripDetailsActivity.this, network, stop.location);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.station_context_directions_from) {
|
||||
final Date arrivalTime = stop.getArrivalTime();
|
||||
final TimeSpec.Absolute time = new TimeSpec.Absolute(DepArr.DEPART,
|
||||
arrivalTime != null ? arrivalTime.getTime() : stop.getDepartureTime().getTime());
|
||||
DirectionsActivity.start(TripDetailsActivity.this, stop.location, trip.to, time,
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.station_context_directions_to) {
|
||||
final Date arrivalTime = stop.getArrivalTime();
|
||||
final TimeSpec.Absolute time = new TimeSpec.Absolute(DepArr.ARRIVE,
|
||||
arrivalTime != null ? arrivalTime.getTime() : stop.getDepartureTime().getTime());
|
||||
DirectionsActivity.start(TripDetailsActivity.this, trip.from, stop.location, time,
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
|
|
|
@ -101,17 +101,15 @@ public class TripsOverviewActivity extends OeffiActivity {
|
|||
|
||||
private @Nullable QueryTripsContext context;
|
||||
private TripsGallery barView;
|
||||
private final NavigableSet<Trip> trips = new TreeSet<>(new Comparator<Trip>() {
|
||||
public int compare(final Trip trip1, final Trip trip2) {
|
||||
if (trip1.equals(trip2))
|
||||
return 0;
|
||||
else
|
||||
return ComparisonChain.start() //
|
||||
.compare(trip1.getFirstDepartureTime(), trip2.getFirstDepartureTime()) //
|
||||
.compare(trip1.getLastArrivalTime(), trip2.getLastArrivalTime()) //
|
||||
.compare(trip1.numChanges, trip2.numChanges, Ordering.natural().nullsLast()) //
|
||||
.result();
|
||||
}
|
||||
private final NavigableSet<Trip> trips = new TreeSet<>((trip1, trip2) -> {
|
||||
if (trip1.equals(trip2))
|
||||
return 0;
|
||||
else
|
||||
return ComparisonChain.start() //
|
||||
.compare(trip1.getFirstDepartureTime(), trip2.getFirstDepartureTime()) //
|
||||
.compare(trip1.getLastArrivalTime(), trip2.getLastArrivalTime()) //
|
||||
.compare(trip1.numChanges, trip2.numChanges, Ordering.natural().nullsLast()) //
|
||||
.result();
|
||||
});
|
||||
private boolean queryMoreTripsRunning = false;
|
||||
|
||||
|
@ -142,45 +140,31 @@ public class TripsOverviewActivity extends OeffiActivity {
|
|||
setContentView(R.layout.directions_trip_overview_content);
|
||||
final MyActionBar actionBar = getMyActionBar();
|
||||
setPrimaryColor(R.color.action_bar_background_directions_dark);
|
||||
actionBar.setBack(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
actionBar.setBack(v -> finish());
|
||||
actionBar.setCustomTitles(R.layout.directions_trip_overview_custom_title);
|
||||
actionBar.addProgressButton().setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
handler.post(checkMoreRunnable);
|
||||
}
|
||||
});
|
||||
actionBar.addProgressButton().setOnClickListener(v -> handler.post(checkMoreRunnable));
|
||||
|
||||
barView = (TripsGallery) findViewById(R.id.trips_bar_view);
|
||||
barView.setOnItemClickListener(new OnItemClickListener() {
|
||||
public void onItemClick(final AdapterView<?> parent, final View v, final int position, final long id) {
|
||||
final Trip trip = (Trip) barView.getAdapter().getItem(position);
|
||||
barView.setOnItemClickListener((parent, v, position, id) -> {
|
||||
final Trip trip = (Trip) barView.getAdapter().getItem(position);
|
||||
|
||||
if (trip != null && trip.legs != null) {
|
||||
TripDetailsActivity.start(TripsOverviewActivity.this, network, trip);
|
||||
if (trip != null && trip.legs != null) {
|
||||
TripDetailsActivity.start(TripsOverviewActivity.this, network, trip);
|
||||
|
||||
final Date firstPublicLegDepartureTime = trip.getFirstPublicLegDepartureTime();
|
||||
final Date lastPublicLegArrivalTime = trip.getLastPublicLegArrivalTime();
|
||||
final Date firstPublicLegDepartureTime = trip.getFirstPublicLegDepartureTime();
|
||||
final Date lastPublicLegArrivalTime = trip.getLastPublicLegArrivalTime();
|
||||
|
||||
// save last trip to history
|
||||
if (firstPublicLegDepartureTime != null && lastPublicLegArrivalTime != null && historyUri != null) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(QueryHistoryProvider.KEY_LAST_DEPARTURE_TIME, firstPublicLegDepartureTime.getTime());
|
||||
values.put(QueryHistoryProvider.KEY_LAST_ARRIVAL_TIME, lastPublicLegArrivalTime.getTime());
|
||||
values.put(QueryHistoryProvider.KEY_LAST_TRIP, serialize(trip));
|
||||
getContentResolver().update(historyUri, values, null, null);
|
||||
}
|
||||
// save last trip to history
|
||||
if (firstPublicLegDepartureTime != null && lastPublicLegArrivalTime != null && historyUri != null) {
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(QueryHistoryProvider.KEY_LAST_DEPARTURE_TIME, firstPublicLegDepartureTime.getTime());
|
||||
values.put(QueryHistoryProvider.KEY_LAST_ARRIVAL_TIME, lastPublicLegArrivalTime.getTime());
|
||||
values.put(QueryHistoryProvider.KEY_LAST_TRIP, serialize(trip));
|
||||
getContentResolver().update(historyUri, values, null, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
barView.setOnScrollListener(new OnScrollListener() {
|
||||
public void onScroll() {
|
||||
handler.post(checkMoreRunnable);
|
||||
}
|
||||
});
|
||||
barView.setOnScrollListener(() -> handler.post(checkMoreRunnable));
|
||||
|
||||
processResult(result, dep);
|
||||
}
|
||||
|
@ -259,21 +243,15 @@ public class TripsOverviewActivity extends OeffiActivity {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
actionBar.startProgress();
|
||||
}
|
||||
});
|
||||
runOnUiThread(() -> actionBar.startProgress());
|
||||
|
||||
try {
|
||||
doRequest();
|
||||
} finally {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
queryMoreTripsRunning = false;
|
||||
runOnUiThread(() -> {
|
||||
queryMoreTripsRunning = false;
|
||||
|
||||
actionBar.stopProgress();
|
||||
}
|
||||
actionBar.stopProgress();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -288,34 +266,24 @@ public class TripsOverviewActivity extends OeffiActivity {
|
|||
final NetworkProvider networkProvider = NetworkProviderFactory.provider(network);
|
||||
final QueryTripsResult result = networkProvider.queryMoreTrips(context, later);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
log.debug("Got {} ({})", result.toShortString(), later ? "later" : "earlier");
|
||||
if (result.status == QueryTripsResult.Status.OK) {
|
||||
processResult(result, later);
|
||||
runOnUiThread(() -> {
|
||||
log.debug("Got {} ({})", result.toShortString(), later ? "later" : "earlier");
|
||||
if (result.status == QueryTripsResult.Status.OK) {
|
||||
processResult(result, later);
|
||||
|
||||
// fetch more
|
||||
handler.postDelayed(checkMoreRunnable, 50);
|
||||
} else if (result.status == QueryTripsResult.Status.NO_TRIPS) {
|
||||
// ignore
|
||||
} else {
|
||||
new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem);
|
||||
}
|
||||
// fetch more
|
||||
handler.postDelayed(checkMoreRunnable, 50);
|
||||
} else if (result.status == QueryTripsResult.Status.NO_TRIPS) {
|
||||
// ignore
|
||||
} else {
|
||||
new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem);
|
||||
}
|
||||
});
|
||||
} catch (final SessionExpiredException | NotFoundException x) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(TripsOverviewActivity.this).longToast(R.string.toast_session_expired);
|
||||
}
|
||||
});
|
||||
runOnUiThread(() -> new Toast(TripsOverviewActivity.this).longToast(R.string.toast_session_expired));
|
||||
} catch (final InvalidDataException x) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(TripsOverviewActivity.this).longToast(R.string.toast_invalid_data,
|
||||
x.getMessage());
|
||||
}
|
||||
});
|
||||
runOnUiThread(() -> new Toast(TripsOverviewActivity.this).longToast(R.string.toast_invalid_data,
|
||||
x.getMessage()));
|
||||
} catch (final IOException x) {
|
||||
final String message = "IO problem while processing " + context + " on " + network + " (try "
|
||||
+ tries + ")";
|
||||
|
@ -323,18 +291,10 @@ public class TripsOverviewActivity extends OeffiActivity {
|
|||
if (tries >= Constants.MAX_TRIES_ON_IO_PROBLEM) {
|
||||
if (x instanceof SocketTimeoutException || x instanceof UnknownHostException
|
||||
|| x instanceof SocketException || x instanceof SSLException) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem);
|
||||
}
|
||||
});
|
||||
runOnUiThread(() -> new Toast(TripsOverviewActivity.this).toast(R.string.toast_network_problem));
|
||||
} else if (x instanceof InternalErrorException) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(TripsOverviewActivity.this).toast(R.string.toast_internal_error,
|
||||
((InternalErrorException) x).getUrl().host());
|
||||
}
|
||||
});
|
||||
runOnUiThread(() -> new Toast(TripsOverviewActivity.this).toast(R.string.toast_internal_error,
|
||||
((InternalErrorException) x).getUrl().host()));
|
||||
} else {
|
||||
throw new RuntimeException(message, x);
|
||||
}
|
||||
|
|
|
@ -65,12 +65,10 @@ public class QueryHistoryViewHolder extends RecyclerView.ViewHolder {
|
|||
final QueryHistoryContextMenuItemListener contextMenuItemListener) {
|
||||
final boolean selected = rowId == selectedRowId;
|
||||
itemView.setActivated(selected);
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
clickListener.onEntryClick(position, from, to);
|
||||
}
|
||||
itemView.setOnClickListener(v -> {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
clickListener.onEntryClick(position, from, to);
|
||||
});
|
||||
|
||||
fromView.setLocation(from);
|
||||
|
@ -84,78 +82,72 @@ public class QueryHistoryViewHolder extends RecyclerView.ViewHolder {
|
|||
final long now = System.currentTimeMillis();
|
||||
tripView.setText(Formats.formatDate(context, now, savedTripDepartureTime) + "\n"
|
||||
+ Formats.formatTime(context, savedTripDepartureTime));
|
||||
tripView.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
clickListener.onSavedTripClick(position, serializedSavedTrip);
|
||||
}
|
||||
tripView.setOnClickListener(v -> {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
clickListener.onSavedTripClick(position, serializedSavedTrip);
|
||||
});
|
||||
} else {
|
||||
tripView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
contextButton.setVisibility(selected ? View.VISIBLE : View.GONE);
|
||||
contextButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new PopupMenu(context, v);
|
||||
final MenuInflater inflater = contextMenu.getMenuInflater();
|
||||
final Menu menu = contextMenu.getMenu();
|
||||
inflater.inflate(R.menu.directions_query_history_context, menu);
|
||||
menu.findItem(R.id.directions_query_history_context_show_trip).setVisible(hasSavedTrip);
|
||||
menu.findItem(R.id.directions_query_history_context_remove_trip).setVisible(hasSavedTrip);
|
||||
menu.findItem(R.id.directions_query_history_context_add_favorite).setVisible(!isFavorite);
|
||||
menu.findItem(R.id.directions_query_history_context_remove_favorite).setVisible(isFavorite);
|
||||
final SubMenu fromMenu;
|
||||
if (from.isIdentified()) {
|
||||
fromMenu = menu.addSubMenu(from.uniqueShortName());
|
||||
inflater.inflate(R.menu.directions_query_history_location_context, fromMenu);
|
||||
fromMenu.findItem(R.id.directions_query_history_location_context_details)
|
||||
.setVisible(from.type == LocationType.STATION);
|
||||
fromMenu.findItem(R.id.directions_query_history_location_context_add_favorite)
|
||||
.setVisible(from.type == LocationType.STATION && (fromFavState == null
|
||||
|| fromFavState != FavoriteStationsProvider.TYPE_FAVORITE));
|
||||
final SubMenu mapMenu = fromMenu.findItem(R.id.directions_query_history_location_context_map)
|
||||
.getSubMenu();
|
||||
StationContextMenu.prepareMapMenu(context, mapMenu, network, from);
|
||||
} else {
|
||||
fromMenu = null;
|
||||
}
|
||||
final SubMenu toMenu;
|
||||
if (to.isIdentified()) {
|
||||
toMenu = menu.addSubMenu(to.uniqueShortName());
|
||||
inflater.inflate(R.menu.directions_query_history_location_context, toMenu);
|
||||
toMenu.findItem(R.id.directions_query_history_location_context_details)
|
||||
.setVisible(to.type == LocationType.STATION);
|
||||
toMenu.findItem(R.id.directions_query_history_location_context_add_favorite)
|
||||
.setVisible(to.type == LocationType.STATION
|
||||
&& (toFavState == null || toFavState != FavoriteStationsProvider.TYPE_FAVORITE));
|
||||
final SubMenu mapMenu = toMenu.findItem(R.id.directions_query_history_location_context_map)
|
||||
.getSubMenu();
|
||||
StationContextMenu.prepareMapMenu(context, mapMenu, network, to);
|
||||
} else {
|
||||
toMenu = null;
|
||||
}
|
||||
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
if (fromMenu != null && item == fromMenu.findItem(item.getItemId()))
|
||||
return contextMenuItemListener.onQueryHistoryContextMenuItemClick(position, from, to,
|
||||
serializedSavedTrip, item.getItemId(), from);
|
||||
else if (toMenu != null && item == toMenu.findItem(item.getItemId()))
|
||||
return contextMenuItemListener.onQueryHistoryContextMenuItemClick(position, from, to,
|
||||
serializedSavedTrip, item.getItemId(), to);
|
||||
else
|
||||
return contextMenuItemListener.onQueryHistoryContextMenuItemClick(position, from, to,
|
||||
serializedSavedTrip, item.getItemId(), null);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
contextButton.setOnClickListener(v -> {
|
||||
final PopupMenu contextMenu = new PopupMenu(context, v);
|
||||
final MenuInflater inflater = contextMenu.getMenuInflater();
|
||||
final Menu menu = contextMenu.getMenu();
|
||||
inflater.inflate(R.menu.directions_query_history_context, menu);
|
||||
menu.findItem(R.id.directions_query_history_context_show_trip).setVisible(hasSavedTrip);
|
||||
menu.findItem(R.id.directions_query_history_context_remove_trip).setVisible(hasSavedTrip);
|
||||
menu.findItem(R.id.directions_query_history_context_add_favorite).setVisible(!isFavorite);
|
||||
menu.findItem(R.id.directions_query_history_context_remove_favorite).setVisible(isFavorite);
|
||||
final SubMenu fromMenu;
|
||||
if (from.isIdentified()) {
|
||||
fromMenu = menu.addSubMenu(from.uniqueShortName());
|
||||
inflater.inflate(R.menu.directions_query_history_location_context, fromMenu);
|
||||
fromMenu.findItem(R.id.directions_query_history_location_context_details)
|
||||
.setVisible(from.type == LocationType.STATION);
|
||||
fromMenu.findItem(R.id.directions_query_history_location_context_add_favorite)
|
||||
.setVisible(from.type == LocationType.STATION && (fromFavState == null
|
||||
|| fromFavState != FavoriteStationsProvider.TYPE_FAVORITE));
|
||||
final SubMenu mapMenu = fromMenu.findItem(R.id.directions_query_history_location_context_map)
|
||||
.getSubMenu();
|
||||
StationContextMenu.prepareMapMenu(context, mapMenu, network, from);
|
||||
} else {
|
||||
fromMenu = null;
|
||||
}
|
||||
final SubMenu toMenu;
|
||||
if (to.isIdentified()) {
|
||||
toMenu = menu.addSubMenu(to.uniqueShortName());
|
||||
inflater.inflate(R.menu.directions_query_history_location_context, toMenu);
|
||||
toMenu.findItem(R.id.directions_query_history_location_context_details)
|
||||
.setVisible(to.type == LocationType.STATION);
|
||||
toMenu.findItem(R.id.directions_query_history_location_context_add_favorite)
|
||||
.setVisible(to.type == LocationType.STATION
|
||||
&& (toFavState == null || toFavState != FavoriteStationsProvider.TYPE_FAVORITE));
|
||||
final SubMenu mapMenu = toMenu.findItem(R.id.directions_query_history_location_context_map)
|
||||
.getSubMenu();
|
||||
StationContextMenu.prepareMapMenu(context, mapMenu, network, to);
|
||||
} else {
|
||||
toMenu = null;
|
||||
}
|
||||
contextMenu.setOnMenuItemClickListener(item -> {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
if (fromMenu != null && item == fromMenu.findItem(item.getItemId()))
|
||||
return contextMenuItemListener.onQueryHistoryContextMenuItemClick(position, from, to,
|
||||
serializedSavedTrip, item.getItemId(), from);
|
||||
else if (toMenu != null && item == toMenu.findItem(item.getItemId()))
|
||||
return contextMenuItemListener.onQueryHistoryContextMenuItemClick(position, from, to,
|
||||
serializedSavedTrip, item.getItemId(), to);
|
||||
else
|
||||
return contextMenuItemListener.onQueryHistoryContextMenuItemClick(position, from, to,
|
||||
serializedSavedTrip, item.getItemId(), null);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,11 +86,7 @@ public abstract class GetAreaRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnResult(final Point[] area) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onResult(area);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onResult(area));
|
||||
}
|
||||
|
||||
protected abstract void onResult(final Point[] area);
|
||||
|
|
|
@ -144,11 +144,7 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
|
|||
((FrameLayout) findViewById(R.id.network_picker_firsttime_message_shadow)).setForeground(null);
|
||||
} else {
|
||||
findViewById(R.id.network_picker_firsttime_message).setVisibility(View.GONE);
|
||||
actionBar.setBack(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
actionBar.setBack(v -> finish());
|
||||
final NetworkId networkId = prefsGetNetworkId();
|
||||
if (networkId != null) {
|
||||
backgroundHandler.post(new GetAreaRunnable(NetworkProviderFactory.provider(networkId), handler) {
|
||||
|
|
|
@ -68,11 +68,7 @@ public class NetworkViewHolder extends RecyclerView.ViewHolder {
|
|||
@Nullable final NetworkContextMenuItemListener contextMenuItemListener) {
|
||||
itemView.setFocusable(isEnabled);
|
||||
if (clickListener != null) {
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
clickListener.onNetworkClick(entry);
|
||||
}
|
||||
});
|
||||
itemView.setOnClickListener(v -> clickListener.onNetworkClick(entry));
|
||||
} else {
|
||||
itemView.setOnClickListener(null);
|
||||
}
|
||||
|
@ -114,17 +110,11 @@ public class NetworkViewHolder extends RecyclerView.ViewHolder {
|
|||
if (contextMenuItemListener != null) {
|
||||
contextButton.setVisibility(View.VISIBLE);
|
||||
contextButtonSpace.setVisibility(View.VISIBLE);
|
||||
contextButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new PopupMenu(context, v);
|
||||
contextMenu.inflate(R.menu.network_picker_context);
|
||||
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
return contextMenuItemListener.onNetworkContextMenuItemClick(entry, item.getItemId());
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
}
|
||||
contextButton.setOnClickListener(v -> {
|
||||
final PopupMenu contextMenu = new PopupMenu(context, v);
|
||||
contextMenu.inflate(R.menu.network_picker_context);
|
||||
contextMenu.setOnMenuItemClickListener(item -> contextMenuItemListener.onNetworkContextMenuItemClick(entry, item.getItemId()));
|
||||
contextMenu.show();
|
||||
});
|
||||
} else {
|
||||
contextButton.setVisibility(View.GONE);
|
||||
|
|
|
@ -137,35 +137,29 @@ public class PlanActivity extends Activity {
|
|||
viewAnimator = (ViewAnimator) findViewById(R.id.plans_layout);
|
||||
|
||||
plan = (ScrollImageView) findViewById(R.id.plans_plan);
|
||||
plan.setOnMoveListener(new OnMoveListener() {
|
||||
public void onMove() {
|
||||
updateBubble();
|
||||
updateScale();
|
||||
plan.setOnMoveListener(() -> {
|
||||
updateBubble();
|
||||
updateScale();
|
||||
|
||||
zoom.clearAnimation();
|
||||
zoom.startAnimation(zoomControlsAnimation);
|
||||
}
|
||||
zoom.clearAnimation();
|
||||
zoom.startAnimation(zoomControlsAnimation);
|
||||
});
|
||||
|
||||
bubble = findViewById(R.id.plans_bubble);
|
||||
bubble.setVisibility(View.GONE);
|
||||
bubble.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final Station selection = checkNotNull(PlanActivity.this.selection);
|
||||
final PopupMenu contextMenu = new StationContextMenu(PlanActivity.this, v, selection.network,
|
||||
selection.location, null, false, false, false, false, false);
|
||||
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.station_context_details) {
|
||||
StationDetailsActivity.start(PlanActivity.this, selection.network, selection.location);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
}
|
||||
bubble.setOnClickListener(v -> {
|
||||
final Station selection = checkNotNull(PlanActivity.this.selection);
|
||||
final PopupMenu contextMenu = new StationContextMenu(PlanActivity.this, v, selection.network,
|
||||
selection.location, null, false, false, false, false, false);
|
||||
contextMenu.setOnMenuItemClickListener(item -> {
|
||||
if (item.getItemId() == R.id.station_context_details) {
|
||||
StationDetailsActivity.start(PlanActivity.this, selection.network, selection.location);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
});
|
||||
|
||||
bubbleName = (TextView) findViewById(R.id.plans_bubble_name);
|
||||
|
@ -173,17 +167,13 @@ public class PlanActivity extends Activity {
|
|||
bubbleLinesView = (LineView) findViewById(R.id.plans_bubble_lines);
|
||||
|
||||
zoom = (ZoomControls) findViewById(R.id.plans_zoom);
|
||||
zoom.setOnZoomInClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
plan.animateScaleStepIn();
|
||||
updateScale();
|
||||
}
|
||||
zoom.setOnZoomInClickListener(v -> {
|
||||
plan.animateScaleStepIn();
|
||||
updateScale();
|
||||
});
|
||||
zoom.setOnZoomOutClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
plan.animateScaleStepOut();
|
||||
updateScale();
|
||||
}
|
||||
zoom.setOnZoomOutClickListener(v -> {
|
||||
plan.animateScaleStepOut();
|
||||
updateScale();
|
||||
});
|
||||
|
||||
final String planId = checkNotNull(getIntent().getExtras().getString(INTENT_EXTRA_PLAN_ID),
|
||||
|
@ -408,11 +398,7 @@ public class PlanActivity extends Activity {
|
|||
for (final Station station : stations) {
|
||||
if (selectedId.equals(station.location.id)) {
|
||||
// delay until after layout finished
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
selectStation(station);
|
||||
}
|
||||
}, 500);
|
||||
handler.postDelayed(() -> selectStation(station), 500);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -113,11 +113,7 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
|
|||
setPrimaryColor(R.color.action_bar_background);
|
||||
actionBar.setPrimaryTitle(R.string.plans_activity_title);
|
||||
actionBar.addButton(R.drawable.ic_search_white_24dp, R.string.plans_picker_action_search_title)
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
onSearchRequested();
|
||||
}
|
||||
});
|
||||
.setOnClickListener(v -> onSearchRequested());
|
||||
|
||||
initNavigation();
|
||||
|
||||
|
@ -132,11 +128,7 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
|
|||
connectivityWarningView = (TextView) findViewById(R.id.plans_picker_connectivity_warning_box);
|
||||
filterBox = findViewById(R.id.plans_picker_filter_box);
|
||||
|
||||
findViewById(R.id.plans_picker_filter_clear).setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
clearListFilter();
|
||||
}
|
||||
});
|
||||
findViewById(R.id.plans_picker_filter_clear).setOnClickListener(v -> clearListFilter());
|
||||
|
||||
connectivityReceiver = new ConnectivityBroadcastReceiver(connectivityManager) {
|
||||
@Override
|
||||
|
@ -308,21 +300,15 @@ public class PlansPickerActivity extends OeffiMainActivity implements ActivityCo
|
|||
final HttpUrl remoteUrl = plan.url != null ? plan.url
|
||||
: Constants.PLANS_BASE_URL.newBuilder().addEncodedPathSegment(planFilename).build();
|
||||
final ListenableFuture<Integer> download = downloader.download(remoteUrl, planFile, false,
|
||||
new Downloader.ProgressCallback() {
|
||||
public void progress(final long contentRead, final long contentLength) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
final RecyclerView.ViewHolder holder = listView.findViewHolderForItemId(plan.rowId);
|
||||
if (holder != null) {
|
||||
final int position = holder.getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
listAdapter.setProgressPermille(position,
|
||||
(int) (contentRead * 1000 / contentLength));
|
||||
}
|
||||
}
|
||||
});
|
||||
(contentRead, contentLength) -> runOnUiThread(() -> {
|
||||
final RecyclerView.ViewHolder holder = listView.findViewHolderForItemId(plan.rowId);
|
||||
if (holder != null) {
|
||||
final int position = holder.getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
listAdapter.setProgressPermille(position,
|
||||
(int) (contentRead * 1000 / contentLength));
|
||||
}
|
||||
});
|
||||
}));
|
||||
actionBar.startProgress();
|
||||
Futures.addCallback(download, new FutureCallback<Integer>() {
|
||||
public void onSuccess(final @Nullable Integer status) {
|
||||
|
|
|
@ -71,11 +71,7 @@ public class PlanViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
public void bind(final PlansAdapter.Plan plan, final PlanClickListener clickListener,
|
||||
final PlanContextMenuItemListener contextMenuItemListener) {
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
clickListener.onPlanClick(plan);
|
||||
}
|
||||
});
|
||||
itemView.setOnClickListener(v -> clickListener.onPlanClick(plan));
|
||||
|
||||
thumbView.setImageDrawable(null);
|
||||
|
||||
|
@ -101,18 +97,13 @@ public class PlanViewHolder extends RecyclerView.ViewHolder {
|
|||
networkLogoView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
contextButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new PopupMenu(context, v);
|
||||
contextMenu.inflate(R.menu.plans_picker_context);
|
||||
contextMenu.getMenu().findItem(R.id.plans_picker_context_remove).setVisible(plan.localFile.exists());
|
||||
contextMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
return contextMenuItemListener.onPlanContextMenuItemClick(plan, item.getItemId());
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
}
|
||||
contextButton.setOnClickListener(v -> {
|
||||
final PopupMenu contextMenu = new PopupMenu(context, v);
|
||||
contextMenu.inflate(R.menu.plans_picker_context);
|
||||
contextMenu.getMenu().findItem(R.id.plans_picker_context_remove).setVisible(plan.localFile.exists());
|
||||
contextMenu.setOnMenuItemClickListener(item -> contextMenuItemListener.onPlanContextMenuItemClick(plan,
|
||||
item.getItemId()));
|
||||
contextMenu.show();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -154,24 +154,18 @@ public class PlansAdapter extends RecyclerView.Adapter<PlanViewHolder> {
|
|||
else
|
||||
thumb = res.getDrawable(R.drawable.ic_oeffi_plans_grey300_72dp).mutate();
|
||||
if (!call.isCanceled()) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
holder.setCall(null);
|
||||
final int position = holder.getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
notifyItemChanged(position, thumb);
|
||||
}
|
||||
handler.post(() -> {
|
||||
holder.setCall(null);
|
||||
final int position1 = holder.getAdapterPosition();
|
||||
if (position1 != RecyclerView.NO_POSITION)
|
||||
notifyItemChanged(position1, thumb);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onFailure(final Call call, final IOException e) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
holder.setCall(null);
|
||||
}
|
||||
});
|
||||
handler.post(() -> holder.setCall(null));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -53,13 +53,10 @@ public class AboutFragment extends PreferenceFragment {
|
|||
final Uri marketUri = Uri.parse(String.format(Constants.MARKET_APP_URL, application.getPackageName()));
|
||||
findPreference(KEY_ABOUT_MARKET_APP).setSummary(marketUri.toString());
|
||||
findPreference(KEY_ABOUT_MARKET_APP).setIntent(new Intent(Intent.ACTION_VIEW, marketUri));
|
||||
findPreference(KEY_ABOUT_CHANGELOG).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
ChangelogDialogBuilder.get(activity, Application.versionCode(application), null,
|
||||
Application.versionFlavor(application), 0, null).show();
|
||||
return true;
|
||||
}
|
||||
findPreference(KEY_ABOUT_CHANGELOG).setOnPreferenceClickListener(preference -> {
|
||||
ChangelogDialogBuilder.get(activity, Application.versionCode(application), null,
|
||||
Application.versionFlavor(application), 0, null).show();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,9 @@ public class DonateFragment extends PreferenceFragment {
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.preference_donate);
|
||||
findPreference(KEY_ABOUT_DONATE_BITCOIN).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
BitcoinIntegration.request(getActivity(), Constants.BITCOIN_ADDRESS);
|
||||
return true;
|
||||
}
|
||||
findPreference(KEY_ABOUT_DONATE_BITCOIN).setOnPreferenceClickListener(preference -> {
|
||||
BitcoinIntegration.request(getActivity(), Constants.BITCOIN_ADDRESS);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,11 +61,7 @@ public class DecodeForeignActivity extends Activity {
|
|||
final Matcher m = Pattern.compile("/t/d(\\d+)").matcher(path);
|
||||
if (m.matches()) {
|
||||
final ProgressDialog progressDialog = ProgressDialog.show(DecodeForeignActivity.this, null,
|
||||
getString(R.string.stations_decode_foreign_progress), true, true, new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
getString(R.string.stations_decode_foreign_progress), true, true, dialog -> finish());
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
final Request.Builder request = new Request.Builder();
|
||||
|
@ -79,18 +75,16 @@ public class DecodeForeignActivity extends Activity {
|
|||
if (mRefresh.find()) {
|
||||
final Uri refreshUri = Uri.parse(mRefresh.group(1));
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
progressDialog.dismiss();
|
||||
if ("mobil.rmv.de".equals(refreshUri.getHost())
|
||||
&& "/mobile".equals(refreshUri.getPath())) {
|
||||
final String id = refreshUri.getQueryParameter("id");
|
||||
StationDetailsActivity.start(DecodeForeignActivity.this,
|
||||
NetworkId.NVV, new Location(LocationType.STATION, id));
|
||||
finish();
|
||||
} else {
|
||||
errorDialog(R.string.stations_decode_foreign_failed);
|
||||
}
|
||||
runOnUiThread(() -> {
|
||||
progressDialog.dismiss();
|
||||
if ("mobil.rmv.de".equals(refreshUri.getHost())
|
||||
&& "/mobile".equals(refreshUri.getPath())) {
|
||||
final String id = refreshUri.getQueryParameter("id");
|
||||
StationDetailsActivity.start(DecodeForeignActivity.this,
|
||||
NetworkId.NVV, new Location(LocationType.STATION, id));
|
||||
finish();
|
||||
} else {
|
||||
errorDialog(R.string.stations_decode_foreign_failed);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -107,11 +101,9 @@ public class DecodeForeignActivity extends Activity {
|
|||
}
|
||||
|
||||
private void onFail() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
progressDialog.dismiss();
|
||||
errorDialog(R.string.stations_decode_foreign_failed);
|
||||
}
|
||||
runOnUiThread(() -> {
|
||||
progressDialog.dismiss();
|
||||
errorDialog(R.string.stations_decode_foreign_failed);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -127,16 +119,8 @@ public class DecodeForeignActivity extends Activity {
|
|||
private void errorDialog(final int resId) {
|
||||
final DialogBuilder builder = DialogBuilder.warn(this, 0);
|
||||
builder.setMessage(resId);
|
||||
builder.setPositiveButton("Ok", new OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("Ok", (dialog, which) -> finish());
|
||||
builder.setOnCancelListener(dialog -> finish());
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,11 +77,7 @@ public class FavoriteStationsActivity extends OeffiActivity
|
|||
final MyActionBar actionBar = getMyActionBar();
|
||||
setPrimaryColor(R.color.action_bar_background_stations);
|
||||
actionBar.setPrimaryTitle(getTitle());
|
||||
actionBar.setBack(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
actionBar.setBack(v -> finish());
|
||||
|
||||
viewAnimator = (ViewAnimator) findViewById(R.id.favorites_layout);
|
||||
|
||||
|
|
|
@ -121,11 +121,7 @@ public class LineView extends TextView {
|
|||
|
||||
// sort by count
|
||||
final List<Entry<Product, Integer>> sortedEntries = new ArrayList<>(productCounts.entrySet());
|
||||
Collections.sort(sortedEntries, new Comparator<Entry<Product, Integer>>() {
|
||||
public int compare(final Entry<Product, Integer> entry1, final Entry<Product, Integer> entry2) {
|
||||
return entry2.getValue().compareTo(entry1.getValue());
|
||||
}
|
||||
});
|
||||
Collections.sort(sortedEntries, (entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue()));
|
||||
|
||||
// condense
|
||||
for (final Map.Entry<Product, Integer> entry : sortedEntries) {
|
||||
|
|
|
@ -122,43 +122,27 @@ public abstract class QueryDeparturesRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnPreExecute() {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onPreExecute();
|
||||
}
|
||||
});
|
||||
handler.post(() -> onPreExecute());
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
}
|
||||
|
||||
private void postOnPostExecute() {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onPostExecute();
|
||||
}
|
||||
});
|
||||
handler.post(() -> onPostExecute());
|
||||
}
|
||||
|
||||
protected void onPostExecute() {
|
||||
}
|
||||
|
||||
private void postOnResult(final QueryDeparturesResult result) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onResult(result);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onResult(result));
|
||||
}
|
||||
|
||||
protected abstract void onResult(QueryDeparturesResult result);
|
||||
|
||||
private void postOnRedirect(final HttpUrl url) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onRedirect(url);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onRedirect(url));
|
||||
}
|
||||
|
||||
protected void onRedirect(final HttpUrl url) {
|
||||
|
@ -166,11 +150,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnBlocked(final HttpUrl url) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onBlocked(url);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onBlocked(url));
|
||||
}
|
||||
|
||||
protected void onBlocked(final HttpUrl url) {
|
||||
|
@ -178,11 +158,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnInternalError(final HttpUrl url) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onInternalError(url);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onInternalError(url));
|
||||
}
|
||||
|
||||
protected void onInternalError(final HttpUrl url) {
|
||||
|
@ -190,11 +166,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnParserException(final String message) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onParserException(message);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onParserException(message));
|
||||
}
|
||||
|
||||
protected void onParserException(final String message) {
|
||||
|
@ -202,11 +174,7 @@ public abstract class QueryDeparturesRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void postOnInputOutputError(final IOException x) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
onInputOutputError(x);
|
||||
}
|
||||
});
|
||||
handler.post(() -> onInputOutputError(x));
|
||||
}
|
||||
|
||||
protected void onInputOutputError(final IOException x) {
|
||||
|
|
|
@ -85,39 +85,37 @@ public class StationContextMenu extends PopupMenu {
|
|||
builder.setTitle(R.string.station_context_launcher_shortcut_title);
|
||||
builder.setView(view);
|
||||
builder.setPositiveButton(R.string.create_launcher_shortcut_dialog_button_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
final EditText nameView = (EditText) view
|
||||
.findViewById(R.id.create_launcher_shortcut_dialog_name);
|
||||
final String shortcutName = nameView.getText().toString();
|
||||
final String shortcutId = "directions-to-" + networkId.name() + "-" + location.id;
|
||||
final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN, null, context,
|
||||
DirectionsShortcutActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_NETWORK, networkId.name());
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_TYPE, location.type.name());
|
||||
if (location.hasId())
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_ID, location.id);
|
||||
if (location.hasCoord()) {
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LAT,
|
||||
location.getLatAs1E6());
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LON,
|
||||
location.getLonAs1E6());
|
||||
}
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_PLACE, location.place);
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_NAME, location.name);
|
||||
|
||||
log.info("creating launcher shortcut {} to {}", shortcutId, location);
|
||||
ShortcutManagerCompat.requestPinShortcut(context,
|
||||
new ShortcutInfoCompat.Builder(context, shortcutId)
|
||||
.setActivity(new ComponentName(context, DirectionsActivity.class))
|
||||
.setShortLabel(shortcutName.length() > 0 ? shortcutName
|
||||
: context.getString(R.string.directions_shortcut_default_name))
|
||||
.setIcon(IconCompat.createWithResource(context,
|
||||
R.mipmap.ic_oeffi_directions_color_48dp))
|
||||
.setIntent(shortcutIntent).build(),
|
||||
null);
|
||||
(DialogInterface.OnClickListener) (dialog, which) -> {
|
||||
final EditText nameView = (EditText) view
|
||||
.findViewById(R.id.create_launcher_shortcut_dialog_name);
|
||||
final String shortcutName = nameView.getText().toString();
|
||||
final String shortcutId = "directions-to-" + networkId.name() + "-" + location.id;
|
||||
final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN, null, context,
|
||||
DirectionsShortcutActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_NETWORK, networkId.name());
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_TYPE, location.type.name());
|
||||
if (location.hasId())
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_ID, location.id);
|
||||
if (location.hasCoord()) {
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LAT,
|
||||
location.getLatAs1E6());
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LON,
|
||||
location.getLonAs1E6());
|
||||
}
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_PLACE, location.place);
|
||||
shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_NAME, location.name);
|
||||
|
||||
log.info("creating launcher shortcut {} to {}", shortcutId, location);
|
||||
ShortcutManagerCompat.requestPinShortcut(context,
|
||||
new ShortcutInfoCompat.Builder(context, shortcutId)
|
||||
.setActivity(new ComponentName(context, DirectionsActivity.class))
|
||||
.setShortLabel(shortcutName.length() > 0 ? shortcutName
|
||||
: context.getString(R.string.directions_shortcut_default_name))
|
||||
.setIcon(IconCompat.createWithResource(context,
|
||||
R.mipmap.ic_oeffi_directions_color_48dp))
|
||||
.setIntent(shortcutIntent).build(),
|
||||
null);
|
||||
});
|
||||
builder.setNegativeButton(R.string.button_cancel, null);
|
||||
return builder.create();
|
||||
|
@ -189,11 +187,9 @@ public class StationContextMenu extends PopupMenu {
|
|||
final String planName = plansCursor
|
||||
.getString(plansCursor.getColumnIndexOrThrow(PlanContentProvider.KEY_PLAN_NAME));
|
||||
plansCursor.close();
|
||||
menu.add(planName).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
PlanActivity.start(context, planId, location.id);
|
||||
return true;
|
||||
}
|
||||
menu.add(planName).setOnMenuItemClickListener(item -> {
|
||||
PlanActivity.start(context, planId, location.id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
stationsCursor.close();
|
||||
|
@ -203,11 +199,9 @@ public class StationContextMenu extends PopupMenu {
|
|||
private static void prepareMapMenuItem(final Context context, final MenuItem item, final Intent intent) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
item.setVisible(pm.resolveActivity(intent, 0) != null);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
item.setOnMenuItemClickListener(item1 -> {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,34 +152,24 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
|
|||
setContentView(R.layout.stations_station_details_content);
|
||||
actionBar = getMyActionBar();
|
||||
setPrimaryColor(R.color.action_bar_background_stations);
|
||||
actionBar.setBack(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
actionBar.setBack(v -> finish());
|
||||
actionBar.swapTitles();
|
||||
actionBar.addProgressButton().setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
load();
|
||||
}
|
||||
});
|
||||
actionBar.addProgressButton().setOnClickListener(v -> load());
|
||||
favoriteButton = actionBar.addToggleButton(R.drawable.ic_star_24dp,
|
||||
R.string.stations_station_details_action_favorite_title);
|
||||
favoriteButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged(final ToggleImageButton buttonView, final boolean isChecked) {
|
||||
if (isChecked) {
|
||||
final Uri rowUri = FavoriteUtils.persist(getContentResolver(),
|
||||
FavoriteStationsProvider.TYPE_FAVORITE, selectedNetwork, selectedStation);
|
||||
if (rowUri != null) {
|
||||
selectedFavState = FavoriteStationsProvider.TYPE_FAVORITE;
|
||||
FavoriteUtils.notifyFavoritesChanged(StationDetailsActivity.this);
|
||||
}
|
||||
} else {
|
||||
final int numRows = FavoriteUtils.delete(getContentResolver(), selectedNetwork, selectedStation.id);
|
||||
if (numRows > 0) {
|
||||
selectedFavState = null;
|
||||
FavoriteUtils.notifyFavoritesChanged(StationDetailsActivity.this);
|
||||
}
|
||||
favoriteButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked) {
|
||||
final Uri rowUri = FavoriteUtils.persist(getContentResolver(),
|
||||
FavoriteStationsProvider.TYPE_FAVORITE, selectedNetwork, selectedStation);
|
||||
if (rowUri != null) {
|
||||
selectedFavState = FavoriteStationsProvider.TYPE_FAVORITE;
|
||||
FavoriteUtils.notifyFavoritesChanged(StationDetailsActivity.this);
|
||||
}
|
||||
} else {
|
||||
final int numRows = FavoriteUtils.delete(getContentResolver(), selectedNetwork, selectedStation.id);
|
||||
if (numRows > 0) {
|
||||
selectedFavState = null;
|
||||
FavoriteUtils.notifyFavoritesChanged(StationDetailsActivity.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -800,11 +790,7 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
|
|||
final Location destination = departure.destination;
|
||||
if (destination != null) {
|
||||
destinationView.setText(Constants.DESTINATION_ARROW_PREFIX + destination.uniqueShortName());
|
||||
itemView.setOnClickListener(destination.id != null ? new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
start(context, network, destination);
|
||||
}
|
||||
} : null);
|
||||
itemView.setOnClickListener(destination.id != null ? (OnClickListener) v -> start(context, network, destination) : null);
|
||||
} else {
|
||||
destinationView.setText(null);
|
||||
itemView.setOnClickListener(null);
|
||||
|
|
|
@ -195,70 +195,54 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
actionBar = getMyActionBar();
|
||||
setPrimaryColor(R.color.action_bar_background_stations);
|
||||
actionBar.setPrimaryTitle(R.string.stations_activity_title);
|
||||
actionBar.setTitlesOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
NetworkPickerActivity.start(StationsActivity.this);
|
||||
}
|
||||
});
|
||||
actionBar.addProgressButton().setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
for (final Station station : stations)
|
||||
station.requestedAt = null;
|
||||
handler.post(initStationsRunnable);
|
||||
}
|
||||
actionBar.setTitlesOnClickListener(v -> NetworkPickerActivity.start(StationsActivity.this));
|
||||
actionBar.addProgressButton().setOnClickListener(v -> {
|
||||
for (final Station station : stations)
|
||||
station.requestedAt = null;
|
||||
handler.post(initStationsRunnable);
|
||||
});
|
||||
actionBar.addButton(R.drawable.ic_search_white_24dp, R.string.stations_action_search_title)
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
onSearchRequested();
|
||||
}
|
||||
});
|
||||
.setOnClickListener(v -> onSearchRequested());
|
||||
filterActionButton = actionBar.addButton(R.drawable.ic_filter_list_24dp, R.string.stations_filter_title);
|
||||
filterActionButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final StationsFilterPopup popup = new StationsFilterPopup(StationsActivity.this, products,
|
||||
new StationsFilterPopup.Listener() {
|
||||
public void filterChanged(final Set<Product> filter) {
|
||||
final Set<Product> added = new HashSet<>(filter);
|
||||
added.removeAll(products);
|
||||
filterActionButton.setOnClickListener(v -> {
|
||||
final StationsFilterPopup popup = new StationsFilterPopup(StationsActivity.this, products,
|
||||
filter -> {
|
||||
final Set<Product> added = new HashSet<>(filter);
|
||||
added.removeAll(products);
|
||||
|
||||
final Set<Product> removed = new HashSet<>(products);
|
||||
removed.removeAll(filter);
|
||||
final Set<Product> removed = new HashSet<>(products);
|
||||
removed.removeAll(filter);
|
||||
|
||||
products.clear();
|
||||
products.addAll(filter);
|
||||
products.clear();
|
||||
products.addAll(filter);
|
||||
|
||||
if (!added.isEmpty()) {
|
||||
handler.post(initStationsRunnable);
|
||||
if (!added.isEmpty()) {
|
||||
handler.post(initStationsRunnable);
|
||||
}
|
||||
|
||||
if (!removed.isEmpty()) {
|
||||
for (final Iterator<Station> i = stations.iterator(); i.hasNext(); ) {
|
||||
final Station station = i.next();
|
||||
if (!filter(station, products)) {
|
||||
i.remove();
|
||||
stationsMap.remove(station.location.id);
|
||||
}
|
||||
|
||||
if (!removed.isEmpty()) {
|
||||
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) {
|
||||
final Station station = i.next();
|
||||
if (!filter(station, products)) {
|
||||
i.remove();
|
||||
stationsMap.remove(station.location.id);
|
||||
}
|
||||
}
|
||||
|
||||
stationListAdapter.notifyDataSetChanged();
|
||||
mapView.invalidate();
|
||||
}
|
||||
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
popup.showAsDropDown(v);
|
||||
}
|
||||
|
||||
stationListAdapter.notifyDataSetChanged();
|
||||
mapView.invalidate();
|
||||
}
|
||||
|
||||
updateGUI();
|
||||
});
|
||||
popup.showAsDropDown(v);
|
||||
});
|
||||
actionBar.overflow(R.menu.stations_options, new PopupMenu.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
if (item.getItemId() == R.id.stations_options_favorites) {
|
||||
FavoriteStationsActivity.start(StationsActivity.this);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
actionBar.overflow(R.menu.stations_options, item -> {
|
||||
if (item.getItemId() == R.id.stations_options_favorites) {
|
||||
FavoriteStationsActivity.start(StationsActivity.this);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -268,26 +252,14 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
|
||||
final Button locationPermissionRequestButton = (Button) findViewById(
|
||||
R.id.stations_location_permission_request_button);
|
||||
locationPermissionRequestButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
ActivityCompat.requestPermissions(StationsActivity.this,
|
||||
new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION }, 0);
|
||||
}
|
||||
});
|
||||
locationPermissionRequestButton.setOnClickListener(v -> ActivityCompat.requestPermissions(StationsActivity.this,
|
||||
new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.ACCESS_BACKGROUND_LOCATION }, 0));
|
||||
|
||||
final Button locationSettingsButton = (Button) findViewById(R.id.stations_list_location_settings);
|
||||
locationSettingsButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||
}
|
||||
});
|
||||
locationSettingsButton.setOnClickListener(v -> startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)));
|
||||
|
||||
final OnClickListener selectNetworkListener = new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
NetworkPickerActivity.start(StationsActivity.this);
|
||||
}
|
||||
};
|
||||
final OnClickListener selectNetworkListener = v -> NetworkPickerActivity.start(StationsActivity.this);
|
||||
final Button networkSettingsButton = (Button) findViewById(R.id.stations_list_empty_network_settings);
|
||||
networkSettingsButton.setOnClickListener(selectNetworkListener);
|
||||
final Button missingCapabilityButton = (Button) findViewById(R.id.stations_network_missing_capability_button);
|
||||
|
@ -597,36 +569,34 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
if (fixedLocation != null && fixedLocation.hasCoord())
|
||||
mapView.animateToLocation(fixedLocation.getLatAsDouble(), fixedLocation.getLonAsDouble());
|
||||
|
||||
findViewById(R.id.stations_location_clear).setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
fixedLocation = null;
|
||||
findViewById(R.id.stations_location_clear).setOnClickListener(v -> {
|
||||
fixedLocation = null;
|
||||
|
||||
if (deviceLocation != null) {
|
||||
mapView.animateToLocation(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble());
|
||||
if (deviceLocation != null) {
|
||||
mapView.animateToLocation(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble());
|
||||
|
||||
final float[] distanceBetweenResults = new float[2];
|
||||
final float[] distanceBetweenResults = new float[2];
|
||||
|
||||
// remove non-favorites and re-calculate distances
|
||||
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) {
|
||||
final Station station = i.next();
|
||||
// remove non-favorites and re-calculate distances
|
||||
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) {
|
||||
final Station station = i.next();
|
||||
|
||||
final Integer favState = favorites.get(station.location.id);
|
||||
if (favState == null || favState != FavoriteStationsProvider.TYPE_FAVORITE) {
|
||||
i.remove();
|
||||
stationsMap.remove(station.location.id);
|
||||
} else if (station.location.hasCoord()) {
|
||||
android.location.Location.distanceBetween(deviceLocation.getLatAsDouble(),
|
||||
deviceLocation.getLonAsDouble(), station.location.getLatAsDouble(),
|
||||
station.location.getLonAsDouble(), distanceBetweenResults);
|
||||
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
|
||||
}
|
||||
final Integer favState = favorites.get(station.location.id);
|
||||
if (favState == null || favState != FavoriteStationsProvider.TYPE_FAVORITE) {
|
||||
i.remove();
|
||||
stationsMap.remove(station.location.id);
|
||||
} else if (station.location.hasCoord()) {
|
||||
android.location.Location.distanceBetween(deviceLocation.getLatAsDouble(),
|
||||
deviceLocation.getLonAsDouble(), station.location.getLatAsDouble(),
|
||||
station.location.getLonAsDouble(), distanceBetweenResults);
|
||||
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
|
||||
}
|
||||
stationListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
handler.post(initStationsRunnable);
|
||||
updateGUI();
|
||||
stationListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
handler.post(initStationsRunnable);
|
||||
updateGUI();
|
||||
});
|
||||
|
||||
handler.post(initStationsRunnable);
|
||||
|
@ -652,11 +622,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
private void setListFilter(final String filter) {
|
||||
searchQuery = filter;
|
||||
|
||||
findViewById(R.id.stations_search_clear).setOnClickListener(new OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
clearListFilter();
|
||||
}
|
||||
});
|
||||
findViewById(R.id.stations_search_clear).setOnClickListener(v -> clearListFilter());
|
||||
|
||||
stations.clear();
|
||||
stationsMap.clear();
|
||||
|
@ -777,17 +743,11 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
final DialogBuilder builder = DialogBuilder.warn(this, R.string.stations_nearby_stations_error_title);
|
||||
builder.setMessage(getString(R.string.stations_nearby_stations_error_message));
|
||||
builder.setPositiveButton(getString(R.string.stations_nearby_stations_error_continue),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
(dialog, _id) -> dialog.dismiss());
|
||||
builder.setNegativeButton(getString(R.string.stations_nearby_stations_error_exit),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
(dialog, _id) -> {
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
@ -825,92 +785,82 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
if (favoriteIds.length() != 0)
|
||||
favoriteIds.setLength(favoriteIds.length() - 1);
|
||||
|
||||
backgroundHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
actionBar.startProgress();
|
||||
loading = true;
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
backgroundHandler.post(() -> {
|
||||
runOnUiThread(() -> {
|
||||
actionBar.startProgress();
|
||||
loading = true;
|
||||
updateGUI();
|
||||
});
|
||||
|
||||
final Builder uriBuilder = NetworkContentProvider.CONTENT_URI.buildUpon();
|
||||
uriBuilder.appendPath(network.name());
|
||||
uriBuilder.appendQueryParameter("lat", Integer.toString(referenceLocation.getLatAs1E6()));
|
||||
uriBuilder.appendQueryParameter("lon", Integer.toString(referenceLocation.getLonAs1E6()));
|
||||
uriBuilder.appendQueryParameter("ids", favoriteIds.toString());
|
||||
final Cursor cursor = getContentResolver().query(uriBuilder.build(), null, null, null, null);
|
||||
final Builder uriBuilder = NetworkContentProvider.CONTENT_URI.buildUpon();
|
||||
uriBuilder.appendPath(network.name());
|
||||
uriBuilder.appendQueryParameter("lat", Integer.toString(referenceLocation.getLatAs1E6()));
|
||||
uriBuilder.appendQueryParameter("lon", Integer.toString(referenceLocation.getLonAs1E6()));
|
||||
uriBuilder.appendQueryParameter("ids", favoriteIds.toString());
|
||||
final Cursor cursor = getContentResolver().query(uriBuilder.build(), null, null, null, null);
|
||||
|
||||
if (cursor != null) {
|
||||
final int nativeIdColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_ID);
|
||||
final int localIdColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_LOCAL_ID);
|
||||
final int placeColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_PLACE);
|
||||
final int nameColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
||||
final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
||||
final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
||||
final int productsColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS);
|
||||
final int linesColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
||||
if (cursor != null) {
|
||||
final int nativeIdColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_ID);
|
||||
final int localIdColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_LOCAL_ID);
|
||||
final int placeColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_PLACE);
|
||||
final int nameColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_NAME);
|
||||
final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT);
|
||||
final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON);
|
||||
final int productsColumnIndex = cursor.getColumnIndex(NetworkContentProvider.KEY_PRODUCTS);
|
||||
final int linesColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES);
|
||||
|
||||
final List<Station> freshStations = new ArrayList<>(cursor.getCount());
|
||||
final List<Station> freshStations = new ArrayList<>(cursor.getCount());
|
||||
|
||||
final float[] distanceBetweenResults = new float[2];
|
||||
final float[] distanceBetweenResults = new float[2];
|
||||
|
||||
final NetworkProvider networkProvider = NetworkProviderFactory.provider(network);
|
||||
final NetworkProvider networkProvider = NetworkProviderFactory.provider(network);
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
final List<LineDestination> lineDestinations = new LinkedList<>();
|
||||
for (final String lineStr : cursor.getString(linesColumnIndex).split(",")) {
|
||||
if (!lineStr.isEmpty()) {
|
||||
final Product product = Product.fromCode(lineStr.charAt(0));
|
||||
final String label = Strings.emptyToNull(lineStr.substring(1));
|
||||
// FIXME don't access networkProvider
|
||||
// from thread
|
||||
final Style style = networkProvider.lineStyle(null, product, label);
|
||||
lineDestinations.add(
|
||||
new LineDestination(new Line(null, null, product, label, style), null));
|
||||
}
|
||||
while (cursor.moveToNext()) {
|
||||
final List<LineDestination> lineDestinations = new LinkedList<>();
|
||||
for (final String lineStr : cursor.getString(linesColumnIndex).split(",")) {
|
||||
if (!lineStr.isEmpty()) {
|
||||
final Product product = Product.fromCode(lineStr.charAt(0));
|
||||
final String label = Strings.emptyToNull(lineStr.substring(1));
|
||||
// FIXME don't access networkProvider
|
||||
// from thread
|
||||
final Style style = networkProvider.lineStyle(null, product, label);
|
||||
lineDestinations.add(
|
||||
new LineDestination(new Line(null, null, product, label, style), null));
|
||||
}
|
||||
|
||||
final String id = localIdColumnIndex != -1 ? cursor.getString(localIdColumnIndex)
|
||||
: cursor.getString(nativeIdColumnIndex);
|
||||
final String place = placeColumnIndex != -1 ? cursor.getString(placeColumnIndex) : null;
|
||||
final String name = cursor.getString(nameColumnIndex);
|
||||
final Point coord = Point.from1E6(cursor.getInt(latColumnIndex),
|
||||
cursor.getInt(lonColumnIndex));
|
||||
final Set<Product> products;
|
||||
if (productsColumnIndex != -1 && !cursor.isNull(productsColumnIndex))
|
||||
products = Product.fromCodes(cursor.getString(productsColumnIndex).toCharArray());
|
||||
else
|
||||
products = null;
|
||||
final Station station = new Station(network, new de.schildbach.pte.dto.Location(
|
||||
LocationType.STATION, id, coord, place, name, products), lineDestinations);
|
||||
if (deviceLocation != null) {
|
||||
android.location.Location.distanceBetween(referenceLocation.getLatAsDouble(),
|
||||
referenceLocation.getLonAsDouble(), coord.getLatAsDouble(), coord.getLonAsDouble(),
|
||||
distanceBetweenResults);
|
||||
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
|
||||
}
|
||||
freshStations.add(station);
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
mergeIntoStations(freshStations, true);
|
||||
}
|
||||
});
|
||||
final String id = localIdColumnIndex != -1 ? cursor.getString(localIdColumnIndex)
|
||||
: cursor.getString(nativeIdColumnIndex);
|
||||
final String place = placeColumnIndex != -1 ? cursor.getString(placeColumnIndex) : null;
|
||||
final String name = cursor.getString(nameColumnIndex);
|
||||
final Point coord = Point.from1E6(cursor.getInt(latColumnIndex),
|
||||
cursor.getInt(lonColumnIndex));
|
||||
final Set<Product> products;
|
||||
if (productsColumnIndex != -1 && !cursor.isNull(productsColumnIndex))
|
||||
products = Product.fromCodes(cursor.getString(productsColumnIndex).toCharArray());
|
||||
else
|
||||
products = null;
|
||||
final Station station = new Station(network, new Location(
|
||||
LocationType.STATION, id, coord, place, name, products), lineDestinations);
|
||||
if (deviceLocation != null) {
|
||||
android.location.Location.distanceBetween(referenceLocation.getLatAsDouble(),
|
||||
referenceLocation.getLonAsDouble(), coord.getLatAsDouble(), coord.getLonAsDouble(),
|
||||
distanceBetweenResults);
|
||||
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
|
||||
}
|
||||
freshStations.add(station);
|
||||
}
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
actionBar.stopProgress();
|
||||
loading = false;
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
cursor.close();
|
||||
|
||||
runOnUiThread(() -> mergeIntoStations(freshStations, true));
|
||||
}
|
||||
|
||||
runOnUiThread(() -> {
|
||||
actionBar.stopProgress();
|
||||
loading = false;
|
||||
updateGUI();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1032,11 +982,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
}
|
||||
|
||||
if (added) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
mapView.zoomToStations(stations);
|
||||
}
|
||||
}, 500);
|
||||
handler.postDelayed(() -> mapView.zoomToStations(stations), 500);
|
||||
}
|
||||
|
||||
updateGUI();
|
||||
|
@ -1065,33 +1011,31 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
}
|
||||
|
||||
private static void sortStations(final List<Station> stations) {
|
||||
Collections.sort(stations, new Comparator<Station>() {
|
||||
public int compare(final Station station1, final Station station2) {
|
||||
ComparisonChain chain = ComparisonChain.start();
|
||||
Collections.sort(stations, (station1, station2) -> {
|
||||
ComparisonChain chain = ComparisonChain.start();
|
||||
|
||||
// order by distance
|
||||
chain = chain.compareTrueFirst(station1.hasDistanceAndBearing, station2.hasDistanceAndBearing)
|
||||
.compare(station1.distance, station2.distance);
|
||||
// order by distance
|
||||
chain = chain.compareTrueFirst(station1.hasDistanceAndBearing, station2.hasDistanceAndBearing)
|
||||
.compare(station1.distance, station2.distance);
|
||||
|
||||
// order by lines
|
||||
final List<LineDestination> lines1 = station1.getLines();
|
||||
final List<LineDestination> lines2 = station2.getLines();
|
||||
final List<LineDestination> lineDestinations1 = lines1 != null ? lines1
|
||||
: Collections.<LineDestination> emptyList();
|
||||
final List<LineDestination> lineDestinations2 = lines2 != null ? lines2
|
||||
: Collections.<LineDestination> emptyList();
|
||||
final int length1 = lineDestinations1.size();
|
||||
final int length2 = lineDestinations2.size();
|
||||
final int length = Math.max(length1, length2);
|
||||
// order by lines
|
||||
final List<LineDestination> lines1 = station1.getLines();
|
||||
final List<LineDestination> lines2 = station2.getLines();
|
||||
final List<LineDestination> lineDestinations1 = lines1 != null ? lines1
|
||||
: Collections.<LineDestination> emptyList();
|
||||
final List<LineDestination> lineDestinations2 = lines2 != null ? lines2
|
||||
: Collections.<LineDestination> emptyList();
|
||||
final int length1 = lineDestinations1.size();
|
||||
final int length2 = lineDestinations2.size();
|
||||
final int length = Math.max(length1, length2);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
final Line line1 = i < length1 ? lineDestinations1.get(i).line : null;
|
||||
final Line line2 = i < length2 ? lineDestinations2.get(i).line : null;
|
||||
chain = chain.compare(line1, line2, Ordering.natural().nullsLast());
|
||||
}
|
||||
|
||||
return chain.result();
|
||||
for (int i = 0; i < length; i++) {
|
||||
final Line line1 = i < length1 ? lineDestinations1.get(i).line : null;
|
||||
final Line line2 = i < length2 ? lineDestinations2.get(i).line : null;
|
||||
chain = chain.compare(line1, line2, Ordering.natural().nullsLast());
|
||||
}
|
||||
|
||||
return chain.result();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1183,58 +1127,40 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
protected void onRedirect(final HttpUrl url) {
|
||||
log.info("Redirect while querying departures on {}", requestedStationId);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(StationsActivity.this).toast(R.string.toast_network_problem);
|
||||
}
|
||||
});
|
||||
handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_network_problem));
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onBlocked(final HttpUrl url) {
|
||||
log.info("Blocked querying departures on {}", requestedStationId);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(StationsActivity.this).toast(R.string.toast_network_blocked,
|
||||
url.host());
|
||||
}
|
||||
});
|
||||
handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_network_blocked,
|
||||
url.host()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInternalError(final HttpUrl url) {
|
||||
log.info("Internal error querying departures on {}", requestedStationId);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(StationsActivity.this).toast(R.string.toast_internal_error,
|
||||
url.host());
|
||||
}
|
||||
});
|
||||
handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_internal_error,
|
||||
url.host()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onParserException(final String message) {
|
||||
log.info("Cannot parse departures on {}: {}", requestedStationId, message);
|
||||
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
final String limitedMessage = message != null
|
||||
? message.substring(0, Math.min(100, message.length())) : null;
|
||||
new Toast(StationsActivity.this).toast(R.string.toast_invalid_data,
|
||||
limitedMessage);
|
||||
}
|
||||
handler.post(() -> {
|
||||
final String limitedMessage = message != null
|
||||
? message.substring(0, Math.min(100, message.length())) : null;
|
||||
new Toast(StationsActivity.this).toast(R.string.toast_invalid_data,
|
||||
limitedMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInputOutputError(final IOException x) {
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
new Toast(StationsActivity.this).toast(R.string.toast_network_problem);
|
||||
}
|
||||
});
|
||||
handler.post(() -> new Toast(StationsActivity.this).toast(R.string.toast_network_problem));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1571,19 +1497,17 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
|
|||
|
||||
lastTime = System.currentTimeMillis();
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
deviceBearing = azimuth;
|
||||
stationListAdapter.setDeviceBearing(azimuth, faceDown);
|
||||
runOnUiThread(() -> {
|
||||
deviceBearing = azimuth;
|
||||
stationListAdapter.setDeviceBearing(azimuth, faceDown);
|
||||
|
||||
// refresh compass needles
|
||||
final int childCount = stationList.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View childAt = stationList.getChildAt(i);
|
||||
final View bearingView = childAt.findViewById(R.id.station_entry_bearing);
|
||||
if (bearingView != null)
|
||||
bearingView.invalidate();
|
||||
}
|
||||
// refresh compass needles
|
||||
final int childCount = stationList.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View childAt = stationList.getChildAt(i);
|
||||
final View bearingView = childAt.findViewById(R.id.station_entry_bearing);
|
||||
if (bearingView != null)
|
||||
bearingView.invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,12 +60,10 @@ public class FavoriteStationViewHolder extends RecyclerView.ViewHolder {
|
|||
final long selectedRowId) {
|
||||
final boolean selected = rowId == selectedRowId;
|
||||
itemView.setActivated(selected);
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
clickListener.onStationClick(position, network, station);
|
||||
}
|
||||
itemView.setOnClickListener(v -> {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
clickListener.onStationClick(position, network, station);
|
||||
});
|
||||
|
||||
if (showNetwork) {
|
||||
|
@ -84,22 +82,18 @@ public class FavoriteStationViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
if (contextMenuItemListener != null) {
|
||||
contextButton.setVisibility(View.VISIBLE);
|
||||
contextButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new StationContextMenu(context, v, network, station,
|
||||
FavoriteStationsProvider.TYPE_FAVORITE, true, false, true, false, false);
|
||||
contextMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
return contextMenuItemListener.onStationContextMenuItemClick(position, network, station,
|
||||
null, item.getItemId());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
}
|
||||
contextButton.setOnClickListener(v -> {
|
||||
final PopupMenu contextMenu = new StationContextMenu(context, v, network, station,
|
||||
FavoriteStationsProvider.TYPE_FAVORITE, true, false, true, false, false);
|
||||
contextMenu.setOnMenuItemClickListener(item -> {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
return contextMenuItemListener.onStationContextMenuItemClick(position, network, station,
|
||||
null, item.getItemId());
|
||||
else
|
||||
return false;
|
||||
});
|
||||
contextMenu.show();
|
||||
});
|
||||
} else {
|
||||
contextButton.setVisibility(View.GONE);
|
||||
|
|
|
@ -185,22 +185,18 @@ public class StationViewHolder extends RecyclerView.ViewHolder {
|
|||
// context button
|
||||
contextButton.setVisibility(itemView.isActivated() ? View.VISIBLE : View.GONE);
|
||||
contextButtonSpace.setVisibility(itemView.isActivated() ? View.VISIBLE : View.GONE);
|
||||
contextButton.setOnClickListener(itemView.isActivated() ? new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
final PopupMenu contextMenu = new StationContextMenu(context, v, station.network, station.location,
|
||||
favState, true, true, true, true, true);
|
||||
contextMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick(final MenuItem item) {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
return contextMenuItemListener.onStationContextMenuItemClick(position, station.network,
|
||||
station.location, station.departures, item.getItemId());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
});
|
||||
contextMenu.show();
|
||||
}
|
||||
contextButton.setOnClickListener(itemView.isActivated() ? (View.OnClickListener) v -> {
|
||||
final PopupMenu contextMenu = new StationContextMenu(context, v, station.network, station.location,
|
||||
favState, true, true, true, true, true);
|
||||
contextMenu.setOnMenuItemClickListener(item -> {
|
||||
final int position = getAdapterPosition();
|
||||
if (position != RecyclerView.NO_POSITION)
|
||||
return contextMenuItemListener.onStationContextMenuItemClick(position, station.network,
|
||||
station.location, station.departures, item.getItemId());
|
||||
else
|
||||
return false;
|
||||
});
|
||||
contextMenu.show();
|
||||
} : null);
|
||||
|
||||
// departures
|
||||
|
|
|
@ -104,12 +104,9 @@ public class StationsAdapter extends RecyclerView.Adapter<StationViewHolder> imp
|
|||
|
||||
// select stations
|
||||
holder.itemView.setActivated(stationsAware.isSelectedStation(station.location.id));
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
final boolean isSelected = stationsAware.isSelectedStation(station.location.id);
|
||||
stationsAware.selectStation(isSelected ? null : station);
|
||||
}
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
final boolean isSelected = stationsAware.isSelectedStation(station.location.id);
|
||||
stationsAware.selectStation(isSelected ? null : station);
|
||||
});
|
||||
|
||||
// populate view
|
||||
|
|
|
@ -77,10 +77,6 @@ public class ChangelogDialogBuilder extends AlertDialog.Builder {
|
|||
: "") + context.getString(R.string.changelog_dialog_title));
|
||||
setView(view);
|
||||
setPositiveButton(context.getString(R.string.changelog_dialog_button_dismiss),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
(dialog, id) -> dialog.dismiss());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,12 +50,7 @@ public class CheatSheet {
|
|||
* The view to add a cheat sheet for.
|
||||
*/
|
||||
public static void setup(View view) {
|
||||
view.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
return showCheatSheet(view, view.getContentDescription());
|
||||
}
|
||||
});
|
||||
view.setOnLongClickListener(v -> showCheatSheet(v, v.getContentDescription()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,12 +64,7 @@ public class CheatSheet {
|
|||
* The string resource containing the text to show on long-press.
|
||||
*/
|
||||
public static void setup(View view, final int textResId) {
|
||||
view.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
return showCheatSheet(view, view.getContext().getString(textResId));
|
||||
}
|
||||
});
|
||||
view.setOnLongClickListener(v -> showCheatSheet(v, v.getContext().getString(textResId)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,12 +78,7 @@ public class CheatSheet {
|
|||
* The text to show on long-press.
|
||||
*/
|
||||
public static void setup(View view, final CharSequence text) {
|
||||
view.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
return showCheatSheet(view, text);
|
||||
}
|
||||
});
|
||||
view.setOnLongClickListener(v -> showCheatSheet(v, text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -356,11 +356,7 @@ public class ErrorReporter implements Thread.UncaughtExceptionHandler {
|
|||
}
|
||||
|
||||
private void callback(final String newVersion) {
|
||||
callbackHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
dialog(context, newVersion);
|
||||
}
|
||||
});
|
||||
callbackHandler.post(() -> dialog(context, newVersion));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -369,39 +365,25 @@ public class ErrorReporter implements Thread.UncaughtExceptionHandler {
|
|||
final DialogBuilder builder = DialogBuilder.warn(context, R.string.alert_crash_report_title);
|
||||
builder.setMessage(newVersion != null ? context.getString(R.string.alert_crash_report_new_version, newVersion)
|
||||
: context.getString(R.string.alert_crash_report_message));
|
||||
builder.setNegativeButton(R.string.alert_crash_report_negative, new OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
stackTraceFile.delete();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.alert_crash_report_negative, (dialog, which) -> stackTraceFile.delete());
|
||||
if (newVersion != null) {
|
||||
builder.setNeutralButton(R.string.alert_crash_report_update, new OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
stackTraceFile.delete();
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse("market://details?id=" + context.getPackageName())));
|
||||
}
|
||||
builder.setNeutralButton(R.string.alert_crash_report_update, (dialog, which) -> {
|
||||
stackTraceFile.delete();
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse("market://details?id=" + context.getPackageName())));
|
||||
});
|
||||
builder.setPositiveButton(R.string.alert_crash_report_download, new OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
stackTraceFile.delete();
|
||||
context.startActivity(
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.OEFFI_BASE_URL + "download.html")));
|
||||
}
|
||||
builder.setPositiveButton(R.string.alert_crash_report_download, (dialog, which) -> {
|
||||
stackTraceFile.delete();
|
||||
context.startActivity(
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.OEFFI_BASE_URL + "download.html")));
|
||||
});
|
||||
} else {
|
||||
builder.setPositiveButton(R.string.alert_crash_report_positive, new OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
sendError(context);
|
||||
stackTraceFile.delete();
|
||||
}
|
||||
builder.setPositiveButton(R.string.alert_crash_report_positive, (dialog, which) -> {
|
||||
sendError(context);
|
||||
stackTraceFile.delete();
|
||||
});
|
||||
}
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
public void onCancel(final DialogInterface dialog) {
|
||||
stackTraceFile.delete();
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(dialog -> stackTraceFile.delete());
|
||||
|
||||
try {
|
||||
builder.show();
|
||||
|
|
|
@ -98,21 +98,13 @@ public class GeocoderThread extends Thread {
|
|||
private void onResult(final Address address) {
|
||||
log.info("Geocoder took {} ms, returned {}", System.currentTimeMillis() - startTime, address);
|
||||
|
||||
callbackHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
callback.onGeocoderResult(address);
|
||||
}
|
||||
});
|
||||
callbackHandler.post(() -> callback.onGeocoderResult(address));
|
||||
}
|
||||
|
||||
private void onFail(final Exception exception) {
|
||||
log.info("Geocoder failed: {}", exception.getMessage());
|
||||
|
||||
callbackHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
callback.onGeocoderFail(exception);
|
||||
}
|
||||
});
|
||||
callbackHandler.post(() -> callback.onGeocoderFail(exception));
|
||||
}
|
||||
|
||||
public static Location addressToLocation(final Address address) {
|
||||
|
|
|
@ -105,11 +105,9 @@ public final class LocationHelper {
|
|||
manager.requestLocationUpdates(provider, 0, 0, listener);
|
||||
|
||||
if (timeout > 0) {
|
||||
handler.postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
log.info("LocationHelper timed out");
|
||||
stop(true);
|
||||
}
|
||||
handler.postDelayed(() -> {
|
||||
log.info("LocationHelper timed out");
|
||||
stop(true);
|
||||
}, timeout);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -114,11 +114,7 @@ public class NavigationMenuAdapter extends RecyclerView.Adapter<NavigationMenuAd
|
|||
itemView.setActivated(item.isChecked());
|
||||
itemView.setFocusable(item.isEnabled());
|
||||
if (item.isEnabled()) {
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(final View v) {
|
||||
menuClickListener.onMenuItemClick(item);
|
||||
}
|
||||
});
|
||||
itemView.setOnClickListener(v -> menuClickListener.onMenuItemClick(item));
|
||||
}
|
||||
|
||||
final boolean primaryItem = item.getTitleCondensed() != null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue