Merge branch 'fix-manula-bg' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-06 22:46:12 +00:00 committed by Gogs
commit 7a41dcbb1f
5 changed files with 57 additions and 55 deletions

View File

@ -4,10 +4,10 @@
package="com.uam.wmi.findmytutor"> package="com.uam.wmi.findmytutor">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

View File

@ -212,7 +212,7 @@ public abstract class BaseActivity
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class); Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
startIntent.putExtra("notify_interval", onlineBackgroundLocationInterval); startIntent.putExtra("notify_interval", onlineBackgroundLocationInterval);
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

@ -162,10 +162,10 @@ public class BlackList extends AppCompatActivity {
private void fetchBlackListedUsers() { private void fetchBlackListedUsers() {
prevSize = blacklistedUsers.size(); prevSize = blacklistedUsers.size();
blacklistedUsers.clear(); blacklistedUsers.clear();
disposable.add(getListOfBlacklistedUsers(tutorId) disposable.add(getListOfBlacklistedUsers(tutorId)
.doOnSubscribe(t -> didFetched = false)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable) .flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
@ -179,11 +179,13 @@ public class BlackList extends AppCompatActivity {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
showError(e); showError(e);
didFetched = false;
} }
@Override @Override
public void onComplete() { public void onComplete() {
Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b)); Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b));
didFetched = true;
refreshUI(); refreshUI();
} }
})); }));

View File

@ -214,10 +214,9 @@ public class SharingFragment extends PreferenceFragment implements SharedPrefere
/** Sharing level list **/ /** Sharing level list **/
locationMode.setOnPreferenceChangeListener((preference, newValue) -> { locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue))); PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
((MapActivity) getActivity()).stopBackgroundLocalizationTask();
((MapActivity) getActivity()).startBackgroundLocalizationTask();
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) { if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
if (!predefinedCoordsList.isEmpty()) { if (!predefinedCoordsList.isEmpty()) {
preferenceCategory.addPreference(manualLocationList); preferenceCategory.addPreference(manualLocationList);

View File

@ -44,7 +44,6 @@ import com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; 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;
@ -61,11 +60,6 @@ import okhttp3.ResponseBody;
public class WhiteList extends AppCompatActivity { public class WhiteList extends AppCompatActivity {
private CompositeDisposable disposable = new CompositeDisposable();
private UserService userService;
private boolean didFetched = false;
private String tutorId;
@BindView(R.id.recycler_view_whitelist) @BindView(R.id.recycler_view_whitelist)
RecyclerView recyclerView; RecyclerView recyclerView;
@BindView(R.id.white_list_empty_text_view) @BindView(R.id.white_list_empty_text_view)
@ -74,7 +68,10 @@ public class WhiteList extends AppCompatActivity {
Switch aSwitch; Switch aSwitch;
@BindView(R.id.add_to_white_list_fab) @BindView(R.id.add_to_white_list_fab)
FloatingActionButton addToWhiteListFab; FloatingActionButton addToWhiteListFab;
private CompositeDisposable disposable = new CompositeDisposable();
private UserService userService;
private boolean didFetched = false;
private String tutorId;
private WhiteListAdapter mAdapter; private WhiteListAdapter mAdapter;
private Integer prevSize; private Integer prevSize;
private List<User> whitelistedUsers = new ArrayList<>(); private List<User> whitelistedUsers = new ArrayList<>();
@ -90,12 +87,12 @@ public class WhiteList extends AppCompatActivity {
userService = ApiClient.getClient(getApplicationContext()) userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class); .create(UserService.class);
if (PrefUtils.isWhiteListing(this)){ if (PrefUtils.isWhiteListing(this)) {
aSwitch.setText(getString(R.string.action_white_list) +" ON"); aSwitch.setText(getString(R.string.action_white_list) + " ON");
aSwitch.setChecked(true); aSwitch.setChecked(true);
handleChangeRequest(true); handleChangeRequest(true);
}else{ } else {
aSwitch.setText(getString(R.string.action_white_list) +" OFF"); aSwitch.setText(getString(R.string.action_white_list) + " OFF");
aSwitch.setChecked(false); aSwitch.setChecked(false);
handleChangeRequest(false); handleChangeRequest(false);
} }
@ -132,7 +129,7 @@ public class WhiteList extends AppCompatActivity {
} }
private Observable<List<String>> getListOfWhitelistedUsers(String userId) { private Observable<List<String>> getListOfWhitelistedUsers(String userId) {
return userService.getTutorWhitelistedByID(userId) return userService.getTutorWhitelistedByID(userId)
.toObservable() .toObservable()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
@ -151,30 +148,33 @@ public class WhiteList extends AppCompatActivity {
whitelistedUsers.clear(); whitelistedUsers.clear();
disposable.add(getListOfWhitelistedUsers(tutorId) disposable.add(getListOfWhitelistedUsers(tutorId)
.subscribeOn(Schedulers.io()) .doOnSubscribe(t -> didFetched = false)
.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable) .observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<String, ObservableSource<User>>) this::getUserObservable) .flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
.subscribeWith(new DisposableObserver<User>() { .flatMap((Function<String, ObservableSource<User>>) this::getUserObservable)
@Override .subscribeWith(new DisposableObserver<User>() {
public void onNext(User user) { @Override
whitelistedUsers.add(user); public void onNext(User user) {
} whitelistedUsers.add(user);
}
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
showError(e); showError(e);
} didFetched = false;
}
@Override @Override
public void onComplete() { public void onComplete() {
Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a,b)); Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a, b));
refreshUI(); didFetched = true;
} refreshUI();
})); }
}));
} }
private void refreshUI(){ private void refreshUI() {
toggleEmptyNotes(); toggleEmptyNotes();
mAdapter.notifyItemRangeInserted(prevSize, whitelistedUsers.size() - prevSize); mAdapter.notifyItemRangeInserted(prevSize, whitelistedUsers.size() - prevSize);
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
@ -184,7 +184,7 @@ public class WhiteList extends AppCompatActivity {
return plCollator.compare(t1.getLastName(), t2.getLastName()); return plCollator.compare(t1.getLastName(), t2.getLastName());
} }
private void showFabDialog(View v){ private void showFabDialog(View v) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext()); LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.white_list_fab_modal, null); @SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.white_list_fab_modal, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this); AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this);
@ -230,7 +230,7 @@ public class WhiteList extends AppCompatActivity {
userService.addStudentToWhitelist(tutorId, studentIdModel) userService.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)
); );
} }
@ -251,15 +251,16 @@ public class WhiteList extends AppCompatActivity {
} else { } else {
message = "Network Error !"; message = "Network Error !";
} }
Log.e("ERR",message); Log.e("ERR", message);
Toast.makeText(this, message, Snackbar.LENGTH_LONG).show(); Toast.makeText(this, message, Snackbar.LENGTH_LONG).show();
} }
private void toggleEmptyNotes() { private void toggleEmptyNotes() {
if (didFetched && whitelistedUsers.size() == 0) { if (didFetched && whitelistedUsers.size() == 0) {
noNotesView.setText(R.string.list_is_empty); noNotesView.setText(R.string.list_is_empty);
noNotesView.setVisibility(View.VISIBLE); noNotesView.setVisibility(View.VISIBLE);
}else if (whitelistedUsers.size() > 0) { } else if (whitelistedUsers.size() > 0) {
noNotesView.setVisibility(View.GONE); noNotesView.setVisibility(View.GONE);
} else { } else {
noNotesView.setText(getString(R.string.loading)); noNotesView.setText(getString(R.string.loading));
@ -271,10 +272,10 @@ public class WhiteList extends AppCompatActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.action_whitelist_info_popup){ if (item.getItemId() == R.id.action_whitelist_info_popup) {
int layoutID = R.layout.info_popup_whitelist; int layoutID = R.layout.info_popup_whitelist;
View popupView = getLayoutInflater().inflate(layoutID,null); View popupView = getLayoutInflater().inflate(layoutID, null);
PopupWindow popupWindow = new PopupWindow(popupView, PopupWindow popupWindow = new PopupWindow(popupView,
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
@ -283,36 +284,36 @@ public class WhiteList extends AppCompatActivity {
// If you need the PopupWindow to dismiss when when touched outside // If you need the PopupWindow to dismiss when when touched outside
popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.setBackgroundDrawable(new ColorDrawable());
// Get the View's(the one that was clicked in the Fragment) location // Get the View's(the one that was clicked in the Fragment) location
View anchorView= getWindow().getDecorView().findViewById(android.R.id.content); View anchorView = getWindow().getDecorView().findViewById(android.R.id.content);
popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0); popupWindow.showAtLocation(anchorView, Gravity.TOP | Gravity.END, 0, 0);
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void handleSwitch(){ private void handleSwitch() {
aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked){ if (isChecked) {
aSwitch.setText(getString(R.string.action_white_list) + " "+ getString(R.string.on)); aSwitch.setText(getString(R.string.action_white_list) + " " + getString(R.string.on));
handleChangeRequest(true); handleChangeRequest(true);
PrefUtils.useWhitelist(this, true); PrefUtils.useWhitelist(this, true);
}else { } else {
aSwitch.setText(getString(R.string.action_white_list) + " "+getString(R.string.off)); aSwitch.setText(getString(R.string.action_white_list) + " " + getString(R.string.off));
handleChangeRequest(false); handleChangeRequest(false);
PrefUtils.useWhitelist(this, false); PrefUtils.useWhitelist(this, false);
} }
}); });
} }
private void handleChangeRequest(boolean value){ private void handleChangeRequest(boolean value) {
IsUsingListBool isUsingListBool = new IsUsingListBool(); IsUsingListBool isUsingListBool = new IsUsingListBool();
isUsingListBool.setIsUsing(value); isUsingListBool.setIsUsing(value);
disposable.add( disposable.add(
userService.setTutorWhitelist(tutorId, isUsingListBool) userService.setTutorWhitelist(tutorId, isUsingListBool)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(()->{ .subscribe(() -> {
},this::showError) }, this::showError)
); );
} }