update Client
changed api calls to Real Calls for right implementation
This commit is contained in:
parent
17fe3f5940
commit
17cf9c2ac4
|
|
@ -26,8 +26,10 @@ uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android
|
|||
android:theme="@style/Theme.VehicleOwner"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="n">
|
||||
<activity android:name=".ui.svi.DashboardActivity"
|
||||
android:theme="@style/Theme.VehicleOwner.NoActionBar">
|
||||
|
||||
<activity
|
||||
android:name=".ui.svi.DashboardActivity"
|
||||
android:theme="@style/Theme.VehicleOwner.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.main.MainActivity"
|
||||
|
|
@ -94,9 +96,9 @@ uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android
|
|||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import eu.csc.ODPAppVehOwnServer.models.auth.AuthenticationRequest;
|
|||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.data.model.Customer;
|
||||
import eu.csc.vehown.data.model.ICustomer;
|
||||
import eu.csc.vehown.services.rest.vehownserver.pub.CustomCall;
|
||||
import eu.csc.vehown.services.rest.vehownserver.pub.OfflineDummyCall;
|
||||
import lombok.var;
|
||||
import retrofit2.Call;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ public class VehOwnApiClientFactory {
|
|||
|
||||
|
||||
if (dummyMode) {
|
||||
return CustomCall.getInstance(new JWTTokenResponse("DUMMY"));
|
||||
return OfflineDummyCall.getInstance(new JWTTokenResponse("DUMMY"));
|
||||
}
|
||||
|
||||
AuthenticationRequest request = new AuthenticationRequest();
|
||||
|
|
@ -100,7 +100,7 @@ public class VehOwnApiClientFactory {
|
|||
public static Call<Long> registerCustomer(Customer customer) {
|
||||
|
||||
if (dummyMode)
|
||||
return CustomCall.getInstance(42L);
|
||||
return OfflineDummyCall.getInstance(42L);
|
||||
|
||||
UserRegistrationDto dto = new UserRegistrationDto();
|
||||
dto.setCity(customer.getCity());
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ import eu.csc.ODPAppVehOwnServer.models.data.PropulsionTypeDto;
|
|||
import eu.csc.ODPAppVehOwnServer.models.regist.CustomerVehicleDto;
|
||||
import eu.csc.vehown.data.model.Customer;
|
||||
import eu.csc.vehown.data.model.Vehicle;
|
||||
import eu.csc.vehown.services.rest.vehownserver.pub.CustomCall;
|
||||
import eu.csc.vehown.services.rest.vehownserver.pub.OfflineDummyCall;
|
||||
import lombok.var;
|
||||
import retrofit2.Call;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -97,43 +98,42 @@ public class VehOwnAppClientDummy implements IVehOwnAppClient {
|
|||
@Override
|
||||
public Call<Void> registerCustomer(Customer customer) {
|
||||
|
||||
return new CustomCall<>(null);
|
||||
return new OfflineDummyCall<>(null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCall<List<LanguageDto>> listLanguages() {
|
||||
public OfflineDummyCall<List<LanguageDto>> listLanguages() {
|
||||
|
||||
List<LanguageDto> result = new ArrayList<>();
|
||||
|
||||
result.add(new LanguageDto("en", "Englisch"));
|
||||
result.add(new LanguageDto("en", "English"));
|
||||
|
||||
|
||||
return new CustomCall<List<LanguageDto>>(result);
|
||||
return new OfflineDummyCall<List<LanguageDto>>(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCall<List<VehicleBrandDto>> listVehicleBrands() throws IOException {
|
||||
return CustomCall.getInstance(this.vehicleBrandDtos);
|
||||
public OfflineDummyCall<List<VehicleBrandDto>> listVehicleBrands() throws IOException {
|
||||
return OfflineDummyCall.getInstance(this.vehicleBrandDtos);
|
||||
}
|
||||
|
||||
public CustomCall<List<VehicleModelDto>> listVehicleModels() throws IOException {
|
||||
return CustomCall.getInstance(this.vehicleModelDtos);
|
||||
public OfflineDummyCall<List<VehicleModelDto>> listVehicleModels() throws IOException {
|
||||
return OfflineDummyCall.getInstance(this.vehicleModelDtos);
|
||||
}
|
||||
|
||||
public CustomCall<List<VehicleModelDto>> listVehicleModels(VehicleBrandDto brand) throws IOException {
|
||||
public OfflineDummyCall<List<VehicleModelDto>> listVehicleModels(VehicleBrandDto brand) throws IOException {
|
||||
|
||||
var op = this.vehicleBrandDtos.stream().filter(x -> x.getId().equals(brand.getId())).findFirst();
|
||||
|
||||
if (op.isPresent())
|
||||
return CustomCall.getInstance(op.get().getModels());
|
||||
return OfflineDummyCall.getInstance(op.get().getModels());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCall<List<PropulsionTypeDto>> listPropulsionTypes() throws IOException {
|
||||
return CustomCall.getInstance(this.propulsionTypeDtos);
|
||||
public OfflineDummyCall<List<PropulsionTypeDto>> listPropulsionTypes() throws IOException {
|
||||
return OfflineDummyCall.getInstance(this.propulsionTypeDtos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -145,17 +145,17 @@ public class VehOwnAppClientDummy implements IVehOwnAppClient {
|
|||
dto.setLicensePlate(body.getLicensePlate());
|
||||
dto.setVin(body.getVin());
|
||||
|
||||
return CustomCall.getInstance(dto);
|
||||
return OfflineDummyCall.getInstance(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Call<Void> deregisterCustomerVehicle(String vin) throws IOException {
|
||||
return null;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Call<List<CustomerVehicleDto>> getCustomerVehicles() throws IOException {
|
||||
return null;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,16 +7,16 @@ import retrofit2.Callback;
|
|||
import retrofit2.Response;
|
||||
|
||||
|
||||
public final class CustomCall<T> implements Call<T> {
|
||||
public final class OfflineDummyCall<T> implements Call<T> {
|
||||
|
||||
private final T content;
|
||||
|
||||
public CustomCall(T content) {
|
||||
public OfflineDummyCall(T content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public static <T> CustomCall<T> getInstance(T content){
|
||||
return new CustomCall<>(content);
|
||||
public static <T> OfflineDummyCall<T> getInstance(T content){
|
||||
return new OfflineDummyCall<>(content);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package eu.csc.vehown.ui.fragments.data;
|
||||
|
||||
import eu.csc.vehown.ui.fragments.data.model.LoggedInUser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Class that handles authentication w/ login credentials and retrieves user information.
|
||||
*/
|
||||
public class LoginDataSource {
|
||||
|
||||
public Result<LoggedInUser> login(String username, String password) {
|
||||
|
||||
try {
|
||||
// TODO: handle loggedInUser authentication
|
||||
LoggedInUser fakeUser =
|
||||
new LoggedInUser(
|
||||
java.util.UUID.randomUUID().toString(),
|
||||
"Jane Doe");
|
||||
return new Result.Success<>(fakeUser);
|
||||
} catch (Exception e) {
|
||||
return new Result.Error(new IOException("Error logging in", e));
|
||||
}
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
// TODO: revoke authentication
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package eu.csc.vehown.ui.fragments.data;
|
||||
|
||||
import eu.csc.vehown.ui.fragments.data.model.LoggedInUser;
|
||||
|
||||
/**
|
||||
* Class that requests authentication and user information from the remote data source and
|
||||
* maintains an in-memory cache of login status and user credentials information.
|
||||
*/
|
||||
public class LoginRepository {
|
||||
|
||||
private static volatile LoginRepository instance;
|
||||
|
||||
private LoginDataSource dataSource;
|
||||
|
||||
// If user credentials will be cached in local storage, it is recommended it be encrypted
|
||||
// @see https://developer.android.com/training/articles/keystore
|
||||
private LoggedInUser user = null;
|
||||
|
||||
// private constructor : singleton access
|
||||
private LoginRepository(LoginDataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public static LoginRepository getInstance(LoginDataSource dataSource) {
|
||||
if (instance == null) {
|
||||
instance = new LoginRepository(dataSource);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
return user != null;
|
||||
}
|
||||
|
||||
public void logout() {
|
||||
user = null;
|
||||
dataSource.logout();
|
||||
}
|
||||
|
||||
private void setLoggedInUser(LoggedInUser user) {
|
||||
this.user = user;
|
||||
// If user credentials will be cached in local storage, it is recommended it be encrypted
|
||||
// @see https://developer.android.com/training/articles/keystore
|
||||
}
|
||||
|
||||
public Result<LoggedInUser> login(String username, String password) {
|
||||
// handle login
|
||||
Result<LoggedInUser> result = dataSource.login(username, password);
|
||||
if (result instanceof Result.Success) {
|
||||
setLoggedInUser(((Result.Success<LoggedInUser>) result).getData());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package eu.csc.vehown.ui.fragments.data;
|
||||
|
||||
/**
|
||||
* A generic class that holds a result success w/ data or an error exception.
|
||||
*/
|
||||
public class Result<T> {
|
||||
// hide the private constructor to limit subclass types (Success, Error)
|
||||
private Result() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this instanceof Result.Success) {
|
||||
Result.Success success = (Result.Success) this;
|
||||
return "Success[data=" + success.getData().toString() + "]";
|
||||
} else if (this instanceof Result.Error) {
|
||||
Result.Error error = (Result.Error) this;
|
||||
return "Error[exception=" + error.getError().toString() + "]";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Success sub-class
|
||||
public final static class Success<T> extends Result {
|
||||
private T data;
|
||||
|
||||
public Success(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
// Error sub-class
|
||||
public final static class Error extends Result {
|
||||
private Exception error;
|
||||
|
||||
public Error(Exception error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public Exception getError() {
|
||||
return this.error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package eu.csc.vehown.ui.fragments.data.model;
|
||||
|
||||
/**
|
||||
* Data class that captures user information for logged in users retrieved from LoginRepository
|
||||
*/
|
||||
public class LoggedInUser {
|
||||
|
||||
private String userId;
|
||||
private String displayName;
|
||||
|
||||
public LoggedInUser(String userId, String displayName) {
|
||||
this.userId = userId;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package eu.csc.vehown.ui.fragments.ui.login;
|
||||
|
||||
/**
|
||||
* Class exposing authenticated user details to the UI.
|
||||
*/
|
||||
class LoggedInUserView {
|
||||
private String displayName;
|
||||
//... other data fields that may be accessible to the UI
|
||||
|
||||
LoggedInUserView(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package eu.csc.vehown.ui.fragments.ui.login;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Data validation state of the login form.
|
||||
*/
|
||||
class LoginFormState {
|
||||
@Nullable
|
||||
private Integer usernameError;
|
||||
@Nullable
|
||||
private Integer passwordError;
|
||||
private boolean isDataValid;
|
||||
|
||||
LoginFormState(@Nullable Integer usernameError, @Nullable Integer passwordError) {
|
||||
this.usernameError = usernameError;
|
||||
this.passwordError = passwordError;
|
||||
this.isDataValid = false;
|
||||
}
|
||||
|
||||
LoginFormState(boolean isDataValid) {
|
||||
this.usernameError = null;
|
||||
this.passwordError = null;
|
||||
this.isDataValid = isDataValid;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Integer getUsernameError() {
|
||||
return usernameError;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Integer getPasswordError() {
|
||||
return passwordError;
|
||||
}
|
||||
|
||||
boolean isDataValid() {
|
||||
return isDataValid;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package eu.csc.vehown.ui.fragments.ui.login;
|
||||
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.databinding.FragmentLoginBinding;
|
||||
|
||||
public class LoginFragment extends Fragment {
|
||||
|
||||
private LoginViewModel loginViewModel;
|
||||
private FragmentLoginBinding binding;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
binding = FragmentLoginBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
loginViewModel = new ViewModelProvider(this, new LoginViewModelFactory())
|
||||
.get(LoginViewModel.class);
|
||||
|
||||
final EditText usernameEditText = binding.username;
|
||||
final EditText passwordEditText = binding.password;
|
||||
final Button loginButton = binding.login;
|
||||
final ProgressBar loadingProgressBar = binding.loading;
|
||||
|
||||
loginViewModel.getLoginFormState().observe(getViewLifecycleOwner(), new Observer<LoginFormState>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable LoginFormState loginFormState) {
|
||||
if (loginFormState == null) {
|
||||
return;
|
||||
}
|
||||
loginButton.setEnabled(loginFormState.isDataValid());
|
||||
if (loginFormState.getUsernameError() != null) {
|
||||
usernameEditText.setError(getString(loginFormState.getUsernameError()));
|
||||
}
|
||||
if (loginFormState.getPasswordError() != null) {
|
||||
passwordEditText.setError(getString(loginFormState.getPasswordError()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
loginViewModel.getLoginResult().observe(getViewLifecycleOwner(), new Observer<LoginResult>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable LoginResult loginResult) {
|
||||
if (loginResult == null) {
|
||||
return;
|
||||
}
|
||||
loadingProgressBar.setVisibility(View.GONE);
|
||||
if (loginResult.getError() != null) {
|
||||
showLoginFailed(loginResult.getError());
|
||||
}
|
||||
if (loginResult.getSuccess() != null) {
|
||||
updateUiWithUser(loginResult.getSuccess());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TextWatcher afterTextChangedListener = new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
loginViewModel.loginDataChanged(usernameEditText.getText().toString(),
|
||||
passwordEditText.getText().toString());
|
||||
}
|
||||
};
|
||||
usernameEditText.addTextChangedListener(afterTextChangedListener);
|
||||
passwordEditText.addTextChangedListener(afterTextChangedListener);
|
||||
passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
loginViewModel.login(usernameEditText.getText().toString(),
|
||||
passwordEditText.getText().toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
loginButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
loadingProgressBar.setVisibility(View.VISIBLE);
|
||||
loginViewModel.login(usernameEditText.getText().toString(),
|
||||
passwordEditText.getText().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateUiWithUser(LoggedInUserView model) {
|
||||
String welcome = getString(R.string.welcome) + model.getDisplayName();
|
||||
// TODO : initiate successful logged in experience
|
||||
if (getContext() != null && getContext().getApplicationContext() != null) {
|
||||
Toast.makeText(getContext().getApplicationContext(), welcome, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void showLoginFailed(@StringRes Integer errorString) {
|
||||
if (getContext() != null && getContext().getApplicationContext() != null) {
|
||||
Toast.makeText(
|
||||
getContext().getApplicationContext(),
|
||||
errorString,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package eu.csc.vehown.ui.fragments.ui.login;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Authentication result : success (user details) or error message.
|
||||
*/
|
||||
class LoginResult {
|
||||
@Nullable
|
||||
private LoggedInUserView success;
|
||||
@Nullable
|
||||
private Integer error;
|
||||
|
||||
LoginResult(@Nullable Integer error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
LoginResult(@Nullable LoggedInUserView success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
LoggedInUserView getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Integer getError() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package eu.csc.vehown.ui.fragments.ui.login;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import android.util.Patterns;
|
||||
|
||||
import eu.csc.vehown.R;
|
||||
import eu.csc.vehown.ui.fragments.data.LoginRepository;
|
||||
import eu.csc.vehown.ui.fragments.data.Result;
|
||||
import eu.csc.vehown.ui.fragments.data.model.LoggedInUser;
|
||||
|
||||
public class LoginViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<LoginFormState> loginFormState = new MutableLiveData<>();
|
||||
private MutableLiveData<LoginResult> loginResult = new MutableLiveData<>();
|
||||
private LoginRepository loginRepository;
|
||||
|
||||
LoginViewModel(LoginRepository loginRepository) {
|
||||
this.loginRepository = loginRepository;
|
||||
}
|
||||
|
||||
LiveData<LoginFormState> getLoginFormState() {
|
||||
return loginFormState;
|
||||
}
|
||||
|
||||
LiveData<LoginResult> getLoginResult() {
|
||||
return loginResult;
|
||||
}
|
||||
|
||||
public void login(String username, String password) {
|
||||
// can be launched in a separate asynchronous job
|
||||
Result<LoggedInUser> result = loginRepository.login(username, password);
|
||||
|
||||
if (result instanceof Result.Success) {
|
||||
LoggedInUser data = ((Result.Success<LoggedInUser>) result).getData();
|
||||
loginResult.setValue(new LoginResult(new LoggedInUserView(data.getDisplayName())));
|
||||
} else {
|
||||
loginResult.setValue(new LoginResult(R.string.login_failed));
|
||||
}
|
||||
}
|
||||
|
||||
public void loginDataChanged(String username, String password) {
|
||||
if (!isUserNameValid(username)) {
|
||||
loginFormState.setValue(new LoginFormState(R.string.invalid_username, null));
|
||||
} else if (!isPasswordValid(password)) {
|
||||
loginFormState.setValue(new LoginFormState(null, R.string.invalid_password));
|
||||
} else {
|
||||
loginFormState.setValue(new LoginFormState(true));
|
||||
}
|
||||
}
|
||||
|
||||
// A placeholder username validation check
|
||||
private boolean isUserNameValid(String username) {
|
||||
if (username == null) {
|
||||
return false;
|
||||
}
|
||||
if (username.contains("@")) {
|
||||
return Patterns.EMAIL_ADDRESS.matcher(username).matches();
|
||||
} else {
|
||||
return !username.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
// A placeholder password validation check
|
||||
private boolean isPasswordValid(String password) {
|
||||
return password != null && password.trim().length() > 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package eu.csc.vehown.ui.fragments.ui.login;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.csc.vehown.ui.fragments.data.LoginDataSource;
|
||||
import eu.csc.vehown.ui.fragments.data.LoginRepository;
|
||||
|
||||
/**
|
||||
* ViewModel provider factory to instantiate LoginViewModel.
|
||||
* Required given LoginViewModel has a non-empty constructor
|
||||
*/
|
||||
public class LoginViewModelFactory implements ViewModelProvider.Factory {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
if (modelClass.isAssignableFrom(LoginViewModel.class)) {
|
||||
return (T) new LoginViewModel(LoginRepository.getInstance(new LoginDataSource()));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown ViewModel class");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,6 @@ public class RegisterCustomerActivity
|
|||
|
||||
sharedPref = SharedPreferencesFactory.getInstance(getApplicationContext());
|
||||
|
||||
|
||||
binding = ActivityRegisterCustomerBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ public class RegistrationViewModel extends ViewModel {
|
|||
|
||||
try {
|
||||
|
||||
VehOwnApiClientFactory.getDataClient().listLanguages().execute().body()
|
||||
VehOwnApiClientFactory.getDataClient().listLanguages()
|
||||
.execute()
|
||||
.body()
|
||||
|
||||
.forEach(languageDto -> {
|
||||
Language lang = new Language();
|
||||
|
|
@ -65,7 +67,11 @@ public class RegistrationViewModel extends ViewModel {
|
|||
if (vehicleBrands.getValue() == null) {
|
||||
List<VehicleBrand> brands = new ArrayList<>();
|
||||
try {
|
||||
VehOwnApiClientFactory.getDataClient().listVehicleBrands().execute().body().forEach(vehicleBrandDto -> {
|
||||
VehOwnApiClientFactory.getDataClient()
|
||||
.listVehicleBrands()
|
||||
.execute()
|
||||
.body()
|
||||
.forEach(vehicleBrandDto -> {
|
||||
VehicleBrand vehicleBrand = new VehicleBrand(vehicleBrandDto.getBrandId(), vehicleBrandDto.getName());
|
||||
List<VehicleModel> vehicleModels = new ArrayList<>();
|
||||
vehicleBrandDto.getModels().forEach(vehicleModelDto -> vehicleModels.add(new VehicleModel(vehicleModelDto.getModelId(), vehicleModelDto.getName())));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
<?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:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/fragment_vertical_margin"
|
||||
android:paddingLeft="@dimen/fragment_horizontal_margin"
|
||||
android:paddingRight="@dimen/fragment_horizontal_margin"
|
||||
android:paddingTop="@dimen/fragment_vertical_margin"
|
||||
tools:context=".ui.fragments.ui.login.LoginFragment">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="96dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:autofillHints="@string/prompt_email"
|
||||
android:hint="@string/prompt_email"
|
||||
android:inputType="textEmailAddress"
|
||||
android:selectAllOnFocus="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:autofillHints="@string/prompt_password"
|
||||
android:hint="@string/prompt_password"
|
||||
android:imeActionLabel="@string/action_sign_in_short"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="textPassword"
|
||||
android:selectAllOnFocus="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/username"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:enabled="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginStart="48dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:layout_marginBottom="64dp"
|
||||
android:text="@string/action_sign_in"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/password"
|
||||
app:layout_constraintVertical_bias="0.2"/>
|
||||
|
||||
<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/password"
|
||||
app:layout_constraintStart_toStartOf="@+id/password"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.3"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<dimen name="fab_margin">48dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<dimen name="fab_margin">200dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<dimen name="fab_margin">48dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -30,4 +30,7 @@
|
|||
<dimen name="inner_frame_layout_padding">5dp</dimen>
|
||||
<dimen name="item_width">200dp</dimen>
|
||||
<dimen name="text_margin">16dp</dimen>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="fragment_horizontal_margin">16dp</dimen>
|
||||
<dimen name="fragment_vertical_margin">16dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -126,6 +126,13 @@
|
|||
<string name="propulsion_type">Propulsion Type</string>
|
||||
<string name="registration_date">Registration Date</string>
|
||||
<string name="use_dark_mode">Use dark mode</string>
|
||||
<!-- Strings related to login -->
|
||||
<string name="prompt_email">Email</string>
|
||||
<string name="prompt_password">Password</string>
|
||||
<string name="title_activity_register_device">RegisterDeviceActivity</string>
|
||||
|
||||
<string name="hello_first_fragment">Hello first fragment</string>
|
||||
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
|
||||
|
||||
<!--string-array name="languages">
|
||||
<item>english</item>
|
||||
|
|
|
|||
|
|
@ -32,4 +32,11 @@ public interface LocalStorageClient extends IVehOwnData {
|
|||
List<SupportedLanguage> getSupportedLanguages();
|
||||
void setSupportedLanguages(List<SupportedLanguage> items);
|
||||
|
||||
|
||||
//region ServerData
|
||||
|
||||
|
||||
|
||||
//endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue