Compare commits

..

14 Commits

Author SHA1 Message Date
faed9e05b7 Merge branch 'develop' of s416084/find-my-tutor-android into master 2019-01-13 15:09:06 +00:00
1095386659 Merge branch 'fix-battery-prompt-5.1' of s416084/find-my-tutor-android into develop 2019-01-13 15:08:19 +00:00
b7e1e4a984 Fix 5.1 2019-01-13 16:06:58 +01:00
4473834218 Merge branch 'develop' of s416084/find-my-tutor-android into master 2019-01-13 13:39:56 +00:00
5a96d93d37 Merge branch 'fix-info-battery-prompt' of s416084/find-my-tutor-android into develop 2019-01-13 13:38:16 +00:00
33cfa90a28 Update gradle 2019-01-13 14:37:15 +01:00
6fa458d198 show prompt only for tutors 2019-01-13 14:36:51 +01:00
2ca95e0ba0 Merge branch 'develop' of s416084/find-my-tutor-android into master 2019-01-13 13:14:13 +00:00
eb30100183 Merge branch 'presence-wifi-approach' of s416084/find-my-tutor-android into develop 2019-01-13 13:11:38 +00:00
e1c266263a Fix low battery mode 2019-01-13 14:10:50 +01:00
d88525a764 Add presence which works with Wifi 2019-01-13 13:44:10 +01:00
430914bab1 Merge branch 'fix-acra' of s416084/find-my-tutor-android into develop 2019-01-13 10:34:55 +00:00
a4c0881300 Merge branch 'develop' of s416084/find-my-tutor-android into master 2019-01-06 18:03:06 +00:00
7e043c9826 Merge branch 'develop' of s416084/find-my-tutor-android into master 2019-01-06 11:02:30 +00:00
13 changed files with 156 additions and 42 deletions

View File

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

View File

@ -6,9 +6,9 @@ import android.content.SharedPreferences;
import android.content.res.Configuration;
import com.uam.wmi.findmytutor.utils.Const;
import com.uam.wmi.findmytutor.utils.LocaleHelper;
import com.uam.wmi.findmytutor.utils.MapUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import static org.acra.ReportField.*;
import org.acra.ACRA;
import org.acra.annotation.AcraLimiter;
import org.acra.annotation.AcraNotification;
@ -17,15 +17,28 @@ import org.acra.config.HttpSenderConfigurationBuilder;
import org.acra.config.ToastConfigurationBuilder;
import org.acra.data.StringFormat;
import org.acra.sender.HttpSender;
import java.util.HashMap;
import java.util.Map;
import static org.acra.ReportField.ANDROID_VERSION;
import static org.acra.ReportField.BUILD_CONFIG;
import static org.acra.ReportField.CUSTOM_DATA;
import static org.acra.ReportField.LOGCAT;
import static org.acra.ReportField.PHONE_MODEL;
import static org.acra.ReportField.REPORT_ID;
import static org.acra.ReportField.SHARED_PREFERENCES;
import static org.acra.ReportField.STACK_TRACE;
import static org.acra.ReportField.USER_APP_START_DATE;
import static org.acra.ReportField.USER_CRASH_DATE;
@AcraNotification(resText = R.string.notification_text,
resTitle = R.string.notification_title,
resChannelName = R.string.notification_channel)
@AcraLimiter(failedReportLimit = 2)
public class FindMyTutor extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
@ -45,6 +58,7 @@ public class FindMyTutor extends Application {
ToastConfigurationBuilder.class
).setResText(R.string.acra_toast_text);
SharedPreferences sharedPreferences = base.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE);
Map header = new HashMap();
String token = sharedPreferences.getString("API_KEY", "KEY_EMPTY");

View File

@ -38,6 +38,7 @@ import com.uam.wmi.findmytutor.utils.ActiveFragment;
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;
@ -161,6 +162,7 @@ public abstract class BaseActivity
protected void logout(){
storeBackgroundLocationStatus(getApplication(), false);
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
PrefUtils.setBatteryExlusionInfoStatus(getApplicationContext(), true);
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
@ -425,7 +427,7 @@ public abstract class BaseActivity
sharingFragment = SharingFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.activity_content, sharingFragment);
ft.addToBackStack(null);
//ft.addToBackStack(null);
ft.commit();
}
@ -435,7 +437,7 @@ public abstract class BaseActivity
userListFragment = UsersListFragment.newInstance();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.activity_content, userListFragment);
ft.addToBackStack(null);
//ft.addToBackStack(null);
ft.commit();
}

View File

@ -27,6 +27,7 @@ import com.uam.wmi.findmytutor.model.ValidateUser;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.LdapService;
import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.MapUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper;
@ -190,6 +191,7 @@ public class LoginActivity extends AppCompatActivity {
getUserProfile(userId.asString());
Intent data = new Intent();
String txt = "Main Activity";
data.setData(Uri.parse(txt));

View File

@ -146,9 +146,13 @@ public class MapActivity extends BaseActivity
handleBackgroundTaskLifeCycle();
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
if(isTutor){
MapUtils.BatteryOptimizationsExceptionCheck(this);
}
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
MapActivity.this.mapboxMap = mapboxMap;

View File

@ -23,6 +23,7 @@ import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.utils.LocaleHelper;
import com.uam.wmi.findmytutor.utils.MapUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import java.util.Locale;
@ -48,8 +49,8 @@ public class StartupActivity extends AppCompatActivity {
finish();
} else {
Intent loginIntent = new Intent(this, LoginActivity.class);
// Intent loginIntent = new Intent(this, ScrollingActivity.class);
startActivityForResult(loginIntent, AUTHENTICATION_REQUEST_CODE);
}
super.onCreate(savedInstanceState);

View File

@ -34,9 +34,11 @@ 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.Const;
import com.uam.wmi.findmytutor.utils.MapUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.SharingLevel;
import com.uam.wmi.findmytutor.utils.WifiUtils;
import org.apache.commons.collections4.queue.CircularFifoQueue;
@ -122,6 +124,12 @@ public class BackgroundLocalizationService extends Service {
mCurrentLocation = locationResult.getLastLocation();
sendCoordinateToBackend(mCurrentLocation);
changeBackgroundMode();
//Restart service when a user started using presence in GPS mode and wmi is currently available
if (WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())
&& PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
restartService();
}
}
}
};
@ -140,10 +148,34 @@ public class BackgroundLocalizationService extends Service {
startForeground(1001, notification);
}
if (!stopService && !PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
if (!stopService) {
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
if (WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())) {
Location presenceFakeLoc = new Location("");
presenceFakeLoc.setLatitude(Const.presenceLatitude);
presenceFakeLoc.setLongitude(Const.presenceLongitude);
presenceFakeLoc.setAltitude(0);
createPresenceLooper(presenceFakeLoc);
} else {
createFusedLocationClient();
} else if (!stopService &&
PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
}
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.EXACT.toString())
|| PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())
) {
createFusedLocationClient();
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
Location manualFakeLoc = new Location("");
manualFakeLoc.setLatitude(0);
manualFakeLoc.setLongitude(0);
manualFakeLoc.setAltitude(0);
createLowBatteryLooper(manualFakeLoc);
}
}
}
private void createLowBatteryLooper(Location fakeLoc) {
mStatusChecker = () -> {
try {
sendCoordinateToBackend(fakeLoc);
@ -151,10 +183,24 @@ public class BackgroundLocalizationService extends Service {
mHandler.postDelayed(mStatusChecker, notify_interval);
}
};
AsyncTask.execute(mStatusChecker);
}
private void createPresenceLooper(Location fakeLoc) {
mStatusChecker = () -> {
try {
if (WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())) {
sendCoordinateToBackend(fakeLoc);
} else {
restartService();
}
} finally {
mHandler.postDelayed(mStatusChecker, notify_interval);
}
};
AsyncTask.execute(mStatusChecker);
}
private void createFusedLocationClient() {
Integer saveMode = Long.valueOf(notify_interval).compareTo(Long.valueOf(offlineBackgroundLocationInterval));
@ -307,6 +353,7 @@ public class BackgroundLocalizationService extends Service {
if (locationLevel.equals(SharingLevel.PRESENCE.toString())) {
if (!MapUtils.checkIfCoordinateIsValid(latitude, longitude)) {
coordinatesHistory.add(fakeLoc);
return null;
}

View File

@ -20,5 +20,7 @@ public class Const {
public final static Range<Double> outsideLatitudeRange = Range.create(52.4651, 52.468837);
public final static Range<Double> outsideLongitudeRange = Range.create(16.9186, 16.936004);
public final static List<String> validApproximatedLocations = Arrays.asList("Skrzydło B", "Skrzydło A", "Aule", "Łącznik", "Biblioteka", "Hol", "Unknown");
public final static String WMI_SSID_NAME = "wmi";
}

View File

@ -3,12 +3,9 @@ package com.uam.wmi.findmytutor.utils;
import android.animation.TypeEvaluator;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.PowerManager;
import android.provider.Settings;
import com.mapbox.mapboxsdk.camera.CameraPosition;
@ -25,6 +22,7 @@ import java.io.InputStream;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
import static com.uam.wmi.findmytutor.utils.Const.outsideLatitudeRange;
import static com.uam.wmi.findmytutor.utils.Const.outsideLongitudeRange;
import static com.uam.wmi.findmytutor.utils.PrefUtils.shouldBatteryExclusionBeShown;
public class MapUtils {
@ -90,6 +88,26 @@ public class MapUtils {
return Const.buildingLatitudeRange.contains(latitude) && Const.buildingLongitudeRange.contains(longitude);
}
public static void BatteryOptimizationsExceptionCheck(Context context) {
if (shouldBatteryExclusionBeShown(getApplicationContext())) {
PrefUtils.setBatteryExlusionInfoStatus(getApplicationContext(), false);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.batter_exclusions_title);
builder.setMessage(R.string.batter_exclusions_message)
.setPositiveButton(R.string.ok, (dialog, id) -> {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null);
intent.setData(uri);
context.startActivity(intent);
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
}).show();
}
}
// Function for marker animation
public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
@ -106,19 +124,4 @@ public class MapUtils {
}
}
public static void BatteryOptimizationsExceptionCheck(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.batter_exclusions_title);
builder.setMessage(R.string.batter_exclusions_message)
.setPositiveButton(R.string.ok, (dialog, id) -> {
Intent intentBatteryUsage = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
context.startActivity(intentBatteryUsage);
})
.setNegativeButton(R.string.cancel, (dialog, id) -> {
// User cancelled the dialog
}).show();
}
}
}

View File

@ -243,4 +243,13 @@ public class PrefUtils {
return getSharedPreferences(context).getBoolean("whitelisting", false);
}
public static Boolean shouldBatteryExclusionBeShown(Context context) {
return getSharedPreferences(context).getBoolean("show_battery_exclusion", false);
}
public static void setBatteryExlusionInfoStatus(Context context, Boolean flag) {
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
editor.putBoolean("show_battery_exclusion", flag);
editor.apply();
}
}

View File

@ -0,0 +1,30 @@
package com.uam.wmi.findmytutor.utils;
import android.content.Context;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;
import java.util.Objects;
public class WifiUtils {
public static String getWifiName(Context context) {
WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (Objects.requireNonNull(manager).isWifiEnabled()) {
WifiInfo wifiInfo = manager.getConnectionInfo();
if (wifiInfo != null) {
NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
return wifiInfo.getSSID();
}
}
}
return null;
}
public static Boolean checkIfUserIsInRangeOfWmiWifi(Context context) {
return Objects.equals(getWifiName(context), Const.WMI_SSID_NAME);
}
}

View File

@ -289,7 +289,7 @@
<string name="available_now">Dostępny teraz</string>
<string name="profile_activity_title">Profil użytkownika</string>
<string name="batter_exclusions_title">Uwaga</string>
<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 "optymalizacja użycia baterii" upewnij się, że opcja optymalizacji jest wyłączona.</string>
<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>

View File

@ -456,7 +456,7 @@
<string name="user_status_label" translatable="false">Status</string>
<string name="available_now">Available now</string>
<string name="last_sign">Last seen</string>
<string name="batter_exclusions_message">To make app fully functional, add FMT to battery saving exclusions. You can change battery options in "Optimise battery usage". Unfortunately, you have to do it manually. Click "ok" to open battery settings and make sure that the application is not optimised.</string>
<string name="batter_exclusions_message">To make app fully functional add FMT to battery saving exclusions. You can change battery options in \"Optimise battery usage\". Unfortunately, you have to do it manually. Click \"ok\" to open battery settings and make sure that the application is not optimised.</string>
<string name="batter_exclusions_title">Please note</string>
<string name="never_logged_in">Never</string>
</resources>