From 8553b934a63f9b649a2a784ca94600206f3d7576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Sat, 3 Nov 2018 16:02:01 +0100 Subject: [PATCH 1/2] hot fix --- app/src/main/AndroidManifest.xml | 4 +- .../findmytutor/activity/BaseActivity.java | 100 +++++++++--------- .../wmi/findmytutor/activity/MapActivity.java | 16 --- .../activity/SettingsActivity.java | 29 +---- 4 files changed, 58 insertions(+), 91 deletions(-) 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) { From 64256d2d677bf8e90463e08c89ed2531a60e0c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Sat, 3 Nov 2018 16:15:55 +0100 Subject: [PATCH 2/2] Update login validation --- .../uam/wmi/findmytutor/activity/LoginActivity.java | 12 ++---------- .../com/uam/wmi/findmytutor/utils/PrefUtils.java | 2 +- app/src/main/res/values-pl/strings.xml | 3 +-- app/src/main/res/values/strings.xml | 5 +++-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index 6b33d70..bc7c95f 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -114,10 +114,6 @@ public class LoginActivity extends AppCompatActivity { mPasswordView.setError(getString(R.string.error_field_required)); focusView = mPasswordView; cancel = true; - } else if (!isPasswordValid(password)) { - mPasswordView.setError(getString(R.string.error_invalid_password)); - focusView = mPasswordView; - cancel = true; } if (cancel) { @@ -130,13 +126,9 @@ public class LoginActivity extends AppCompatActivity { } private boolean isEmailValid(String loginName) { - Pattern pattern = Pattern.compile("^s\\d+"); + Pattern pattern = Pattern.compile("\\s"); Matcher matcher = pattern.matcher(loginName); - return matcher.find(); - } - - private boolean isPasswordValid(String password) { - return password.length() > 4; + return !matcher.find(); } @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java index 2977ea2..f6b7d13 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java @@ -121,7 +121,7 @@ public class PrefUtils { } public static String getLocale(Context context) { - return getSharedPreferences(context).getString("LOCALE", null); + return getSharedPreferences(context).getString("LOCALE", "pl"); } diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index b686890..7f81b8f 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -111,13 +111,12 @@ Notatka Dyżury Dyżury - Niepoprawny format loginu. Zakład Loading … Logo find my tutor Login (Ldap) Zaloguj! - + Niepoprawny format loginu. Lista użytkowników diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d7eab17..264cb47 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -170,12 +170,13 @@ Note Duty Hours Duty Hours - Invalid format login. Use s11111 format + Department Loading … Logo find my tutor - Login (sXXXXXX) + Login (Ldap) Log in Users list + Invalid login format.