Fix BG & UI

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-27 20:53:01 +01:00
parent ab74f0b7e1
commit c452e5dbf5
6 changed files with 81 additions and 97 deletions

View File

@ -100,7 +100,6 @@ public abstract class BaseActivity
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
@ -194,7 +193,7 @@ public abstract class BaseActivity
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
startForegroundService(startIntent);
} else {
startService(startIntent);

View File

@ -154,7 +154,7 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, password);
LdapUser fuser = new LdapUser(email,password,"wmi","tutor","marek","nocny","szmare@wmi.pl");
LdapUser fuser = new LdapUser(email,password,"tutor","tutor","mieszko","nocny","szmsdsdsdsdare@wmi.pl");
// disposable.add(ldapService.validate(user)
disposable.add(ldapService.fakeValidate(fuser)
.subscribeOn(Schedulers.io())

View File

@ -1,12 +1,7 @@
package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
@ -16,52 +11,34 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.annimon.stream.Collector;
import com.annimon.stream.Stream;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.Feedback;
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.service.FeedbackService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Response;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
public class SharingFragment extends PreferenceFragment {
private HashMap<Integer, String> locationLevelMapping;
private HashMap<Integer, String> statusMapping;
private PredefinedStatusesService statusesService;
private CompositeDisposable disposable;
protected Preference locationSharing;
protected Preference locationMode;
protected Preference manualLocationList;
@ -69,7 +46,15 @@ public class SharingFragment extends PreferenceFragment {
protected RightButtonPreference manualLocationButton;
protected Preference manualStatus;
protected ListPreference statusList;
protected List<PredefinedCoordViewModel> predefinedCoordsList= new ArrayList<>();
protected List<PredefinedCoordViewModel> predefinedCoordsList = new ArrayList<>();
private HashMap<Integer, String> locationLevelMapping;
private HashMap<Integer, String> statusMapping;
private PredefinedStatusesService statusesService;
private CompositeDisposable disposable;
public static SharingFragment newInstance() {
return new SharingFragment();
}
void getStatuses(CompositeDisposable disposable) {
@ -91,29 +76,29 @@ public class SharingFragment extends PreferenceFragment {
}));
}
void getLocations(CompositeDisposable disposable) {
disposable.add(statusesService.getUserPredefinedCoords(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<PredefinedCoordViewModel>>() {
void getLocations(CompositeDisposable disposable) {
disposable.add(statusesService.getUserPredefinedCoords(PrefUtils.getUserId(getApplicationContext()))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<PredefinedCoordViewModel>>() {
@Override
public void onSuccess(List<PredefinedCoordViewModel> coords) {
List<String> names = Stream.of(coords).map(PredefinedCoordViewModel::getName).collect(com.annimon.stream.Collectors.toList());
predefinedCoordsList.addAll(coords);
String [] stringnames = names.toArray(new String[0]);
@Override
public void onSuccess(List<PredefinedCoordViewModel> coords) {
List<String> names = Stream.of(coords).map(PredefinedCoordViewModel::getName).collect(com.annimon.stream.Collectors.toList());
predefinedCoordsList.addAll(coords);
String[] stringnames = names.toArray(new String[0]);
setListPreferenceData(manualLocationList.getKey(),stringnames);
setListPreferenceData(manualLocationList.getKey(), stringnames);
}
}
@Override
public void onError(Throwable e) {
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
@Override
public void onError(Throwable e) {
Toast.makeText(getApplicationContext(), "Error handling status fetch", Toast.LENGTH_SHORT).show();
}
}));
}
}
}));
}
@SuppressLint("ResourceType")
@Override
@ -132,9 +117,9 @@ public class SharingFragment extends PreferenceFragment {
disposable = new CompositeDisposable();
getStatuses(disposable);
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
getLocations(disposable);
}
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
getLocations(disposable);
}
locationLevelMapping = new HashMap<Integer, String>();
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
@ -158,11 +143,11 @@ public class SharingFragment extends PreferenceFragment {
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual") ) {
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
preferenceCategory.addPreference(manualLocationList);
getLocations(disposable);
preferenceCategory.addPreference(manualLocationButton);
getLocations(disposable);
preferenceCategory.addPreference(manualLocationButton);
} else {
preferenceCategory.removePreference(manualLocationList);
@ -180,10 +165,9 @@ public class SharingFragment extends PreferenceFragment {
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference;
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter( p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).single();
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).single();
PrefUtils.putManualLocation(getApplicationContext(),temp.getGeoData());
// ((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData());
return true;
});
@ -199,7 +183,7 @@ public class SharingFragment extends PreferenceFragment {
/** Status list change listener **/
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference;
CharSequence [] entries = lp.getEntries();
CharSequence[] entries = lp.getEntries();
PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]);
return true;
@ -218,11 +202,6 @@ public class SharingFragment extends PreferenceFragment {
}
public static SharingFragment newInstance() {
return new SharingFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
@ -231,7 +210,7 @@ public class SharingFragment extends PreferenceFragment {
return view;
}
protected void setListPreferenceData(String lp_name, String [] entries) {
protected void setListPreferenceData(String lp_name, String[] entries) {
//todo bug z pustym statusem
ListPreference lp = (ListPreference) findPreference(lp_name);
lp.setEntries(entries);
@ -250,21 +229,20 @@ public class SharingFragment extends PreferenceFragment {
setListPreferenceData(statusList.getKey(), statusesArray);
statusList.setValueIndex(resp.size() - 1);
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() -1 ));
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() - 1));
}
private void handleError (Throwable error){
if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(getApplicationContext(),
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
private void handleError(Throwable error) {
if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(getApplicationContext(),
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("FEEDBACK", error.getMessage());
}
} else {
Toast.makeText(getApplicationContext(),
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -25,14 +25,12 @@ import android.util.Log;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
import com.uam.wmi.findmytutor.utils.Consts;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.SharingLevel;
@ -40,6 +38,8 @@ import com.uam.wmi.findmytutor.utils.mapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -61,7 +61,8 @@ public class BackgroundLocalizationService extends Service {
private static long notify_interval = 10000;
Location mLastLocation;
Boolean stopService = false;
Intent intent;
public static String str_receiver = "background.location.broadcast";
ArrayList<String> providers = new ArrayList<String>();
LocationListener[] mLocationListeners;
@ -146,17 +147,22 @@ public class BackgroundLocalizationService extends Service {
}
if (!stopService) {
mStatusChecker = () -> {
try {
fn_getlocation();
} finally {
mHandler.postDelayed(mStatusChecker, notify_interval);
}
};
AsyncTask.execute(mStatusChecker);
Timer mTimer = new Timer();
mTimer.schedule(new TimerTaskToGetLocation(), 20, notify_interval);
intent = new Intent(str_receiver);
fn_getlocation();
}
}
private class TimerTaskToGetLocation extends TimerTask {
@Override
public void run() {
mHandler.post(BackgroundLocalizationService.this::fn_getlocation);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)

View File

@ -15,21 +15,30 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/feedback_input"
android:layout_marginBottom="@dimen/dimen_10"
android:layout_marginBottom="15dp"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:lineSpacingExtra="10sp"
android:text="placeholder"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<TextView
android:id="@+id/feedback_modal_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="placeholder"
android:textColor="@color/note_list_text"
android:textSize="14sp" />
<EditText
android:id="@+id/feedback_input"
android:layout_width="315dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:layout_marginTop="70dp"
android:ems="10"
android:hint="@string/modal_feedback_hint"
android:inputType="textMultiLine"
@ -55,13 +64,5 @@
android:layout_alignEnd="@+id/feedback_input"
android:textSize="14sp" />
<TextView
android:id="@+id/feedback_modal_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/feedback_input"
android:layout_alignEnd="@+id/feedback_input"
android:layout_marginEnd="0dp"
android:layout_marginBottom="-50dp"
android:textSize="14sp" />
</RelativeLayout>

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/drawer_group_tutor">
<item
<!-- <item
android:id="@+id/nav_item_one"
android:icon="@drawable/ic_people_white"
android:title="@string/navigation_item_whitelist" />
<item
android:id="@+id/nav_item_two"
android:icon="@drawable/ic_people_black"
android:title="@string/navigation_item_blacklist" />
android:title="@string/navigation_item_blacklist" />-->
<item
android:id="@+id/nav_item_three"
android:icon="@drawable/outline_person_white_24dp"