Add single commit screen with diff (#1048)

Also addresses the already closed #946

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

Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1048
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-03-09 12:52:34 +01:00 committed by M M Arif
parent ff41e82baf
commit ea30556844
17 changed files with 578 additions and 77 deletions

View File

@ -109,7 +109,7 @@ dependencies {
implementation "androidx.work:work-runtime:$work_version"
implementation "io.mikael:urlbuilder:2.0.9"
implementation "org.codeberg.gitnex-garage:emoji-java:v5.1.2"
implementation "org.codeberg.gitnex:tea4j:1.0.30"
implementation "org.codeberg.gitnex:tea4j:1.1.1"
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
implementation 'androidx.biometric:biometric:1.1.0'
implementation 'com.github.chrisvest:stormpot:2.4.2'

View File

@ -103,9 +103,6 @@
<activity
android:name=".activities.CreateOrganizationActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
<activity
android:name=".activities.FileDiffActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
<activity
android:name=".activities.DiffActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
@ -113,6 +110,10 @@
<activity
android:name=".activities.CommitsActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
<activity
android:name=".activities.CommitDetailActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
android:theme="@android:style/Theme.NoTitleBar" />
<activity
android:name=".helpers.ssl.MemorizingActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"

View File

@ -0,0 +1,49 @@
package org.mian.gitnex.activities;
import android.os.Bundle;
import androidx.activity.OnBackPressedCallback;
import org.mian.gitnex.R;
import org.mian.gitnex.databinding.ActivityCommitDetailsBinding;
import org.mian.gitnex.fragments.CommitDetailFragment;
import org.mian.gitnex.fragments.DiffFragment;
/**
* @author qwerty287
*/
public class CommitDetailActivity extends BaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityCommitDetailsBinding binding = ActivityCommitDetailsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
CommitDetailFragment fragment = CommitDetailFragment.newInstance();
getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if(getSupportFragmentManager().findFragmentById(R.id.fragment_container) instanceof DiffFragment) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
} else {
finish();
}
}
});
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit();
}
}

View File

