multi delete status
mailto in tutor tab translation for no tut tab
This commit is contained in:
parent
01c75bf96d
commit
0092de8376
@ -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<PredefinedCoordViewModel> coords) {
|
||||
|
||||
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||
locationMap = new HashMap<String, String>();
|
||||
locationUUIDs = new ArrayList<String>();
|
||||
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<String>();
|
||||
predefinedLocationsList = new ArrayList<>();
|
||||
getStatuses(disposable);
|
||||
getLocations(disposable);
|
||||
locationLevelMapping = new HashMap<Integer, String>();
|
||||
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<Integer, String>();
|
||||
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<List<String>> 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<String> toBeDeleted) {
|
||||
// Log.d("MANAGE-PREF", toBeDeleted.toString());
|
||||
|
||||
if (service.equals("status")) {
|
||||
Observable<String> toDelete = Observable.fromIterable(toBeDeleted);
|
||||
|
||||
disposable.add(
|
||||
toDelete.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(this::deleteStatus)
|
||||
.subscribeWith(new DisposableObserver<List<String>>(){
|
||||
@Override
|
||||
public void onNext(List<String> 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<String> uuidsToBeDeleted = new ArrayList<String>();
|
||||
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())
|
||||
|
@ -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: <a href=\""+tutorTabViewModel.getEmailTutorTab()+"\">"+tutorTabViewModel.getEmailTutorTab() +"</a>"));
|
||||
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);
|
||||
}
|
||||
|
@ -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<String> statusesList;
|
||||
|
||||
public StatusesListModel(){}
|
||||
|
||||
public StatusesListModel(List<String> _statusesList){
|
||||
this.statusesList = _statusesList;
|
||||
}
|
||||
|
||||
public List<String> getStatusesList() {
|
||||
return statusesList;
|
||||
}
|
||||
|
||||
public void setStatusesList(List<String> statusesList) {
|
||||
this.statusesList = statusesList;
|
||||
}
|
||||
}
|
@ -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<List<String>> 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<List<String>> deleteUserPredefinedStatus(@Path("tutorId") String tutorId, @Body String status);
|
||||
Single<List<String>> deleteUserPredefinedStatus(@Path("tutorId") String tutorId, @Body StatusesListModel statusesLis);
|
||||
|
||||
/* @GET("api/users/predefined/coordinate/{tutorId}")
|
||||
Single<List<PredefinedCoordViewModel>> getUserPredefinedCoords(@Path("tutorId") String tutorId);
|
||||
|
@ -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" />
|
||||
</LinearLayout>
|
||||
|
@ -290,6 +290,7 @@
|
||||
<string name="profile_activity_title">Profil użytkownika</string>
|
||||
<string name="batter_exclusions_title">Uwaga</string>
|
||||
<string name="batter_exclusions_message">Aby aplikacja była w pełni funkcjonalna, dodaj FMT do wyjątku w oszczędzaniu baterii</string>
|
||||
<string name="no_tutor_tab">Zakładka użytkownika nie istnieje</string>
|
||||
|
||||
</resources>
|
||||
|
||||
|
@ -458,4 +458,5 @@
|
||||
<string name="last_sign">Last seen</string>
|
||||
<string name="batter_exclusions_message">To make app fully functional, add FMT to battery saving exclusions</string>
|
||||
<string name="batter_exclusions_title">Please note</string>
|
||||
<string name="no_tutor_tab">Tutor tab not found for this user</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user