Search in sources :

Example 1 with SimpleDialogs

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();
    }
}
Also used : SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs)

Example 2 with SimpleDialogs

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;
}
Also used : ImageButton(android.widget.ImageButton) Timetable(de.bahnhoefe.deutschlands.bahnhofsfotos.util.Timetable) CheckedInputStream(java.util.zip.CheckedInputStream) Bundle(android.os.Bundle) ParcelFileDescriptor(android.os.ParcelFileDescriptor) ActivityDetailsBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityDetailsBinding) PackageManager(android.content.pm.PackageManager) InboxResponse(de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxResponse) ProblemType(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProblemType) NonNull(androidx.annotation.NonNull) BitmapCache(de.bahnhoefe.deutschlands.bahnhofsfotos.util.BitmapCache) Uri(android.net.Uri) LinkMovementMethod(android.text.method.LinkMovementMethod) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) StringUtils(org.apache.commons.lang3.StringUtils) ConnectionUtil(de.bahnhoefe.deutschlands.bahnhofsfotos.util.ConnectionUtil) Gson(com.google.gson.Gson) Locale(java.util.Locale) MediaStore(android.provider.MediaStore) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) MediaType(okhttp3.MediaType) Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) NavUtils(androidx.core.app.NavUtils) DbAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.DbAdapter) ProviderApp(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProviderApp) Set(java.util.Set) StationInfoBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.StationInfoBinding) UploadBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.UploadBinding) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ListAdapter(android.widget.ListAdapter) RSAPIClient(de.bahnhoefe.deutschlands.bahnhofsfotos.rsapi.RSAPIClient) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) FileProvider(androidx.core.content.FileProvider) Constants(de.bahnhoefe.deutschlands.bahnhofsfotos.util.Constants) EditorInfo(android.view.inputmethod.EditorInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Call(retrofit2.Call) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) FileUtils(de.bahnhoefe.deutschlands.bahnhofsfotos.util.FileUtils) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) ProblemReport(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProblemReport) KeyValueSpinnerItem(de.bahnhoefe.deutschlands.bahnhofsfotos.util.KeyValueSpinnerItem) Response(retrofit2.Response) Intent.createChooser(android.content.Intent.createChooser) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) RequestBody(okhttp3.RequestBody) InboxStateQuery(de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxStateQuery) Country(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Country) URLConnection(java.net.URLConnection) Toast(android.widget.Toast) Menu(android.view.Menu) BitmapAvailableHandler(de.bahnhoefe.deutschlands.bahnhofsfotos.util.BitmapAvailableHandler) ActionBar(android.app.ActionBar) TaskStackBuilder(android.app.TaskStackBuilder) NavItem(de.bahnhoefe.deutschlands.bahnhofsfotos.util.NavItem) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) ComponentName(android.content.ComponentName) ActivityCompat(androidx.core.app.ActivityCompat) FileOutputStream(java.io.FileOutputStream) Point(android.graphics.Point) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) WHITE(android.graphics.Color.WHITE) File(java.io.File) Color(android.graphics.Color) ArrayAdapter(android.widget.ArrayAdapter) URLEncoder(java.net.URLEncoder) Callback(retrofit2.Callback) ReportProblemBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ReportProblemBinding) Bitmap(android.graphics.Bitmap) Upload(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) CRC32(java.util.zip.CRC32) Activity(android.app.Activity) ValueAnimator(android.animation.ValueAnimator) Timetable(de.bahnhoefe.deutschlands.bahnhofsfotos.util.Timetable) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Intent(android.content.Intent) ProviderApp(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProviderApp) Point(android.graphics.Point)

Example 3 with SimpleDialogs

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));
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) StationFilter(de.bahnhoefe.deutschlands.bahnhofsfotos.util.StationFilter) Uri(android.net.Uri) WindowManager(android.view.WindowManager) LocationListener(android.location.LocationListener) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Align(org.mapsforge.core.graphics.Align) GeoItem(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.GeoItem) NONE(android.view.Menu.NONE) Manifest(android.Manifest) CheckBox(android.widget.CheckBox) Map(java.util.Map) AndroidGraphicFactory(org.mapsforge.map.android.graphics.AndroidGraphicFactory) TileRendererLayer(org.mapsforge.map.layer.renderer.TileRendererLayer) View(android.view.View) IMapViewPosition(org.mapsforge.map.model.IMapViewPosition) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) MapFile(org.mapsforge.map.reader.MapFile) DbAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.DbAdapter) Layer(org.mapsforge.map.layer.Layer) SubMenu(android.view.SubMenu) MapPosition(org.mapsforge.core.model.MapPosition) XmlRenderTheme(org.mapsforge.map.rendertheme.XmlRenderTheme) FileNotFoundException(java.io.FileNotFoundException) MapZoomControls(org.mapsforge.map.android.input.MapZoomControls) AbstractTileSource(org.mapsforge.map.layer.download.tilesource.AbstractTileSource) List(java.util.List) DocumentFile(androidx.documentfile.provider.DocumentFile) Marker(org.mapsforge.map.layer.overlay.Marker) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) TileCache(org.mapsforge.map.layer.cache.TileCache) Location(android.location.Location) LocationManager(android.location.LocationManager) Window(android.view.Window) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) Intent(android.content.Intent) FontStyle(org.mapsforge.core.graphics.FontStyle) HashMap(java.util.HashMap) TapHandler(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.TapHandler) Point(org.mapsforge.core.model.Point) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) VibrationEffect(android.os.VibrationEffect) Bitmap(org.mapsforge.core.graphics.Bitmap) InternalRenderTheme(org.mapsforge.map.rendertheme.InternalRenderTheme) Toast(android.widget.Toast) FontFamily(org.mapsforge.core.graphics.FontFamily) Menu(android.view.Menu) StreamRenderTheme(org.mapsforge.map.rendertheme.StreamRenderTheme) DbsTileSource(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.DbsTileSource) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) WeakReference(java.lang.ref.WeakReference) AndroidUtil(org.mapsforge.map.android.util.AndroidUtil) OnlineTileSource(org.mapsforge.map.layer.download.tilesource.OnlineTileSource) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) ActivityCompat(androidx.core.app.ActivityCompat) TileDownloadLayer(org.mapsforge.map.layer.download.TileDownloadLayer) FileInputStream(java.io.FileInputStream) StationFilterBar(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.StationFilterBar) LatLong(org.mapsforge.core.model.LatLong) ActivityMapsBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityMapsBinding) MapDataStore(org.mapsforge.map.datastore.MapDataStore) ClusterManager(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.ClusterManager) MapInfoFragment(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.MapInfoFragment) Color(android.graphics.Color) Paint(org.mapsforge.core.graphics.Paint) Upload(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Vibrator(android.os.Vibrator) Style(org.mapsforge.core.graphics.Style) OpenStreetMapMapnik(org.mapsforge.map.layer.download.tilesource.OpenStreetMapMapnik) Activity(android.app.Activity) Bitmap(org.mapsforge.core.graphics.Bitmap) MarkerBitmap(de.bahnhoefe.deutschlands.bahnhofsfotos.mapsforge.MarkerBitmap) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) Marker(org.mapsforge.map.layer.overlay.Marker) Point(org.mapsforge.core.model.Point) Vibrator(android.os.Vibrator) LatLong(org.mapsforge.core.model.LatLong)

Example 4 with SimpleDialogs

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();
        }
    });
}
Also used : SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs)

Example 5 with SimpleDialogs

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);
    }
}
Also used : SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs)

Aggregations

SimpleDialogs (de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs)11 Upload (de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload)4 ArrayList (java.util.ArrayList)4 TaskStackBuilder (android.app.TaskStackBuilder)3 Intent (android.content.Intent)3 Point (android.graphics.Point)3 ContextThemeWrapper (android.view.ContextThemeWrapper)3 NonNull (androidx.annotation.NonNull)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 List (java.util.List)3 Activity (android.app.Activity)2 Context (android.content.Context)2 PackageManager (android.content.pm.PackageManager)2 Color (android.graphics.Color)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2