Skip to content

Commit

Permalink
Version 1.0.1.97
Browse files Browse the repository at this point in the history
What's new:
- Optimization for Android 10

Signed-off-by: developerfromjokela <developerfromjokela@gmail.com>
  • Loading branch information
developerfromjokela committed Sep 10, 2020
1 parent a2b591c commit 60def54
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 76 deletions.
32 changes: 16 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'com.android.application'
def versionMajor = 1
def versionMinor = 0
def versionPatch = 1
def versionBuild = 96 // 0-50=Alpha / 51-98=RC / 90-99=stable
def versionBuild = 97 // 0-50=Alpha / 51-98=RC / 90-99=stable
android {
compileSdkVersion 30
defaultConfig {
Expand Down Expand Up @@ -42,25 +42,25 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
implementation 'com.squareup.okhttp3:okhttp:3.13.1'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.5.0'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.preference:preference:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.github.MikeOrtiz:TouchImageView:1.4.1'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
//implementation 'com.github.niqdev:mjpeg-view:1.6.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,28 @@ public static <T> T createService(Class<T> serviceClass, String BASE_URL) throws
if (retrofit == null) {


// example.com because we don't need baseurl, but it's required
retrofit = new Retrofit.Builder()
.client(createOkHttpClientNoCache())
.baseUrl(BASE_URL)
.baseUrl("http://example.com")
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit.create(serviceClass);
}

private static OkHttpClient createOkHttpClientNoCache() throws NoSuchAlgorithmException {
private static OkHttpClient createOkHttpClientNoCache() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
if (!BuildConfig.DEBUG)
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
SSLContext sslContext = SSLContext.getDefault();
return new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60 / 2, TimeUnit.SECONDS)
.addInterceptor(logging)
.writeTimeout(60, TimeUnit.SECONDS)
.cache(null)
.hostnameVerifier(motionEyeVerifier)
.sslSocketFactory(sslContext.getSocketFactory())
.build();
}

Expand All @@ -76,7 +75,6 @@ private static OkHttpClient createOkHttpClient(Context context, boolean enableCa
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
if (!BuildConfig.DEBUG)
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
SSLContext sslContext = SSLContext.getDefault();
File httpCacheDirectory = new File(context.getCacheDir(), "http-cache");
int cacheSize = 20 * 1024 * 1024; // 10 MiB
okhttp3.Cache cache = new okhttp3.Cache(httpCacheDirectory, cacheSize);
Expand All @@ -89,7 +87,6 @@ private static OkHttpClient createOkHttpClient(Context context, boolean enableCa
.writeTimeout(60, TimeUnit.SECONDS)
.cache(cache)
.hostnameVerifier(motionEyeVerifier)
.sslSocketFactory(sslContext.getSocketFactory())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ public void onClick(View view) {
}


private static String removeSlash(String url) {
if (url.endsWith("/")) {
return url.substring(0, url.length() - 1);
} else
return url;
}

private void setListenersForSetupItems(View view, final int position) {

Log.e("Setup", String.valueOf(position));
Expand Down Expand Up @@ -501,6 +508,7 @@ public void run() {
}
}

Log.e("SSS", url);
if (!URLUtil.isValidUrl(url)) {
url = "http://" + url;
if (URLUtil.isValidUrl(url))
Expand Down Expand Up @@ -714,6 +722,7 @@ public void onClick(View v) {
}


Log.e("SETUP", device.getDeviceUrlCombo());
validateServer(new TestInterface() {
@Override
public void TestSuccessful(String response, int status) {
Expand Down Expand Up @@ -862,55 +871,6 @@ public void TestFailed(String response, int status2) {

}


private void validateServer(TestInterface testInterface, String serverurl) {
Log.e("Setup", serverurl);
String baseurl;

Log.e("Setup", String.valueOf(serverurl.split("//").length));
if (!serverurl.contains("://"))
baseurl = removeSlash("http://" + serverurl);
else
baseurl = removeSlash(serverurl);

Log.e("Setup", baseurl);
ApiInterface apiInterface = null;
try {
apiInterface = ServiceGenerator.createService(ApiInterface.class, baseurl);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
testInterface.TestFailed(e.getMessage(), 700);
return;
}
Call<ResponseBody> call = apiInterface.login(baseurl + "/login", device.getUser().getUsername(), device.getUser().getPassword(), "login");
Log.e("Setup", baseurl);
call.enqueue(new Callback<ResponseBody>() {

@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.e("Setup", call.request().body().contentType().toString());
try {
if (response.isSuccessful())
testInterface.TestSuccessful(Jsoup.parse(response.body().string()).wholeText(), response.code());
else
testInterface.TestFailed(Jsoup.parse(response.errorBody().string()).wholeText(), response.code());
} catch (Exception e) {
e.printStackTrace();
testInterface.TestFailed(e.getMessage(), 700);

}
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
t.printStackTrace();
t.fillInStackTrace();
testInterface.TestFailed(t.getMessage(), 700);

}
});
}

private void getServerDetails(TestInterface testInterface, String serverurl) {
Log.e("Setup", serverurl);
String baseurl;
Expand Down Expand Up @@ -1075,12 +1035,52 @@ public void onFailure(Call<ResponseBody> call, Throwable t) {
});
}

private static String removeSlash(String url) {
if (!url.endsWith("/"))
return url;
String[] parts = url.split("/");
private void validateServer(TestInterface testInterface, String serverurl) {
Log.e("Setup1", serverurl);
String baseurl;

Log.e("Setup2", String.valueOf(serverurl.split("//").length));
if (!serverurl.contains("://"))
baseurl = removeSlash("http://" + serverurl);
else
baseurl = removeSlash(serverurl);

Log.e("Setup3", baseurl);
ApiInterface apiInterface = null;
try {
apiInterface = ServiceGenerator.createService(ApiInterface.class, baseurl);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
testInterface.TestFailed(e.getMessage(), 700);
return;
}
Call<ResponseBody> call = apiInterface.login(baseurl + "/login", device.getUser().getUsername(), device.getUser().getPassword(), "login");
Log.e("Setup", baseurl);
call.enqueue(new Callback<ResponseBody>() {

return parts[0];
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.e("Setup", call.request().body().contentType().toString());
try {
if (response.isSuccessful())
testInterface.TestSuccessful(Jsoup.parse(response.body().string()).wholeText(), response.code());
else
testInterface.TestFailed(Jsoup.parse(response.errorBody().string()).wholeText(), response.code());
} catch (Exception e) {
e.printStackTrace();
testInterface.TestFailed(e.getMessage(), 700);

}
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
t.printStackTrace();
t.fillInStackTrace();
testInterface.TestFailed(t.getMessage(), 700);

}
});
}

@Override
Expand Down

1 comment on commit 60def54

@developerfromjokela
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I correct, not for Android 10 but for Android 11

Please sign in to comment.