validator and transaltions
This commit is contained in:
parent
6c66b6d975
commit
056c21d352
@ -49,6 +49,7 @@ import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedCoordinatesService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleUtils;
|
||||
@ -370,6 +371,8 @@ Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
|
||||
if (TextUtils.isEmpty(body)) {
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.modal_location_hint), Toast.LENGTH_SHORT).show();
|
||||
modalUserInput.requestFocus();
|
||||
}else if (body.length() > Const.maxPredefinedCordNameLength){
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.manual_location_tolong_error)+": "+Const.maxPredefinedCordNameLength, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
sendLocation(body, latLng);
|
||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(), body);
|
||||
|
@ -27,6 +27,7 @@ import com.uam.wmi.findmytutor.model.StatusesListModel;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedCoordinatesService;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
@ -275,11 +276,14 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
});
|
||||
/** Custom status edittext change listener **/
|
||||
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), (String) newValue)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
if (newValue.toString().length() > Const.maxStatusLength) {
|
||||
Toast.makeText(getApplicationContext(), getString(R.string.status_max_length) + " :"+Const.maxStatusLength, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), (String) newValue)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
@ -297,25 +301,19 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
|
||||
public void showRemoveDialog(CharSequence[] entries, String service) {
|
||||
boolean[] checked = new boolean[entries.length];
|
||||
ArrayList<String> tobeDeleted = new ArrayList<String>();
|
||||
ArrayList<String> tobeDeleted = new ArrayList<>();
|
||||
// Log.d("sharingDialog", "no to siup");
|
||||
builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (checked[i] == true) {
|
||||
tobeDeleted.add((String) entries[i]);
|
||||
}
|
||||
builder.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (checked[i]) {
|
||||
tobeDeleted.add((String) entries[i]);
|
||||
}
|
||||
removeEntries(service, tobeDeleted);
|
||||
}
|
||||
removeEntries(service, tobeDeleted);
|
||||
// Log.d("MANAGE-PREF",tobeDeleted.toString());
|
||||
}
|
||||
});
|
||||
builder.setMultiChoiceItems(entries, checked, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
builder.setMultiChoiceItems(entries, checked, (dialog, which, isChecked) -> {
|
||||
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
@ -331,12 +329,14 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
|
||||
protected void removeEntries(String service, ArrayList<String> toBeDeleted) {
|
||||
|
||||
if (service.equals("status")) {
|
||||
disposable.add(
|
||||
statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), new StatusesListModel(toBeDeleted))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleDeleteStatuses, this::handleError)
|
||||
);
|
||||
if (toBeDeleted.size() > 0){
|
||||
disposable.add(
|
||||
statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), new StatusesListModel(toBeDeleted))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleDeleteStatuses, this::handleError)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ArrayList<String> uuidsToBeDeleted = new ArrayList<String>();
|
||||
for (String name : toBeDeleted) {
|
||||
|
@ -28,11 +28,15 @@ import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.TutorTabApi;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -197,20 +201,20 @@ public class TutorTab extends AppCompatActivity {
|
||||
|
||||
private void setUpSaveListener(Button button) {
|
||||
button.setOnClickListener(view -> {
|
||||
if( isEmailValid(userEmail.getText().toString())){
|
||||
if (isFormValid()){
|
||||
newTab = new TutorTabViewModel(PrefUtils.getUserId(getApplicationContext()),
|
||||
userRoom.getText().toString(),
|
||||
userEmail.getText().toString(),
|
||||
userNote.getText().toString(),
|
||||
dutyHoursAdapter.getDutyList());
|
||||
Log.e("kurwo",newTab.toString());
|
||||
|
||||
if(ifTutorTabExists){
|
||||
putUserTab(newTab);
|
||||
}else{
|
||||
}else {
|
||||
postUserTab(newTab);
|
||||
ifTutorTabExists=true;
|
||||
ifTutorTabExists = true;
|
||||
}
|
||||
}else{
|
||||
userEmail.setError(getString(R.string.error_invalid_email));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -283,6 +287,48 @@ public class TutorTab extends AppCompatActivity {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
public boolean isFormValid(){
|
||||
boolean emailOK = isEmailValid(userEmail.getText().toString());
|
||||
if (!emailOK) {
|
||||
userEmail.setError(getString(R.string.error_invalid_email));
|
||||
}
|
||||
boolean userRoomOK = userRoom.getText().toString().length() < Const.maxRoomLength;
|
||||
if (!userRoomOK){
|
||||
userRoom.setError(getString(R.string.max_room_lenth_error)+": "+Const.maxRoomLength);
|
||||
}
|
||||
boolean userNoteOK = userNote.getText().toString().length() < Const.maxNoteLength;
|
||||
if (!userNoteOK){
|
||||
userNote.setError(getString(R.string.max_note_length_error)+ ": "+Const.maxNoteLength);
|
||||
}
|
||||
|
||||
boolean dutyHoursAdapterOK = true;
|
||||
for (DutyHourViewModel oo:
|
||||
dutyHoursAdapter.getDutyList()) {
|
||||
// TIME
|
||||
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
|
||||
Date start, end = null;
|
||||
try {
|
||||
start = format.parse(oo.getStart());
|
||||
end = format.parse(oo.getEnd());
|
||||
if (start.compareTo(end) > 0) {
|
||||
Toast.makeText(getApplicationContext(), R.string.end_b4_start_error, Toast.LENGTH_LONG).show();
|
||||
dutyHoursAdapterOK = false;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// DAY
|
||||
boolean dayOK = oo.getDay().length() < Const.maxDayLength;
|
||||
if (!dayOK){
|
||||
Toast.makeText(getApplicationContext(), getString(R.string.max_day_length_error) + ": " + Const.maxDayLength, Toast.LENGTH_LONG).show();
|
||||
dutyHoursAdapterOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
return emailOK && userRoomOK && userNoteOK && dutyHoursAdapterOK;
|
||||
}
|
||||
|
||||
public boolean isEmailValid(String email)
|
||||
{
|
||||
String regExpn =
|
||||
|
@ -21,6 +21,13 @@ public class Const {
|
||||
public final static Range<Double> outsideLongitudeRange = Range.create(16.9186, 16.936004);
|
||||
public final static List<String> validApproximatedLocations = Arrays.asList("Skrzydło B", "Skrzydło A", "Aule", "Łącznik", "Biblioteka", "Hol", "Unknown");
|
||||
public final static String WMI_SSID_NAME = "wmi";
|
||||
|
||||
public final static int maxPredefinedCordNameLength = 20;
|
||||
public final static int maxStatusLength = 50;
|
||||
public final static int maxDayLength = 20;
|
||||
public final static int maxNoteLength = 100;
|
||||
public final static int maxRoomLength = 10;
|
||||
public final static int maxDepartmentLength = 100;
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,7 +168,7 @@
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginTop="15dp"
|
||||
app:counterEnabled="true"
|
||||
app:counterMaxLength="1000">
|
||||
app:counterMaxLength="100">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/userNote"
|
||||
@ -178,7 +178,7 @@
|
||||
android:hint="@string/tutorTabHint"
|
||||
android:inputType="textMultiLine"
|
||||
android:lineSpacingExtra="8sp"
|
||||
android:maxLength="1000"
|
||||
android:maxLength="100"
|
||||
android:maxLines="7"
|
||||
android:paddingTop="15dp"
|
||||
android:requiresFadingEdge="vertical"
|
||||
|
@ -296,5 +296,12 @@
|
||||
<!--(ENG) ask for gps -->
|
||||
<string name="enable_sharing">Włącz lokalizację</string>
|
||||
<string name="use_gps">Aby użyć tej funkcji musisz włączyć lokalizowanie urządzenia.</string>
|
||||
<string name="delete">USUŃ</string>
|
||||
<string name="status_max_length">Maksymalna długość statusu</string>
|
||||
<string name="max_note_length_error">Maksymalna długość notatki</string>
|
||||
<string name="max_day_length_error">Maksymalna długość pola dzień</string>
|
||||
<string name="max_room_lenth_error">Maksymalna długość pola pokój</string>
|
||||
<string name="manual_location_tolong_error">Maksymalna długość nazwy lokalizacji</string>
|
||||
<string name="end_b4_start_error">Data końcowa wcześniej niż początkowa</string>
|
||||
</resources>
|
||||
|
||||
|
@ -464,4 +464,11 @@
|
||||
<!--(ENG) ask for gps -->
|
||||
<string name="enable_sharing">Enable localization</string>
|
||||
<string name="use_gps">In order to use this function you have to enable localization.</string>
|
||||
<string name="delete">DELETE</string>
|
||||
<string name="status_max_length">Status max length</string>
|
||||
<string name="end_b4_start_error">End hour before start</string>
|
||||
<string name="max_day_length_error">Max day length</string>
|
||||
<string name="max_note_length_error">Max note length</string>
|
||||
<string name="max_room_lenth_error">Max room length</string>
|
||||
<string name="manual_location_tolong_error">Max manual location name</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user