parent
3590e6cdcf
commit
d71681981d
|
|
@ -1,5 +1,6 @@
|
|||
package eu.csc.vehown.ui.register;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -28,8 +29,11 @@ import eu.csc.vehown.ui.modal.Helper;
|
|||
import eu.csc.vehown.ui.pub.UIUtils;
|
||||
import eu.csc.vehown.ui.viewmodels.AppViewModelFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterVehicleActivity extends AppCompatActivity implements IVehOwnConsts {
|
||||
|
|
@ -75,7 +79,7 @@ public class RegisterVehicleActivity extends AppCompatActivity implements IVehOw
|
|||
setContentView(binding.getRoot());
|
||||
|
||||
mandatoryFields = new ArrayList<>(Arrays.asList(binding.spBrand, binding.spModel, binding.editPowertrain, binding.editVariant,
|
||||
binding.editVIN, binding.editLicensePlate, binding.spPropulsion, binding.datePickerRegistration));
|
||||
binding.editVIN, binding.editLicensePlate, binding.spPropulsion));
|
||||
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
timer = () -> Helper.hideSoftKeyboard(this);
|
||||
|
|
@ -136,12 +140,7 @@ public class RegisterVehicleActivity extends AppCompatActivity implements IVehOw
|
|||
});
|
||||
Helper.addListener(mandatoryFields, focusListener, changedListener);
|
||||
//binding.datePickerRegistration.setMaxDate();
|
||||
binding.datePickerRegistration.setOnDateChangedListener(new DatePicker.OnDateChangedListener() {
|
||||
@Override
|
||||
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
//XX
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (id != null) {
|
||||
|
||||
|
|
@ -234,10 +233,35 @@ public class RegisterVehicleActivity extends AppCompatActivity implements IVehOw
|
|||
}
|
||||
|
||||
*/
|
||||
binding.btnChooseDate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDatePicker();
|
||||
}
|
||||
});
|
||||
model.fetchData();
|
||||
|
||||
}
|
||||
|
||||
private void showDatePicker() {
|
||||
DatePickerDialog dialog = new DatePickerDialog(this);
|
||||
// DatePickerDialog dialog = new DatePickerDialog(getBaseContext());
|
||||
dialog.setOnDateSetListener(new DatePickerDialog.OnDateSetListener() {
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
|
||||
Log.d("DATE", year + " "+month + " "+dayOfMonth + " ");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
Date today = new Date(year-1900, month, dayOfMonth);//getting date
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");//formating according to my need
|
||||
String date = formatter.format(today);
|
||||
binding.tvDatePickerRegistration.setText(date);
|
||||
binding.tvDatePickerRegistration.setTag(today);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private Vehicle getVehicle() {
|
||||
Vehicle vehicle = new Vehicle();
|
||||
vehicle.setBrand(((VehicleBrand) binding.spBrand.getSelectedItem()).getName());
|
||||
|
|
@ -247,7 +271,7 @@ public class RegisterVehicleActivity extends AppCompatActivity implements IVehOw
|
|||
vehicle.setVin(binding.editVIN.getText().toString());
|
||||
vehicle.setLicensePlate(binding.editLicensePlate.getText().toString());
|
||||
vehicle.setPropulsionType(((VehiclePropulsionType) binding.spPropulsion.getSelectedItem()).getName());
|
||||
vehicle.setRegistrationDate(UIUtils.getDateFromDatePicker(binding.datePickerRegistration));
|
||||
vehicle.setRegistrationDate((Date) binding.tvDatePickerRegistration.getTag());
|
||||
|
||||
return vehicle;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ import eu.csc.vehown.ui.viewmodels.AbstractBaseViewModel;
|
|||
import lombok.Getter;
|
||||
|
||||
public class ShowVehicleAndDevicesViewModel extends AbstractBaseViewModel {
|
||||
@Getter
|
||||
|
||||
@Getter
|
||||
private final MutableLiveData<List<Vehicle>> mVehicles;
|
||||
|
||||
@Getter
|
||||
|
|
|
|||
|
|
@ -154,20 +154,27 @@
|
|||
android:text="@string/registration_date"
|
||||
/>
|
||||
|
||||
<DatePicker
|
||||
android:id="@+id/datePickerRegistration"
|
||||
android:layout_width="wrap_content"
|
||||
<EditText
|
||||
android:inputType="date"
|
||||
android:enabled="false"
|
||||
android:id="@+id/tvDatePickerRegistration"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/tvRegistrationDate"
|
||||
android:calendarViewShown="false"
|
||||
android:datePickerMode="spinner"/>
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnChooseDate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:layout_below="@+id/tvDatePickerRegistration" />
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/barrier"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_below="@id/datePickerRegistration"/>
|
||||
android:layout_below="@id/btnChooseDate"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llLocalButtons"
|
||||
|
|
|
|||
Loading…
Reference in New Issue