refactoring content

This commit is contained in:
yb 2022-07-01 03:21:39 +02:00
parent df864606a2
commit 50ad2e1ef4
19 changed files with 659 additions and 85 deletions

View File

@ -13,6 +13,7 @@ import eu.csc.vehown.ui.fragments.details.FragmentDetailVehicle;
import eu.csc.vehown.ui.md.ItemDetailFragment;
import eu.csc.vehown.ui.register.RegisterVehicleActivity;
import eu.csc.vehown.ui.register.ShowVehiclesAndDevicesFragment;
import eu.csc.vehown.ui.registration.devices.DeviceRegistrationFragment;
import static eu.csc.vehown.ui.fragments.details.AbstractDetailFragment.ARG_ITEM_ID;
@ -22,6 +23,8 @@ public class ActivityBaseDetailContent extends AbstractAppCompatActivity {
private static final String ARG_ITEM_TYPE = "ty";
private static final int ARG_ITEM_TYPE_VEHICLE = 1;
private static final int ARG_ITEM_TYPE_DEVICE = 2;
private static final int ARG_ITEM_TYPE_VEHICLE_REGISTER = 3;
private static final int ARG_ITEM_TYPE_DEVICE_REGISTER = 4;
public static Intent getVehicleDetailInstance(FragmentActivity activity, String vin) {
Intent intent = new Intent(activity, ActivityBaseDetailContent.class);
@ -29,6 +32,12 @@ public class ActivityBaseDetailContent extends AbstractAppCompatActivity {
intent.putExtra(ARG_ITEM_TYPE, ARG_ITEM_TYPE_VEHICLE);
return intent;
}
public static Intent getDeviceRegistrationInstance(FragmentActivity activity) {
Intent intent = new Intent(activity, ActivityBaseDetailContent.class);
intent.putExtra(ARG_ITEM_TYPE, ARG_ITEM_TYPE_DEVICE_REGISTER);
return intent;
}
public static Intent getDeviceDetailInstance(FragmentActivity activity, String identifier) {
Intent intent = new Intent(activity, ActivityBaseDetailContent.class);
@ -44,8 +53,14 @@ public class ActivityBaseDetailContent extends AbstractAppCompatActivity {
if (getIntent() != null) {
int typeId = getIntent().getIntExtra(ARG_ITEM_TYPE, 0);
String id = getIntent().getStringExtra(ARG_ITEM_ID);
String id = null;
if(getIntent().hasExtra(ARG_ITEM_ID)){
id = getIntent().getStringExtra(ARG_ITEM_ID);
}
switch (typeId) {
case ARG_ITEM_TYPE_DEVICE_REGISTER:
switchFragment(R.id.flContent, DeviceRegistrationFragment.newInstance());
break;
case ARG_ITEM_TYPE_VEHICLE:
Log.d("DATA", getIntent().getStringExtra(ARG_ITEM_ID));
switchFragment(R.id.flContent, FragmentDetailVehicle.newInstance(id));

View File

@ -1,11 +1,13 @@
package eu.csc.vehown.ui.base;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
@ -13,6 +15,8 @@ import androidx.navigation.ui.NavigationUI;
import eu.csc.vehown.R;
import eu.csc.vehown.databinding.ActivityBaseRegistrationBinding;
import static eu.csc.vehown.ui.fragments.details.AbstractDetailFragment.ARG_ITEM_ID;
/**
* @see eu.csc.vehown.ui.registration.vehicle.FragmentVehicleRegistration
*/
@ -20,12 +24,23 @@ public class BaseRegistrationActivity extends AppCompatActivity implements ICall
private ActivityBaseRegistrationBinding binding;
public static Intent getDeviceRegistrationInstance(FragmentActivity activity) {
Intent intent = new Intent(activity, BaseRegistrationActivity.class);
intent.putExtra("ARG_ITEM_TYPE", 1);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityBaseRegistrationBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
int typeId = 0;
if (getIntent() != null) {
typeId = getIntent().getIntExtra("ARG_ITEM_TYPE", 0);
}
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
@ -38,6 +53,7 @@ public class BaseRegistrationActivity extends AppCompatActivity implements ICall
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_base_registration);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView, navController);
}

View File

@ -1,10 +1,13 @@
package eu.csc.vehown.ui.pub;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.DatePicker;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.FragmentActivity;
import java.util.Date;
@ -30,11 +33,13 @@ public class UIUtils {
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
}
});
builder.setNegativeButton("Abort", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
dialog.dismiss();
}
});
// 3. Get the <code><a href="/reference/android/app/AlertDialog.html">AlertDialog</a></code> from <code><a href="/reference/android/app/AlertDialog.Builder.html#create()">create()</a></code>
@ -42,4 +47,19 @@ public class UIUtils {
dialog.show();
}
public static AlertDialog showConfirmationDialog(Context context, DialogInterface.OnClickListener ok, DialogInterface.OnClickListener abort) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage("Are you sure")
.setTitle("Confirm");
builder.setPositiveButton("Ok", ok);
builder.setNegativeButton("Abort",abort);
// 3. Get the <code><a href="/reference/android/app/AlertDialog.html">AlertDialog</a></code> from <code><a href="/reference/android/app/AlertDialog.Builder.html#create()">create()</a></code>
AlertDialog dialog = builder.create();
return dialog;
}
}

