Commit 21fa8be5 authored by M M Arif's avatar M M Arif

Fix login issues, fix url cache issue

Signed-off-by: M M Arif's avatarM M Arif <mmarif@swatian.com>
parent 352859aa
......@@ -37,6 +37,7 @@ dependencies {
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
......
......@@ -108,7 +108,6 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
private void login() {
TinyDB tinyDb = new TinyDB(getApplicationContext());
AppUtil appUtil = new AppUtil();
boolean connToInternet = AppUtil.haveNetworkConnection(LoginActivity.this);
tinyDb.remove("loginUid");
......@@ -119,17 +118,17 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
String loginUid = login_uid.getText().toString();
String loginPass = login_passwd.getText().toString();
if (!instanceUrl.startsWith("http://") || !instanceUrl.startsWith("https://")) {
instanceUrl = "https://" + instanceUrl + "/api/v1/";
if(AppUtil.httpCheck(instanceUrl)) {
instanceUrl = instanceUrl + "/api/v1/";
}
else {
instanceUrl = instanceUrl + "/api/v1/";
instanceUrl = "https://" + instanceUrl + "/api/v1/";
}
tinyDb.putString("loginUid", loginUid);
tinyDb.putString("instanceUrl", instanceUrl);
//Log.i("TinyDB old Token: ", tinyDb.getString("loginUid" + "-token"));
Log.i("instanceUrl: ", instanceUrl);
if(connToInternet) {
......
package org.mian.gitnex.clients;
import android.util.Log;
import org.mian.gitnex.interfaces.ApiInterface;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
......@@ -15,40 +12,27 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static RetrofitClient mInstance;
private Retrofit retrofit;
private RetrofitClient(String instanceUrl) {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
okhttp3.Response response = chain.proceed(request);
if (response.code() == 400 || response.code() == 500 || response.code() == 502) {
Log.i("Error-code", String.valueOf(response.code()));
return response;
}
return response;
}
})
.build();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
retrofit = new Retrofit.Builder()
.baseUrl(instanceUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
//.client(httpClient.build())
.build();
}
public static synchronized RetrofitClient getInstance(String instanceUrl) {
if (mInstance == null) {
mInstance = new RetrofitClient(instanceUrl);
}
return mInstance;
return new RetrofitClient(instanceUrl);
}
public ApiInterface getApiInterface() {
......
......@@ -84,4 +84,11 @@ public class AppUtil {
}
public static boolean httpCheck(String url) {
String pattern = "^(http|https)://.*$";
return url.matches(pattern);
}
}
<vector android:height="24dp" android:tint="#CFCFCF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
</vector>
<vector android:height="24dp" android:tint="#CFCFCF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/>
</vector>
<vector android:height="24dp" android:tint="#CFCFCF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>
<vector android:height="24dp" android:tint="#CFCFCF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM10,17l-4,-4 1.41,-1.41L10,14.17l6.59,-6.59L18,9l-8,8z"/>
</vector>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment