Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
427 changes: 427 additions & 0 deletions org.envirocar.app/res/layout/activity_logbook_edit_fueling_card.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions org.envirocar.app/res/values-de/strings_logbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<string name="logbook_dialog_uploading_fueling_header">Hochladen</string>
<string name="logbook_dialog_uploading_fueling_car">Registrierung des Fahrzeugtyps...</string>
<string name="logbook_dialog_uploading_fueling_content">Der Tankeintrag wird hochgeladen...</string>
<string name="logbook_edit_fueling">Tanken bearbeiten</string>
<string name="logbook_dialog_editing_fueling_header">Bearbeitung</string>
<string name="logbook_dialog_editing_fueling_content">Bearbeiten der Betankung.</string>
<string name="logbook_fuel_edited_successfully">Tanken wurde erfolgreich bearbeitet.</string>
<string name="logbook_background_not_logged_in_first">AUSGELOGGT</string>
<string name="logbook_background_no_fuelings_first">KEINE EINTRÄGE</string>
<string name="logbook_background_no_fuelings_second">Es sind keine Tankeinträge\ndem eingeloggten Nutzer zugeordnet.</string>
Expand Down
4 changes: 4 additions & 0 deletions org.envirocar.app/res/values/strings_logbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<string name="logbook_dialog_uploading_fueling_header">Uploading</string>
<string name="logbook_dialog_uploading_fueling_car">Registering car type before uploading fueling.</string>
<string name="logbook_dialog_uploading_fueling_content">Uploading the fueling.</string>
<string name="logbook_edit_fueling">Edit Fueling</string>
<string name="logbook_dialog_editing_fueling_header">Editing</string>
<string name="logbook_dialog_editing_fueling_content">Editing the fueling.</string>
<string name="logbook_fuel_edited_successfully">Fueling has been edited successfully.</string>
<string name="logbook_background_not_logged_in_first">NOT LOGGED IN</string>
<string name="logbook_background_no_fuelings_first">NO FUELINGS</string>
<string name="logbook_background_no_fuelings_second">There are no fuelings assigned\nto the current user.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.envirocar.app.views.dashboard.DashboardFragment;
import org.envirocar.app.views.logbook.LogbookActivity;
import org.envirocar.app.views.logbook.LogbookAddFuelingFragment;
import org.envirocar.app.views.logbook.LogbookEditFuelingFragment;
import org.envirocar.app.views.login.SigninActivity;
import org.envirocar.app.views.login.SignupActivity;
import org.envirocar.app.views.obdselection.OBDSelectionActivity;
Expand Down Expand Up @@ -116,6 +117,7 @@ public interface BaseApplicationComponent {
void inject(TrackListRemoteCardFragment fragment);
void inject(CarSelectionAddCarFragment carSelectionAddCarFragment);
void inject(LogbookAddFuelingFragment logbookAddFuelingFragment);
void inject(LogbookEditFuelingFragment logbookEditFuelingFragment);
void inject(OBDSelectionFragment obdSelectionFragment);
void inject(OthersFragment othersFragment);
void inject(CarSelectionHsnTsnFragment hsnTsnFragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,4 @@ public int getCount() {
return Math.min(2, super.getCount());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,4 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
appUpdateCheck();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
*/
package org.envirocar.app.views.logbook;

import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.os.Build;

import android.content.Intent;
import android.os.Bundle;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.FragmentManager;

import android.view.View;
import android.widget.AdapterView;
Expand All @@ -40,17 +36,19 @@
import org.envirocar.app.BaseApplicationComponent;
import org.envirocar.app.R;
import org.envirocar.app.handler.preferences.CarPreferenceHandler;
import org.envirocar.app.views.utils.DateUtils;
import org.envirocar.app.views.utils.ECAnimationUtils;
import org.envirocar.core.ContextInternetAccessProvider;
import org.envirocar.core.InternetAccessProvider;
import org.envirocar.core.UserManager;
import org.envirocar.core.entity.Car;
import org.envirocar.core.entity.Fueling;
import org.envirocar.core.exception.NotConnectedException;
import org.envirocar.core.exception.UnauthorizedException;
import org.envirocar.app.injection.BaseInjectorActivity;
import org.envirocar.core.logging.Logger;
import org.envirocar.app.handler.DAOProvider;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -90,7 +88,6 @@ public class LogbookActivity extends BaseInjectorActivity implements LogbookUiLi
protected ListView fuelingList;
@BindView(R.id.overlay)
protected View overlayView;

@BindView(R.id.layout_general_info_background)
protected View infoBackground;
@BindView(R.id.layout_general_info_background_img)
Expand All @@ -100,15 +97,11 @@ public class LogbookActivity extends BaseInjectorActivity implements LogbookUiLi
@BindView(R.id.layout_general_info_background_secondline)
protected TextView infoBackgroundSecond;

// @BindView(R.id.activity_logbook_not_logged_in)
// protected View notLoggedInView;
// @BindView(R.id.activity_logbook_no_fuelings_info_view)
// protected View noFuelingsView;

protected LogbookListAdapter fuelingListAdapter;
protected final List<Fueling> fuelings = new ArrayList<Fueling>();
protected final List<Fueling> fuelings = new ArrayList<>();

private LogbookAddFuelingFragment addFuelingFragment;
private LogbookEditFuelingFragment editFuelingFragment = new LogbookEditFuelingFragment();
private final CompositeDisposable subscription = new CompositeDisposable();

@Override
Expand Down Expand Up @@ -136,6 +129,36 @@ protected void onCreate(Bundle savedInstanceState) {
fuelingListAdapter = new LogbookListAdapter(this, fuelings);
fuelingList.setAdapter(fuelingListAdapter);

fuelingList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Fueling fueling = fuelings.get(position);
// to pass all the data
final DecimalFormat DECIMAL_FORMATTER = new DecimalFormat("#.##");

String date = DateUtils.getDateString(getApplicationContext(), fueling.getTime());
String totalPrice = String.format("%s €", DECIMAL_FORMATTER.format(fueling.getCost()));
String pricePerLiter = String.format("%s l/€", DECIMAL_FORMATTER.format(fueling.getCost() / fueling.getVolume()));
String kmAndLiter = String.format("%s km", fueling.getMilage());
String fueledVolume = String.format("%s l", fueling.getVolume());
Car car = fueling.getCar();
String carText = String.format("%s %s (%s / %sccm)",
car.getManufacturer(),
car.getModel(),
car.getConstructionYear(),
car.getEngineDisplacement());
String comment = fueling.getComment();
boolean isPartial =false;
boolean missedPrevious =false;
if (fueling.isMissedFuelStop()) {
missedPrevious = true;
}
if (fueling.isPartialFueling()) {
isPartial = true;
}
LogbookActivity.this.showEditFuelingCard(position, date, totalPrice, pricePerLiter, kmAndLiter, fueledVolume, carText, comment, isPartial, missedPrevious);
}
});
fuelingList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long
Expand All @@ -147,10 +170,11 @@ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, l
.setMessage(R.string.logbook_dialog_delete_fueling_content)
.setIcon(R.drawable.ic_delete_fueling_24)
.setPositiveButton(R.string.menu_delete,
(dialog, which) -> deleteFueling(fueling))
(dialog, which) -> deleteFueling(fueling,false))
.setNegativeButton(R.string.cancel,null)
.show();
return false;
// return true so that it itemLongClick and itemClick doesn't collide
return true;
}
});

