Browse Source

Refactor commits (#452)

code reformat

check for same gitea version

change link to button `view in browser`

add search by commit hash

Fix crash for custom attr caused by context and clean up

Refactor commits, remove fastadapter

Co-authored-by: 6543 <6543@noreply.gitea.io>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: #452
Reviewed-by: 6543 <6543@noreply.gitea.io>
pull/464/head
parent
commit
195bfc8fe2
9 changed files with 366 additions and 312 deletions
  1. +0
    -1
      README.md
  2. +0
    -5
      app/build.gradle
  3. +169
    -207
      app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java
  4. +103
    -90
      app/src/main/java/org/mian/gitnex/adapters/CommitsAdapter.java
  5. +76
    -0
      app/src/main/java/org/mian/gitnex/clients/AppApiService.java
  6. +1
    -1
      app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java
  7. +1
    -1
      app/src/main/java/org/mian/gitnex/fragments/PullRequestsFragment.java
  8. +4
    -0
      app/src/main/java/org/mian/gitnex/models/Commits.java
  9. +12
    -7
      app/src/main/res/layout/list_commits.xml

+ 0
- 1
README.md View File

@@ -86,7 +86,6 @@ Open source libraries
- Caverock/androidsvg
- Droidsonroids.gif/android-gif-drawable
- Barteksc/AndroidPdfViewer
- Mikepenz/fastadapter
- Ge0rg/MemorizingTrustManager

[Follow me on Fediverse - mastodon.social/@mmarif](https://mastodon.social/@mmarif)

+ 0
- 5
app/build.gradle View File

@@ -35,7 +35,6 @@ configurations {
dependencies {
def lifecycle_version = "2.2.0"
def markwon_version = '4.3.1'
def fastadapter = "3.3.1"
def acra = "5.5.0"

implementation fileTree(include: ['*.jar'], dir: 'libs')
@@ -82,10 +81,6 @@ dependencies {
implementation "com.github.chrisbanes:PhotoView:2.3.0"
implementation "com.pddstudio:highlightjs-android:1.5.0"
implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
//noinspection GradleDependency
implementation "com.mikepenz:fastadapter:$fastadapter"
implementation "com.mikepenz:fastadapter-commons:$fastadapter"
implementation "com.mikepenz:fastadapter-extensions:$fastadapter"
implementation "ch.acra:acra-mail:$acra"
implementation "ch.acra:acra-limiter:$acra"
implementation "ch.acra:acra-notification:$acra"


+ 169
- 207
app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java View File

@@ -1,5 +1,6 @@
package org.mian.gitnex.activities;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.method.ScrollingMovementMethod;
@@ -13,312 +14,273 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.mikepenz.fastadapter.IItemAdapter;
import com.mikepenz.fastadapter.adapters.ItemAdapter;
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter;
import com.mikepenz.fastadapter.listeners.ItemFilterListener;
import com.mikepenz.fastadapter_extensions.items.ProgressItem;
import com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.adapters.CommitsAdapter;
import org.mian.gitnex.clients.AppApiService;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.VersionCheck;
import org.mian.gitnex.interfaces.ApiInterface;
import org.mian.gitnex.models.Commits;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static com.mikepenz.fastadapter.adapters.ItemAdapter.items;

/**
* Author M M Arif
*/

public class CommitsActivity extends BaseActivity implements ItemFilterListener<CommitsAdapter> {
public class CommitsActivity extends BaseActivity {

private View.OnClickListener onClickListener;
private TextView noData;
private ProgressBar progressBar;
private SwipeRefreshLayout swipeRefreshLayout;
private String TAG = "CommitsActivity - ";
private int resultLimit = 50;
private boolean loadNextFlag = false;
private Context ctx;
private View.OnClickListener onClickListener;
private TextView noData;
private ProgressBar progressBar;
private String TAG = "CommitsActivity";
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
private int pageSize = 1;

private List<CommitsAdapter> items = new ArrayList<>();
private FastItemAdapter<CommitsAdapter> fastItemAdapter;
private ItemAdapter footerAdapter;
private EndlessRecyclerOnScrollListener endlessRecyclerOnScrollListener;
private RecyclerView recyclerView;
private List<Commits> commitsList;
private CommitsAdapter adapter;
private ApiInterface api;

@Override
protected int getLayoutResourceId(){
return R.layout.activity_commits;
}
@Override
protected int getLayoutResourceId() {

@Override
public void onCreate(Bundle savedInstanceState) {
return R.layout.activity_commits;
}

super.onCreate(savedInstanceState);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@Override
public void onCreate(Bundle savedInstanceState) {

TinyDB tinyDb = new TinyDB(getApplicationContext());
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
super.onCreate(savedInstanceState);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ctx = this;

String branchName = getIntent().getStringExtra("branchName");
TinyDB tinyDb = new TinyDB(ctx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];

TextView toolbar_title = findViewById(R.id.toolbar_title);
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
toolbar_title.setText(branchName);
String branchName = getIntent().getStringExtra("branchName");

ImageView closeActivity = findViewById(R.id.close);
noData = findViewById(R.id.noDataCommits);
progressBar = findViewById(R.id.progress_bar);
swipeRefreshLayout = findViewById(R.id.pullToRefresh);
TextView toolbar_title = findViewById(R.id.toolbar_title);
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
toolbar_title.setText(branchName);

RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
recyclerView.setHasFixedSize(true);
ImageView closeActivity = findViewById(R.id.close);
noData = findViewById(R.id.noDataCommits);
progressBar = findViewById(R.id.progress_bar);
SwipeRefreshLayout swipeRefresh = findViewById(R.id.pullToRefresh);

initCloseListener();
closeActivity.setOnClickListener(onClickListener);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);

fastItemAdapter = new FastItemAdapter<>();
fastItemAdapter.withSelectable(true);
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) >= 1) {
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
}

footerAdapter = items();
//noinspection unchecked
fastItemAdapter.addAdapter(1, footerAdapter);
recyclerView = findViewById(R.id.recyclerView);
commitsList = new ArrayList<>();

fastItemAdapter.getItemFilter().withFilterPredicate((IItemAdapter.Predicate<CommitsAdapter>) (item, constraint) -> item.getCommitTitle().toLowerCase().contains(Objects.requireNonNull(constraint).toString().toLowerCase()));
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {

fastItemAdapter.getItemFilter().withItemFilterListener(this);
swipeRefresh.setRefreshing(false);
loadInitial(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName);
adapter.notifyDataChanged();

recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(fastItemAdapter);
}, 200));

endlessRecyclerOnScrollListener = new EndlessRecyclerOnScrollListener(footerAdapter) {
adapter = new CommitsAdapter(ctx, commitsList);
adapter.setLoadMoreListener(() -> recyclerView.post(() -> {

@Override
public void onLoadMore(final int currentPage) {
if(commitsList.size() == resultLimit || pageSize == resultLimit) {

loadNext(instanceUrl, instanceToken, repoOwner, repoName, currentPage, branchName);
int page = (commitsList.size() + resultLimit) / resultLimit;
loadMore(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, branchName);

}
}

};
}));

swipeRefreshLayout.setOnRefreshListener(() -> {
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
recyclerView.setAdapter(adapter);

progressBar.setVisibility(View.VISIBLE);
fastItemAdapter.clear();
endlessRecyclerOnScrollListener.resetPageCount();
swipeRefreshLayout.setRefreshing(false);
api = AppApiService.createService(ApiInterface.class, instanceUrl, ctx);
loadInitial(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName);

});
}

recyclerView.addOnScrollListener(endlessRecyclerOnScrollListener);
private void loadInitial(String token, String repoOwner, String repoName, String branchName) {

loadInitial(instanceUrl, instanceToken, repoOwner, repoName, branchName);
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, 1, branchName);

assert savedInstanceState != null;
fastItemAdapter.withSavedInstanceState(savedInstanceState);
call.enqueue(new Callback<List<Commits>>() {

}
@Override
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {

private void loadInitial(String instanceUrl, String token, String repoOwner, String repoName, String branchName) {
if(response.isSuccessful()) {

Call<List<Commits>> call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getRepositoryCommits(token, repoOwner, repoName, 1, branchName);
assert response.body() != null;
if(response.body().size() > 0) {

call.enqueue(new Callback<List<Commits>>() {
commitsList.clear();
commitsList.addAll(response.body());
adapter.notifyDataChanged();
noData.setVisibility(View.GONE);

@Override
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
}
else {
commitsList.clear();
adapter.notifyDataChanged();
noData.setVisibility(View.VISIBLE);
}

if (response.isSuccessful()) {
progressBar.setVisibility(View.GONE);

assert response.body() != null;
}
else {

if(response.body().size() > 0) {
Log.e(TAG, String.valueOf(response.code()));

if(response.body().size() == resultLimit) {
loadNextFlag = true;
}
}

for (int i = 0; i < response.body().size(); i++) {
}

items.add(new CommitsAdapter(getApplicationContext()).withNewItems(response.body().get(i).getCommit().getMessage(), response.body().get(i).getHtml_url(),
response.body().get(i).getCommit().getCommitter().getName(), response.body().get(i).getCommit().getCommitter().getDate()));
@Override
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {

}
Log.e(TAG, t.toString());
}

fastItemAdapter.add(items);
});

}
else {
}

noData.setVisibility(View.VISIBLE);
private void loadMore(String token, String repoOwner, String repoName, final int page, String branchName) {

}
//add loading progress view
commitsList.add(new Commits("load"));
adapter.notifyItemInserted((commitsList.size() - 1));

progressBar.setVisibility(View.GONE);
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, page, branchName);

}
else {
call.enqueue(new Callback<List<Commits>>() {

Log.e(TAG, String.valueOf(response.code()));
@Override
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {

}
if(response.isSuccessful()) {

}
//remove loading view
commitsList.remove(commitsList.size() - 1);

@Override
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
List<Commits> result = response.body();

Log.e(TAG, t.toString());
assert result != null;
if(result.size() > 0) {

}
pageSize = result.size();
commitsList.addAll(result);

});
}
else {

}
Toasty.info(ctx, getString(R.string.noMoreData));
adapter.setMoreDataAvailable(false);

private void loadNext(String instanceUrl, String token, String repoOwner, String repoName, final int currentPage, String branchName) {
}

footerAdapter.clear();
//noinspection unchecked
footerAdapter.add(new ProgressItem().withEnabled(false));
Handler handler = new Handler();
adapter.notifyDataChanged();

handler.postDelayed(() -> {
}
else {

Call<List<Commits>> call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getRepositoryCommits(token, repoOwner, repoName, currentPage + 1, branchName);
Log.e(TAG, String.valueOf(response.code()));

call.enqueue(new Callback<List<Commits>>() {
}

@Override
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
}

if (response.isSuccessful()) {
@Override
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {

assert response.body() != null;
Log.e(TAG, t.toString());

if (response.body().size() > 0) {
}

loadNextFlag = response.body().size() == resultLimit;
});

for (int i = 0; i < response.body().size(); i++) {
}

fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new CommitsAdapter(getApplicationContext()).withNewItems(response.body().get(i).getCommit().getMessage(),
response.body().get(i).getHtml_url(), response.body().get(i).getCommit().getCommitter().getName(),
response.body().get(i).getCommit().getCommitter().getDate()));
@Override
public boolean onCreateOptionsMenu(Menu menu) {

}
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search_menu, menu);

footerAdapter.clear();
MenuItem searchItem = menu.findItem(R.id.action_search);
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);

}
else {
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {

footerAdapter.clear();
}
@Override
public boolean onQueryTextSubmit(String query) {

progressBar.setVisibility(View.GONE);
return false;
}

}
else {
@Override
public boolean onQueryTextChange(String newText) {

Log.e(TAG, String.valueOf(response.code()));
filter(newText);
return true;
}

}
});

}
return super.onCreateOptionsMenu(menu);

@Override
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
}

Log.e(TAG, t.toString());
private void filter(String text) {

}
List<Commits> arr = new ArrayList<>();

});
for(Commits d : commitsList) {
if(d.getCommit().getMessage().toLowerCase().contains(text) || d.getSha().toLowerCase().contains(text)) {
arr.add(d);
}
}

}, 1000);
adapter.updateList(arr);
}

if(!loadNextFlag) {
private void initCloseListener() {

footerAdapter.clear();

}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search_menu, menu);

MenuItem searchItem = menu.findItem(R.id.action_search);
androidx.appcompat.widget.SearchView searchView = (androidx.appcompat.widget.SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);

searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {

@Override
public boolean onQueryTextSubmit(String query) {
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
fastItemAdapter.filter(newText);
return true;
}

});

endlessRecyclerOnScrollListener.enable();
return super.onCreateOptionsMenu(menu);

}

@Override
public void itemsFiltered(@Nullable CharSequence constraint, @Nullable List<CommitsAdapter> results) {
endlessRecyclerOnScrollListener.disable();
}

@Override
public void onReset() {
endlessRecyclerOnScrollListener.enable();
}

private void initCloseListener() {
onClickListener = view -> {
getIntent().removeExtra("branchName");
finish();
};
}
onClickListener = view -> {
getIntent().removeExtra("branchName");
finish();
};
}

}



