refactoring content
This commit is contained in:
parent
1f9c481244
commit
3590e6cdcf
|
|
@ -17,6 +17,7 @@ uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android
|
|||
android:required="false" />
|
||||
|
||||
<application
|
||||
android:name=".ApplicationEx"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,31 @@
|
|||
package eu.csc.log;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import eu.csc.vehown.ApplicationEx;
|
||||
import eu.csc.vehown.persist.localstorage.entity.EntityLog;
|
||||
|
||||
public class Log {
|
||||
private static final String TAG = "VehAppLog";
|
||||
private static Context ctx;
|
||||
|
||||
public static void d(String msg) {
|
||||
d(TAG, msg);
|
||||
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg) {
|
||||
android.util.Log.d(tag, msg);
|
||||
if(ctx !=null)
|
||||
{
|
||||
EntityLog.log(ctx, EntityLog.Type.General, tag+ ": " + msg);
|
||||
}
|
||||
//EntityLog.log();
|
||||
}
|
||||
|
||||
public static void setup(Context context) {
|
||||
ctx = context;
|
||||
//setLevel(context);
|
||||
//setupBugsnag(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package eu.csc.vehown;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import eu.csc.log.Log;
|
||||
import eu.csc.vehown.persist.localstorage.PersistenceFactory;
|
||||
import eu.csc.vehown.persist.localstorage.entity.EntityLog;
|
||||
import lombok.var;
|
||||
|
||||
public class ApplicationEx extends Application {@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
android.util.Log.d("ApplicationEx", "item.toString()");
|
||||
Log.setup(this);
|
||||
|
||||
var db = PersistenceFactory.generateDatabase(this);
|
||||
long from = new Date().getTime() - 24 * 3600 * 1000L;
|
||||
|
||||
Log.d("ApplicationEx", "PERS");
|
||||
for(var item:db.log().getLogs(from, null)){
|
||||
android.util.Log.d("LOGS", item.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,4 +3,7 @@ package eu.csc.vehown.ui.base;
|
|||
|
||||
import androidx.fragment.app.Fragment;
|
||||
public abstract class AbstractFragment extends Fragment {
|
||||
|
||||
public static final String CUSTOM_RESULT_CODE = "c_c";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ 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;
|
||||
import static eu.csc.vehown.ui.fragments.details.AbstractDetailFragment.ARG_RESULT_CODE;
|
||||
|
||||
|
||||
public class ActivityBaseDetailContent extends AbstractAppCompatActivity {
|
||||
|
|
@ -32,10 +33,18 @@ public class ActivityBaseDetailContent extends AbstractAppCompatActivity {
|
|||
intent.putExtra(ARG_ITEM_TYPE, ARG_ITEM_TYPE_VEHICLE);
|
||||
return intent;
|
||||
}
|
||||
public static Intent getDeviceRegistrationInstance(FragmentActivity activity) {
|
||||
public static Intent getVehicleRegistrationInstance(FragmentActivity activity, int resultCode) {
|
||||
Intent intent = new Intent(activity, ActivityBaseDetailContent.class);
|
||||
|
||||
intent.putExtra(ARG_ITEM_TYPE, ARG_ITEM_TYPE_DEVICE_REGISTER);
|
||||
intent.putExtra(ARG_RESULT_CODE, resultCode);
|
||||
return intent;
|
||||
}
|
||||
public static Intent getDeviceRegistrationInstance(FragmentActivity activity, int resultCode) {
|
||||
Intent intent = new Intent(activity, ActivityBaseDetailContent.class);
|
||||
|
||||
intent.putExtra(ARG_ITEM_TYPE, ARG_ITEM_TYPE_DEVICE_REGISTER);
|
||||
intent.putExtra(ARG_RESULT_CODE, resultCode);
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
|
@ -53,13 +62,17 @@ public class ActivityBaseDetailContent extends AbstractAppCompatActivity {
|
|||
|
||||
if (getIntent() != null) {
|
||||
int typeId = getIntent().getIntExtra(ARG_ITEM_TYPE, 0);
|
||||
Integer resultCode = null;
|
||||
String id = null;
|
||||
if(getIntent().hasExtra(ARG_ITEM_ID)){
|
||||
id = getIntent().getStringExtra(ARG_ITEM_ID);
|
||||
}
|
||||
if(getIntent().hasExtra(ARG_RESULT_CODE)){
|
||||
resultCode = getIntent().getIntExtra(ARG_RESULT_CODE, 0);
|
||||
}
|
||||
switch (typeId) {
|
||||
case ARG_ITEM_TYPE_DEVICE_REGISTER:
|
||||
switchFragment(R.id.flContent, DeviceRegistrationFragment.newInstance());
|
||||
switchFragment(R.id.flContent, DeviceRegistrationFragment.newSingleInstance(resultCode));
|
||||
break;
|
||||
case ARG_ITEM_TYPE_VEHICLE:
|
||||
Log.d("DATA", getIntent().getStringExtra(ARG_ITEM_ID));
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ import androidx.fragment.app.Fragment;
|
|||
|
||||
public abstract class AbstractDetailFragment extends Fragment {
|
||||
public static final String ARG_ITEM_ID = "item_id";
|
||||
public static final String ARG_RESULT_CODE = "item_result_code";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import androidx.fragment.app.Fragment;
|
|||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -22,6 +21,8 @@ import android.widget.EditText;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import eu.csc.log.Log;
|
||||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.databinding.FragmentLoginBinding;
|
||||
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClient;
|
||||
|
|
@ -141,17 +142,17 @@ public class LoginFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
if(localStorageClient.getIsLoggedIn() && localStorageClient.getLoggedInUser() != null && localStorageClient.getLoggedInUser().getPassword() != null){
|
||||
Log.d(TAG, "IS LOGGED IN");
|
||||
binding.btnLogout.setEnabled(true);
|
||||
usernameEditText.setText(localStorageClient.getLoggedInUser().getEmail());
|
||||
passwordEditText.setText(localStorageClient.getLoggedInUser().getPassword());
|
||||
}else{
|
||||
if (localStorageClient.getIsLoggedIn() && localStorageClient.getLoggedInUser() != null && localStorageClient.getLoggedInUser().getPassword() != null) {
|
||||
eu.csc.log.Log.d(TAG, "IS LOGGED IN");
|
||||
binding.btnLogout.setEnabled(true);
|
||||
usernameEditText.setText(localStorageClient.getLoggedInUser().getEmail());
|
||||
passwordEditText.setText(localStorageClient.getLoggedInUser().getPassword());
|
||||
} else {
|
||||
|
||||
Log.d(TAG, "IS NOT LOGGED IN");
|
||||
usernameEditText.setText("test@test.test");
|
||||
passwordEditText.setText("yannyann1");
|
||||
}
|
||||
Log.d(TAG, "IS NOT LOGGED IN");
|
||||
usernameEditText.setText("test@test.test");
|
||||
passwordEditText.setText("yannyann1");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUiWithUser(LoggedInUserView model) {
|
||||
|
|
@ -173,7 +174,7 @@ if(localStorageClient.getIsLoggedIn() && localStorageClient.getLoggedInUser() !=
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if(binding.cbRemember.isChecked()){
|
||||
if (binding.cbRemember.isChecked()) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import androidx.lifecycle.ViewModel;
|
||||
import android.util.Patterns;
|
||||
|
||||
import eu.csc.log.Log;
|
||||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.data.model.LoggedInUser;
|
||||
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClient;
|
||||
|
|
@ -36,6 +37,7 @@ public class LoginViewModel extends AbstractBaseViewModel {
|
|||
|
||||
public void login(String username, String password) {
|
||||
// can be launched in a separate asynchronous job
|
||||
Log.d("try login");
|
||||
executorService.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.content.IntentFilter;
|
|||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
|
|
@ -21,6 +20,7 @@ import androidx.navigation.ui.NavigationUI;
|
|||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import eu.csc.log.CSCLog4jFactory;
|
||||
import eu.csc.log.Log;
|
||||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.broadcast.VehicleEventReceivedReceiver;
|
||||
import eu.csc.vehown.persist.sharedPreferences.LocalStorageClient;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ public class ItemDetailHostActivity extends AppCompatActivity {
|
|||
|
||||
public enum LIST_TYPES{
|
||||
DEVICES,
|
||||
VEHICLES
|
||||
VEHICLES,
|
||||
LOGS
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public class ShowVehicleAndDevicesViewModel extends AbstractBaseViewModel {
|
|||
}
|
||||
|
||||
public void deleteDevice(CustomerDevice item) {
|
||||
this.localStorageClient.deleteDevice(item.getSerialNumber());reloadDevices();
|
||||
this.localStorageClient.deleteDevice(item.getSerialNumber());
|
||||
reloadDevices();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
private ShowVehicleAndDevicesViewModel model;
|
||||
private ActivityResultLauncher<Intent> launcherEditVehicle, launcherEditDevice;
|
||||
//TODO private DeviceAdapter deviceAdapter;
|
||||
private static final int LAUNCH_ACTIVITY_REGISTER_DEVICE = 1;
|
||||
private static final int LAUNCH_ACTIVITY_REGISTER_VEHICLE = 2;
|
||||
private String TAG = ShowVehiclesAndDevicesFragment.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
|
@ -61,12 +64,18 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
});
|
||||
|
||||
launcherEditDevice = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
Log.d(TAG, "GETTING RESULT");
|
||||
Log.d(TAG, "GETTING RESULT: " + result.getResultCode());
|
||||
|
||||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
model.reloadDevices();
|
||||
//TODO Device device = ...
|
||||
// deviceAdapter.update(device);
|
||||
// deviceAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +118,22 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == LAUNCH_ACTIVITY_REGISTER_VEHICLE ) {
|
||||
if(resultCode == Activity.RESULT_OK){
|
||||
model.reloadVehicles();
|
||||
}
|
||||
}
|
||||
if (requestCode == LAUNCH_ACTIVITY_REGISTER_DEVICE ) {
|
||||
if(resultCode == Activity.RESULT_OK){
|
||||
model.reloadDevices();
|
||||
}
|
||||
}
|
||||
} //onActivityResult
|
||||
|
||||
public class VehicleAdapter extends RecyclerView.Adapter<VehicleAdapter.ViewHolder> {
|
||||
|
||||
private final List<Vehicle> listVehicles = new ArrayList<>();
|
||||
|
|
@ -205,12 +230,10 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
// intent = RegisterVehicleActivity.editCurrentItem(getActivity(), vehicle.getVin());
|
||||
|
||||
} else {
|
||||
|
||||
intent = RegisterVehicleActivity.createNew(getActivity());
|
||||
}
|
||||
|
||||
//TODO intent.putExtra(VIN, vehicle.getVin());
|
||||
//TODO intent.putExtra(POSITION, position);
|
||||
|
||||
launcherEditVehicle.launch(intent);
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +337,8 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
// intent = RegisterVehicleActivity.editCurrentItem(getActivity(), vehicle.getVin());
|
||||
|
||||
} else {
|
||||
//intent = Register.createNew(getActivity());
|
||||
intent = ActivityBaseDetailContent.getDeviceRegistrationInstance(getActivity(),Activity.RESULT_OK);
|
||||
|
||||
}
|
||||
|
||||
//TODO intent.putExtra(VIN, vehicle.getVin());
|
||||
|
|
@ -331,7 +355,7 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
// intent = RegisterVehicleActivity.editCurrentItem(getActivity(), vehicle.getVin());
|
||||
|
||||
} else {
|
||||
intent = ActivityBaseDetailContent.getDeviceRegistrationInstance(getActivity());
|
||||
intent = ActivityBaseDetailContent.getDeviceRegistrationInstance(getActivity(),Activity.RESULT_OK);
|
||||
|
||||
// intent = CustomerDe.show(getActivity());
|
||||
}
|
||||
|
|
@ -339,7 +363,7 @@ public class ShowVehiclesAndDevicesFragment extends AbstractFragment {
|
|||
//TODO intent.putExtra(VIN, vehicle.getVin());
|
||||
//TODO intent.putExtra(POSITION, position);
|
||||
|
||||
launcherEditVehicle.launch(intent);
|
||||
launcherEditDevice.launch(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,19 +8,26 @@ import android.text.TextWatcher;
|
|||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.data.model.CustomerDevice;
|
||||
import eu.csc.vehown.databinding.DeviceRegistrationFragmentBinding;
|
||||
import eu.csc.vehown.databinding.FragmentDashboardBinding;
|
||||
import eu.csc.vehown.ui.base.AbstractFragment;
|
||||
import eu.csc.vehown.ui.md.ItemDetailFragment;
|
||||
import eu.csc.vehown.ui.modal.Helper;
|
||||
import eu.csc.vehown.ui.models.Result;
|
||||
import eu.csc.vehown.ui.pub.UIUtils;
|
||||
|
|
@ -28,16 +35,27 @@ import eu.csc.vehown.ui.register.RegisterCustomerActivity;
|
|||
import eu.csc.vehown.ui.register.RegistrationViewModel;
|
||||
import eu.csc.vehown.ui.registration.customer.ItemListDialogFragment;
|
||||
import eu.csc.vehown.ui.viewmodels.AppViewModelFactory;
|
||||
import lombok.var;
|
||||
|
||||
public class DeviceRegistrationFragment extends Fragment {
|
||||
public class DeviceRegistrationFragment extends AbstractFragment {
|
||||
|
||||
private DeviceRegistrationViewModel mViewModel;
|
||||
private DeviceRegistrationFragmentBinding binding;
|
||||
|
||||
private Integer result_code;
|
||||
|
||||
public static DeviceRegistrationFragment newInstance() {
|
||||
return new DeviceRegistrationFragment();
|
||||
}
|
||||
|
||||
public static DeviceRegistrationFragment newSingleInstance(int code) {
|
||||
var result = new DeviceRegistrationFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(CUSTOM_RESULT_CODE, code);
|
||||
result.setArguments(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
|
@ -46,14 +64,24 @@ public class DeviceRegistrationFragment extends Fragment {
|
|||
|
||||
|
||||
View root = binding.getRoot();
|
||||
Bundle args = getArguments();
|
||||
if (args != null && args.containsKey(CUSTOM_RESULT_CODE)) {
|
||||
result_code = args.getInt(CUSTOM_RESULT_CODE);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
mViewModel = new ViewModelProvider(this, new AppViewModelFactory(getContext()))
|
||||
.get(DeviceRegistrationViewModel.class);
|
||||
mViewModel = new ViewModelProvider(this).get(DeviceRegistrationViewModel.class);
|
||||
EditText edSerialnumber = binding.edSerialnumber;
|
||||
Button btnRegister = binding.btnRegisterDevice;
|
||||
Button btnFindSerialnumber = binding.btnFindSerialnumber;
|
||||
Button btnStore = binding.btnStore;
|
||||
ProgressBar progressBar = binding.loading;
|
||||
|
||||
var textInputLayout = binding.textField;
|
||||
|
||||
|
||||
edSerialnumber.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
|
@ -70,16 +98,60 @@ public class DeviceRegistrationFragment extends Fragment {
|
|||
mViewModel.getMSerialnumber().postValue(s.toString());
|
||||
}
|
||||
});
|
||||
mViewModel.getMSerialnumber().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(String s) {
|
||||
btnRegister.setEnabled(s != null && !s.equals(""));
|
||||
}
|
||||
});
|
||||
btnRegister.setOnClickListener(new View.OnClickListener() {
|
||||
mViewModel.getMSerialnumber().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(String s) {
|
||||
btnFindSerialnumber.setEnabled(s != null && !s.equals(""));
|
||||
}
|
||||
});
|
||||
|
||||
mViewModel.getMCustomerDevice().observe(getViewLifecycleOwner(), new Observer<CustomerDevice>() {
|
||||
@Override
|
||||
public void onChanged(CustomerDevice customerDevice) {
|
||||
btnStore.setEnabled(customerDevice != null);
|
||||
if(customerDevice == null){
|
||||
|
||||
}else{
|
||||
|
||||
textInputLayout.getEditText().setText(customerDevice.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btnStore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mViewModel.doRegisterDevice();
|
||||
mViewModel.storeDevice();
|
||||
|
||||
if (result_code != null)
|
||||
{
|
||||
getActivity().setResult(result_code);
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btnFindSerialnumber.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
CustomerDevice item = new CustomerDevice();
|
||||
item.setName(edSerialnumber.getText().toString());
|
||||
item.setSerialNumber(edSerialnumber.getText().toString());
|
||||
item.setDeviceNumber(edSerialnumber.getText().toString());
|
||||
mViewModel.getMCustomerDevice().postValue(item);
|
||||
|
||||
/*
|
||||
|
||||
mViewModel.storeDevice();
|
||||
//mViewModel.doRegisterDevice();
|
||||
if (result_code != null)
|
||||
{
|
||||
getActivity().setResult(result_code);
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -89,17 +161,17 @@ mViewModel.getMSerialnumber().observe(getViewLifecycleOwner(), new Observer<Stri
|
|||
mViewModel.getMIsEnabled().observe(getViewLifecycleOwner(), new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if(aBoolean != null && aBoolean == false){
|
||||
btnRegister.setEnabled(false);
|
||||
if (aBoolean != null && aBoolean == false) {
|
||||
btnFindSerialnumber.setEnabled(false);
|
||||
edSerialnumber.setEnabled(false);
|
||||
|
||||
if(mViewModel.getMSerialnumber().getValue() != null)
|
||||
if (mViewModel.getMSerialnumber().getValue() != null)
|
||||
progressBar.setVisibility(View.GONE);
|
||||
else
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
} else {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
btnRegister.setEnabled(true);
|
||||
btnFindSerialnumber.setEnabled(true);
|
||||
edSerialnumber.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -108,9 +180,10 @@ mViewModel.getMSerialnumber().observe(getViewLifecycleOwner(), new Observer<Stri
|
|||
mViewModel.getMRegistrationResult().observe(getViewLifecycleOwner(), new Observer<Result<CustomerDevice>>() {
|
||||
@Override
|
||||
public void onChanged(Result<CustomerDevice> result) {
|
||||
if(result instanceof Result.Success){
|
||||
if (result instanceof Result.Success) {
|
||||
mViewModel.getMIsEnabled().postValue(true);
|
||||
}else{
|
||||
|
||||
} else {
|
||||
Helper.showErrorDialog(getContext(), "ERROR", result.toString(), new Helper.IDialogOkHandler() {
|
||||
@Override
|
||||
public void onOk() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ public class DeviceRegistrationViewModel extends AbstractBaseViewModel {
|
|||
@Getter
|
||||
private final MutableLiveData<String> mSerialnumber;
|
||||
@Getter
|
||||
private final MutableLiveData<CustomerDevice> mCustomerDevice;
|
||||
@Getter
|
||||
private final MutableLiveData<Boolean> mIsEnabled;
|
||||
|
||||
@Getter
|
||||
|
|
@ -43,6 +45,7 @@ public class DeviceRegistrationViewModel extends AbstractBaseViewModel {
|
|||
mRegistrationResult = new MutableLiveData<>();
|
||||
|
||||
mSerialnumber.setValue(localStorage.getLastSerialnumber());
|
||||
mCustomerDevice = new MutableLiveData<>();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -85,5 +88,15 @@ public class DeviceRegistrationViewModel extends AbstractBaseViewModel {
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void storeDevice() {
|
||||
CustomerDevice item = new CustomerDevice();
|
||||
item.setDeviceNumber(getMSerialnumber().getValue());
|
||||
item.setSerialNumber(getMSerialnumber().getValue());
|
||||
item.setName(getMSerialnumber().getValue());
|
||||
|
||||
|
||||
localStorageClient.storeDevice(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +44,6 @@
|
|||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/layoutDevice"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
||||
app:backgroundTint="@android:color/holo_red_light"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -1,78 +1,88 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.registration.devices.DeviceRegistrationFragment"
|
||||
android:id="@+id/frameLayout2"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello"
|
||||
android:id="@+id/textView2"
|
||||
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
android:layout_marginTop="15dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
<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/frameLayout2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
tools:context=".ui.registration.devices.DeviceRegistrationFragment">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSerialnumber"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="6dp"
|
||||
android:text="Serialnumber"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@+id/textView2"
|
||||
app:layout_constraintTop_toTopOf="@id/textView2" />
|
||||
android:id="@+id/tvSerialnumber"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="6dp"
|
||||
android:text="Serialnumber"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edSerialnumber"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSerialnumber" />
|
||||
android:id="@+id/edSerialnumber"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvSerialnumber" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRegisterDevice"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/btnFindSerialnumber"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:enabled="false"
|
||||
|
||||
android:text="@string/btn_find"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@+id/edSerialnumber" />
|
||||
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textField"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Serialnumber"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnFindSerialnumber">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:enabled="false"
|
||||
android:text="@string/btn_registration"
|
||||
android:enabled="false" />
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/edSerialnumber"
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
app:layout_constraintHorizontal_bias="0.5"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnStore"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:enabled="false"
|
||||
android:text="@string/btn_store"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textField" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="64dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginBottom="64dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/btnRegisterDevice"
|
||||
app:layout_constraintStart_toStartOf="@+id/btnRegisterDevice"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.3"/>
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginTop="64dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginBottom="64dp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/btnFindSerialnumber"
|
||||
app:layout_constraintStart_toStartOf="@+id/btnFindSerialnumber"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.3" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -77,6 +77,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/btn_login"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
|
||||
android:enabled="false"/>
|
||||
|
||||
<Button
|
||||
|
|
@ -85,6 +87,8 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="@string/btn_logout"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
|
||||
android:enabled="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -30,5 +30,6 @@
|
|||
<color name="grey7">#cccccc</color>
|
||||
<color name="grey8">#e5e5e5</color>
|
||||
<color name="orange">#ff9900</color>
|
||||
<color name="red">#FF0000</color>
|
||||
|
||||
</resources>
|
||||
|
|
@ -186,6 +186,8 @@
|
|||
<string name="attachment_api_url">RestApi Url</string>
|
||||
<string name="btn_login">Login</string>
|
||||
<string name="btn_logout">Logout</string>
|
||||
<string name="btn_find">Find</string>
|
||||
<string name="btn_store">Store</string>
|
||||
|
||||
<!--string-array name="languages">
|
||||
<item>english</item>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package eu.csc.vehown;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class Helper {
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("@@");
|
||||
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(4);
|
||||
public static final long MIN_REQUIRED_SPACE = 250 * 1024L * 1024L;
|
||||
|
||||
public static long getAvailableStorageSpace() {
|
||||
StatFs stats = new StatFs(Environment.getDataDirectory().getAbsolutePath());
|
||||
return stats.getAvailableBlocksLong() * stats.getBlockSizeLong();
|
||||
}
|
||||
public static String humanReadableByteCount(long bytes) {
|
||||
return humanReadableByteCount(bytes, true);
|
||||
}
|
||||
|
||||
public static String humanReadableByteCount(long bytes, boolean si) {
|
||||
int sign = (int) Math.signum(bytes);
|
||||
bytes = Math.abs(bytes);
|
||||
|
||||
int unit = (si ? 1000 : 1024);
|
||||
if (bytes < unit)
|
||||
return sign * bytes + " B";
|
||||
|
||||
int exp = (int) (Math.log(bytes) / Math.log(unit));
|
||||
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
|
||||
return df.format(sign * bytes / Math.pow(unit, exp)) + " " + pre + "B";
|
||||
}
|
||||
|
||||
public static long getTotalStorageSpace() {
|
||||
StatFs stats = new StatFs(Environment.getDataDirectory().getAbsolutePath());
|
||||
return stats.getTotalBytes();
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ public abstract class VehicleOwnerDatabase extends RoomDatabase {
|
|||
public abstract LeaseEntityDao leaseDao();
|
||||
public abstract VehicleInfoDao vehicleInfoDao();
|
||||
public abstract VehicleSystemDao vehicleSystemDao();
|
||||
public abstract EntityLogDao log();
|
||||
|
||||
public abstract MobilePhoneDao mobilePhoneDao();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package eu.csc.vehown.persist.localstorage.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.csc.vehown.persist.localstorage.entity.EntityLog;
|
||||
import eu.csc.vehown.persist.localstorage.entity.events.EventEntity;
|
||||
|
||||
@Dao
|
||||
public interface EntityLogDao extends BaseDao<EntityLog> {
|
||||
@Query("SELECT * FROM log" +
|
||||
" WHERE time > :from" +
|
||||
" AND (:type IS NULL OR type = :type)" +
|
||||
" ORDER BY time DESC" +
|
||||
" LIMIT 2000")
|
||||
LiveData<List<EntityLog>> liveLogs(long from, Integer type);
|
||||
|
||||
@Query("SELECT * FROM log" +
|
||||
" WHERE time > :from" +
|
||||
" AND (:type IS NULL OR type = :type)" +
|
||||
" ORDER BY time DESC")
|
||||
List<EntityLog> getLogs(long from, Integer type);
|
||||
|
||||
@Insert
|
||||
long insertLog(EntityLog log);
|
||||
|
||||
@Query("DELETE FROM log" +
|
||||
" WHERE id IN (SELECT id FROM log" +
|
||||
" WHERE time < :before ORDER BY time LIMIT :limit)")
|
||||
int deleteLogs(long before, int limit);
|
||||
}
|
||||
|
||||
|
|
@ -15,8 +15,10 @@ import java.util.Date;
|
|||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import eu.csc.vehown.Helper;
|
||||
import eu.csc.vehown.persist.localstorage.PersistenceFactory;
|
||||
import eu.csc.vehown.persist.localstorage.VehicleOwnerDatabase;
|
||||
import lombok.ToString;
|
||||
|
||||
@Entity(
|
||||
tableName = EntityLog.TABLE_NAME,
|
||||
|
|
@ -26,6 +28,7 @@ import eu.csc.vehown.persist.localstorage.VehicleOwnerDatabase;
|
|||
@Index(value = {"time"})
|
||||
}
|
||||
)
|
||||
@ToString
|
||||
public class EntityLog {
|
||||
static final String TABLE_NAME = "log";
|
||||
|
||||
|
|
@ -36,7 +39,7 @@ public class EntityLog {
|
|||
private static final long LOG_CLEANUP_INTERVAL = 3600 * 1000L; // milliseconds
|
||||
private static final long LOG_KEEP_DURATION = 12 * 3600 * 1000L; // milliseconds
|
||||
private static final int LOG_DELETE_BATCH_SIZE = 50;
|
||||
|
||||
private static final ExecutorService executor = Helper.executorService;
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
public Long id;
|
||||
@NonNull
|
||||
|
|
@ -49,14 +52,15 @@ public class EntityLog {
|
|||
@NonNull
|
||||
public String data;
|
||||
|
||||
enum Type {General, Statistics, Scheduling, Network, Account, Protocol, Classification, Notification, Rules, Debug}
|
||||
public enum Type {General, Statistics, Scheduling, Network, Account, Protocol, Classification, Notification, Rules, Debug}
|
||||
|
||||
|
||||
static void log(final Context context, @NonNull Type type, String data) {
|
||||
|
||||
public static void log(final Context context, @NonNull Type type, String data) {
|
||||
log(context, type, null, null, null, data);
|
||||
}
|
||||
|
||||
static void log(final Context context, @NonNull Type type, Long account, Long folder, Long message, String data) {
|
||||
public static void log(final Context context, @NonNull Type type, Long account, Long folder, Long message, String data) {
|
||||
Log.i(EntityLog.class.getSimpleName(), data);
|
||||
|
||||
if (context == null)
|
||||
|
|
@ -79,7 +83,7 @@ public class EntityLog {
|
|||
|
||||
final VehicleOwnerDatabase db = PersistenceFactory.generateDatabase(context);
|
||||
final Context acontext = context.getApplicationContext();
|
||||
/*
|
||||
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -106,7 +110,7 @@ public class EntityLog {
|
|||
db.log().insertLog(entry);
|
||||
db.setTransactionSuccessful();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
Log.e(EntityLog.class.getSimpleName(),"insertLog", ex);
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
|
@ -119,10 +123,10 @@ public class EntityLog {
|
|||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
static void clear(final Context context) {
|
||||
public static void clear(final Context context) {
|
||||
final Context acontext = context.getApplicationContext();
|
||||
/*
|
||||
executor.submit(new Runnable() {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public class LocalStorageClientImpl implements LocalStorageClient {
|
|||
}
|
||||
|
||||
protected LocalStorageClientImpl(Context context) {
|
||||
|
||||
this.sharedPreferences = context.getSharedPreferences(
|
||||
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
|
||||
|
||||
|
|
@ -248,7 +249,7 @@ public class LocalStorageClientImpl implements LocalStorageClient {
|
|||
public void deleteDevice(String serialNumber) {
|
||||
var items = loadDevices();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (serialNumber.equals(items.get(i))) {
|
||||
if (serialNumber.equals(items.get(i).getSerialNumber())) {
|
||||
items.remove(i);
|
||||
getEditor().putString(PREF_DEVICES, gson.toJson(items)).apply();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue