use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs in project RSAndroidApp by RailwayStations.
the class DetailsActivity method onNewIntent.
@Override
protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
boolean directPicture = false;
if (intent != null) {
upload = (Upload) intent.getSerializableExtra(EXTRA_UPLOAD);
station = (Station) intent.getSerializableExtra(EXTRA_STATION);
latitude = (Double) intent.getSerializableExtra(EXTRA_LATITUDE);
longitude = (Double) intent.getSerializableExtra(EXTRA_LONGITUDE);
if (station == null && upload != null && upload.isUploadForExistingStation()) {
station = baseApplication.getDbAdapter().getStationForUpload(upload);
}
if (latitude == null && longitude == null && upload != null && upload.isUploadForMissingStation()) {
latitude = upload.getLat();
longitude = upload.getLon();
}
if (station == null && (latitude == null || longitude == null)) {
Log.w(TAG, "EXTRA_BAHNHOF and EXTRA_LATITUDE or EXTRA_LONGITUDE in intent data missing");
Toast.makeText(this, R.string.station_or_coords_not_found, Toast.LENGTH_LONG).show();
finish();
return;
}
setButtonEnabled(binding.details.buttonReportProblem, station != null);
binding.details.marker.setImageDrawable(ContextCompat.getDrawable(this, getMarkerRes()));
directPicture = intent.getBooleanExtra(EXTRA_TAKE_FOTO, false);
if (station != null) {
bahnhofId = station.getId();
binding.details.etbahnhofname.setText(station.getTitle());
binding.details.etbahnhofname.setInputType(EditorInfo.TYPE_NULL);
binding.details.etbahnhofname.setSingleLine(false);
if (upload == null) {
upload = baseApplication.getDbAdapter().getPendingUploadForStation(station);
}
if (station.hasPhoto()) {
if (ConnectionUtil.checkInternetConnection(this)) {
BitmapCache.getInstance().getFoto(this, station.getPhotoUrl());
}
setPictureButtonsEnabled(canSetPhoto());
// check for local photo
final var localFile = getStoredMediaFile(upload);
if (localFile != null && localFile.canRead()) {
new SimpleDialogs().confirm(this, R.string.local_photo_exists, (dialog, which) -> {
setPictureButtonsEnabled(true);
setLocalBitmap(upload);
});
}
} else if (upload != null && upload.isPendingPhotoUpload()) {
setLocalBitmap(upload);
} else {
setLocalBitmap(upload);
}
} else {
if (upload == null) {
upload = baseApplication.getDbAdapter().getPendingUploadForCoordinates(latitude, longitude);
}
binding.details.etbahnhofname.setInputType(EditorInfo.TYPE_CLASS_TEXT);
if (upload != null) {
binding.details.etbahnhofname.setText(upload.getTitle());
}
setLocalBitmap(upload);
}
}
if (directPicture) {
takePicture();
}
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs in project RSAndroidApp by RailwayStations.
the class DetailsActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == R.id.nav_to_station) {
startNavigation(DetailsActivity.this);
} else if (itemId == R.id.timetable) {
final Intent timetableIntent = new Timetable().createTimetableIntent(Country.getCountryByCode(countries, station.getCountry()), station);
if (timetableIntent != null) {
startActivity(timetableIntent);
} else {
Toast.makeText(this, R.string.timetable_missing, Toast.LENGTH_LONG).show();
}
} else if (itemId == R.id.share_photo) {
final Intent shareIntent = createFotoSendIntent();
shareIntent.putExtra(Intent.EXTRA_TEXT, Country.getCountryByCode(countries, station != null ? station.getCountry() : null).getTwitterTags() + " " + binding.details.etbahnhofname.getText());
shareIntent.setType("image/jpeg");
startActivity(createChooser(shareIntent, "send"));
} else if (itemId == R.id.station_info) {
showStationInfo(null);
} else if (itemId == R.id.provider_android_app) {
final List<ProviderApp> providerApps = Country.getCountryByCode(countries, station.getCountry()).getCompatibleProviderApps();
if (providerApps.size() == 1) {
providerApps.get(0).openAppOrPlayStore(this);
} else if (providerApps.size() > 1) {
final CharSequence[] appNames = providerApps.stream().map(ProviderApp::getName).toArray(CharSequence[]::new);
new SimpleDialogs().simpleSelect(this, getResources().getString(R.string.choose_provider_app), appNames, (dialog, which) -> {
if (which >= 0 && providerApps.size() > which) {
providerApps.get(which).openAppOrPlayStore(DetailsActivity.this);
}
});
} else {
Toast.makeText(this, R.string.provider_app_missing, Toast.LENGTH_LONG).show();
}
} else if (itemId == android.R.id.home) {
navigateUp();
} else {
return super.onOptionsItemSelected(item);
}
return true;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs in project RSAndroidApp by RailwayStations.
the class MapsActivity method onLongPress.
private void onLongPress(final LatLong tapLatLong) {
if (missingMarker == null) {
// marker to show at the location
final Drawable drawable = ContextCompat.getDrawable(this, R.drawable.marker_missing);
assert drawable != null;
final Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
missingMarker = new Marker(tapLatLong, bitmap, -(bitmap.getWidth() / 2), -bitmap.getHeight()) {
@Override
public boolean onTap(final LatLong tapLatLong, final Point layerXY, final Point tapXY) {
new SimpleDialogs().confirm(MapsActivity.this, R.string.add_missing_station, (dialogInterface, i) -> {
final Intent intent = new Intent(MapsActivity.this, DetailsActivity.class);
intent.putExtra(DetailsActivity.EXTRA_LATITUDE, getLatLong().latitude);
intent.putExtra(DetailsActivity.EXTRA_LONGITUDE, getLatLong().longitude);
startActivity(intent);
});
return false;
}
};
binding.map.mapView.getLayerManager().getLayers().add(missingMarker);
} else {
missingMarker.setLatLong(tapLatLong);
missingMarker.requestRedraw();
}
// feedback for long click
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150, VibrationEffect.DEFAULT_AMPLITUDE));
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs in project RSAndroidApp by RailwayStations.
the class MainActivity method showApiUrlDialog.
private void showApiUrlDialog() {
new SimpleDialogs().prompt(this, R.string.apiUrl, EditorInfo.TYPE_TEXT_VARIATION_URI, R.string.api_url_hint, baseApplication.getApiUrl(), v -> {
try {
if (StringUtils.isEmpty(v)) {
// set to default
baseApplication.setApiUrl(null);
} else {
if (!Uri.parse(v).getScheme().matches("https?")) {
throw new IllegalArgumentException("Only http(s) URIs are allowed");
}
baseApplication.setApiUrl(v);
}
baseApplication.setLastUpdate(0);
recreate();
} catch (final Exception e) {
Toast.makeText(getBaseContext(), getString(R.string.invalid_api_url), Toast.LENGTH_LONG).show();
}
});
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs in project RSAndroidApp by RailwayStations.
the class MyDataActivity method login.
public void login(final View view) {
final String username = binding.myData.etEmailOrNickname.getText().toString();
final String password = binding.myData.etPassword.getText().toString();
if (isLoginDataAvailable(username, password)) {
baseApplication.setEmail(username);
baseApplication.setPassword(password);
rsapiClient.setCredentials(username, password);
loadRemoteProfile();
} else {
new SimpleDialogs().confirm(this, R.string.missing_login_data);
}
}
Aggregations