mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-26 16:04:07 +08:00
small refactor and cleanup
This commit is contained in:
parent
9d182821d2
commit
03528f653a
@ -1,84 +0,0 @@
|
|||||||
package org.mian.gitnex.clients;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
|
|
||||||
import org.mian.gitnex.util.AppUtil;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.X509TrustManager;
|
|
||||||
import okhttp3.Cache;
|
|
||||||
import okhttp3.Interceptor;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
|
||||||
import retrofit2.Retrofit;
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class IssuesService {
|
|
||||||
|
|
||||||
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context ctx) {
|
|
||||||
|
|
||||||
final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
|
|
||||||
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
|
|
||||||
int cacheSize = 50 * 1024 * 1024; // 50MB
|
|
||||||
Cache cache = new Cache(httpCacheDirectory, cacheSize);
|
|
||||||
|
|
||||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
|
||||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
||||||
|
|
||||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
|
||||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
|
||||||
|
|
||||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
||||||
.cache(cache)
|
|
||||||
//.addInterceptor(logging)
|
|
||||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
|
||||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
|
||||||
.addInterceptor(new Interceptor() {
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Response intercept(@NonNull Chain chain) throws IOException {
|
|
||||||
|
|
||||||
Request request = chain.request();
|
|
||||||
if(connToInternet) {
|
|
||||||
request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
|
|
||||||
}
|
|
||||||
return chain.proceed(request);
|
|
||||||
}
|
|
||||||
}).build();
|
|
||||||
|
|
||||||
Retrofit.Builder builder = new Retrofit.Builder()
|
|
||||||
.baseUrl(instanceURL)
|
|
||||||
.client(okHttpClient)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create());
|
|
||||||
|
|
||||||
Retrofit retrofit = builder.build();
|
|
||||||
return retrofit.create(serviceClass);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
Log.e("onFailure", e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
package org.mian.gitnex.clients;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
|
|
||||||
import org.mian.gitnex.util.AppUtil;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.X509TrustManager;
|
|
||||||
import okhttp3.Cache;
|
|
||||||
import okhttp3.Interceptor;
|
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
|
||||||
import retrofit2.Retrofit;
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class PullRequestsService {
|
|
||||||
|
|
||||||
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context ctx) {
|
|
||||||
|
|
||||||
final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
|
|
||||||
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
|
|
||||||
int cacheSize = 50 * 1024 * 1024; // 50MB
|
|
||||||
Cache cache = new Cache(httpCacheDirectory, cacheSize);
|
|
||||||
|
|
||||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
|
||||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
|
||||||
|
|
||||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
|
||||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
|
||||||
|
|
||||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
|
||||||
.cache(cache)
|
|
||||||
//.addInterceptor(logging)
|
|
||||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
|
||||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
|
||||||
.addInterceptor(new Interceptor() {
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Response intercept(@NonNull Chain chain) throws IOException {
|
|
||||||
|
|
||||||
Request request = chain.request();
|
|
||||||
if(connToInternet) {
|
|
||||||
request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
|
|
||||||
}
|
|
||||||
return chain.proceed(request);
|
|
||||||
}
|
|
||||||
}).build();
|
|
||||||
|
|
||||||
Retrofit.Builder builder = new Retrofit.Builder()
|
|
||||||
.baseUrl(instanceURL)
|
|
||||||
.client(okHttpClient)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create());
|
|
||||||
|
|
||||||
Retrofit retrofit = builder.build();
|
|
||||||
return retrofit.create(serviceClass);
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
Log.e("onFailure", e.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||||
import org.mian.gitnex.adapters.IssuesAdapter;
|
import org.mian.gitnex.adapters.IssuesAdapter;
|
||||||
import org.mian.gitnex.clients.IssuesService;
|
import org.mian.gitnex.clients.AppApiService;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
@ -143,7 +143,7 @@ public class IssuesFragment extends Fragment {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
api = IssuesService.createService(ApiInterface.class, instanceUrl, getContext());
|
api = AppApiService.createService(ApiInterface.class, instanceUrl, getContext());
|
||||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, resultLimit, requestType, tinyDb.getString("repoIssuesState"));
|
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, resultLimit, requestType, tinyDb.getString("repoIssuesState"));
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -23,7 +23,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||||
import org.mian.gitnex.adapters.PullRequestsAdapter;
|
import org.mian.gitnex.adapters.PullRequestsAdapter;
|
||||||
import org.mian.gitnex.clients.PullRequestsService;
|
import org.mian.gitnex.clients.AppApiService;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
@ -145,7 +145,7 @@ public class PullRequestsFragment extends Fragment {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
apiPR = PullRequestsService.createService(ApiInterface.class, instanceUrl, context);
|
apiPR = AppApiService.createService(ApiInterface.class, instanceUrl, context);
|
||||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, tinyDb.getString("repoPrState"), resultLimit);
|
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, tinyDb.getString("repoPrState"), resultLimit);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:context=".activities.RepoDetailActivity">
|
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
||||||
android:id="@+id/pullToRefreshClosed"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/recyclerViewClosed"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="?attr/primaryBackgroundColor"
|
|
||||||
android:padding="4dp"
|
|
||||||
android:scrollbars="vertical" />
|
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progress_barClosed"
|
|
||||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:indeterminate="true"
|
|
||||||
android:visibility="visible" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/noDataIssuesClosed"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_margin="15dp"
|
|
||||||
android:text="@string/noDataIssueTab"
|
|
||||||
android:textColor="?attr/primaryTextColor"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
@ -1,48 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?attr/primaryBackgroundColor"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:id="@+id/issuesMain">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:id="@+id/appbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:theme="@style/AppTheme.AppBarOverlay">
|
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
|
||||||
android:id="@+id/tabs"
|
|
||||||
app:tabMode="fixed"
|
|
||||||
app:tabTextAppearance="@style/customTabLayout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:background="?attr/primaryBackgroundColor"
|
|
||||||
app:tabTextColor="?attr/primaryTextColor"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabItem
|
|
||||||
android:id="@+id/issuesTabOpen"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/tabIssueOpen" />
|
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabItem
|
|
||||||
android:id="@+id/issuesTabClosed"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/tabIssueClosed" />
|
|
||||||
|
|
||||||
</com.google.android.material.tabs.TabLayout>
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
|
||||||
android:id="@+id/issuesContainer"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
Loading…
Reference in New Issue
Block a user