Refactor whitelist

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-17 22:02:05 +01:00
parent c6c492cd77
commit 5982e650e9
9 changed files with 86 additions and 50 deletions

View File

@ -3,6 +3,9 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules"> <option name="modules">

View File

@ -10,7 +10,7 @@ android {
applicationId "com.uam.wmi.findmytutor" applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 27 targetSdkVersion 27
versionCode 71 versionCode 72
versionName "1.0.0" versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true

View File

@ -326,6 +326,16 @@ public abstract class BaseActivity
MenuItem myActionMenuItem = menu.findItem(R.id.action_search); MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
searchView = (SearchView) myActionMenuItem.getActionView(); searchView = (SearchView) myActionMenuItem.getActionView();
RxSearchObservable.fromView(searchView)
.skip(0)
.map(String::toLowerCase)
.filter(t -> !t.isEmpty())
.debounce(250, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.switchMap((Function<String, ObservableSource<String>>) Observable::just)
.subscribe(this::executeSearch);
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> { searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) { if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
restoreMapMarkers(); restoreMapMarkers();
@ -341,15 +351,7 @@ public abstract class BaseActivity
} }
}); });
RxSearchObservable.fromView(searchView)
.skip(0)
.map(String::toLowerCase)
.filter(t -> !t.isEmpty())
.debounce(250, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.switchMap((Function<String, ObservableSource<String>>) Observable::just)
.subscribe(this::executeSearch);
return true; return true;
} }

View File