View File

@ -0,0 +1,52 @@
package eu.csc.vehown.ui.register;
import android.bluetooth.BluetoothClass;
import androidx.lifecycle.MutableLiveData;
import java.util.List;
import eu.csc.vehown.data.model.CustomerDevice;
import eu.csc.vehown.data.model.Vehicle;
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClient;
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClientImpl;
import eu.csc.vehown.ui.viewmodels.AbstractBaseViewModel;
import lombok.Getter;
public class ShowVehicleAndDevicesViewModel extends AbstractBaseViewModel {
@Getter
private final MutableLiveData<List<Vehicle>> mVehicles;
@Getter
private final MutableLiveData<List<CustomerDevice>> mDevices;
public ShowVehicleAndDevicesViewModel(LocalStorageClient localStorage) {
super(localStorage);
mDevices = new MutableLiveData<>();
mVehicles = new MutableLiveData<>();
}
public void deleteVehicle(Vehicle vehicle) {
localStorageClient.deleteVehicle(vehicle);
reloadVehicles();
}
public void init() {
reloadVehicles();
reloadDevices();
}
public void reloadVehicles() {
this.mVehicles.postValue(localStorageClient.loadVehicles());
}
public void reloadDevices() {
mDevices.postValue(localStorageClient.loadDevices());
}
public void deleteDevice(CustomerDevice item) {
this.localStorageClient.deleteDevice(item.getSerialNumber());reloadDevices();
}
}

View File

