diff --git a/.idea/misc.xml b/.idea/misc.xml index dc44dda..b0c7b20 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -29,7 +29,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 81ba8e3..bb3f482 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index 19a6dac..4b9afd4 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -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(); - - } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 878b5b1..e6578a4 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -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()) { diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java index a374c44..9679394 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java @@ -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; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/EnableLocalization.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/EnableLocalization.java new file mode 100644 index 0000000..8ed7f67 --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/EnableLocalization.java @@ -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)); + } +} diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index b1ea608..e3c9ee9 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -293,6 +293,8 @@ 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. Nigdy - + + Włącz lokalizację + Aby użyć tej funkcji musisz włączyć lokalizowanie urządzenia. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index edbbefa..4e6178a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -460,4 +460,8 @@ Please note Tutor tab not found for this user Never + + + Enable localization + In order to use this function you have to enable localization.