Update (Support Library / GSON / OkHttp)

This commit is contained in:
David-Development 2017-03-21 21:52:40 +01:00
parent a134e567f6
commit 8b4bcf2b66
15 changed files with 84 additions and 59 deletions

View file

@ -63,7 +63,7 @@ repositories {
} }
final SUPPORT_VERSION = '25.1.0' final SUPPORT_VERSION = '25.3.0'
dependencies { dependencies {
// core android studio module // core android studio module
@ -80,10 +80,12 @@ dependencies {
compile "com.android.support:customtabs:${SUPPORT_VERSION}" compile "com.android.support:customtabs:${SUPPORT_VERSION}"
compile 'de.mrmaffen:holocircularprogressbar:1.0.1' compile 'de.mrmaffen:holocircularprogressbar:1.0.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.google.code.gson:gson:2.4' compile 'com.google.code.gson:gson:2.8.0'
compile 'com.jakewharton:butterknife:7.0.1' compile 'com.jakewharton:butterknife:7.0.1'
//compile group: 'com.jakewharton', name: 'butterknife', version: '8.5.1'
compile 'com.sothree.slidinguppanel:library:3.2.1' compile 'com.sothree.slidinguppanel:library:3.2.1'
compile 'com.squareup.okhttp:okhttp:2.5.0' //compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'org.greenrobot:eventbus:3.0.0' compile 'org.greenrobot:eventbus:3.0.0'
compile 'de.greenrobot:greendao:2.0.0' compile 'de.greenrobot:greendao:2.0.0'
compile 'de.greenrobot:greendao-generator:2.0.0' compile 'de.greenrobot:greendao-generator:2.0.0'
@ -105,12 +107,15 @@ dependencies {
testCompile 'com.google.dexmaker:dexmaker-mockito:1.2' testCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'com.squareup.okhttp:mockwebserver:2.5.0' //androidTestCompile 'com.squareup.okhttp:mockwebserver:2.5.0'
// https://mvnrepository.com/artifact/com.squareup.okhttp3/mockwebserver
androidTestCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.6.0'
androidTestCompile "com.android.support:support-annotations:${SUPPORT_VERSION}" androidTestCompile "com.android.support:support-annotations:${SUPPORT_VERSION}"
androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') { androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
// this library uses the newest app compat v22 but the espresso contrib still v21. // this library uses the newest app compat v22 but the espresso contrib still v21.
// you have to specifically exclude the older versions of the contrib library or // you have to specifically exclude the older versions of the contrib library or

View file

@ -5,9 +5,6 @@ import android.test.suitebuilder.annotation.LargeTest;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -20,6 +17,9 @@ import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.owncloud.API; import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2; import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@LargeTest @LargeTest

View file

@ -4,8 +4,6 @@ import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import com.squareup.okhttp.HttpUrl;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -18,6 +16,7 @@ import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags; import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest; import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.owncloud.API; import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import okhttp3.HttpUrl;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@LargeTest @LargeTest

View file

@ -214,17 +214,19 @@ public class NewsReaderDetailFragment extends Fragment {
Log.v(TAG, "RefreshCurrentRssView"); Log.v(TAG, "RefreshCurrentRssView");
NewsListRecyclerAdapter nra = ((NewsListRecyclerAdapter) recyclerView.getAdapter()); NewsListRecyclerAdapter nra = ((NewsListRecyclerAdapter) recyclerView.getAdapter());
nra.refreshAdapterDataAsync(new NewsListRecyclerAdapter.IOnRefreshFinished() { if(nra != null) {
@Override nra.refreshAdapterDataAsync(new NewsListRecyclerAdapter.IOnRefreshFinished() {
public void OnRefreshFinished() { @Override
pbLoading.setVisibility(View.GONE); public void OnRefreshFinished() {
pbLoading.setVisibility(View.GONE);
if (layoutManagerSavedState != null) { if (layoutManagerSavedState != null) {
recyclerView.getLayoutManager().onRestoreInstanceState(layoutManagerSavedState); recyclerView.getLayoutManager().onRestoreInstanceState(layoutManagerSavedState);
layoutManagerSavedState = null; layoutManagerSavedState = null;
}
} }
} });
}); }
} }
/** /**

View file

@ -45,7 +45,6 @@ import android.widget.TextView;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer; import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.squareup.okhttp.HttpUrl;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -68,6 +67,7 @@ import de.luhmer.owncloudnewsreader.model.UserInfo;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest; import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.owncloud.API; import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
import okhttp3.HttpUrl;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView; import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
/** /**

View file

@ -51,7 +51,6 @@ import android.support.design.widget.AppBarLayout;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatCheckBox; import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.AppCompatCheckedTextView; import android.support.v7.widget.AppCompatCheckedTextView;
import android.support.v7.widget.AppCompatDrawableManager;
import android.support.v7.widget.AppCompatEditText; import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatRadioButton; import android.support.v7.widget.AppCompatRadioButton;
import android.support.v7.widget.AppCompatSpinner; import android.support.v7.widget.AppCompatSpinner;
@ -150,7 +149,7 @@ public class SettingsActivity extends PreferenceActivity {
Toolbar toolbar = (Toolbar) appBarLayout.getChildAt(0); Toolbar toolbar = (Toolbar) appBarLayout.getChildAt(0);
final Drawable backarrow = AppCompatDrawableManager.get().getDrawable(this, R.drawable.ic_arrow_back_black_24dp); final Drawable backarrow = ContextCompat.getDrawable(this, R.drawable.ic_arrow_back_black_24dp);
backarrow.setColorFilter(ContextCompat.getColor(this, R.color.tintColorDark), PorterDuff.Mode.SRC_ATOP); backarrow.setColorFilter(ContextCompat.getColor(this, R.color.tintColorDark), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(backarrow); toolbar.setNavigationIcon(backarrow);
toolbar.setTitle(R.string.title_activity_settings); toolbar.setTitle(R.string.title_activity_settings);

View file

@ -25,31 +25,36 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import de.luhmer.owncloudnewsreader.SettingsActivity; import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.model.Tuple; import de.luhmer.owncloudnewsreader.model.Tuple;
import de.luhmer.owncloudnewsreader.ssl.MemorizingTrustManager; import de.luhmer.owncloudnewsreader.ssl.MemorizingTrustManager;
import de.luhmer.owncloudnewsreader.ssl.TLSSocketFactory; import de.luhmer.owncloudnewsreader.ssl.TLSSocketFactory;
import okhttp3.Credentials;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class HttpJsonRequest { public class HttpJsonRequest {
@ -76,8 +81,24 @@ public class HttpJsonRequest {
private String credentials; private String credentials;
private HttpUrl oc_root_url; private HttpUrl oc_root_url;
private X509TrustManager systemDefaultTrustManager() {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:"
+ Arrays.toString(trustManagers));
}
return (X509TrustManager) trustManagers[0];
} catch (GeneralSecurityException e) {
throw new AssertionError(); // The system has no TLS. Just give up.
}
}
private HttpJsonRequest(Context context) { private HttpJsonRequest(Context context) {
client = new OkHttpClient(); OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
// set location of the keystore // set location of the keystore
MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks"); MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks");
@ -85,30 +106,32 @@ public class HttpJsonRequest {
// register MemorizingTrustManager for HTTPS // register MemorizingTrustManager for HTTPS
try { try {
SSLContext sc = SSLContext.getInstance("TLS"); SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, MemorizingTrustManager.getInstanceList(context), sc.init(null, MemorizingTrustManager.getInstanceList(context), new java.security.SecureRandom());
new java.security.SecureRandom());
// enables TLSv1.1/1.2 for Jelly Bean Devices // enables TLSv1.1/1.2 for Jelly Bean Devices
TLSSocketFactory tlsSocketFactory = new TLSSocketFactory(sc); TLSSocketFactory tlsSocketFactory = new TLSSocketFactory(sc);
client.setSslSocketFactory(tlsSocketFactory); clientBuilder.sslSocketFactory(tlsSocketFactory, systemDefaultTrustManager());
} catch (KeyManagementException | NoSuchAlgorithmException e) { } catch (KeyManagementException | NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();
} }
client.setConnectTimeout(10000, TimeUnit.MILLISECONDS); clientBuilder.connectTimeout(10, TimeUnit.SECONDS);
client.setReadTimeout(120, TimeUnit.SECONDS); clientBuilder.readTimeout(120, TimeUnit.SECONDS);
// disable hostname verification, when preference is set // disable hostname verification, when preference is set
// (this still shows a certification dialog, which requires user interaction!) // (this still shows a certification dialog, which requires user interaction!)
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
if(sp.getBoolean(SettingsActivity.CB_DISABLE_HOSTNAME_VERIFICATION_STRING, false)) if(sp.getBoolean(SettingsActivity.CB_DISABLE_HOSTNAME_VERIFICATION_STRING, false))
client.setHostnameVerifier(new HostnameVerifier() { clientBuilder.hostnameVerifier(new HostnameVerifier() {
@Override @Override
public boolean verify(String hostname, SSLSession session) { public boolean verify(String hostname, SSLSession session) {
return true; return true;
} }
}); });
imageClient = client.clone();
client.interceptors().add(new AuthorizationInterceptor());
clientBuilder.interceptors().add(new AuthorizationInterceptor());
imageClient = clientBuilder.build();
client = clientBuilder.build();
setCredentials(sp.getString(SettingsActivity.EDT_USERNAME_STRING, null), sp.getString(SettingsActivity.EDT_PASSWORD_STRING, null), sp.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null)); setCredentials(sp.getString(SettingsActivity.EDT_USERNAME_STRING, null), sp.getString(SettingsActivity.EDT_PASSWORD_STRING, null), sp.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null));
} }
@ -138,7 +161,7 @@ public class HttpJsonRequest {
Request request = chain.request(); Request request = chain.request();
// only add Authorization header for urls on the configured owncloud host // only add Authorization header for urls on the configured owncloud host
if(oc_root_url.host().equals(request.httpUrl().host())) if(oc_root_url.host().equals(request.url().host()))
request = request.newBuilder() request = request.newBuilder()
.addHeader("Authorization",credentials) .addHeader("Authorization",credentials)
.build(); .build();

View file

@ -4,14 +4,15 @@ import android.content.Context;
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream; import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader; import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.ResponseBody;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.ResponseBody;
public class OkHttpImageDownloader extends BaseImageDownloader { public class OkHttpImageDownloader extends BaseImageDownloader {
@SuppressWarnings("unused") @SuppressWarnings("unused")

View file

@ -23,8 +23,6 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
import android.content.Context; import android.content.Context;
import com.squareup.okhttp.HttpUrl;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.List; import java.util.List;
@ -33,6 +31,7 @@ import java.util.regex.Pattern;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags; import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2; import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
import okhttp3.HttpUrl;
public abstract class API { public abstract class API {
private HttpUrl baseUrl; private HttpUrl baseUrl;

View file

@ -25,7 +25,6 @@ import android.content.Context;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonToken;
import com.squareup.okhttp.HttpUrl;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -44,6 +43,7 @@ import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest; import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1; import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2; import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
import okhttp3.HttpUrl;
public class OwnCloudReaderMethods { public class OwnCloudReaderMethods {

View file

@ -24,8 +24,6 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import com.squareup.okhttp.HttpUrl;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -35,6 +33,7 @@ import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags; import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest; import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener; import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import okhttp3.HttpUrl;
public class OwnCloud_Reader { public class OwnCloud_Reader {

View file

@ -23,8 +23,6 @@ package de.luhmer.owncloudnewsreader.reader.owncloud.apiv1;
import android.content.Context; import android.content.Context;
import com.squareup.okhttp.HttpUrl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -32,6 +30,7 @@ import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.owncloud.API; import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
import okhttp3.HttpUrl;
public class APIv1 extends API { public class APIv1 extends API {

View file

@ -23,14 +23,13 @@ package de.luhmer.owncloudnewsreader.reader.owncloud.apiv2;
import android.content.Context; import android.content.Context;
import com.squareup.okhttp.HttpUrl;
import java.util.List; import java.util.List;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags; import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.owncloud.API; import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods; import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
import okhttp3.HttpUrl;
public class APIv2 extends API { public class APIv2 extends API {

View file

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
} }
} }

View file

@ -1,6 +1,6 @@
#Thu Aug 25 13:49:16 CEST 2016 #Fri Mar 10 18:52:43 CET 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip