Search in sources :

Example 11 with SimpleDialogs

use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs in project RSAndroidApp by RailwayStations.

the class OutboxActivity method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final BaseApplication baseApplication = (BaseApplication) getApplication();
    dbAdapter = baseApplication.getDbAdapter();
    final ActivityOutboxBinding binding = ActivityOutboxBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    adapter = new OutboxAdapter(OutboxActivity.this, dbAdapter.getOutbox());
    binding.lstUploads.setAdapter(adapter);
    // item click
    binding.lstUploads.setOnItemClickListener((parent, view, position, id) -> {
        final Upload upload = dbAdapter.getUploadById(id);
        final Intent detailIntent = new Intent(OutboxActivity.this, DetailsActivity.class);
        detailIntent.putExtra(DetailsActivity.EXTRA_UPLOAD, upload);
        startActivity(detailIntent);
    });
    binding.lstUploads.setOnItemLongClickListener((parent, view, position, id) -> {
        final String uploadId = String.valueOf(id);
        new SimpleDialogs().confirm(OutboxActivity.this, getResources().getString(R.string.delete_upload, uploadId), (dialog, which) -> {
            dbAdapter.deleteUpload(id);
            FileUtils.deleteQuietly(FileUtils.getStoredMediaFile(this, id));
            adapter.changeCursor(dbAdapter.getOutbox());
        });
        return true;
    });
    final List<InboxStateQuery> query = new ArrayList<>();
    for (final Upload upload : dbAdapter.getPendingUploads(true)) {
        query.add(new InboxStateQuery(upload.getRemoteId()));
    }
    baseApplication.getRsapiClient().queryUploadState(query).enqueue(new Callback<>() {

        @Override
        public void onResponse(@NonNull final Call<List<InboxStateQuery>> call, @NonNull final Response<List<InboxStateQuery>> response) {
            final List<InboxStateQuery> stateQueries = response.body();
            if (stateQueries != null) {
                dbAdapter.updateUploadStates(stateQueries);
                adapter.changeCursor(dbAdapter.getOutbox());
            } else {
                Log.w(TAG, "Upload states not processable");
            }
        }

        @Override
        public void onFailure(@NonNull final Call<List<InboxStateQuery>> call, @NonNull final Throwable t) {
            Log.e(TAG, "Error retrieving upload state", t);
            Toast.makeText(OutboxActivity.this, R.string.error_retrieving_upload_state, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : InboxStateQuery(de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxStateQuery) ArrayList(java.util.ArrayList) Upload(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload) ActivityOutboxBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityOutboxBinding) Intent(android.content.Intent) OutboxAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.OutboxAdapter) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) ArrayList(java.util.ArrayList) List(java.util.List)

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