final implementation and ui completion of commits list
This commit is contained in:
parent
c8164c56d0
commit
ea9025296a
@ -33,15 +33,15 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
def lifecycle_version = "2.2.0"
|
||||
final def markwon_version = '4.2.1'
|
||||
def paging_version = "2.1.2"
|
||||
def markwon_version = "4.2.1"
|
||||
def fastadapter = "3.3.1"
|
||||
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "androidx.appcompat:appcompat:1.1.0"
|
||||
implementation "com.google.android.material:material:1.2.0-alpha05"
|
||||
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
|
||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation "junit:junit:4.13"
|
||||
androidTestImplementation "androidx.test:runner:1.2.0"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
|
||||
implementation "com.github.vihtarb:tooltip:0.2.0"
|
||||
@ -80,5 +80,8 @@ 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"
|
||||
implementation "androidx.paging:paging-runtime:$paging_version"
|
||||
//noinspection GradleDependency
|
||||
implementation "com.mikepenz:fastadapter:$fastadapter"
|
||||
implementation "com.mikepenz:fastadapter-commons:$fastadapter"
|
||||
implementation "com.mikepenz:fastadapter-extensions:$fastadapter"
|
||||
}
|
||||
|
@ -1,78 +0,0 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.paging.PagedListAdapter;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.models.Commits;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CommitsAdapter extends PagedListAdapter<Commits, CommitsAdapter.CommitsViewHolder> {
|
||||
|
||||
private Context mCtx;
|
||||
|
||||
public CommitsAdapter(Context mCtx) {
|
||||
|
||||
super(DIFF_CALLBACK);
|
||||
this.mCtx = mCtx;
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CommitsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
View view = LayoutInflater.from(mCtx).inflate(R.layout.list_commits, parent, false);
|
||||
return new CommitsViewHolder(view);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CommitsViewHolder holder, int position) {
|
||||
|
||||
Commits commit_ = getItem(position);
|
||||
|
||||
if (commit_ != null) {
|
||||
holder.commitTitle.setText(commit_.getCommit().getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static DiffUtil.ItemCallback<Commits> DIFF_CALLBACK =
|
||||
new DiffUtil.ItemCallback<Commits>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(Commits oldCommit, Commits newCommit) {
|
||||
return oldCommit.getSha().equals(newCommit.getSha());
|
||||
}
|
||||
|
||||
@SuppressLint("DiffUtilEquals")
|
||||
@Override
|
||||
public boolean areContentsTheSame(Commits oldCommit, @NonNull Commits newCommit) {
|
||||
return oldCommit.equals(newCommit);
|
||||
}
|
||||
};
|
||||
|
||||
static class CommitsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView commitTitle;
|
||||
|
||||
CommitsViewHolder(View itemView) {
|
||||
|
||||
super(itemView);
|
||||
commitTitle = itemView.findViewById(R.id.commitTitle);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
package org.mian.gitnex.datasource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.paging.PageKeyedDataSource;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.models.Commits;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CommitsDataSource extends PageKeyedDataSource<Integer, Commits> {
|
||||
|
||||
private String TAG = "CommitsDataSource";
|
||||
private Context ctx;
|
||||
|
||||
private static final int FIRST_PAGE = 1;
|
||||
|
||||
private String instanceUrl;
|
||||
private String instanceToken;
|
||||
private String owner;
|
||||
private String repo;
|
||||
|
||||
CommitsDataSource(Context ctx, String instanceUrl, String instanceToken, String owner, String repo) {
|
||||
|
||||
this.ctx = ctx;
|
||||
this.instanceUrl = instanceUrl;
|
||||
this.instanceToken = instanceToken;
|
||||
this.owner = owner;
|
||||
this.repo = repo;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams<Integer> params, @NonNull final LoadInitialCallback<Integer, Commits> callback) {
|
||||
|
||||
RetrofitClient.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getRepositoryCommits(instanceToken, owner, repo, FIRST_PAGE)
|
||||
.enqueue(new Callback<List<Commits>>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
||||
|
||||
if (response.body() != null) {
|
||||
|
||||
callback.onResult(response.body(), null, FIRST_PAGE + 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, Objects.requireNonNull(t.getMessage()));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBefore(@NonNull final LoadParams<Integer> params, @NonNull final LoadCallback<Integer, Commits> callback) {
|
||||
|
||||
RetrofitClient.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getRepositoryCommits(instanceToken, owner, repo, params.key)
|
||||
.enqueue(new Callback<List<Commits>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
||||
|
||||
Integer adjacentKey = (params.key > 1) ? params.key - 1 : null;
|
||||
|
||||
if (response.body() != null) {
|
||||
|
||||
callback.onResult(response.body(), adjacentKey);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, Objects.requireNonNull(t.getMessage()));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAfter(@NonNull final LoadParams<Integer> params, @NonNull final LoadCallback<Integer, Commits> callback) {
|
||||
|
||||
RetrofitClient.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getRepositoryCommits(instanceToken, owner, repo, params.key)
|
||||
.enqueue(new Callback<List<Commits>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
||||
|
||||
if (response.body() != null) {
|
||||
|
||||
boolean next = false;
|
||||
if(response.body().size() > 0) {
|
||||
next = true;
|
||||
}
|
||||
|
||||
Integer key = next ? params.key + 1 : null;
|
||||
|
||||
callback.onResult(response.body(), key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, Objects.requireNonNull(t.getMessage()));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package org.mian.gitnex.datasource;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.paging.DataSource;
|
||||
import androidx.paging.PageKeyedDataSource;
|
||||
import org.mian.gitnex.models.Commits;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CommitsDataSourceFactory extends DataSource.Factory {
|
||||
|
||||
private Context ctx;
|
||||
private String instanceUrl;
|
||||
private String instanceToken;
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
private int listLimit;
|
||||
|
||||
public CommitsDataSourceFactory(Context ctx, String instanceUrl, String instanceToken, String repoOwner, String repoName, int listLimit) {
|
||||
|
||||
this.ctx = ctx;
|
||||
this.instanceUrl = instanceUrl;
|
||||
this.instanceToken = instanceToken;
|
||||
this.repoOwner = repoOwner;
|
||||
this.repoName = repoName;
|
||||
this.listLimit = listLimit;
|
||||
|
||||
}
|
||||
|
||||
private MutableLiveData<PageKeyedDataSource<Integer, Commits>> itemLiveDataSource = new MutableLiveData<>();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DataSource<Integer, Commits> create() {
|
||||
|
||||
CommitsDataSource itemDataSource = new CommitsDataSource(ctx, instanceUrl, instanceToken, repoOwner, repoName);
|
||||
itemLiveDataSource.postValue(itemDataSource);
|
||||
return itemDataSource;
|
||||
|
||||
}
|
||||
|
||||
public MutableLiveData<PageKeyedDataSource<Integer, Commits>> getItemLiveDataSource() {
|
||||
|
||||
return itemLiveDataSource;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +1,59 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.paging.PagedList;
|
||||
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.adapters.CommitsAdapter;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.items.CommitsItems;
|
||||
import org.mian.gitnex.models.Commits;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import org.mian.gitnex.viewmodels.CommitsViewModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import static com.mikepenz.fastadapter.adapters.ItemAdapter.items;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CommitsFragment extends Fragment {
|
||||
public class CommitsFragment extends Fragment implements ItemFilterListener<CommitsItems> {
|
||||
|
||||
private CommitsViewModel commitsViewModel;
|
||||
private CommitsAdapter commitsAdapter;
|
||||
private TextView noData;
|
||||
private ProgressBar progressBar;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
private String TAG = "CommitsFragment - ";
|
||||
private int resultLimit = 50;
|
||||
private boolean loadNextFlag = false;
|
||||
|
||||
private int listLimit = 50;
|
||||
private List<CommitsItems> items = new ArrayList<>();
|
||||
private FastItemAdapter<CommitsItems> fastItemAdapter;
|
||||
private ItemAdapter footerAdapter;
|
||||
private EndlessRecyclerOnScrollListener endlessRecyclerOnScrollListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -51,48 +71,244 @@ public class CommitsFragment extends Fragment {
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
TextView noDataCommits = v.findViewById(R.id.noDataCommits);
|
||||
ProgressBar progressBar = v.findViewById(R.id.progress_bar);
|
||||
noData = v.findViewById(R.id.noDataCommits);
|
||||
progressBar = v.findViewById(R.id.progress_bar);
|
||||
swipeRefreshLayout = v.findViewById(R.id.pullToRefresh);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
RecyclerView recyclerView = v.findViewById(R.id.recyclerView);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
//CommitsViewModel commitsViewModel = new ViewModelProvider(this).get(CommitsViewModel.class);
|
||||
fastItemAdapter = new FastItemAdapter<>();
|
||||
fastItemAdapter.withSelectable(true);
|
||||
|
||||
commitsAdapter = new CommitsAdapter(getContext());
|
||||
|
||||
commitsViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public <VM extends ViewModel> VM create(@NonNull Class<VM> modelClass) {
|
||||
footerAdapter = items();
|
||||
//noinspection unchecked
|
||||
return (VM) new CommitsViewModel (getContext(), instanceUrl, instanceToken, repoOwner, repoName, listLimit);
|
||||
}
|
||||
fastItemAdapter.addAdapter(1, footerAdapter);
|
||||
|
||||
}).get(CommitsViewModel.class);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> commitsViewModel.refresh());
|
||||
|
||||
//noinspection unchecked
|
||||
commitsViewModel.itemPagedList.observe(getViewLifecycleOwner(), new Observer<PagedList<Commits>>() {
|
||||
fastItemAdapter.getItemFilter().withFilterPredicate(new IItemAdapter.Predicate<CommitsItems>() {
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nullable PagedList<Commits> items) {
|
||||
public boolean filter(@NonNull CommitsItems item, CharSequence constraint) {
|
||||
|
||||
commitsAdapter.submitList(items);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
return item.getCommitTitle().toString().toLowerCase().contains(constraint.toString().toLowerCase());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
recyclerView.setAdapter(commitsAdapter);
|
||||
fastItemAdapter.getItemFilter().withItemFilterListener(this);
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.setAdapter(fastItemAdapter);
|
||||
|
||||
endlessRecyclerOnScrollListener = new EndlessRecyclerOnScrollListener(footerAdapter) {
|
||||
|
||||
@Override
|
||||
public void onLoadMore(final int currentPage) {
|
||||
|
||||
loadNext(instanceUrl, instanceToken, repoOwner, repoName, currentPage);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
fastItemAdapter.clear();
|
||||
endlessRecyclerOnScrollListener.resetPageCount();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
});
|
||||
|
||||
recyclerView.addOnScrollListener(endlessRecyclerOnScrollListener);
|
||||
|
||||
loadInitial(instanceUrl, instanceToken, repoOwner, repoName);
|
||||
|
||||
assert savedInstanceState != null;
|
||||
fastItemAdapter.withSavedInstanceState(savedInstanceState);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
private void loadInitial(String instanceUrl, String token, String repoOwner, String repoName) {
|
||||
|
||||
Call<List<Commits>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getContext())
|
||||
.getApiInterface()
|
||||
.getRepositoryCommits(token, repoOwner, repoName, 1);
|
||||
|
||||
call.enqueue(new Callback<List<Commits>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
if(response.body().size() == resultLimit) {
|
||||
loadNextFlag = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < response.body().size(); i++) {
|
||||
|
||||
items.add(new CommitsItems(getContext()).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()));
|
||||
|
||||
}
|
||||
|
||||
fastItemAdapter.add(items);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadNext(String instanceUrl, String token, String repoOwner, String repoName, final int currentPage) {
|
||||
|
||||
footerAdapter.clear();
|
||||
//noinspection unchecked
|
||||
footerAdapter.add(new ProgressItem().withEnabled(false));
|
||||
Handler handler = new Handler();
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Call<List<Commits>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, getContext())
|
||||
.getApiInterface()
|
||||
.getRepositoryCommits(token, repoOwner, repoName, currentPage + 1);
|
||||
|
||||
call.enqueue(new Callback<List<Commits>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
|
||||
if (response.body().size() > 0) {
|
||||
|
||||
loadNextFlag = response.body().size() == resultLimit;
|
||||
|
||||
for (int i = 0; i < response.body().size(); i++) {
|
||||
|
||||
fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new CommitsItems(getContext()).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()));
|
||||
|
||||
}
|
||||
|
||||
footerAdapter.clear();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
footerAdapter.clear();
|
||||
}
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
|
||||
if(!loadNextFlag) {
|
||||
|
||||
footerAdapter.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemsFiltered(@Nullable CharSequence constraint, @Nullable List<CommitsItems> results) {
|
||||
endlessRecyclerOnScrollListener.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReset() {
|
||||
endlessRecyclerOnScrollListener.enable();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class IssuesOpenFragment extends Fragment {
|
||||
private int pageSize = 1;
|
||||
private TextView noDataIssues;
|
||||
private int resultLimit = 50;
|
||||
private String requestType = "issues" ;
|
||||
private String requestType = "issues";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
180
app/src/main/java/org/mian/gitnex/items/CommitsItems.java
Normal file
180
app/src/main/java/org/mian/gitnex/items/CommitsItems.java
Normal file
@ -0,0 +1,180 @@
|
||||
package org.mian.gitnex.items;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.mikepenz.fastadapter.FastAdapter;
|
||||
import com.mikepenz.fastadapter.items.AbstractItem;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CommitsItems extends AbstractItem<CommitsItems, CommitsItems.ViewHolder> {
|
||||
|
||||
final private Context ctx;
|
||||
private String commitTitle;
|
||||
private String commitHtmlUrl;
|
||||
private String commitCommitter;
|
||||
private Date commitDate;
|
||||
|
||||
private boolean isSelectable = true;
|
||||
|
||||
public CommitsItems(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
public CommitsItems withNewItems(String commitTitle, String commitHtmlUrl, String commitCommitter, Date commitDate) {
|
||||
|
||||
this.setNewItems(commitTitle, commitHtmlUrl, commitCommitter, commitDate);
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
private void setNewItems(String commitTitle, String commitHtmlUrl, String commitCommitter, Date commitDate) {
|
||||
|
||||
this.commitTitle = commitTitle;
|
||||
this.commitHtmlUrl = commitHtmlUrl;
|
||||
this.commitCommitter = commitCommitter;
|
||||
this.commitDate = commitDate;
|
||||
|
||||
}
|
||||
|
||||
public String getCommitTitle() {
|
||||
return commitTitle;
|
||||
}
|
||||
|
||||
private String getCommitHtmlUrl() {
|
||||
return commitHtmlUrl;
|
||||
}
|
||||
|
||||
private String getcommitCommitter() {
|
||||
return commitCommitter;
|
||||
}
|
||||
|
||||
private Date getcommitDate() {
|
||||
return commitDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommitsItems withEnabled(boolean enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelectable() {
|
||||
return isSelectable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommitsItems withSelectable(boolean selectable) {
|
||||
|
||||
this.isSelectable = selectable;
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return R.id.commitList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutRes() {
|
||||
return R.layout.list_commits;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CommitsItems.ViewHolder getViewHolder(@NonNull View v) {
|
||||
|
||||
return new CommitsItems.ViewHolder(v);
|
||||
|
||||
}
|
||||
|
||||
public class ViewHolder extends FastAdapter.ViewHolder<CommitsItems> {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(ctx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
TextView commitTitleVw;
|
||||
TextView commitCommitterVw;
|
||||
TextView commitDateVw;
|
||||
TextView commitHtmlUrlVw;
|
||||
|
||||
public ViewHolder(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);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(CommitsItems item, @NonNull List<Object> payloads) {
|
||||
|
||||
commitTitleVw.setText(item.getCommitTitle());
|
||||
commitCommitterVw.setText(ctx.getString(R.string.commitCommittedBy, item.getcommitCommitter()));
|
||||
|
||||
switch (timeFormat) {
|
||||
case "pretty": {
|
||||
PrettyTime prettyTime = new PrettyTime(new Locale(locale));
|
||||
String createdTime = prettyTime.format(item.getcommitDate());
|
||||
commitDateVw.setText(createdTime);
|
||||
commitDateVw.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(item.getcommitDate()), ctx));
|
||||
break;
|
||||
}
|
||||
case "normal": {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + ctx.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(item.getcommitDate());
|
||||
commitDateVw.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
case "normal1": {
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + ctx.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
||||
String createdTime = formatter.format(item.getcommitDate());
|
||||
commitDateVw.setText(createdTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
commitHtmlUrlVw.setText(Html.fromHtml("<a href='" + item.getCommitHtmlUrl() + "'>" + ctx.getResources().getString(R.string.viewInBrowser) + "</a> "));
|
||||
commitHtmlUrlVw.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbindView(@NonNull CommitsItems item) {
|
||||
|
||||
commitTitleVw.setText(null);
|
||||
commitCommitterVw.setText(null);
|
||||
commitDateVw.setText(null);
|
||||
commitHtmlUrlVw.setText(null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package org.mian.gitnex.models;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -40,7 +41,7 @@ public class Commits {
|
||||
|
||||
String name;
|
||||
String email;
|
||||
String date;
|
||||
Date date;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -50,7 +51,7 @@ public class Commits {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@ -60,7 +61,7 @@ public class Commits {
|
||||
|
||||
String name;
|
||||
String email;
|
||||
String date;
|
||||
Date date;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -70,7 +71,7 @@ public class Commits {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
package org.mian.gitnex.viewmodels;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.paging.LivePagedListBuilder;
|
||||
import androidx.paging.PageKeyedDataSource;
|
||||
import androidx.paging.PagedList;
|
||||
import org.mian.gitnex.datasource.CommitsDataSource;
|
||||
import org.mian.gitnex.datasource.CommitsDataSourceFactory;
|
||||
import org.mian.gitnex.models.Commits;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class CommitsViewModel extends ViewModel {
|
||||
|
||||
private CommitsDataSourceFactory itemDataSourceFactory;
|
||||
public LiveData itemPagedList;
|
||||
|
||||
public CommitsViewModel(Context ctx, String instannceUrl, String instanceToken, String owner, String repo, int listLimit) {
|
||||
|
||||
itemDataSourceFactory = new CommitsDataSourceFactory(ctx, instannceUrl, instanceToken, owner, repo, listLimit);
|
||||
LiveData<PageKeyedDataSource<Integer, Commits>> liveDataSource = itemDataSourceFactory.getItemLiveDataSource();
|
||||
PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setEnablePlaceholders(true)
|
||||
.setPageSize(listLimit).build();
|
||||
//noinspection unchecked
|
||||
itemPagedList = new LivePagedListBuilder(itemDataSourceFactory, pagedListConfig)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
||||
Objects.requireNonNull(itemDataSourceFactory.getItemLiveDataSource().getValue()).invalidate();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,10 @@
|
||||
<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"
|
||||
android:background="?attr/primaryBackgroundColor" >
|
||||
android:background="?attr/primaryBackgroundColor">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayoutFrame"
|
||||
@ -16,20 +17,55 @@
|
||||
android:layout_margin="15dp"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/commitTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".70"
|
||||
android:id="@+id/commitTitleVw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/commitTitle"
|
||||
android:textIsSelectable="true"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/commitCommitterVw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/frameViewnDate"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/frameViewInBrowser"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".25"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/commitHtmlUrlVw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:text="@string/viewInBrowser"
|
||||
android:textColorLink="@color/lightBlue"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/commitDateVw"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".25"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -506,6 +506,7 @@
|
||||
<string name="strPrivate" translatable="false">private</string>
|
||||
<string name="strPublic" translatable="false">public</string>
|
||||
<string name="defaultCopy" translatable="false">Default</string>
|
||||
<string name="viewInBrowser">View in Browser</string>
|
||||
<!-- generic copy -->
|
||||
|
||||
<string name="translateText">Translate GitNex with Crowdin</string>
|
||||
@ -562,4 +563,5 @@
|
||||
<string name="createRepository">Create Repository</string>
|
||||
<string name="repositoryTabCommits">Commits</string>
|
||||
<string name="commitTitle">Commit Title</string>
|
||||
<string name="commitCommittedBy">Committed by %1$s</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user