diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3a4122d..5b1bc92 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -13,9 +13,9 @@
-
-
+
+
missingPermissions = new ArrayList();
+
+ for (final String permission : REQUIRED_SDK_PERMISSIONS) {
+ final int result = ContextCompat.checkSelfPermission(this, permission);
+ if (result != PackageManager.PERMISSION_GRANTED) {
+ missingPermissions.add(permission);
+ }
+ }
+ if (!missingPermissions.isEmpty()) {
+ // request all missing permissions
+ final String[] permissions = missingPermissions
+ .toArray(new String[missingPermissions.size()]);
+ ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE_ASK_PERMISSIONS);
+ } else {
+ final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length];
+ Arrays.fill(grantResults, PackageManager.PERMISSION_GRANTED);
+ onRequestPermissionsResult(REQUEST_CODE_ASK_PERMISSIONS, REQUIRED_SDK_PERMISSIONS,
+ grantResults);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
+ @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case REQUEST_CODE_ASK_PERMISSIONS:
+ for (int index = permissions.length - 1; index >= 0; --index) {
+ if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {
+ // exit the app if one permission is not granted
+ Toast.makeText(this, "Required permission '" + permissions[index]
+ + "' not granted, exiting", Toast.LENGTH_LONG).show();
+ finish();
+ return;
+ }
+ }
+
+ break;
+ }
}
public void stopBackgroundLocalizationTask() {
@@ -182,39 +231,8 @@ public abstract class BaseActivity
actionBarDrawerToggle.syncState();
- /* if (isTutor) {
- startLocalizationService();
- }*/
}
- /* public void startLocalizationService() {
- if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
-
- if ((ActivityCompat.shouldShowRequestPermissionRationale(BaseActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
-
- } else {
- ActivityCompat.requestPermissions(BaseActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION
-
- },
- REQUEST_PERMISSIONS);
- }
- } else {
-
- if (isTutor) {
- Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- startForegroundService(intent);
- } else {
- startService(intent);
- }
-
- } else {
- Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
- }
- }
- }*/
-
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -264,20 +282,6 @@ public abstract class BaseActivity
return super.onOptionsItemSelected(item);
}
- @Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
-
- switch (requestCode) {
- case REQUEST_PERMISSIONS: {
- if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- boolean_permission = true;
- } else {
- Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();
- }
- }
- }
- }
@Override
protected void onStart() {
diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java
index d718a92..305fcd0 100644
--- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java
+++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java
@@ -198,22 +198,6 @@ public class MapActivity extends BaseActivity
}
- public void setLocale(String localeName) {
- if (!localeName.equals(currentLanguage)) {
- myLocale = new Locale(localeName);
- Resources res = getResources();
- DisplayMetrics dm = res.getDisplayMetrics();
- Configuration conf = res.getConfiguration();
- conf.locale = myLocale;
- res.updateConfiguration(conf, dm);
- Intent refresh = new Intent(this, MapActivity.class);
- refresh.putExtra(currentLang, localeName);
- startActivity(refresh);
- } else {
- Toast.makeText(this, "Language already selected!", Toast.LENGTH_SHORT).show();
- }
- }
-
// Add the mapView lifecycle to the activity's lifecycle methods
diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java
index 9ee6011..a188c9a 100644
--- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java
+++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SettingsActivity.java
@@ -1,14 +1,9 @@
package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
@@ -16,39 +11,28 @@ import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
-import android.util.Log;
import android.view.MenuItem;
-import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.utils.PrefUtils;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Set;
-import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
+import java.util.Locale;
public class SettingsActivity extends AppCompatPreferenceActivity {
private static final String TAG = SettingsActivity.class.getSimpleName();
- Locale myLocale;
- String currentLanguage = "pl", currentLang;
+
+ String currentLang;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
-
- // load settings fragment
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();
}
-
public void setLocale(String localeName) {
-
Locale myLocale = new Locale(localeName);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
@@ -60,7 +44,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
startActivity(refresh);
}
-
public static class MainPreferenceFragment extends PreferenceFragment {
@SuppressLint("ResourceType")
@Override
@@ -71,6 +54,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
Preference languagesList = findPreference(getResources().getString(R.string.key_language));
languagesList.setOnPreferenceChangeListener((preference, newValue) -> {
+
if (!newValue.toString().equals("0")){
((SettingsActivity)getActivity()).setLocale("pl");
PrefUtils.storeLocale(getActivity(),"pl");
@@ -81,16 +65,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
return true;
});
-
-
-
-
}
}
-
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {