From 3c795c6eef4d8637ef67691053897a8e0fddab77 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Wed, 31 Jan 2018 21:57:50 +0100 Subject: [PATCH] upgrade to minSdkVersion 18, fix some lint warnings --- app/build.gradle | 2 +- .../keylesspalace/tusky/ComposeActivity.java | 3 +- .../tusky/EditProfileActivity.java | 50 ++++++------------- .../keylesspalace/tusky/util/OkHttpUtils.java | 19 +++---- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 97f2e71cd..036c73439 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { buildToolsVersion '27.0.1' defaultConfig { applicationId "com.keylesspalace.tusky" - minSdkVersion 15 + minSdkVersion 18 targetSdkVersion 27 versionCode 31 versionName "1.4.1" diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index beb846786..36652b9b0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -1030,8 +1030,7 @@ public final class ComposeActivity extends BaseActivity } private void onMediaPick() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && - ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, diff --git a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.java b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.java index ccc6950e0..56f71006f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/EditProfileActivity.java @@ -23,7 +23,6 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -109,7 +108,7 @@ public class EditProfileActivity extends BaseActivity { setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { - actionBar.setTitle(getString(R.string.title_edit_profile)); + actionBar.setTitle(R.string.title_edit_profile); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); } @@ -130,39 +129,23 @@ public class EditProfileActivity extends BaseActivity { headerBase64 = null; } - avatarButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onMediaPick(PickType.AVATAR); - } - }); - headerButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onMediaPick(PickType.HEADER); - } - }); + avatarButton.setOnClickListener(v -> onMediaPick(PickType.AVATAR)); + headerButton.setOnClickListener(v -> onMediaPick(PickType.HEADER)); - avatarPreview.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - avatarPreview.setImageBitmap(null); - avatarPreview.setVisibility(View.INVISIBLE); - avatarBase64 = null; - } + avatarPreview.setOnClickListener(v -> { + avatarPreview.setImageBitmap(null); + avatarPreview.setVisibility(View.INVISIBLE); + avatarBase64 = null; }); - headerPreview.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - headerPreview.setImageBitmap(null); - headerPreview.setVisibility(View.INVISIBLE); - headerBase64 = null; - } + headerPreview.setOnClickListener(v -> { + headerPreview.setImageBitmap(null); + headerPreview.setVisibility(View.INVISIBLE); + headerBase64 = null; }); mastodonApi.accountVerifyCredentials().enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(@NonNull Call call, @NonNull Response response) { if (!response.isSuccessful()) { onAccountVerifyCredentialsFailed(); return; @@ -187,7 +170,7 @@ public class EditProfileActivity extends BaseActivity { } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { onAccountVerifyCredentialsFailed(); } }); @@ -214,8 +197,7 @@ public class EditProfileActivity extends BaseActivity { return; } currentlyPicking = pickType; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && - ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, @@ -314,7 +296,7 @@ public class EditProfileActivity extends BaseActivity { profile.header = headerBase64; mastodonApi.accountUpdateCredentials(profile).enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(@NonNull Call call, @NonNull Response response) { if (!response.isSuccessful()) { onSaveFailure(); return; @@ -326,7 +308,7 @@ public class EditProfileActivity extends BaseActivity { } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(@NonNull Call call, @NonNull Throwable t) { onSaveFailure(); } }); diff --git a/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java index 0873b2189..eeafffde9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/OkHttpUtils.java @@ -17,7 +17,6 @@ package com.keylesspalace.tusky.util; import android.content.SharedPreferences; import android.os.Build; -import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.util.Log; @@ -48,7 +47,6 @@ import okhttp3.ConnectionSpec; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.Response; public class OkHttpUtils { private static final String TAG = "OkHttpUtils"; // logging tag @@ -108,15 +106,12 @@ public class OkHttpUtils { */ @NonNull private static Interceptor getUserAgentInterceptor() { - return new Interceptor() { - @Override - public Response intercept(Chain chain) throws IOException { - Request originalRequest = chain.request(); - Request requestWithUserAgent = originalRequest.newBuilder() - .header("User-Agent", "Tusky/"+ BuildConfig.VERSION_NAME+" Android/"+Build.VERSION.RELEASE) - .build(); - return chain.proceed(requestWithUserAgent); - } + return chain -> { + Request originalRequest = chain.request(); + Request requestWithUserAgent = originalRequest.newBuilder() + .header("User-Agent", "Tusky/"+ BuildConfig.VERSION_NAME+" Android/"+Build.VERSION.RELEASE) + .build(); + return chain.proceed(requestWithUserAgent); }; } @@ -164,7 +159,7 @@ public class OkHttpUtils { } private static OkHttpClient.Builder enableHigherTlsOnPreLollipop(OkHttpClient.Builder builder) { - if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) { + if (Build.VERSION.SDK_INT < 22) { try { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm());