Browse Source

Kitkat specific fixes

pull/61/merge
Apostolos Fanakis 6 years ago
parent
commit
5acaea6dce
  1. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  2. 14
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  3. 37
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

9
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.activities.main;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
@ -11,6 +12,7 @@ import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentPagerAdapter;
@ -54,6 +56,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
private ViewPager viewPager; private ViewPager viewPager;
private TabLayout tabLayout; private TabLayout tabLayout;
//Fix for vector drawables on android <21
static {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

14
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -128,7 +128,7 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
updateDrawer(); updateDrawer();
if(!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key),false)) if (!sharedPreferences.getBoolean(getString(R.string.user_consent_shared_preference_key), false))
showUserConsentDialog(); showUserConsentDialog();
} }
@ -760,7 +760,7 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
//----------------------------PRIVACY POLICY------------------ //----------------------------PRIVACY POLICY------------------
private void showUserConsentDialog(){ private void showUserConsentDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle); AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
builder.setTitle("User Agreement"); builder.setTitle("User Agreement");
builder.setMessage(R.string.user_agreement_dialog_text); builder.setMessage(R.string.user_agreement_dialog_text);
@ -788,7 +788,7 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void showPrivacyPolicyDialog() { protected void showPrivacyPolicyDialog() {
TextView privacyPolicyTextView = new TextView(this); TextView privacyPolicyTextView = new TextView(this);
privacyPolicyTextView.setPadding(30,20,30,20); privacyPolicyTextView.setPadding(30, 20, 30, 20);
privacyPolicyTextView.setTextColor(ContextCompat.getColor(this, R.color.primary_text)); privacyPolicyTextView.setTextColor(ContextCompat.getColor(this, R.color.primary_text));
SpannableConfiguration configuration = SpannableConfiguration.builder(this).linkResolver(new LinkResolverDef()).build(); SpannableConfiguration configuration = SpannableConfiguration.builder(this).linkResolver(new LinkResolverDef()).build();
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
@ -812,7 +812,7 @@ public abstract class BaseActivity extends AppCompatActivity {
Timber.e(e, "Error in Privacy Policy dialog."); Timber.e(e, "Error in Privacy Policy dialog.");
} finally { } finally {
try { try {
if(reader!=null) if (reader != null)
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
Timber.e(e, "Error in Privacy Policy dialog (closing reader)."); Timber.e(e, "Error in Privacy Policy dialog (closing reader).");
@ -820,12 +820,12 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
} }
private void addUserConsent(){ private void addUserConsent() {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(getString(R.string.user_consent_shared_preference_key), true).apply(); editor.putBoolean(getString(R.string.user_consent_shared_preference_key), true).apply();
} }
private void setUserDataShareEnabled(boolean enabled){ private void setUserDataShareEnabled(boolean enabled) {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), enabled).apply(); editor.putBoolean(getString(R.string.pref_privacy_crashlytics_enable_key), enabled).apply();
editor.putBoolean(getString(R.string.pref_privacy_analytics_enable_key), enabled).apply(); editor.putBoolean(getString(R.string.pref_privacy_analytics_enable_key), enabled).apply();
@ -836,7 +836,7 @@ public abstract class BaseActivity extends AppCompatActivity {
this.mainActivity = mainActivity; this.mainActivity = mainActivity;
} }
private void startLoginActivity(){ private void startLoginActivity() {
Intent intent = new Intent(BaseActivity.this, LoginActivity.class); Intent intent = new Intent(BaseActivity.this, LoginActivity.class);
startActivity(intent); startActivity(intent);
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);

37
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.widget.ImageView; import android.widget.ImageView;
@ -25,6 +26,9 @@ import com.squareup.picasso.Picasso;
import net.gotev.uploadservice.UploadService; import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.okhttp.OkHttpStack; import net.gotev.uploadservice.okhttp.OkHttpStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -35,6 +39,8 @@ import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CrashReportingTree; import gr.thmmy.mthmmy.utils.CrashReportingTree;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
import okhttp3.CipherSuite;
import okhttp3.ConnectionSpec;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@ -82,14 +88,14 @@ public class BaseApplication extends Application {
firebaseAnalytics = FirebaseAnalytics.getInstance(this); firebaseAnalytics = FirebaseAnalytics.getInstance(this);
boolean enableAnalytics = settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_analytics_enable_key), false); boolean enableAnalytics = settingsSharedPrefs.getBoolean(getString(R.string.pref_privacy_analytics_enable_key), false);
firebaseAnalytics.setAnalyticsCollectionEnabled(enableAnalytics); firebaseAnalytics.setAnalyticsCollectionEnabled(enableAnalytics);
if(enableAnalytics) if (enableAnalytics)
Timber.i("Starting app with Analytics enabled."); Timber.i("Starting app with Analytics enabled.");
else else
Timber.i("Starting app with Analytics disabled."); Timber.i("Starting app with Analytics disabled.");
SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext());
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor);
client = new OkHttpClient.Builder() OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(cookieJar) .cookieJar(cookieJar)
.addInterceptor(chain -> { .addInterceptor(chain -> {
Request request = chain.request(); Request request = chain.request();
@ -103,9 +109,25 @@ public class BaseApplication extends Application {
} }
return chain.proceed(request); return chain.proceed(request);
}) })
.callTimeout(30, TimeUnit.SECONDS) .callTimeout(30, TimeUnit.SECONDS);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats
// Necessary because our servers don't have the right cipher suites.
// https://github.com/square/okhttp/issues/4053
List<CipherSuite> cipherSuites = new ArrayList<>(ConnectionSpec.MODERN_TLS.cipherSuites());
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
ConnectionSpec legacyTls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.cipherSuites(cipherSuites.toArray(new CipherSuite[0]))
.build(); .build();
sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs,draftsPrefs);
builder.connectionSpecs(Arrays.asList(legacyTls, ConnectionSpec.CLEARTEXT));
}
client = builder.build();
sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs, draftsPrefs);
Picasso picasso = new Picasso.Builder(getApplicationContext()) Picasso picasso = new Picasso.Builder(getApplicationContext())
.downloader(new OkHttp3Downloader(client)) .downloader(new OkHttp3Downloader(client))
.build(); .build();
@ -170,13 +192,13 @@ public class BaseApplication extends Application {
public void setFirebaseAnalyticsCollection(boolean enabled) { public void setFirebaseAnalyticsCollection(boolean enabled) {
firebaseAnalytics.setAnalyticsCollectionEnabled(enabled); firebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
if(!enabled) if (!enabled)
firebaseAnalytics.resetAnalyticsData(); firebaseAnalytics.resetAnalyticsData();
} }
// Set up Crashlytics, disabled for debug builds // Set up Crashlytics, disabled for debug builds
public void startFirebaseCrashlyticsCollection() { public void startFirebaseCrashlyticsCollection() {
if(!Fabric.isInitialized()){ if (!Fabric.isInitialized()) {
Crashlytics crashlyticsKit = new Crashlytics.Builder() Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()) .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build(); .build();
@ -184,8 +206,7 @@ public class BaseApplication extends Application {
Fabric.with(this, crashlyticsKit); Fabric.with(this, crashlyticsKit);
Timber.plant(new CrashReportingTree()); Timber.plant(new CrashReportingTree());
Timber.i("Crashlytics enabled."); Timber.i("Crashlytics enabled.");
} } else
else
Timber.i("Crashlytics were already initialized for this app session."); Timber.i("Crashlytics were already initialized for this app session.");
} }
} }

Loading…
Cancel
Save