Add support for PR commits (#1152)

Can be found under the changes option of PRs.

Closes https://codeberg.org/gitnex/GitNex/issues/332

Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1152
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
qwerty287 2022-06-30 12:36:13 +02:00 committed by M M Arif
parent 339a6655bf
commit d3cc481a4d
24 changed files with 651 additions and 287 deletions

View File

@ -48,8 +48,6 @@ public class CommitsActivity extends BaseActivity {
private RecyclerView recyclerView;
private List<Commit> commitsList;
private CommitsAdapter adapter;
private ProgressBar progressLoadMore;
public RepositoryContext repository;
@Override
@ -73,7 +71,6 @@ public class CommitsActivity extends BaseActivity {
ImageView closeActivity = activityCommitsBinding.close;
noData = activityCommitsBinding.noDataCommits;
progressLoadMore = activityCommitsBinding.progressLoadMore;
progressBar = activityCommitsBinding.progressBar;
SwipeRefreshLayout swipeRefresh = activityCommitsBinding.pullToRefresh;
@ -159,7 +156,7 @@ public class CommitsActivity extends BaseActivity {
private void loadMore(String repoOwner, String repoName, final int page, String branchName, int resultLimit) {
progressLoadMore.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
Call<List<Commit>> call = RetrofitClient.getApiInterface(ctx).repoGetAllCommits(repoOwner, repoName, branchName, null, page, resultLimit);
@ -190,7 +187,7 @@ public class CommitsActivity extends BaseActivity {
Log.e(TAG, String.valueOf(response.code()));
}
progressLoadMore.setVisibility(View.GONE);
progressBar.setVisibility(View.GONE);
}
@Override

View File

@ -4,8 +4,8 @@ import android.os.Bundle;
import androidx.activity.OnBackPressedCallback;
import org.mian.gitnex.R;
import org.mian.gitnex.databinding.ActivityDiffBinding;
import org.mian.gitnex.fragments.DiffFilesFragment;
import org.mian.gitnex.fragments.DiffFragment;
import org.mian.gitnex.fragments.PullRequestChangesFragment;
/**
* @author opyale
@ -13,6 +13,8 @@ import org.mian.gitnex.fragments.DiffFragment;
public class DiffActivity extends BaseActivity {
public PullRequestChangesFragment fragment = PullRequestChangesFragment.newInstance();
@Override
public void onCreate(Bundle savedInstanceState) {
@ -22,8 +24,6 @@ public class DiffActivity extends BaseActivity {
setContentView(binding.getRoot());
DiffFilesFragment fragment = DiffFilesFragment.newInstance();
getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
@Override

View File

@ -16,10 +16,12 @@ import org.gitnex.tea4j.v2.models.Commit;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CommitDetailActivity;
import org.mian.gitnex.activities.CommitsActivity;
import org.mian.gitnex.activities.DiffActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.contexts.IssueContext;
import java.util.List;
import java.util.Objects;
@ -156,9 +158,15 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
commitSha.setText(commitsModel.getSha().substring(0, Math.min(commitsModel.getSha().length(), 10)));
rootView.setOnClickListener(v -> {
Intent intent = ((CommitsActivity) context).repository.getIntent(context, CommitDetailActivity.class);
intent.putExtra("sha", commitsModel.getSha());
context.startActivity(intent);
Intent intent;
if(context instanceof CommitsActivity) {
intent = ((CommitsActivity) context).repository.getIntent(context, CommitDetailActivity.class);
} else {
intent = IssueContext.fromIntent(((DiffActivity) context).getIntent()).getRepository()
.getIntent(context, CommitDetailActivity.class);
}
intent.putExtra("sha", commitsModel.getSha());
context.startActivity(intent);
});
}

View File

@ -1,90 +1,121 @@
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.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CommitDetailActivity;
import org.mian.gitnex.activities.DiffActivity;
import org.mian.gitnex.fragments.DiffFragment;
import org.mian.gitnex.helpers.FileDiffView;
import org.mian.gitnex.helpers.contexts.IssueContext;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author opyale
* @author M M Arif
*/
public class DiffFilesAdapter extends BaseAdapter {
public class DiffFilesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final Pattern statisticsPattern = Pattern.compile("(\\d+).*?,.*?(\\d+)");
private final Context context;
private final List<FileDiffView> fileDiffViews;
private List<FileDiffView> fileDiffViews;
private final IssueContext issue;
private final String fragmentType;
public DiffFilesAdapter(Context context, List<FileDiffView> fileDiffViews, IssueContext issue, String fragmentType) {
public DiffFilesAdapter(Context context, List<FileDiffView> fileDiffViews) {
this.context = context;
this.fileDiffViews = fileDiffViews;
this.issue = issue;
this.fragmentType = fragmentType;
}
private static class ViewHolder {
private final TextView fileName;
private final TextView fileStatistics;
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
return new DiffFilesAdapter.FilesHolder(inflater.inflate(R.layout.list_diff_files, parent, false));
}
public ViewHolder(TextView fileName, TextView fileStatistics) {
this.fileName = fileName;
this.fileStatistics = fileStatistics;
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
((DiffFilesAdapter.FilesHolder) holder).bindData(fileDiffViews.get(position));
}
class FilesHolder extends RecyclerView.ViewHolder {
FileDiffView diffFilesObject;
TextView fileName;
TextView fileStatistics;
LinearLayout main_frame;
FilesHolder(View itemView) {
super(itemView);
fileName = itemView.findViewById(R.id.fileName);
fileStatistics = itemView.findViewById(R.id.fileStatistics);
main_frame = itemView.findViewById(R.id.main_frame);
main_frame.setOnClickListener(v -> {
if(fragmentType.equalsIgnoreCase("commit")){
((CommitDetailActivity) context).getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, DiffFragment.newInstance(diffFilesObject, fragmentType))
.commit();
}
else {
((DiffActivity) context).getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, DiffFragment.newInstance(diffFilesObject, issue))
.commit();
}
});
}
void bindData(FileDiffView fileDiffView) {
this.diffFilesObject = fileDiffView;
fileName.setText(fileDiffView.getFileName());
Matcher matcher = statisticsPattern.matcher(fileDiffView.getFileInfo());
if(matcher.find() && matcher.groupCount() == 2) {
fileStatistics.setText(context.getString(R.string.diffStatistics, matcher.group(1), matcher.group(2)));
} else {
fileStatistics.setText(fileDiffView.getFileInfo());
}
}
}
@Override
public int getCount() {
return fileDiffViews.size();
}
@Override
public Object getItem(int position) {
return fileDiffViews.get(position);
}
@Override
public long getItemId(int position) {
public int getItemViewType(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if(convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.list_diff_files, parent, false);
viewHolder = new ViewHolder(
convertView.findViewById(R.id.fileName),
convertView.findViewById(R.id.fileStatistics)
);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
FileDiffView fileDiffView = fileDiffViews.get(position);
viewHolder.fileName.setText(fileDiffView.getFileName());
Matcher matcher = statisticsPattern.matcher(fileDiffView.getFileInfo());
if(matcher.find() && matcher.groupCount() == 2) {
viewHolder.fileStatistics.setText(context.getString(R.string.diffStatistics, matcher.group(1), matcher.group(2)));
} else {
viewHolder.fileStatistics.setText(fileDiffView.getFileInfo());
}
return convertView;
public int getItemCount() {
return fileDiffViews.size();
}
public void updateList(List<FileDiffView> list) {
fileDiffViews = list;
}
@SuppressLint("NotifyDataSetChanged")
public void notifyDataChanged() {
notifyDataSetChanged();
}
}

View File

@ -18,7 +18,6 @@ import org.mian.gitnex.R;
import org.mian.gitnex.actions.MilestoneActions;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.Constants;
import org.mian.gitnex.helpers.Markdown;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
@ -179,7 +178,7 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
if(dataModel.getDueOn() != null) {
String TAG = Constants.tagMilestonesAdapter;
String TAG = "MilestonesAdapter";
if(timeFormat.equals("normal") || timeFormat.equals("pretty")) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));

View File

@ -10,7 +10,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import org.mian.gitnex.databinding.BottomSheetDraftsBinding;
import org.mian.gitnex.helpers.Constants;
import org.mian.gitnex.structs.BottomSheetListener;
/**
@ -19,7 +18,7 @@ import org.mian.gitnex.structs.BottomSheetListener;
public class BottomSheetDraftsFragment extends BottomSheetDialogFragment {
private String TAG = Constants.tagDraftsBottomSheet;
private String TAG = "BottomSheetDraftsFragment";
private BottomSheetListener bmListener;
@Nullable

View File

@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.vdurmont.emoji.EmojiParser;
import org.gitnex.tea4j.v2.models.Commit;
import org.mian.gitnex.R;
@ -20,7 +21,6 @@ import org.mian.gitnex.activities.ProfileActivity;
import org.mian.gitnex.adapters.DiffFilesAdapter;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.databinding.CustomCommitHeaderBinding;
import org.mian.gitnex.databinding.FragmentCommitDetailsBinding;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
@ -29,7 +29,9 @@ import org.mian.gitnex.helpers.ParseDiff;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.contexts.IssueContext;
import org.mian.gitnex.helpers.contexts.RepositoryContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
@ -46,7 +48,8 @@ public class CommitDetailFragment extends Fragment {
private String repoOwner;
private String repoName;
private String sha;
private List<FileDiffView> fileDiffViews = new ArrayList<>();
private DiffFilesAdapter adapter;
private int loadingFinished = 0;
public static CommitDetailFragment newInstance() {
@ -63,22 +66,24 @@ public class CommitDetailFragment extends Fragment {
binding = FragmentCommitDetailsBinding.inflate(getLayoutInflater(), container, false);
IssueContext issue = IssueContext.fromIntent(requireActivity().getIntent());
RepositoryContext repository = RepositoryContext.fromIntent(requireActivity().getIntent());
repoOwner = repository.getOwner();
repoName = repository.getName();
sha = requireActivity().getIntent().getStringExtra("sha");
binding.toolbarTitle.setText(sha.substring(0, Math.min(sha.length(), 10)));
adapter = new DiffFilesAdapter(requireContext(), fileDiffViews, issue, "commit");
binding.diffFiles.setHasFixedSize(true);
binding.diffFiles.setLayoutManager(new LinearLayoutManager(requireContext()));
binding.diffFiles.setAdapter(adapter);
getCommit();
getDiff();
binding.close.setOnClickListener((v) -> requireActivity().finish());
binding.diffFiles.setOnItemClickListener((parent, view, position, id) -> requireActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position), "commit"))
.commit());
return binding.getRoot();
}
@ -93,15 +98,16 @@ public class CommitDetailFragment extends Fragment {
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
checkLoading();
assert response.body() != null;
switch(response.code()) {
case 200:
List<FileDiffView> fileDiffViews;
assert response.body() != null;
fileDiffViews = ParseDiff.getFileDiffViewArray(response.body());
DiffFilesAdapter adapter = new DiffFilesAdapter(requireContext(), fileDiffViews);
requireActivity().runOnUiThread(() -> binding.diffFiles.setAdapter(adapter));
requireActivity().runOnUiThread(() -> {
adapter.updateList(fileDiffViews);
adapter.notifyDataChanged();
});
break;
case 401:
@ -139,11 +145,6 @@ public class CommitDetailFragment extends Fragment {
public void onResponse(@NonNull Call<Commit> call, @NonNull Response<Commit> response) {
checkLoading();
CustomCommitHeaderBinding binding = CustomCommitHeaderBinding.inflate(getLayoutInflater());
binding.getRoot().setOnClickListener((v) -> {
// we need a ClickListener here to prevent that the ItemClickListener of the diffFiles ListView handles clicks for the header
});
CommitDetailFragment.this.binding.diffFiles.addHeaderView(binding.getRoot());
Commit commitsModel = response.body();
if(commitsModel == null) {
onFailure(call, new Throwable());

View File

@ -7,6 +7,7 @@ import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.DiffFilesAdapter;
import org.mian.gitnex.clients.RetrofitClient;
@ -17,6 +18,7 @@ import org.mian.gitnex.helpers.ParseDiff;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.contexts.IssueContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Response;
@ -29,6 +31,8 @@ public class DiffFilesFragment extends Fragment {
private FragmentDiffFilesBinding binding;
private Context ctx;
private List<FileDiffView> fileDiffViews = new ArrayList<>();
private DiffFilesAdapter adapter;
public DiffFilesFragment() {}
@ -49,18 +53,16 @@ public class DiffFilesFragment extends Fragment {
IssueContext issue = IssueContext.fromIntent(requireActivity().getIntent());
binding.progressBar.setVisibility(View.VISIBLE);
binding.toolbarTitle.setText(R.string.processingText);
binding.close.setOnClickListener(v -> requireActivity().finish());
binding.diffFiles.setOnItemClickListener((parent, view, position, id) -> requireActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position), issue))
.commit());
adapter = new DiffFilesAdapter(ctx, fileDiffViews, issue, "");
binding.diffFiles.setHasFixedSize(true);
binding.diffFiles.setLayoutManager(new LinearLayoutManager(ctx));
binding.diffFiles.setAdapter(adapter);
getPullDiffFiles(issue.getRepository().getOwner(), issue.getRepository().getName(), String.valueOf(issue.getIssueIndex()));
return binding.getRoot();
}
private void getPullDiffFiles(String owner, String repo, String pullIndex) {
@ -81,7 +83,7 @@ public class DiffFilesFragment extends Fragment {
switch(response.code()) {
case 200:
List<FileDiffView> fileDiffViews = ParseDiff.getFileDiffViewArray(response.body());
fileDiffViews = ParseDiff.getFileDiffViewArray(response.body());
int filesCount = fileDiffViews.size();
@ -89,12 +91,12 @@ public class DiffFilesFragment extends Fragment {
getResources().getString(R.string.fileDiffViewHeader, Integer.toString(filesCount)) :
getResources().getString(R.string.fileDiffViewHeaderSingle, Integer.toString(filesCount));
DiffFilesAdapter adapter = new DiffFilesAdapter(ctx, fileDiffViews);
requireActivity().runOnUiThread(() -> {
binding.toolbarTitle.setVisibility(View.VISIBLE);
binding.progressBar.setVisibility(View.GONE);
binding.diffFiles.setAdapter(adapter);
binding.toolbarTitle.setText(toolbarTitleText);
adapter.updateList(fileDiffViews);
adapter.notifyDataChanged();
});
break;
@ -119,7 +121,5 @@ public class DiffFilesFragment extends Fragment {
});
thread.start();
}
}

View File

@ -8,6 +8,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.DiffActivity;
import org.mian.gitnex.adapters.DiffAdapter;
import org.mian.gitnex.databinding.FragmentDiffBinding;
import org.mian.gitnex.helpers.FileDiffView;
@ -65,7 +66,7 @@ public class DiffFragment extends Fragment {
ctx = requireContext();
if(Objects.equals(type, "pull")) {
binding.close.setOnClickListener(v -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, DiffFilesFragment.newInstance()).commit());
binding.close.setOnClickListener(v -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, ((DiffActivity) requireActivity()).fragment).commit());
} else {
binding.close.setOnClickListener(v -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, CommitDetailFragment.newInstance()).commit());
}

View File

@ -27,7 +27,7 @@ import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
* @author M M Arif
*/
public class ExplorePublicOrganizationsFragment extends Fragment {
@ -37,7 +37,7 @@ public class ExplorePublicOrganizationsFragment extends Fragment {
private OrganizationsListAdapter adapter;
private Context context;
private int pageSize;
private final String TAG = Constants.publicOrganizations;
private final String TAG = "PublicOrganizations";
private int resultLimit;
@Nullable

View File

@ -37,7 +37,7 @@ public class MyProfileFollowersFragment extends Fragment {
private List<User> dataList;
private UsersAdapter adapter;
private int pageSize;
private final String TAG = Constants.tagFollowers;
private final String TAG = "MyProfileFollowersFragment";
private int resultLimit;
@Override

View File

@ -26,7 +26,7 @@ import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
* @author M M Arif
*/
public class MyProfileFollowingFragment extends Fragment {
@ -37,7 +37,7 @@ public class MyProfileFollowingFragment extends Fragment {
private List<User> dataList;
private UsersAdapter adapter;
private int pageSize;
private final String TAG = Constants.tagFollowing;
private final String TAG = "MyProfileFollowingFragment";
private int resultLimit;
@Override

View File

@ -0,0 +1,61 @@
package org.mian.gitnex.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import com.google.android.material.tabs.TabLayoutMediator;
import org.mian.gitnex.R;
import org.mian.gitnex.databinding.FragmentPrChangesBinding;
/**
* @author qwerty287
*/
public class PullRequestChangesFragment extends Fragment {
private FragmentPrChangesBinding binding;
private final DiffFilesFragment diffFilesFragment = DiffFilesFragment.newInstance();
private final PullRequestCommitsFragment pullRequestCommitsFragment = PullRequestCommitsFragment.newInstance();
public PullRequestChangesFragment() {}
public static PullRequestChangesFragment newInstance() {
return new PullRequestChangesFragment();
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentPrChangesBinding.inflate(inflater, container, false);
binding.close.setOnClickListener(v -> requireActivity().finish());
binding.container.setAdapter(new FragmentStateAdapter(requireActivity()) {
@NonNull
@Override
public Fragment createFragment(int position) {
if(position == 0) {
return diffFilesFragment;
} else {
return pullRequestCommitsFragment;
}
}
@Override
public int getItemCount() {
return 2;
}
});
String[] tabs = new String[]{getString(R.string.tabTextFiles), getString(R.string.commits)};
new TabLayoutMediator(binding.tabs, binding.container, (tab, position) -> tab.setText(tabs[position])).attach();
return binding.getRoot();
}
}

View File

@ -0,0 +1,252 @@
package org.mian.gitnex.fragments;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
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.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import org.gitnex.tea4j.v2.models.Commit;
import org.jetbrains.annotations.NotNull;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.CommitsAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.databinding.ActivityCommitsBinding;
import org.mian.gitnex.helpers.Constants;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.contexts.IssueContext;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* @author qwerty287
*/
public class PullRequestCommitsFragment extends Fragment {
private ActivityCommitsBinding binding;
private Context ctx;
private final String TAG = "PullRequestCommitsFragment";
private int resultLimit;
private int pageSize = 1;
private final List<Commit> commitsList = new ArrayList<>();
private CommitsAdapter adapter;
public PullRequestCommitsFragment() {}
public static PullRequestCommitsFragment newInstance() {
return new PullRequestCommitsFragment();
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(binding != null) {
ctx = requireContext();
return binding.getRoot();
}
binding = ActivityCommitsBinding.inflate(inflater, container, false);
ctx = requireContext();
IssueContext issue = IssueContext.fromIntent(requireActivity().getIntent());
binding.toolbar.setVisibility(View.GONE);
resultLimit = Constants.getCurrentResultLimit(ctx);
binding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
binding.pullToRefresh.setRefreshing(false);
loadInitial(issue, resultLimit);
adapter.notifyDataChanged();
}, 200));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, 0, 0);
binding.pullToRefresh.setLayoutParams(params);
RelativeLayout.LayoutParams paramsProgressBar = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
paramsProgressBar.setMargins(0, 0, 0, 0);
binding.progressBar.setLayoutParams(paramsProgressBar);
adapter = new CommitsAdapter(ctx, commitsList);
adapter.setLoadMoreListener(() -> binding.recyclerView.post(() -> {
if(commitsList.size() == resultLimit || pageSize == resultLimit) {
int page = (commitsList.size() + resultLimit) / resultLimit;
loadMore(page, issue, resultLimit);
}
}));
binding.recyclerView.setHasFixedSize(true);
binding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
binding.recyclerView.setAdapter(adapter);
loadInitial(issue, resultLimit);
return binding.getRoot();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getClass().getName();
}
private void loadInitial(IssueContext issue, int resultLimit) {
Call<List<Commit>> call = RetrofitClient.getApiInterface(ctx).repoGetPullRequestCommits(issue.getRepository().getOwner(),
issue.getRepository().getName(), (long) issue.getIssueIndex(), 1, resultLimit);
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<List<Commit>> call, @NonNull Response<List<Commit>> response) {
if(response.code() == 200) {
assert response.body() != null;
if(response.body().size() > 0) {
commitsList.clear();
commitsList.addAll(response.body());
adapter.notifyDataChanged();
binding.noDataCommits.setVisibility(View.GONE);
}
else {
commitsList.clear();
adapter.notifyDataChanged();
binding.noDataCommits.setVisibility(View.VISIBLE);
}
}
if(response.code() == 409) {
binding.noDataCommits.setVisibility(View.VISIBLE);
}
else {
Log.e(TAG, String.valueOf(response.code()));
}
binding.progressBar.setVisibility(View.GONE);
}
@Override
public void onFailure(@NonNull Call<List<Commit>> call, @NonNull Throwable t) {
Toasty.error(ctx, getResources().getString(R.string.genericServerResponseError));
}
});
}
private void loadMore(final int page, IssueContext issue, int resultLimit) {
binding.progressBar.setVisibility(View.VISIBLE);
Call<List<Commit>> call = RetrofitClient.getApiInterface(ctx).repoGetPullRequestCommits(issue.getRepository().getOwner(),
issue.getRepository().getName(), (long) issue.getIssueIndex(), page, resultLimit);
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<List<Commit>> call, @NonNull Response<List<Commit>> response) {
if(response.isSuccessful()) {
List<Commit> result = response.body();
assert result != null;
if(result.size() > 0) {
pageSize = result.size();
commitsList.addAll(result);
}
else {
adapter.setMoreDataAvailable(false);
}
adapter.notifyDataChanged();
}
else {
Log.e(TAG, String.valueOf(response.code()));
}
binding.progressBar.setVisibility(View.GONE);
}
@Override
public void onFailure(@NonNull Call<List<Commit>> call, @NonNull Throwable t) {
Toasty.error(ctx, getResources().getString(R.string.genericServerResponseError));
}
});
}
@Override
public void onCreateOptionsMenu(@NotNull Menu menu, MenuInflater inflater) {
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) {
filter(newText);
return true;
}
});
}
private void filter(String text) {
List<Commit> arr = new ArrayList<>();
for(Commit d : commitsList) {
if(d.getCommit().getMessage().toLowerCase().contains(text) || d.getSha().toLowerCase().contains(text)) {
arr.add(d);
}
}
adapter.updateList(arr);
}
}

View File

@ -46,7 +46,7 @@ public class PullRequestsFragment extends Fragment {
private List<PullRequest> prList;
private PullRequestsAdapter adapter;
private final String TAG = Constants.tagPullRequestsList;
private final String TAG = "PullRequestFragment";
private Context context;
private int pageSize = Constants.prPageInit;
private int resultLimit;

View File

@ -13,20 +13,6 @@ public class Constants {
return ((BaseActivity) context).getAccount().requiresVersion("1.15") ? ((BaseActivity) context).getAccount().getDefaultPageLimit() : ((BaseActivity) context).getAccount().getMaxPageLimit();
}
// tags
public static final String tagPullRequestsList = "PullRequestFragment";
public static final String tagIssuesList = "IssuesListFragment";
public static final String tagMilestonesAdapter = "MilestonesAdapter";
public static final String draftsApi = "DraftsApi";
public static final String repositoriesApi = "RepositoriesApi";
public static final String tagDraftsBottomSheet = "BottomSheetDraftsFragment";
public static final String userAccountsApi = "UserAccountsApi";
public static final String publicOrganizations = "PublicOrganizations";
public static final String exploreUsers = "ExploreUsers";
public static final String exploreIssues = "ExploreIssues";
public static final String tagFollowers = "TagFollowers";
public static final String tagFollowing = "TagFollowing";
// issues variables
public static final int issuesPageInit = 1;
public static final String issuesRequestType = "issues";

View File

@ -52,15 +52,15 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullToRefresh"
android:layout_width="match_parent"
android:layout_marginTop="56dp"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginTop="56dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"
android:scrollbars="vertical" />
android:scrollbars="vertical"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
@ -73,16 +73,6 @@
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
app:indicatorColor="?attr/progressIndicatorColor" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progressLoadMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:visibility="gone"
android:indeterminate="true"
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
app:indicatorColor="?attr/progressIndicatorColor" />
<TextView
android:id="@+id/noDataCommits"
android:layout_width="match_parent"

View File

@ -1,100 +0,0 @@
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="?attr/primaryBackgroundColor"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/linearLayoutFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical"
android:background="?attr/primaryBackgroundColor">
<TextView
android:id="@+id/commitSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textColor="?attr/primaryTextColor"
android:textSize="18sp"
tools:text="This is a test" />
<TextView
android:id="@+id/commitBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:alpha=".8"
android:textColor="?attr/primaryTextColor"
android:textSize="14sp"
tools:text="This is a test commit message" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/commitAuthorAvatar"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_marginEnd="5dp"
android:contentDescription="@string/generalImgContentText"
tools:srcCompat="@tools:sample/avatars" />
<ImageView
android:id="@+id/commitCommitterAvatar"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_marginEnd="5dp"
android:contentDescription="@string/generalImgContentText"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/commitAuthorAndCommitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:textSize="12sp"
android:textColor="?attr/primaryTextColor"
tools:text="opyale authored and opyale committed" />
</LinearLayout>
<TextView
android:id="@+id/commitSha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:alpha=".8"
android:drawablePadding="10dp"
android:textSize="12sp"
android:layout_marginStart="10dp"
android:gravity="center_vertical"
android:textColor="?attr/primaryTextColor"
app:drawableLeftCompat="@drawable/ic_commit"
tools:text="357f3qd5s" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dividerColor" />
</LinearLayout>

View File

@ -58,15 +58,119 @@
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
app:indicatorColor="?attr/progressIndicatorColor" />
<ListView
android:id="@+id/diff_files"
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:nestedScrollingEnabled="false"
android:background="?attr/primaryBackgroundColor"
android:headerDividersEnabled="true"
android:fastScrollEnabled="true"
tools:listitem="@layout/list_diff_files" />
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/primaryBackgroundColor">
<LinearLayout
android:id="@+id/linearLayoutFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical"
android:background="?attr/primaryBackgroundColor">
<TextView
android:id="@+id/commitSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textColor="?attr/primaryTextColor"
android:textSize="18sp"
tools:text="This is a test" />
<TextView
android:id="@+id/commitBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:alpha=".8"
android:textColor="?attr/primaryTextColor"
android:textSize="14sp"
tools:text="This is a test commit message" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal"
tools:ignore="UseCompoundDrawables">
<ImageView
android:id="@+id/commitAuthorAvatar"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_marginEnd="5dp"
android:contentDescription="@string/generalImgContentText"
tools:srcCompat="@tools:sample/avatars" />
<ImageView
android:id="@+id/commitCommitterAvatar"
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:layout_marginEnd="5dp"
android:contentDescription="@string/generalImgContentText"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/commitAuthorAndCommitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:textSize="12sp"
android:textColor="?attr/primaryTextColor"
tools:text="opyale authored and opyale committed" />
</LinearLayout>
<TextView
android:id="@+id/commitSha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:alpha=".8"
android:drawablePadding="10dp"
android:textSize="12sp"
android:layout_marginStart="10dp"
android:gravity="center_vertical"
android:textColor="?attr/primaryTextColor"
app:drawableLeftCompat="@drawable/ic_commit"
tools:text="357f3qd5s" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dividerColor" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/diff_files"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:headerDividersEnabled="true"
android:nestedScrollingEnabled="false"
android:background="?attr/primaryBackgroundColor"
tools:listitem="@layout/list_diff_files"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View File

@ -50,7 +50,6 @@
<ListView
android:id="@+id/diff"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollEnabled="true" />
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -5,49 +5,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="@style/Widget.AppCompat.SearchView">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBackgroundColor">
<ImageView
android:id="@+id/close"
android:layout_width="@dimen/close_button_size"
android:layout_height="@dimen/close_button_size"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:contentDescription="@string/close"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:clickable="true"
android:src="@drawable/ic_close" />
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/fileDiffViewHeader"
android:textColor="?attr/primaryTextColor"
android:ellipsize="none"
android:scrollbars="horizontal"
android:singleLine="true"
android:layout_marginEnd="20dp"
android:textSize="18sp" />
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress_bar"
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
@ -56,10 +13,27 @@
android:indeterminate="true"
app:indicatorColor="?attr/progressIndicatorColor" />
<ListView
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/fileDiffViewHeader"
android:textColor="?attr/primaryTextColor"
android:ellipsize="none"
android:scrollbars="horizontal"
android:singleLine="true"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:textSize="15sp"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/diff_files"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollEnabled="true" />
android:background="?attr/primaryBackgroundColor"
android:scrollbars="vertical" />
</LinearLayout>

View File

@ -0,0 +1,60 @@
<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="?attr/primaryBackgroundColor"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="@style/Widget.AppCompat.SearchView">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/primaryBackgroundColor">
<ImageView
android:id="@+id/close"
android:layout_width="@dimen/close_button_size"
android:layout_height="@dimen/close_button_size"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:contentDescription="@string/close"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:focusable="true"
android:clickable="true"
android:src="@drawable/ic_close" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"
app:tabIndicatorColor="?attr/pagerTabIndicatorColor"
app:tabIndicatorFullWidth="false"
app:tabMode="fixed"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabTextAppearance="@style/customTabLayout"
app:tabTextColor="?attr/primaryTextColor" />
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"

View File

@ -766,6 +766,7 @@
<string name="repoAdopted">Adopted repository %s</string>
<string name="unadoptedRepos">Unadopted Repositories</string>
<string name="unadoptedReposMessage">- Adopt will add repository %s to organization/user %s.\n- Delete will remove it from the system.</string>
<string name="commits">Commits</string>
<!-- wiki -->
<string name="wiki">Wiki</string>