Expand Down Expand Up @@ -184,6 +208,11 @@ public void onBackPressed() {
LOG.info("AddFuelingCard was visible. Closing this card...");
return;
}
if(editFuelingFragment != null && editFuelingFragment.isVisible()){
editFuelingFragment.closeThisFragment();
LOG.info("EditFuelingCard was visible. Closing this card...");
return;
}
super.onBackPressed();
}

Expand All @@ -201,6 +230,10 @@ protected void onClickNewFuelingFAB() {
public void onHideAddFuelingCard() {
hideAddFuelingCard();
}
@Override
public void onHideEditFuelingCard() {
hideEditFuelingCard();
}

@Override
public void onFuelingUploaded(Fueling fueling) {
Expand All @@ -218,6 +251,24 @@ public void onFuelingUploaded(Fueling fueling) {
}
}

public void onFuelingUpdated(Fueling fueling,int position ){
LOG.info("onFuelingUpdated()");
if (!this.fuelings.contains(fueling)) {
final Fueling tempFueling = fuelings.get(position);

deleteFueling(tempFueling,true);
fuelings.set(position, fueling);
Collections.sort(fuelings);
fuelingListAdapter.notifyDataSetChanged();

// Hide the NoFuelingsView if it is visible.
if (!fuelings.isEmpty() && infoBackground.getVisibility() == View.VISIBLE) {
ECAnimationUtils.animateHideView(LogbookActivity.this,
infoBackground, R.anim.fade_out);
}
}
}

/**
* Downloads the fuelings
*/
Expand Down Expand Up @@ -271,7 +322,7 @@ public void onNext(List<Fueling> result) {
*
* @param fueling the fueling to delete.
*/
private void deleteFueling(final Fueling fueling) {
private void deleteFueling(final Fueling fueling, boolean isEdit) {
subscription.add(daoProvider.getFuelingDAO()
.deleteFuelingObservable(fueling)
.subscribeOn(Schedulers.io())
Expand All @@ -290,8 +341,10 @@ public void onComplete() {
}
fuelingListAdapter.notifyDataSetChanged();

// Show a notification about the success.
showSnackbarInfo(R.string.logbook_deletion_success_tmp);
// Show a notification about the success when its not have been deleted while editing.
if(! isEdit) {
showSnackbarInfo(R.string.logbook_deletion_success_tmp);
}
}

@Override
Expand Down Expand Up @@ -356,6 +409,28 @@ private void showAddFuelingCard() {
.commit();
LOG.info("AddFuelingCard should now be visible");
}
private void showEditFuelingCard(int position, String date, String totalPrice, String pricePerLiter, String kmAndLiter, String fueledVolume, String carText, String comment, boolean isPartial, boolean missedPrevious) {
LOG.info("showEditFuelingCard()");
Bundle bundle = new Bundle();
bundle.putInt("pos", position);
bundle.putString("date", date);
bundle.putString("totalPrice", totalPrice);
bundle.putString("pricePerLiter", pricePerLiter);
bundle.putString("kmAndLiter", kmAndLiter);
bundle.putString("fueledVolume", fueledVolume);
bundle.putString("carText", carText);
bundle.putString("comment", comment);
bundle.putBoolean("isPartial", isPartial);
bundle.putBoolean("missedPrevious", missedPrevious);
LogbookEditFuelingFragment fragment = new LogbookEditFuelingFragment();
fragment.setArguments(bundle);
ECAnimationUtils.animateShowView(this, overlayView, R.anim.fade_in);
ECAnimationUtils.animateHideView(this, newFuelingFab, R.anim.fade_out);
getSupportFragmentManager().beginTransaction()
.replace(R.id.activity_logbook_container, fragment)
.commit();
LOG.info("EditFueling should now be visible");
}

/**
* Hides the AddFuelingCard
Expand All @@ -370,6 +445,20 @@ private void hideAddFuelingCard() {
ECAnimationUtils.animateShowView(LogbookActivity.this, newFuelingFab, R.anim.fade_in);
ECAnimationUtils.animateHideView(this, overlayView, R.anim.fade_out);
}
private void hideEditFuelingCard() {
LOG.info("hideEditFuelingCard()");

// editFuelingFragment giving null, couldn't find a reason :/
// getSupportFragmentManager()
// .beginTransaction()
// .remove(editFuelingFragment)
// .commit();
// editFuelingFragment = null;
Intent intent = new Intent(this, LogbookActivity.class);
startActivity(intent);
ECAnimationUtils.animateShowView(LogbookActivity.this, newFuelingFab, R.anim.fade_in);
ECAnimationUtils.animateHideView(this, overlayView, R.anim.fade_out);
}

private void showSnackbarInfo(int resourceID) {
Snackbar.make(newFuelingFab, resourceID, Snackbar.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,4 @@ public void hideKeyboard(View view) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

}
}
Loading