@ -252,9 +252,10 @@ public class DeepLinksActivity extends BaseActivity {
new Handler(Looper.getMainLooper()).postDelayed(() ->
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pullNew"), 500);
}
else if(data.getPathSegments().get(2).equals("commit")) { // commits (no API yet to properly implement)
else if(data.getPathSegments().get(2).equals("commit")) {
repoIntent.putExtra("sha", data.getLastPathSegment());
new Handler(Looper.getMainLooper()).postDelayed(() ->
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "commit"), 500);
}
else if(data.getPathSegments().get(2).equals("commits")) { // commits list
String branch = data.getLastPathSegment();

View File

@ -284,6 +284,11 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe
intent1.putExtra("branchName", branch);
ctx.startActivity(intent1);
break;
case "commit":
Intent intent2 = new Intent(ctx, CommitDetailActivity.class);
intent2.putExtra("sha", mainIntent.getStringExtra("sha"));
ctx.startActivity(intent2);
break;
case "issue":
RepoDetailActivity.mViewPager.setCurrentItem(2);
break;
@ -800,6 +805,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe
@Override
protected void onDestroy() {
super.onDestroy();
if(!isFinishing()) {
return;
}
@ -808,7 +814,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetListe
.getAccountById(getIntent().getIntExtra("oldAccountId", 0));
AppUtil.switchToAccount(this, a);
}
super.onDestroy();
}
// Issues milestone filter interface

View File

@ -1,6 +1,7 @@
package org.mian.gitnex.adapters;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,11 +13,14 @@ import androidx.recyclerview.widget.RecyclerView;
import com.vdurmont.emoji.EmojiParser;
import org.gitnex.tea4j.models.Commits;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CommitDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.fragments.CommitDetailFragment;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import java.util.List;
import java.util.Objects;
/**
* Author M M Arif
@ -83,7 +87,6 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
View rootView;
TextView commitSubject;
TextView commitBody;
TextView commitAuthorAndCommitter;
ImageView commitAuthorAvatar;
ImageView commitCommitterAvatar;
@ -96,7 +99,6 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
rootView = itemView;
commitSubject = itemView.findViewById(R.id.commitSubject);
commitBody = itemView.findViewById(R.id.commitBody);
commitAuthorAndCommitter = itemView.findViewById(R.id.commitAuthorAndCommitter);
commitAuthorAvatar = itemView.findViewById(R.id.commitAuthorAvatar);
commitCommitterAvatar = itemView.findViewById(R.id.commitCommitterAvatar);
@ -108,31 +110,24 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
String[] commitMessageParts = commitsModel.getCommit().getMessage().split("(\r\n|\n)", 2);
if(commitMessageParts.length > 1 && !commitMessageParts[1].trim().isEmpty()) {
commitBody.setVisibility(View.VISIBLE);
commitSubject.setText(EmojiParser.parseToUnicode(commitMessageParts[0].trim()));
commitBody.setText(EmojiParser.parseToUnicode(commitMessageParts[1].trim()));
} else {
commitSubject.setText(EmojiParser.parseToUnicode(commitMessageParts[0].trim()));
commitBody.setVisibility(View.GONE);
}
commitSubject.setText(EmojiParser.parseToUnicode(commitMessageParts[0].trim()));
if(commitsModel.getCommitter().getId() != commitsModel.getAuthor().getId()) {
if(!Objects.equals(commitsModel.getCommit().getCommitter().getEmail(), commitsModel.getCommit().getAuthor().getEmail())) {
commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(context
.getString(R.string.commitAuthoredByAndCommittedByWhen, commitsModel.getAuthor().getUsername(), commitsModel.getCommitter().getUsername(),
.getString(R.string.commitAuthoredByAndCommittedByWhen, commitsModel.getCommit().getAuthor().getName(), commitsModel.getCommit().getCommitter().getName(),
TimeHelper
.formatTime(commitsModel.getCommit().getCommitter().getDate(), context.getResources().getConfiguration().locale, "pretty",
context)), HtmlCompat.FROM_HTML_MODE_COMPACT));
} else {
commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(context
.getString(R.string.commitCommittedByWhen, commitsModel.getCommitter().getUsername(),
.getString(R.string.commitCommittedByWhen, commitsModel.getCommit().getCommitter().getName(),
TimeHelper
.formatTime(commitsModel.getCommit().getCommitter().getDate(), context.getResources().getConfiguration().locale, "pretty",
context)), HtmlCompat.FROM_HTML_MODE_COMPACT));
}
if(commitsModel.getAuthor().getAvatar_url() != null &&
if(commitsModel.getAuthor() != null && commitsModel.getAuthor().getAvatar_url() != null &&
!commitsModel.getAuthor().getAvatar_url().isEmpty()) {
commitAuthorAvatar.setVisibility(View.VISIBLE);
@ -151,7 +146,8 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
commitAuthorAvatar.setVisibility(View.GONE);
}
if(!commitsModel.getAuthor().getLogin().equals(commitsModel.getCommitter().getLogin()) &&
if(commitsModel.getCommitter() != null &&
!commitsModel.getAuthor().getLogin().equals(commitsModel.getCommitter().getLogin()) &&
commitsModel.getCommitter().getAvatar_url() != null &&
!commitsModel.getCommitter().getAvatar_url().isEmpty()) {
@ -172,7 +168,11 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
commitSha.setText(commitsModel.getSha().substring(0, Math.min(commitsModel.getSha().length(), 10)));
rootView.setOnClickListener(v -> AppUtil.openUrlInBrowser(context, commitsModel.getHtml_url()));
rootView.setOnClickListener(v -> {
Intent intent = new Intent(context, CommitDetailActivity.class);
intent.putExtra("sha", commitsModel.getSha());
context.startActivity(intent);
});
}
}

View File

@ -28,6 +28,7 @@ public class DiffAdapter extends BaseAdapter {
private final List<Integer> selectedLines;
private final Typeface typeface;
private final String type;
private static int COLOR_ADDED;
private static int COLOR_REMOVED;
@ -35,11 +36,12 @@ public class DiffAdapter extends BaseAdapter {
private static int COLOR_SELECTED;
private static int COLOR_FONT;
public DiffAdapter(Context context, FragmentManager fragmentManager, List<String> lines) {
public DiffAdapter(Context context, FragmentManager fragmentManager, List<String> lines, String type) {
this.context = context;
this.fragmentManager = fragmentManager;
this.lines = lines;
this.type = type;
selectedLines = new ArrayList<>();
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/sourcecodeproregular.ttf");
@ -84,44 +86,47 @@ public class DiffAdapter extends BaseAdapter {
}
convertView.setOnClickListener(v -> {
if(type.equals("pull")) {
convertView.setOnClickListener(v -> {
if(selectedLines.contains(position)) {
if(selectedLines.contains(position)) {
selectedLines.remove((Object) position);
v.setBackgroundColor(getLineColor(lines.get(position)));
} else {
selectedLines.remove((Object) position);
v.setBackgroundColor(getLineColor(lines.get(position)));
}
else {
selectedLines.add(position);
v.setBackgroundColor(COLOR_SELECTED);
}
});
selectedLines.add(position);
v.setBackgroundColor(COLOR_SELECTED);
}
});
convertView.setOnLongClickListener(v -> {
convertView.setOnLongClickListener(v -> {
if(selectedLines.contains(position)) {
if(selectedLines.contains(position)) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("```\n");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("```\n");
for(Integer selectedLine : selectedLines.stream().sorted().collect(Collectors.toList())) {
stringBuilder.append(lines.get(selectedLine));
stringBuilder.append("\n");
for(Integer selectedLine : selectedLines.stream().sorted().collect(Collectors.toList())) {
stringBuilder.append(lines.get(selectedLine));
stringBuilder.append("\n");
}
stringBuilder.append("```\n\n");
selectedLines.clear();
Bundle bundle = new Bundle();
bundle.putString("commentBody", stringBuilder.toString());
bundle.putBoolean("cursorToEnd", true);
BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet");
}
stringBuilder.append("```\n\n");
selectedLines.clear();
return true;
Bundle bundle = new Bundle();
bundle.putString("commentBody", stringBuilder.toString());
bundle.putBoolean("cursorToEnd", true);
BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet");
}
return true;
});
});
}
String line = lines.get(position);

View File

@ -0,0 +1,250 @@
package org.mian.gitnex.fragments;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.Fragment;
import com.vdurmont.emoji.EmojiParser;
import org.gitnex.tea4j.models.Commits;
import org.gitnex.tea4j.models.FileDiffView;
import org.mian.gitnex.R;
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.*;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* @author qwerty287
*/
public class CommitDetailFragment extends Fragment {
private FragmentCommitDetailsBinding binding;
private String repoOwner;
private String repoName;
private String sha;
private int loadingFinished = 0;
public static CommitDetailFragment newInstance() {
return new CommitDetailFragment();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
binding = FragmentCommitDetailsBinding.inflate(getLayoutInflater(), container, false);
String repoFullName = TinyDB.getInstance(requireContext()).getString("repoFullName");
String[] parts = repoFullName.split("/");
repoOwner = parts[0];
repoName = parts[1];
sha = requireActivity().getIntent().getStringExtra("sha");
binding.toolbarTitle.setText(sha.substring(0, Math.min(sha.length(), 10)));
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();
}
private void getDiff() {
Call<ResponseBody> call = new Version(TinyDB.getInstance(requireContext()).getString("giteaVersion")).higherOrEqual("1.16.0") ?
RetrofitClient.getApiInterface(requireContext()).getCommitDiff(Authorization.get(requireContext()), repoOwner, repoName, sha) :
RetrofitClient.getWebInterface(requireContext()).getCommitDiff(Authorization.getWeb(requireContext()), repoOwner, repoName, sha);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
checkLoading();
assert response.body() != null;
switch(response.code()) {
case 200:
List<FileDiffView> fileDiffViews;
try {
fileDiffViews = ParseDiff.getFileDiffViewArray(response.body().string());
} catch(IOException e) {
onFailure(call, e);
return;
}
DiffFilesAdapter adapter = new DiffFilesAdapter(requireContext(), fileDiffViews);
requireActivity().runOnUiThread(() -> binding.diffFiles.setAdapter(adapter));
break;
case 401:
requireActivity().runOnUiThread(() -> AlertDialogs.authorizationTokenRevokedDialog(requireContext(), getString(R.string.alertDialogTokenRevokedTitle),
getString(R.string.alertDialogTokenRevokedMessage), getString(R.string.cancelButton), getString(R.string.cancelButton)));
break;
case 403:
requireActivity().runOnUiThread(() -> Toasty.error(requireContext(), getString(R.string.authorizeError)));
break;
case 404:
requireActivity().runOnUiThread(() -> Toasty.warning(requireContext(), getString(R.string.apiNotFound)));
break;
default:
requireActivity().runOnUiThread(() -> Toasty.error(requireContext(), getString(R.string.labelGeneralError)));
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
checkLoading();
Toasty.error(requireContext(), getString(R.string.genericError));
}
});
}
private void getCommit() {
RetrofitClient.getApiInterface(requireContext()).getCommit(Authorization.get(requireContext()), repoOwner, repoName, sha)
.enqueue(new Callback<Commits>() {
@Override
public void onResponse(@NonNull Call<Commits> call, @NonNull Response<Commits> 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());
assert response.body() != null;
Commits commitsModel = response.body();
String[] commitMessageParts = commitsModel.getCommit().getMessage().split("(\r\n|\n)", 2);
if(commitMessageParts.length > 1 && !commitMessageParts[1].trim().isEmpty()) {
binding.commitBody.setVisibility(View.VISIBLE);
binding.commitSubject.setText(EmojiParser.parseToUnicode(commitMessageParts[0].trim()));
binding.commitBody.setText(EmojiParser.parseToUnicode(commitMessageParts[1].trim()));
} else {
binding.commitSubject.setText(EmojiParser.parseToUnicode(commitMessageParts[0].trim()));
binding.commitBody.setVisibility(View.GONE);
}
if(!Objects.equals(commitsModel.getCommit().getCommitter().getEmail(), commitsModel.getCommit().getCommitter().getEmail())) {
binding.commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(CommitDetailFragment.this
.getString(R.string.commitAuthoredByAndCommittedByWhen, commitsModel.getCommit().getAuthor().getName(), commitsModel.getCommit().getCommitter().getName(),
TimeHelper
.formatTime(commitsModel.getCommit().getCommitter().getDate(), getResources().getConfiguration().locale, "pretty",
requireContext())), HtmlCompat.FROM_HTML_MODE_COMPACT));
} else {
binding.commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(CommitDetailFragment.this
.getString(R.string.commitCommittedByWhen, commitsModel.getCommit().getCommitter().getName(),
TimeHelper
.formatTime(commitsModel.getCommit().getCommitter().getDate(), getResources().getConfiguration().locale, "pretty",
requireContext())), HtmlCompat.FROM_HTML_MODE_COMPACT));
}
if(commitsModel.getAuthor() != null && commitsModel.getAuthor().getAvatar_url() != null &&
!commitsModel.getAuthor().getAvatar_url().isEmpty()) {
binding.commitAuthorAvatar.setVisibility(View.VISIBLE);
int imgRadius = AppUtil.getPixelsFromDensity(requireContext(), 3);
PicassoService.getInstance(requireContext()).get()
.load(commitsModel.getAuthor().getAvatar_url())
.placeholder(R.drawable.loader_animated)
.transform(new RoundedTransformation(imgRadius, 0))
.resize(120, 120)
.centerCrop().into(binding.commitAuthorAvatar);
binding.commitAuthorAvatar.setOnClickListener((v) -> {
Intent intent = new Intent(requireContext(), ProfileActivity.class);
intent.putExtra("username", commitsModel.getAuthor().getUsername());
startActivity(intent);
});
} else {
binding.commitAuthorAvatar.setImageDrawable(null);
binding.commitAuthorAvatar.setVisibility(View.GONE);
}
if(commitsModel.getCommitter() != null &&
!commitsModel.getAuthor().getLogin().equals(commitsModel.getCommitter().getLogin()) &&
commitsModel.getCommitter().getAvatar_url() != null &&
!commitsModel.getCommitter().getAvatar_url().isEmpty()) {
binding.commitCommitterAvatar.setVisibility(View.VISIBLE);
int imgRadius = AppUtil.getPixelsFromDensity(requireContext(), 3);
PicassoService.getInstance(requireContext()).get()
.load(commitsModel.getCommitter().getAvatar_url())
.placeholder(R.drawable.loader_animated)
.transform(new RoundedTransformation(imgRadius, 0))
.resize(120, 120)
.centerCrop().into(binding.commitCommitterAvatar);
binding.commitCommitterAvatar.setOnClickListener((v) -> {
Intent intent = new Intent(requireContext(), ProfileActivity.class);
intent.putExtra("username", commitsModel.getCommitter().getUsername());
startActivity(intent);
});
} else {
binding.commitCommitterAvatar.setImageDrawable(null);
binding.commitCommitterAvatar.setVisibility(View.GONE);
}
binding.commitSha.setText(commitsModel.getSha().substring(0, Math.min(commitsModel.getSha().length(), 10)));
binding.commitSha.setOnClickListener((v) -> {
ClipboardManager clipboard = (ClipboardManager) requireContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("commitSha", commitsModel.getSha());
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.success(requireContext(), getString(R.string.copyShaToastMsg));
});
}
@Override
public void onFailure(@NonNull Call<Commits> call, @NonNull Throwable t) {
checkLoading();
Toasty.error(requireContext(), getString(R.string.genericError));
requireActivity().finish();
}
});
}
private void checkLoading() {
loadingFinished += 1;
if(loadingFinished >= 2) {
binding.progressBar.setVisibility(View.GONE);
}
}
}

View File

@ -61,7 +61,7 @@ public class DiffFilesFragment extends Fragment {
binding.diffFiles.setOnItemClickListener((parent, view, position, id) -> requireActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position)))
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position), "pull"))
.commit());
getPullDiffFiles(repoOwner, repoName, pullIndex);

View File

@ -12,6 +12,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.adapters.DiffAdapter;
import org.mian.gitnex.databinding.FragmentDiffBinding;
import java.util.Arrays;
import java.util.Objects;
/**
* @author opyale
@ -23,6 +24,7 @@ public class DiffFragment extends Fragment {
private Context ctx;
private FileDiffView fileDiffView;
private String type;
public DiffFragment() {}
@ -30,10 +32,11 @@ public class DiffFragment extends Fragment {
this.fileDiffView = fileDiffView;
}
public static DiffFragment newInstance(FileDiffView fileDiffView) {
public static DiffFragment newInstance(FileDiffView fileDiffView, String type) {
DiffFragment fragment = new DiffFragment();
fragment.setFileDiffView(fileDiffView);
fragment.type = type;
return fragment;
}
@ -44,14 +47,15 @@ public class DiffFragment extends Fragment {
binding = FragmentDiffBinding.inflate(inflater, container, false);
ctx = requireContext();
binding.close.setOnClickListener(v -> requireActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, DiffFilesFragment.newInstance())
.commit());
if(Objects.equals(type, "pull")) {
binding.close.setOnClickListener(v -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, DiffFilesFragment.newInstance()).commit());
} else {
binding.close.setOnClickListener(v -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, CommitDetailFragment.newInstance()).commit());
}
binding.toolbarTitle.setText(fileDiffView.getFileName());
binding.diff.setDivider(null);
binding.diff.setAdapter(new DiffAdapter(ctx, getChildFragmentManager(), Arrays.asList(fileDiffView.toString().split("\\R"))));
binding.diff.setAdapter(new DiffAdapter(ctx, getChildFragmentManager(), Arrays.asList(fileDiffView.toString().split("\\R")), type));
return binding.getRoot();

View File

@ -20,6 +20,7 @@ import org.commonmark.parser.InlineParserFactory;
import org.commonmark.parser.Parser;
import org.commonmark.parser.PostProcessor;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CommitDetailActivity;
import org.mian.gitnex.activities.IssueDetailActivity;
import org.mian.gitnex.activities.ProfileActivity;
import org.mian.gitnex.clients.PicassoService;
@ -382,18 +383,20 @@ public class Markdown {
view.getContext().startActivity(i);
}
else if(link.startsWith("gitnexcommit://")) {
// this is not supported by GitNex itself right now, so let's open the browser
TinyDB tinyDB = TinyDB.getInstance(context);
String instanceUrl = tinyDB.getString("instanceUrl");
instanceUrl = instanceUrl.substring(0, instanceUrl.lastIndexOf("api/v1/"));
link = link.substring(15);
Intent i = new Intent(view.getContext(), CommitDetailActivity.class);
String sha;
if(link.contains("/")) {
AppUtil.openUrlInBrowser(context,
instanceUrl + link.substring(0, link.lastIndexOf("/")) + "/commit/" + link.split("/")[2]);
sha = link.split("/")[2];
tinyDB.putString("repoFullName", link.split("/")[0] + link.split("/")[1]);
}
else {
AppUtil.openUrlInBrowser(context, instanceUrl + tinyDB.getString("repoFullName") + "/commit/" + link);
sha = link.substring(1);
}
i.putExtra("sha", sha);
view.getContext().startActivity(i);
}
else {
AppUtil.openUrlInBrowser(view.getContext(), link);

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,100 @@
<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

@ -0,0 +1,72 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Widget.AppCompat.SearchView"
app:elevation="0dp"
app:layout_constraintTop_toTopOf="parent">
<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_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/close"
android:focusable="true"
android:gravity="center_vertical"
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:layout_marginEnd="20dp"
android:ellipsize="none"
android:scrollbars="horizontal"
android:singleLine="true"
android:textColor="?attr/primaryTextColor"
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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
app:indicatorColor="?attr/progressIndicatorColor" />
<ListView
android:id="@+id/diff_files"
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" />
</LinearLayout>

View File

@ -2,12 +2,15 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
app:elevation="0dp"
android:theme="@style/Widget.AppCompat.SearchView">
<com.google.android.material.appbar.MaterialToolbar

View File

@ -23,16 +23,6 @@
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"
@ -53,13 +43,14 @@
android:layout_width="@dimen/list_avatar_size"
android:layout_height="@dimen/list_avatar_size"
android:contentDescription="@string/generalImgContentText"
android:layout_marginEnd="5dp"
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_marginStart="5dp"
android:layout_marginEnd="5dp"
android:contentDescription="@string/generalImgContentText"
tools:srcCompat="@tools:sample/avatars" />
@ -67,7 +58,8 @@
android:id="@+id/commitAuthorAndCommitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textSize="12sp"
android:textColor="?attr/primaryTextColor"
tools:text="opyale authored and opyale committed" />
@ -78,10 +70,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginStart="10dp"
android:alpha=".8"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:textColor="?attr/primaryTextColor"
android:textSize="12sp"
app:drawableLeftCompat="@drawable/ic_commit"
tools:text="357f3qd5s" />

View File

@ -463,6 +463,7 @@
<string name="copyIssueUrl">Copy Issue URL</string>
<string name="copyIssueUrlToastMsg">URL copied to clipboard</string>
<string name="copyIssueCommentToastMsg">Comment copied to clipboard</string>
<string name="copyShaToastMsg">SHA copied to clipboard</string>
<string name="milestoneCompletion">%1$d\uFF05 completed</string>