From 0092de8376ddd171c331b593014db1deda18b384 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Mon, 14 Jan 2019 17:54:08 +0100 Subject: [PATCH] multi delete status mailto in tutor tab translation for no tut tab --- .../findmytutor/activity/SharingFragment.java | 89 ++++--------------- .../activity/UsersListFragment.java | 15 +++- .../findmytutor/model/StatusesListModel.java | 27 ++++++ .../service/PredefinedStatusesService.java | 6 +- app/src/main/res/layout/user_list_modal.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 62 insertions(+), 78 deletions(-) create mode 100644 app/src/main/java/com/uam/wmi/findmytutor/model/StatusesListModel.java diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 137c5a0..da66372 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -3,7 +3,6 @@ package com.uam.wmi.findmytutor.activity; import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.FragmentTransaction; -import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; @@ -24,30 +23,26 @@ import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel; -import com.uam.wmi.findmytutor.model.User; +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.EnableSharingDialog; -import com.uam.wmi.findmytutor.utils.LocaleHelper; import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.RightButtonPreference; import com.uam.wmi.findmytutor.utils.SharingLevel; -import org.reactivestreams.Subscriber; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Objects; -import io.reactivex.Observable; + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; @@ -121,8 +116,8 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere public void onSuccess(List coords) { String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext()); - locationMap = new HashMap(); - locationUUIDs = new ArrayList(); + locationMap = new HashMap<>(); + locationUUIDs = new ArrayList<>(); for (PredefinedCoordViewModel i : coords) locationMap.put(i.getPredefinedCoordinateId(), i.getName()); for (PredefinedCoordViewModel i : coords) @@ -185,16 +180,16 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere locationService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class); disposable = new CompositeDisposable(); statusesArray = new String[0]; - predefinedLocationsList = new ArrayList(); + predefinedLocationsList = new ArrayList<>(); getStatuses(disposable); getLocations(disposable); - locationLevelMapping = new HashMap(); + locationLevelMapping = new HashMap<>(); locationLevelMapping.put(0, SharingLevel.PRESENCE.toString()); locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString()); locationLevelMapping.put(2, SharingLevel.EXACT.toString()); locationLevelMapping.put(3, SharingLevel.MANUAL.toString()); - statusMapping = new HashMap(); + statusMapping = new HashMap<>(); statusMapping.put(0, "available"); statusMapping.put(1, "consultation"); statusMapping.put(2, "busy"); @@ -273,15 +268,11 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere lp.setSummary(entries[Integer.parseInt((String) newValue)]); return true; }); - statusList.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - - if (statusesArray.length == 0) { - builder.setTitle("nie ma wody na pustyni"); - } - return true; + statusList.setOnPreferenceClickListener(preference -> { + if (statusesArray.length == 0) { + builder.setTitle("Status"); } + return true; }); /** Custom status edittext change listener **/ manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { @@ -338,62 +329,15 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere return view; } - private Observable> deleteStatus(String statusId) { - String myID = PrefUtils.getUserId(getApplicationContext()); - return statusesService - .deleteUserPredefinedStatus(myID, statusId) - .toObservable() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); - } - protected void removeEntries(String service, ArrayList toBeDeleted) { -// Log.d("MANAGE-PREF", toBeDeleted.toString()); + if (service.equals("status")) { - Observable toDelete = Observable.fromIterable(toBeDeleted); - disposable.add( - toDelete.subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .flatMap(this::deleteStatus) - .subscribeWith(new DisposableObserver>(){ - @Override - public void onNext(List oo) { - Log.e("onNext", oo.toString()); - afterDeleted = oo; - } - - @Override - public void onError(Throwable e) { - showError(e); - } - - @Override - public void onComplete() { - Log.e("onComplete", afterDeleted.toString()); - - if (toBeDeleted.size() == statusesArray.length){ - Log.e("onComplete taaak", afterDeleted.toString()); - afterDeleted.clear(); - } - handleDeleteStatuses(afterDeleted); - } - }) + statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), new StatusesListModel(toBeDeleted)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::handleDeleteStatuses, this::handleError) ); - - - - -// -// for (String uuid : toBeDeleted) { -// disposable.add(statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), uuid) -// .subscribeOn(Schedulers.io()) -// .observeOn(AndroidSchedulers.mainThread()) -// .subscribe(this::handleDeleteStatuses, this::handleError)); -// } - - - } else { ArrayList uuidsToBeDeleted = new ArrayList(); for (String name : toBeDeleted) { @@ -404,7 +348,6 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere } } for (String uuid : uuidsToBeDeleted) { -// predefinedCoordsList.removeIf(x -> x.getPredefinedCoordinateId().equals(uuid)); predefinedCoordsList.removeAll(Stream.of(predefinedCoordsList).filter(x -> x.getPredefinedCoordinateId().equals(uuid)).toList()); disposable.add(locationService.deleteUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), uuid) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java index 11cf999..7ecd1a3 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java @@ -13,9 +13,11 @@ import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; +import android.text.Html; import android.text.Spannable; import android.text.SpannableString; import android.text.format.DateFormat; +import android.text.method.LinkMovementMethod; import android.text.style.ImageSpan; import android.util.Log; import android.view.Gravity; @@ -29,6 +31,7 @@ import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import com.annimon.stream.Stream; import com.github.ybq.android.spinkit.SpinKitView; @@ -271,7 +274,9 @@ public class UsersListFragment extends Fragment { } userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom())); - userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab())); + userEmail.setText(Html.fromHtml("Email: "+tutorTabViewModel.getEmailTutorTab() +"")); + userEmail.setMovementMethod(LinkMovementMethod.getInstance()); + userNote.setText(String.format("%s: %s", getString(R.string.userNote), userNoteText)); department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment())); userDutyHoursTitle.setText(String.format("%s:", getString(R.string.userDutyHoursHeader))); @@ -381,6 +386,14 @@ public class UsersListFragment extends Fragment { if (e instanceof HttpException) { ResponseBody responseBody = ((HttpException) e).response().errorBody(); message = RestApiHelper.getErrorMessage(responseBody); + if(((HttpException) e).response().code() == 404){ + if (PrefUtils.getLocale(getApplicationContext()).equals("pl") || + PrefUtils.getLocale(getApplicationContext()).equals("pl-PL") || + PrefUtils.getLocale(getApplicationContext()).equals("[pl-PL]")) { + message = getString(R.string.no_tutor_tab); + } + } + } else { message = getString(R.string.network_err); } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/model/StatusesListModel.java b/app/src/main/java/com/uam/wmi/findmytutor/model/StatusesListModel.java new file mode 100644 index 0000000..2344b5e --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/model/StatusesListModel.java @@ -0,0 +1,27 @@ +package com.uam.wmi.findmytutor.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class StatusesListModel +{ + @SerializedName("statusesList") + @Expose + public List statusesList; + + public StatusesListModel(){} + + public StatusesListModel(List _statusesList){ + this.statusesList = _statusesList; + } + + public List getStatusesList() { + return statusesList; + } + + public void setStatusesList(List statusesList) { + this.statusesList = statusesList; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/PredefinedStatusesService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/PredefinedStatusesService.java index 2a3e8cf..d4fc008 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/PredefinedStatusesService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/PredefinedStatusesService.java @@ -1,9 +1,8 @@ package com.uam.wmi.findmytutor.service; -import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel; +import com.uam.wmi.findmytutor.model.StatusesListModel; import java.util.List; import io.reactivex.Single; import retrofit2.http.Body; -import retrofit2.http.DELETE; import retrofit2.http.GET; import retrofit2.http.HTTP; import retrofit2.http.POST; @@ -16,9 +15,8 @@ public interface PredefinedStatusesService { @POST("api/users/predefined/status/{tutorId}") Single> postUserPredefinedStatus(@Path("tutorId") String tutorId, @Body String status); -// @DELETE("api/users/predefined/status/{tutorId}") @HTTP(method = "DELETE", path = "api/users/predefined/status/{tutorId}", hasBody = true) - Single> deleteUserPredefinedStatus(@Path("tutorId") String tutorId, @Body String status); + Single> deleteUserPredefinedStatus(@Path("tutorId") String tutorId, @Body StatusesListModel statusesLis); /* @GET("api/users/predefined/coordinate/{tutorId}") Single> getUserPredefinedCoords(@Path("tutorId") String tutorId); diff --git a/app/src/main/res/layout/user_list_modal.xml b/app/src/main/res/layout/user_list_modal.xml index 9f0abcd..6e115fa 100644 --- a/app/src/main/res/layout/user_list_modal.xml +++ b/app/src/main/res/layout/user_list_modal.xml @@ -131,6 +131,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:autoLink="web|email" android:paddingLeft="10dp" android:textColor="@color/mapboxWhite" /> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index d900396..622420b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -290,6 +290,7 @@ Profil użytkownika Uwaga Aby aplikacja była w pełni funkcjonalna, dodaj FMT do wyjątku w oszczędzaniu baterii + Zakładka użytkownika nie istnieje diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f3afc42..9671236 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -458,4 +458,5 @@ Last seen To make app fully functional, add FMT to battery saving exclusions Please note + Tutor tab not found for this user