Merge branch 'fix-sharing-gps' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-14 22:25:30 +00:00 committed by Gogs
commit b47537f0b6
8 changed files with 113 additions and 42 deletions

View File

@ -29,7 +29,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -10,7 +10,7 @@ android {
applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22
targetSdkVersion 27
versionCode 69
versionCode 70
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

View File

@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -35,17 +36,18 @@ import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.ActiveFragment;
import com.uam.wmi.findmytutor.utils.EnableLocalization;
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
import com.uam.wmi.findmytutor.utils.LocaleHelper;
import com.uam.wmi.findmytutor.utils.LocaleUtils;
import com.uam.wmi.findmytutor.utils.MapUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
import com.uam.wmi.findmytutor.utils.SharingLevel;
import com.uam.wmi.findmytutor.utils.WifiUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
@ -54,8 +56,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
import static com.uam.wmi.findmytutor.utils.Const.defaultMapZoom;
import static com.uam.wmi.findmytutor.utils.Const.onlineBackgroundLocationInterval;
import static com.uam.wmi.findmytutor.utils.Const.searchMapZoom;
@ -70,24 +70,20 @@ public abstract class BaseActivity
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS};
public DrawerLayout drawerLayout;
public ActiveFragment activeFragment = ActiveFragment.NONE;
public SearchView searchView;
public MenuItem infoMenuItem;
protected BottomNavigationView navigationView;
protected NavigationView drawerNavigationView;
protected DrawerLayout sideDrawer;
protected Toolbar toolbar;
protected boolean isTutor;
String tag = getClass().getName();
protected FeedbackUtils feedbackUtils;
String tag = getClass().getName();
private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment;
private Fragment userListFragment;
public ActiveFragment activeFragment = ActiveFragment.NONE;
private Fragment activeBottomMenu = null;
public SearchView searchView;
public MenuItem infoMenuItem;
private Fragment activeBottomMenu = null;
@Override
protected void attachBaseContext(Context base) {
@ -111,33 +107,33 @@ public abstract class BaseActivity
if (itemName.equals(getResources().getString(R.string.navigation_item_whitelist))) {
launchIntent = new Intent(getApplicationContext(), WhiteList.class);
startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
launchIntent = new Intent(getApplicationContext(),BlackList.class);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
launchIntent = new Intent(getApplicationContext(), BlackList.class);
startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
launchIntent = new Intent(getApplicationContext(), TutorTab.class);
startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
launchIntent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if (PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
logout();
} else if (itemName.equals(getResources().getString(R.string.navigation_item_feedback))) {
feedbackUtils.showNoteDialog("FEEDBACK");
} else if (itemName.equals(getResources().getString(R.string.navigation_item_feedback))) {
feedbackUtils.showNoteDialog("FEEDBACK");
/*showNoteDialog(BaseActivity.this, );*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_bug))) {
feedbackUtils.showNoteDialog("BUG REPORT");
/*showNoteDialog(BaseActivity.this, "BUG REPORT");*/
}
/*showNoteDialog(BaseActivity.this, );*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_bug))) {
feedbackUtils.showNoteDialog("BUG REPORT");
/*showNoteDialog(BaseActivity.this, "BUG REPORT");*/
}
sideDrawer.closeDrawers();
@ -159,7 +155,7 @@ public abstract class BaseActivity
}
protected void logout(){
protected void logout() {
storeBackgroundLocationStatus(getApplication(), false);
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
PrefUtils.setBatteryExlusionInfoStatus(getApplicationContext(), true);
@ -193,6 +189,23 @@ public abstract class BaseActivity
onRequestPermissionsResult(REQUEST_CODE_ASK_PERMISSIONS, REQUIRED_SDK_PERMISSIONS,
grantResults);
}
}
public void statusCheck() {
final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!Objects.requireNonNull(manager).isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();
}
}
private void buildAlertMessageNoGps() {
EnableLocalization sharingDialog = new EnableLocalization();
sharingDialog.show(getFragmentManager(), "Sharing");
}
@Override
@ -221,11 +234,22 @@ public abstract class BaseActivity
stopIntent.putExtra("request_stop", true);
stopService(stopIntent);
}
public void startBackgroundLocalizationTask() {
checkPermissions();
if (!PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())
&& !PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())
) {
statusCheck();
}
if (!WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())
&& PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())){
statusCheck();
}
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), true);
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
@ -312,8 +336,8 @@ public abstract class BaseActivity
((UsersListFragment) userListFragment).restoreUsersList();
}
if(hasFocus && activeFragment.equals(ActiveFragment.NONE)){
adjustMapToSearch(searchMapZoom);
if (hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
adjustMapToSearch(searchMapZoom);
}
});
@ -351,9 +375,9 @@ public abstract class BaseActivity
return true;
}
if (item.getItemId()==R.id.action_info){
if (item.getItemId() == R.id.action_info) {
int layoutID;
switch (activeFragment){
switch (activeFragment) {
case SHARED_PREFERENCES:
layoutID = R.layout.info_popup_sharing_tab;
break;
@ -364,7 +388,7 @@ public abstract class BaseActivity
layoutID = R.layout.info_popup_map;
}
View popupView = getLayoutInflater().inflate(layoutID,null);
View popupView = getLayoutInflater().inflate(layoutID, null);
PopupWindow popupWindow = new PopupWindow(popupView,
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
@ -373,8 +397,8 @@ public abstract class BaseActivity
// If you need the PopupWindow to dismiss when when touched outside
popupWindow.setBackgroundDrawable(new ColorDrawable());
// Get the View's(the one that was clicked in the Fragment) location
View anchorView= getWindow().getDecorView().findViewById(android.R.id.content);
popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0);
View anchorView = getWindow().getDecorView().findViewById(android.R.id.content);
popupWindow.showAtLocation(anchorView, Gravity.TOP | Gravity.END, 0, 0);
}
return super.onOptionsItemSelected(item);
@ -453,9 +477,8 @@ public abstract class BaseActivity
}
abstract int getNavigationMenuItemId();
abstract int getContentViewId();
}

View File

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

View File

@ -7,6 +7,7 @@ import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
@ -21,6 +22,7 @@ import android.os.Looper;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import com.annimon.stream.Stream;
@ -35,6 +37,7 @@ 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.Const;
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
import com.uam.wmi.findmytutor.utils.MapUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.SharingLevel;
@ -44,6 +47,7 @@ import org.apache.commons.collections4.queue.CircularFifoQueue;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;

View File

@ -0,0 +1,37 @@
package com.uam.wmi.findmytutor.utils;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.activity.MapActivity;
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
public class EnableLocalization extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.enable_sharing)
.setMessage(R.string.use_gps)
.setPositiveButton(R.string.possitive_dialog_button, (dialog, which) ->
dialogPositiveAnswer(getActivity())
)
.setNegativeButton(R.string.negative_dialog_button, (dialog, which) -> {
PrefUtils.storeEnableSharingLocalization(getActivity(), false);
dialog.cancel();
}).create();
}
private void dialogPositiveAnswer(Context context) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
}

View File

@ -293,6 +293,8 @@
<string name="batter_exclusions_message">Aby aplikacja była w pełni funkcjonalna, dodaj FMT do wyjątków w oszczędzaniu baterii. Po wciśnięciu przycisku \"ok\" zostaniesz przeniesiony do opcji zarządzania baterią. W panelu \"Bateria\" upewnij się, że opcja optymalizacji jest wyłączona.</string>
<string name="never_logged_in">Nigdy</string>
<!--(ENG) ask for gps -->
<string name="enable_sharing">Włącz lokalizację</string>
<string name="use_gps">Aby użyć tej funkcji musisz włączyć lokalizowanie urządzenia.</string>
</resources>

View File

@ -460,4 +460,8 @@
<string name="batter_exclusions_title">Please note</string>
<string name="no_tutor_tab">Tutor tab not found for this user</string>
<string name="never_logged_in">Never</string>
<!--(ENG) ask for gps -->
<string name="enable_sharing">Enable localization</string>
<string name="use_gps">In order to use this function you have to enable localization.</string>
</resources>