@ -1,12 +1,14 @@
package eu.csc.vehown.ui.register;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
@ -15,40 +17,49 @@ import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import eu.csc.vehown.R;
import eu.csc.vehown.data.model.CustomerDevice;
import eu.csc.vehown.data.model.Vehicle;
import eu.csc.vehown.databinding.FragmentShowVehiclesAndDevicesBinding;
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClient;
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClientImpl;
import eu.csc.vehown.persist.sharedPreferences.SharedPreferencesFactory;
import eu.csc.vehown.ui.base.AbstractFragment;
import eu.csc.vehown.ui.base.ActivityBaseDetailContent;
import eu.csc.vehown.ui.base.BaseRegistrationActivity;
import eu.csc.vehown.ui.pub.UIUtils;
import eu.csc.vehown.ui.viewmodels.AppViewModelFactory;
import lombok.var;
import java.util.ArrayList;
import java.util.List;
public class ShowVehiclesAndDevicesFragment extends Fragment {
/**
* @see ShowVehicleAndDevicesViewModel
*/
public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
// private LocalStorageClient sharedPref;
private FragmentShowVehiclesAndDevicesBinding binding;
private RegistrationViewModel model;
private ShowVehicleAndDevicesViewModel model;
private ActivityResultLauncher<Intent> launcherEditVehicle, launcherEditDevice;
private VehicleAdapter vehicleAdapter;
//TODO private DeviceAdapter deviceAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentShowVehiclesAndDevicesBinding.inflate(inflater, container, false);
// sharedPref = SharedPreferencesFactory.getInstance(getActivity());
launcherEditVehicle = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
//TODO Vehicle vehicle = model.getVehicle();
// vehicleAdapter.update(vehicle);
// vehicleAdapter.notifyDataSetChanged();
model.reloadVehicles();
}
});
launcherEditDevice = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
//TODO Device device = ...
@ -59,14 +70,39 @@ public class ShowVehiclesAndDevicesFragment extends Fragment {
return binding.getRoot();
}
private ShowVehicleAndDevicesViewModel loadViewModel() {
return model = new ViewModelProvider(this, new AppViewModelFactory(getContext())).get(ShowVehicleAndDevicesViewModel.class);
}
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//Toolbar toolbar = view.findViewById(R.id.toolbar);
//toolbar.setTitle(R.string.show_vehicles_and_devices);
model = loadViewModel();
model.getMVehicles().observe(getViewLifecycleOwner(), new Observer<List<Vehicle>>() {
@Override
public void onChanged(List<Vehicle> items) {
var vehicleAdapter = new VehicleAdapter(items, model);
binding.listVehicles.setAdapter(vehicleAdapter);
}
});
model.getMDevices().observe(getViewLifecycleOwner(), new Observer<List<CustomerDevice>>() {
@Override
public void onChanged(List<CustomerDevice> items) {
var adapter = new DeviceAdapter(items, model);
binding.listDevices.setAdapter(adapter);
}
});
model.init();
// model = new ViewModelProvider(this, new AppViewModelFactory(getActivity())).get(RegistrationViewModel.class);
model = new ViewModelProvider(this, new AppViewModelFactory(getActivity())).get(RegistrationViewModel.class);
vehicleAdapter = new VehicleAdapter(model.getStoredUserVehicles());
binding.listVehicles.setAdapter(vehicleAdapter);
//TODO deviceAdapter = new DeviceAdapter();
// binding.listDevices.setAdapter(deviceAdapter);
@ -77,9 +113,12 @@ public class ShowVehiclesAndDevicesFragment extends Fragment {
private final List<Vehicle> listVehicles = new ArrayList<>();
VehicleAdapter(List<Vehicle> items) {
ShowVehicleAndDevicesViewModel model;
VehicleAdapter(List<Vehicle> items, ShowVehicleAndDevicesViewModel model) {
listVehicles.add(null);
listVehicles.addAll(items);
this.model = model;
}
@ -91,7 +130,7 @@ public class ShowVehiclesAndDevicesFragment extends Fragment {
@Override
@NonNull
public VehicleAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_vehicle, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_vehicle_modern, parent, false);
return new VehicleAdapter.ViewHolder(view);
}
@ -101,12 +140,40 @@ public class ShowVehiclesAndDevicesFragment extends Fragment {
if (vehicle == null) {
holder.imgVehicle.setImageResource(R.drawable.ic_add_vehicle);
holder.imgVehicle.setOnClickListener(v -> callVehicleActivity(null, -1));
holder.tvVehicle.setText("");
holder.imageButton.setEnabled(false);
holder.imageButton.setVisibility(View.INVISIBLE);
holder.tvVin.setText("");
holder.tvDetails.setText("");
} else {
holder.itemView.setTag(vehicle);
holder.itemView.setOnClickListener(v -> callVehicleActivity(vehicle, position));
//holder.imgVehicle.setImageResource(vehicle.getBitmap());
holder.tvVehicle.setText(vehicle.getName());
holder.tvDetails.setText(vehicle.getName());
holder.tvVin.setText(vehicle.getVin());
holder.imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
var dialog = UIUtils.showConfirmationDialog(getContext(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
model.deleteVehicle(vehicle);
dialog.dismiss();
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog.show();
//UIUtils.showQuestionDialog(v)
}
});
}
}
@ -117,12 +184,16 @@ public class ShowVehiclesAndDevicesFragment extends Fragment {
class ViewHolder extends RecyclerView.ViewHolder {
final ImageView imgVehicle;
final TextView tvVehicle;
final TextView tvVin;
final TextView tvDetails;
final ImageButton imageButton;
ViewHolder(View view) {
super(view);
imgVehicle = view.findViewById(R.id.imgVehicle);
tvVehicle = view.findViewById(R.id.tvVehicle);
tvDetails = view.findViewById(R.id.tvDetails);
tvVin = view.findViewById(R.id.tvVin);
imageButton = view.findViewById(R.id.btnDelete);
}
}
@ -139,6 +210,135 @@ public class ShowVehiclesAndDevicesFragment extends Fragment {
//TODO intent.putExtra(VIN, vehicle.getVin());
//TODO intent.putExtra(POSITION, position);
launcherEditVehicle.launch(intent);
}
}
public class DeviceAdapter extends RecyclerView.Adapter<DeviceAdapter.ViewHolder> {
private final List<CustomerDevice> items = new ArrayList<>();
ShowVehicleAndDevicesViewModel model;
DeviceAdapter(List<CustomerDevice> items, ShowVehicleAndDevicesViewModel model) {
this.items.add(null);
this.items.addAll(items);
this.model = model;
}
public void update(int position, CustomerDevice vehicle) {
items.set(position, vehicle);
notifyDataSetChanged();
}
@Override
@NonNull
public DeviceAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_device_modern, parent, false);
return new DeviceAdapter.ViewHolder(view);
}
@Override
public void onBindViewHolder(final DeviceAdapter.ViewHolder holder, int position) {
var item = items.get(position);
if (item == null) {
holder.img.setImageResource(R.drawable.ic_add);
holder.img.setOnClickListener(v -> callDeviceActivity(null, -1));
holder.imageButton.setEnabled(false);
holder.imageButton.setVisibility(View.INVISIBLE);
holder.tvName.setText("");
holder.tvSerialnumber.setText("");
} else {
holder.itemView.setTag(item);
holder.itemView.setOnClickListener(v -> callDeviceActivity(item, position));
//holder.imgVehicle.setImageResource(vehicle.getBitmap());
holder.tvName.setText(item.getName());
holder.tvSerialnumber.setText(item.getSerialNumber());
holder.imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
var dialog = UIUtils.showConfirmationDialog(getContext(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
model.deleteDevice(item);
dialog.dismiss();
}
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
dialog.show();
//UIUtils.showQuestionDialog(v)
}
});
}
}
@Override
public int getItemCount() {
return items.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
final ImageView img;
final TextView tvSerialnumber;
final TextView tvName;
final ImageButton imageButton;
ViewHolder(View view) {
super(view);
img = view.findViewById(R.id.img);
tvName = view.findViewById(R.id.tvName);
tvSerialnumber = view.findViewById(R.id.tvSerialnumber);
imageButton = view.findViewById(R.id.btnDelete);
}
}
private void callVehicleActivity(CustomerDevice item, int position) {
Log.d(ShowVehiclesAndDevicesFragment.class.getSimpleName(), "" + item);
Intent intent = null;
if (item != null) {
intent = ActivityBaseDetailContent.getDeviceDetailInstance(getActivity(), item.getSerialNumber());
// intent = RegisterVehicleActivity.editCurrentItem(getActivity(), vehicle.getVin());
} else {
//intent = Register.createNew(getActivity());
}
//TODO intent.putExtra(VIN, vehicle.getVin());
//TODO intent.putExtra(POSITION, position);
launcherEditVehicle.launch(intent);
}
private void callDeviceActivity(CustomerDevice item, int position) {
Log.d(ShowVehiclesAndDevicesFragment.class.getSimpleName(), "" + item);
Intent intent = null;
if (item != null) {
intent = ActivityBaseDetailContent.getDeviceDetailInstance(getActivity(), item.getSerialNumber());
// intent = RegisterVehicleActivity.editCurrentItem(getActivity(), vehicle.getVin());
} else {
intent = ActivityBaseDetailContent.getDeviceRegistrationInstance(getActivity());
// intent = CustomerDe.show(getActivity());
}
//TODO intent.putExtra(VIN, vehicle.getVin());
//TODO intent.putExtra(POSITION, position);
launcherEditVehicle.launch(intent);
}
}

