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))) { } else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) { if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask(); stopBackgroundLocalizationTask();
} }
@ -194,7 +193,7 @@ public abstract class BaseActivity
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); 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); startForegroundService(startIntent);
} else { } else {
startService(startIntent); startService(startIntent);

View File

@ -154,7 +154,7 @@ public class LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) { private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, 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.validate(user)
disposable.add(ldapService.fakeValidate(fuser) disposable.add(ldapService.fakeValidate(fuser)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())

View File

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

View File

@ -25,14 +25,12 @@ import android.util.Log;
import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.mapbox.geojson.Point; import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization; 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.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.SharingLevel; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -61,7 +61,8 @@ public class BackgroundLocalizationService extends Service {
private static long notify_interval = 10000; private static long notify_interval = 10000;
Location mLastLocation; Location mLastLocation;
Boolean stopService = false; Boolean stopService = false;
Intent intent;
public static String str_receiver = "background.location.broadcast";
ArrayList<String> providers = new ArrayList<String>(); ArrayList<String> providers = new ArrayList<String>();
LocationListener[] mLocationListeners; LocationListener[] mLocationListeners;
@ -146,17 +147,22 @@ public class BackgroundLocalizationService extends Service {
} }
if (!stopService) { 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) @RequiresApi(api = Build.VERSION_CODES.O)

View File

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

View File

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