@ -151,7 +151,6 @@ public class MapActivity extends BaseActivity
if(isTutor){ if(isTutor){
MapUtils.BatteryOptimizationsExceptionCheck(this); MapUtils.BatteryOptimizationsExceptionCheck(this);
} }
} }
@Override @Override
@ -222,7 +221,6 @@ public class MapActivity extends BaseActivity
} }
String sharingLevelToRender = sharingLevel; String sharingLevelToRender = sharingLevel;
Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
if (PrefUtils.getLocale(getApplicationContext()).equals("pl") || if (PrefUtils.getLocale(getApplicationContext()).equals("pl") ||
PrefUtils.getLocale(getApplicationContext()).equals("pl-PL") || PrefUtils.getLocale(getApplicationContext()).equals("pl-PL") ||
@ -341,19 +339,21 @@ Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
public void showLocationDialog(LatLng latLng) { public void showLocationDialog(LatLng latLng) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null); @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null);
EditText modalUserInput = view.findViewById(R.id.manual_input);
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this); AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null); alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
alertDialogBuilderUserInput alertDialogBuilderUserInput
.setPositiveButton(R.string.lbl_ok, null) .setPositiveButton(R.string.lbl_yes, null)
.setNegativeButton(R.string.lbl_cancel, null); .setNegativeButton(R.string.lbl_no, null)
.setTitle(R.string.manual_modal_title);
final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
EditText modalUserInput = view.findViewById(R.id.manual_input);
alertDialog.setOnShowListener(dialogInterface -> { alertDialog.setOnShowListener(dialogInterface -> {
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
@ -384,7 +384,6 @@ Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
alertDialog.show(); alertDialog.show();
} }
private void sendLocation(String body, LatLng latLng) { private void sendLocation(String body, LatLng latLng) {
PredefinedCoordinatesService predefinedCoordinatesService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class); PredefinedCoordinatesService predefinedCoordinatesService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class);

View File

@ -38,7 +38,7 @@ import com.uam.wmi.findmytutor.model.IsUsingListBool;
import com.uam.wmi.findmytutor.model.StudentIdModel; import com.uam.wmi.findmytutor.model.StudentIdModel;
import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.WhiteListService;
import com.uam.wmi.findmytutor.utils.LocaleHelper; import com.uam.wmi.findmytutor.utils.LocaleHelper;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration; import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
@ -51,16 +51,14 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
@ -80,7 +78,7 @@ public class WhiteList extends AppCompatActivity {
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private UserService userService; private WhiteListService whiteListService;
private boolean didFetched = false; private boolean didFetched = false;
private String tutorId; private String tutorId;
private WhiteListAdapter mAdapter; private WhiteListAdapter mAdapter;
@ -102,8 +100,8 @@ public class WhiteList extends AppCompatActivity {
ButterKnife.bind(this); ButterKnife.bind(this);
tutorId = PrefUtils.getUserId(getApplicationContext()); tutorId = PrefUtils.getUserId(getApplicationContext());
userService = ApiClient.getClient(getApplicationContext()) whiteListService = ApiClient.getClient(getApplicationContext())
.create(UserService.class); .create(WhiteListService.class);
if (PrefUtils.isWhiteListing(this)) { if (PrefUtils.isWhiteListing(this)) {
aSwitch.setText(getString(R.string.action_white_list) +" "+getString(R.string.on) ); aSwitch.setText(getString(R.string.action_white_list) +" "+getString(R.string.on) );
@ -148,14 +146,14 @@ public class WhiteList extends AppCompatActivity {
} }
private Observable<List<String>> getListOfWhitelistedUsers(String userId) { private Observable<List<String>> getListOfWhitelistedUsers(String userId) {
return userService.getTutorWhitelistedByID(userId) return whiteListService.getTutorWhitelist(userId)
.toObservable() .toObservable()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
} }
private Observable<User> getUserObservable(String userId) { private Observable<User> getUserObservable(String userId) {
return userService return whiteListService
.getUserById(userId) .getUserById(userId)
.toObservable() .toObservable()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -169,7 +167,10 @@ public class WhiteList extends AppCompatActivity {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap(Observable::fromIterable) .flatMap(Observable::fromIterable)
.flatMap(this::getUserObservable) .flatMap(this::getUserObservable)
.subscribe(user -> whitelistedUsers.add(user), this::handleError,this::handleComplete)); .subscribe(user -> whitelistedUsers.add(user),
this::handleError,
this::handleComplete)
);
} }
private void handleDoOnSubscribe(Disposable disposable) { private void handleDoOnSubscribe(Disposable disposable) {
@ -210,7 +211,7 @@ public class WhiteList extends AppCompatActivity {
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null);
final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); Objects.requireNonNull(alertDialog.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
EditText modalUserInput = view.findViewById(R.id.white_list_modal_input); EditText modalUserInput = view.findViewById(R.id.white_list_modal_input);
@ -241,7 +242,7 @@ public class WhiteList extends AppCompatActivity {
StudentIdModel studentIdModel = new StudentIdModel(body); StudentIdModel studentIdModel = new StudentIdModel(body);
disposable.add( disposable.add(
userService.addStudentToWhitelist(tutorId, studentIdModel) whiteListService.addStudentToWhitelist(tutorId, studentIdModel)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleAddUser, this::showError) .subscribe(this::handleAddUser, this::showError)
@ -326,7 +327,7 @@ public class WhiteList extends AppCompatActivity {
IsUsingListBool isUsingListBool = new IsUsingListBool(); IsUsingListBool isUsingListBool = new IsUsingListBool();
isUsingListBool.setIsUsing(value); isUsingListBool.setIsUsing(value);
disposable.add( disposable.add(
userService.setTutorWhitelist(tutorId, isUsingListBool) whiteListService.setTutorWhitelist(tutorId, isUsingListBool)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> { .subscribe(() -> {

View File

@ -0,0 +1,35 @@
package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.IsUsingListBool;
import com.uam.wmi.findmytutor.model.StudentIdModel;
import com.uam.wmi.findmytutor.model.User;
import java.util.List;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
public interface WhiteListService {
@GET("api/users/{id}")
Single<User> getUserById(@Path("id") String userID);
@GET("api/users/whitelist/{tutorId}")
Single<List<String>> getTutorWhitelist(@Path("tutorId") String tutorID);
@PUT("api/users/whitelist/{tutorId}")
Completable setTutorWhitelist(@Path("tutorId") String tutorID, @Body IsUsingListBool isUsing);
@POST("api/users/whitelist/{tutorId}")
Observable<User> addStudentToWhitelist(@Path("tutorId") String tutorID, @Body StudentIdModel student);
@DELETE("api/users/whitelist/{tutorId}")
Completable removeStudentFromWhitelist(@Path("tutorId") String tutorID, @Body StudentIdModel student);
}

View File

@ -10,28 +10,14 @@
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"> android:paddingBottom="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/feedback_modal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/feedback_input"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="@string/manual_modal_title"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<EditText <EditText
android:id="@+id/manual_input" android:id="@+id/manual_input"
android:layout_width="315dp" android:layout_width="315dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" android:layout_marginTop="10dp"
android:ems="10" android:ems="10"
android:hint="@string/modal_manual_hint"
android:maxLength="30" android:maxLength="30"
android:maxLines="1" android:maxLines="1"
android:requiresFadingEdge="vertical" android:requiresFadingEdge="vertical"

View File

@ -146,13 +146,13 @@
<string name="modal_feedback_thankyou">Dziękujemy za przesłanie feedbacku.</string> <string name="modal_feedback_thankyou">Dziękujemy za przesłanie feedbacku.</string>
<string name="remove_manual_location">Usuń manualną lokację</string> <string name="remove_manual_location">Usuń manualną lokację</string>
<string name="title_activity_tutor_tab">Profil</string> <string name="title_activity_tutor_tab">Profil</string>
<string name="saveButton">Zapisz!</string> <string name="saveButton">Zapisz</string>
<string name="tutorTabHint">Edytuj swoją notatkę. Będzie widoczna dla innych.</string> <string name="tutorTabHint">Edytuj swoją notatkę. Będzie widoczna dla innych.</string>
<string name="modal_location_send">WYŚLIJ</string> <string name="modal_location_send">WYŚLIJ</string>
<string name="modal_location_hint">Proszę nazwać wybraną lokację.</string> <string name="modal_location_hint">Proszę nazwać wybraną lokację.</string>
<string name="manual_modal_title">Czy chcesz zapisać tę lokalizację?</string> <string name="manual_modal_title">Czy chcesz zapisać tę lokalizację?</string>
<string name="lbl_ok">Zapisz!</string> <string name="lbl_ok">Zapisz</string>
<string name="lbl_cancel">Zakończ!</string> <string name="lbl_cancel">Zakończ</string>
<string name="manual_marker_info">Twój marker zniknie w ciągu kilku minut.</string> <string name="manual_marker_info">Twój marker zniknie w ciągu kilku minut.</string>
<string name="manual_location_selected">Lokalizacja manualna wybrana!</string> <string name="manual_location_selected">Lokalizacja manualna wybrana!</string>
<string name="location_saved">Lokacja zapisana!</string> <string name="location_saved">Lokacja zapisana!</string>
@ -303,5 +303,9 @@
<string name="max_room_lenth_error">Maksymalna długość pola pokój</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="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> <string name="end_b4_start_error">Data końcowa wcześniej niż początkowa</string>
<!--(ENG) Modal ans -->
<string name="lbl_yes">Tak</string>
<string name="lbl_no">Nie</string>
</resources> </resources>

View File

@ -222,7 +222,7 @@
<string name="nav_profile">User profile</string> <string name="nav_profile">User profile</string>
<string name="remove_manual_location">Remove Manual location</string> <string name="remove_manual_location">Remove Manual location</string>
<string name="title_activity_tutor_tab">TutorTab</string> <string name="title_activity_tutor_tab">TutorTab</string>
<string name="manual_modal_title">Manual localization</string> <string name="manual_modal_title">Do you want to save this localization?</string>
<string name="lbl_ok">Save</string> <string name="lbl_ok">Save</string>
<string name="lbl_cancel">Cancel</string> <string name="lbl_cancel">Cancel</string>
<string name="manual_marker_info">Your marker will disappear in next couple minutes</string> <string name="manual_marker_info">Your marker will disappear in next couple minutes</string>
@ -471,4 +471,10 @@
<string name="max_note_length_error">Max note length</string> <string name="max_note_length_error">Max note length</string>
<string name="max_room_lenth_error">Max room length</string> <string name="max_room_lenth_error">Max room length</string>
<string name="manual_location_tolong_error">Max manual location name</string> <string name="manual_location_tolong_error">Max manual location name</string>
<!--(ENG) Modal ans -->
<string name="lbl_yes">Yes</string>
<string name="lbl_no">No</string>
</resources> </resources>