View File

@ -173,9 +173,10 @@ public class FragmentVehicleRegistration extends Fragment {
if(mCallback != null){
mCallback.showIdle("RUNNING");
mViewModel.storeVehicle(getVehicle());
}
//mViewModel.storeVehicle(getVehicle());
//Helper.infoDialog(handler, getApplicationContext(), "success");
});

View File

@ -10,6 +10,7 @@ import eu.csc.vehown.persist.sharedPreferences.SharedPreferencesFactory;
import eu.csc.vehown.ui.fragments.data.LoginRepository;
import eu.csc.vehown.ui.fragments.ui.login.LoginViewModel;
import eu.csc.vehown.ui.register.RegistrationViewModel;
import eu.csc.vehown.ui.register.ShowVehicleAndDevicesViewModel;
import eu.csc.vehown.ui.registration.customer.FragmentCustomerRegistrationViewModel;
import eu.csc.vehown.ui.registration.data.CustomerContentDataSource;
import eu.csc.vehown.ui.registration.data.CustomerRegistrationRepository;
@ -47,6 +48,10 @@ public class AppViewModelFactory implements ViewModelProvider.Factory {
LoginRepository.getInstance(new CustomerContentDataSource(), localStorage));
}
if (modelClass.isAssignableFrom(ShowVehicleAndDevicesViewModel.class)) {
return (T) new ShowVehicleAndDevicesViewModel(
localStorage);
}
if (modelClass.isAssignableFrom(CustomerRegistrationViewModel.class)) {
return (T) new CustomerRegistrationViewModel(CustomerRegistrationRepository.getInstance(
new CustomerContentDataSource(),

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

View File

@ -0,0 +1,49 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/img"
android:layout_width="@dimen/systemImageWidthSmall"
android:layout_height="@dimen/systemImageHeightSmall"
android:contentDescription="@string/vehicle_image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/layoutDevice"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/layoutDevice"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="@color/green"
layout="@layout/list_detail_device"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/btnDelete"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/img"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:src="@drawable/ic_baseline_delete_24"
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/layoutDevice"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,23 +1,48 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgVehicle"
android:layout_width="@dimen/systemImageWidthSmall"
android:layout_height="@dimen/systemImageHeightSmall"
android:contentDescription="@string/vehicle_image"/>
<ImageView
android:id="@+id/imgVehicle"
android:layout_width="@dimen/systemImageWidthSmall"
android:layout_height="@dimen/systemImageHeightSmall"
android:contentDescription="@string/vehicle_image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tvVehicle"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvVehicle"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="@color/green"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/btnDelete"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imgVehicle"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:src="@drawable/ic_baseline_delete_24"
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/tvVehicle"
app:layout_constraintTop_toTopOf="parent"
<TextView
android:id="@+id/tvVehicle"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginStart="10dp"
android:textStyle="bold"
android:textColor="@color/green"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,49 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llVehicle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgVehicle"
android:layout_width="@dimen/systemImageWidthSmall"
android:layout_height="@dimen/systemImageHeightSmall"
android:contentDescription="@string/vehicle_image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/layoutVehicle"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/layoutVehicle"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="@color/green"
layout="@layout/list_detail_vehicle"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/btnDelete"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imgVehicle"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:src="@drawable/ic_baseline_delete_24"
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/layoutVehicle"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,57 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
android:layout_height="0dp"
android:layout_weight="1.0">
<TextView
android:id="@+id/tvVehicles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/vehicles"
android:textSize="@dimen/fontL"
android:textStyle="normal"/>
android:id="@+id/tvVehicles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/vehicles"
android:textSize="@dimen/fontL"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listVehicles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tvVehicles"
android:layout_marginTop="10dp"
tools:listitem="@layout/content_vehicle"
app:layoutManager="LinearLayoutManager"/>
android:id="@+id/listVehicles"
android:layout_width="match_parent"
</RelativeLayout>
android:divider="#000"
android:dividerHeight="2dp"
android:layout_height="0dp"
android:layout_marginTop="10dp"
app:layoutManager="LinearLayoutManager"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@+id/toggleButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvVehicles"
app:layout_constraintWidth_default="wrap"
tools:listitem="@layout/content_vehicle_modern" />
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/listVehicles"
app:layout_constraintBottom_toBottomOf="parent"
>
<Button
android:id="@+id/button1"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="@+id/button2"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:id="@+id/button3"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3" />
</com.google.android.material.button.MaterialButtonToggleGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
<TextView
android:id="@+id/tvDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/devices"
android:textSize="@dimen/fontL"
android:textStyle="normal"/>
android:id="@+id/tvDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/devices"
android:textSize="@dimen/fontL"
android:textStyle="normal" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listDevices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tvDevices"
android:layout_marginTop="10dp"
tools:listitem="@layout/content_device"
app:layoutManager="LinearLayoutManager"/>
android:id="@+id/listDevices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tvDevices"
android:layout_marginTop="10dp"
app:layoutManager="LinearLayoutManager"
tools:listitem="@layout/content_device_modern" />
</RelativeLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/green"
android:textStyle="bold" />
<TextView
android:id="@+id/tvSerialnumber"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvVin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/green"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -43,11 +43,7 @@ public class Vehicle implements Serializable {
}
public boolean equalsIdentification(Vehicle vehicle) {
if(vin == null)
return false;
if(licensePlate == null)
return false;
return vin.equals(vehicle.vin) || licensePlate.equals(vehicle.licensePlate);
}
}

View File

@ -51,6 +51,8 @@ public interface LocalStorageClient extends IVehOwnData {
void deleteVehicles();
void deleteDevice(String serialNumber);
//region ServerData

View File

@ -31,12 +31,14 @@ public class LocalStorageClientImpl implements LocalStorageClient {
private static final String PREF_CUSTOMER = "customer";
private static final String PREF_VEHICLES = "vehicles";
private static final String PREF_DEVICES = "devices";
// private static final String KEY_LOGGEDINUSERNAME = "prefs_loggedin_username";
private File tokenDir;
private File eventsDir;
private String TAG = LocalStorageClientImpl.class.getSimpleName();
public static LocalStorageClientImpl getInstance(Context context) {
return new LocalStorageClientImpl(context);
}
@ -170,13 +172,31 @@ public class LocalStorageClientImpl implements LocalStorageClient {
@Override
public List<CustomerDevice> loadDevices() {
throw new UnsupportedOperationException();
String json = sharedPreferences.getString(PREF_DEVICES, null);
if (json == null)
return new ArrayList<>();
Type listOfMyClassObject = new TypeToken<ArrayList<CustomerDevice>>() {
}.getType();
List<CustomerDevice> items = gson.fromJson(json, listOfMyClassObject);
return items;
}
@Override
public void storeDevice(CustomerDevice vehicle) {
public void storeDevice(CustomerDevice item) {
throw new UnsupportedOperationException();
var items = loadDevices();
for (int i = 0; i < items.size(); i++) {
if (item.getSerialNumber().equals(items.get(i).getSerialNumber())) {
items.set(i, item);
getEditor().putString(PREF_DEVICES, gson.toJson(items)).apply();
return;
}
}
items.add(item);
getEditor().putString(PREF_DEVICES, gson.toJson(items)).apply();
}
@Override
@ -224,6 +244,18 @@ public class LocalStorageClientImpl implements LocalStorageClient {
getEditor().putString(PREF_VEHICLES, null).apply();
}
@Override
public void deleteDevice(String serialNumber) {
var items = loadDevices();
for (int i = 0; i < items.size(); i++) {
if (serialNumber.equals(items.get(i))) {
items.remove(i);
getEditor().putString(PREF_DEVICES, gson.toJson(items)).apply();
return;
}
}
}
private SharedPreferences.Editor getEditor() {
return sharedPreferences.edit();
}