+ 103
- 90
app/src/main/java/org/mian/gitnex/adapters/CommitsAdapter.java View File

@@ -1,18 +1,21 @@
package org.mian.gitnex.adapters;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.items.AbstractItem;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.models.Commits;
import org.mian.gitnex.util.TinyDB;
import java.util.Date;
import java.util.List;
import java.util.Locale;

@@ -20,142 +23,152 @@ import java.util.Locale;
* Author M M Arif
*/

public class CommitsAdapter extends AbstractItem<CommitsAdapter, CommitsAdapter.ViewHolder> {
public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

final private Context ctx;
private String commitTitle;
private String commitHtmlUrl;
private String commitCommitter;
private Date commitDate;
private Context ctx;
private final int TYPE_LOAD = 0;
private List<Commits> commitsList;
private CommitsAdapter.OnLoadMoreListener loadMoreListener;
private boolean isLoading = false;
private boolean isMoreDataAvailable = true;

private boolean isSelectable = true;
public CommitsAdapter(Context ctx, List<Commits> commitsListMain) {

public CommitsAdapter(Context ctx) {
this.ctx = ctx;
}

public CommitsAdapter withNewItems(String commitTitle, String commitHtmlUrl, String commitCommitter, Date commitDate) {

this.setNewItems(commitTitle, commitHtmlUrl, commitCommitter, commitDate);
return this;
this.commitsList = commitsListMain;

}

private void setNewItems(String commitTitle, String commitHtmlUrl, String commitCommitter, Date commitDate) {

this.commitTitle = commitTitle;
this.commitHtmlUrl = commitHtmlUrl;
this.commitCommitter = commitCommitter;
this.commitDate = commitDate;
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

}
LayoutInflater inflater = LayoutInflater.from(ctx);

public String getCommitTitle() {
return commitTitle;
}
if(viewType == TYPE_LOAD) {
return new CommitsHolder(inflater.inflate(R.layout.list_commits, parent, false));
}
else {
return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
}

private String getCommitHtmlUrl() {
return commitHtmlUrl;
}

private String getcommitCommitter() {
return commitCommitter;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

private Date getcommitDate() {
return commitDate;
}
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {

@Override
public boolean isEnabled() {
return true;
}
isLoading = true;
loadMoreListener.onLoadMore();

@Override
public CommitsAdapter withEnabled(boolean enabled) {
return null;
}
}

@Override
public boolean isSelectable() {
return isSelectable;
}
if(getItemViewType(position) == TYPE_LOAD) {

@Override
public CommitsAdapter withSelectable(boolean selectable) {
((CommitsHolder) holder).bindData(commitsList.get(position));

this.isSelectable = selectable;
return this;
}

}

@Override
public int getType() {
return R.id.commitList;
}
public int getItemViewType(int position) {

if(commitsList.get(position).getSha() != null) {
return TYPE_LOAD;
}
else {
return 1;
}

@Override
public int getLayoutRes() {
return R.layout.list_commits;
}

@NonNull
@Override
public CommitsAdapter.ViewHolder getViewHolder(@NonNull View v) {
public int getItemCount() {

return new CommitsAdapter.ViewHolder(v);
return commitsList.size();

}

public class ViewHolder extends FastAdapter.ViewHolder<CommitsAdapter> {
class CommitsHolder extends RecyclerView.ViewHolder {

final TinyDB tinyDb = new TinyDB(ctx);
final String locale = tinyDb.getString("locale");
final String timeFormat = tinyDb.getString("dateFormat");
TextView commitTitle;
TextView commitCommitter;
TextView commitDate;
Button commitHtmlUrl;

TextView commitTitleVw;
TextView commitCommitterVw;
TextView commitDateVw;
TextView commitHtmlUrlVw;

public ViewHolder(View itemView) {
CommitsHolder(View itemView) {

super(itemView);

commitTitleVw = itemView.findViewById(R.id.commitTitleVw);
commitCommitterVw = itemView.findViewById(R.id.commitCommitterVw);
commitDateVw = itemView.findViewById(R.id.commitDateVw);
commitHtmlUrlVw = itemView.findViewById(R.id.commitHtmlUrlVw);
commitTitle = itemView.findViewById(R.id.commitTitleVw);
commitCommitter = itemView.findViewById(R.id.commitCommitterVw);
commitDate = itemView.findViewById(R.id.commitDateVw);
commitHtmlUrl = itemView.findViewById(R.id.commitHtmlUrlVw);

}

@Override
public void bindView(CommitsAdapter item, @NonNull List<Object> payloads) {
@SuppressLint("SetTextI18n")
void bindData(Commits commitsModel) {

final TinyDB tinyDb = new TinyDB(ctx);
final String locale = tinyDb.getString("locale");
final String timeFormat = tinyDb.getString("dateFormat");

commitTitleVw.setText(item.getCommitTitle());
commitCommitterVw.setText(ctx.getString(R.string.commitCommittedBy, item.getcommitCommitter()));
commitTitle.setText(commitsModel.getCommit().getMessage());
commitCommitter.setText(ctx.getString(R.string.commitCommittedBy, commitsModel.getCommit().getCommitter().getName()));

commitDateVw.setText(TimeHelper.formatTime(item.getcommitDate(), new Locale(locale), timeFormat, ctx));
commitDate.setText(TimeHelper.formatTime(commitsModel.getCommit().getCommitter().getDate(), new Locale(locale), timeFormat, ctx));

if(timeFormat.equals("pretty")) {
commitDateVw.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(item.getcommitDate()), ctx));
commitDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(commitsModel.getCommit().getCommitter().getDate()), ctx));
}

commitHtmlUrlVw.setText(Html.fromHtml("<a href='" + item.getCommitHtmlUrl() + "'>" + ctx.getResources().getString(R.string.viewInBrowser) + "</a> "));
commitHtmlUrlVw.setMovementMethod(LinkMovementMethod.getInstance());
commitHtmlUrl.setOnClickListener(v -> ctx.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(commitsModel.getHtml_url()))));

}

@Override
public void unbindView(@NonNull CommitsAdapter item) {
}

static class LoadHolder extends RecyclerView.ViewHolder {

commitTitleVw.setText(null);
commitCommitterVw.setText(null);
commitDateVw.setText(null);
commitHtmlUrlVw.setText(null);
LoadHolder(View itemView) {

super(itemView);
}

}

public void setMoreDataAvailable(boolean moreDataAvailable) {

isMoreDataAvailable = moreDataAvailable;

}

public void notifyDataChanged() {

notifyDataSetChanged();
isLoading = false;

}

public interface OnLoadMoreListener {

void onLoadMore();

}

public void setLoadMoreListener(CommitsAdapter.OnLoadMoreListener loadMoreListener) {

this.loadMoreListener = loadMoreListener;

}

public void updateList(List<Commits> list) {

commitsList = list;
notifyDataSetChanged();
}

}

+ 76
- 0
app/src/main/java/org/mian/gitnex/clients/AppApiService.java View File

@@ -0,0 +1,76 @@
package org.mian.gitnex.clients;

import android.content.Context;
import android.util.Log;
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
import org.mian.gitnex.util.AppUtil;
import java.io.File;
import java.security.SecureRandom;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
* Author M M Arif
*/

public class AppApiService {

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(chain -> {

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
- 1
app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java View File

@@ -76,7 +76,7 @@ public class IssuesFragment extends Fragment {
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);

// if gitea is 1.12 or higher use the new limit
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) < 1) {
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) >= 1) {
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
}



+ 1
- 1
app/src/main/java/org/mian/gitnex/fragments/PullRequestsFragment.java View File

@@ -76,7 +76,7 @@ public class PullRequestsFragment extends Fragment {
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);

// if gitea is 1.12 or higher use the new limit
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) < 1) {
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) >= 1) {
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
}



+ 4
- 0
app/src/main/java/org/mian/gitnex/models/Commits.java View File

@@ -29,6 +29,10 @@ public class Commits {
return html_url;
}

public Commits(String url) {
this.url = url;
}

public static class commitObject {

private String url;


+ 12
- 7
app/src/main/res/layout/list_commits.xml View File

@@ -1,10 +1,10 @@
<?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:id="@+id/commitList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".activities.CommitsActivity"
android:background="?attr/primaryBackgroundColor">

<LinearLayout
@@ -37,7 +37,6 @@
android:id="@+id/frameViewnDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<LinearLayout
@@ -47,13 +46,18 @@
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
<Button
android:id="@+id/commitHtmlUrlVw"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_height="wrap_content"
android:text="@string/viewInBrowser"
android:textColorLink="@color/lightBlue"
android:textSize="14sp" />
android:layout_marginTop="15dp"
android:textColor="@color/btnTextColor"
android:textSize="14sp"
android:minHeight="0dp"
android:minWidth="0dp"
android:padding="8dp"
android:background="@drawable/shape_buttons" />

</LinearLayout>

@@ -64,7 +68,8 @@
android:layout_height="wrap_content"
android:gravity="end"
android:textColor="?attr/primaryTextColor"
android:textSize="14sp" />
android:textSize="14sp"
android:layout_marginTop="20dp"/>

</LinearLayout>



Loading…
Cancel
Save