2022-02-22 07:23:46 +01:00
|
|
|
package org.mian.gitnex.adapters;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.helpers.contexts.IssueContext;
|
2022-02-22 07:23:46 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
2022-04-18 09:10:54 +02:00
|
|
|
* @author opyale
|
2022-02-22 07:23:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class DiffAdapter extends BaseAdapter {
|
|
|
|
|
|
|
|
private final Context context;
|
|
|
|
private final FragmentManager fragmentManager;
|
|
|
|
private final List<String> lines;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
private final IssueContext issue;
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
private final List<Integer> selectedLines;
|
|
|
|
private final Typeface typeface;
|
2022-03-09 12:52:34 +01:00
|
|
|
private final String type;
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
private static int COLOR_ADDED;
|
|
|
|
private static int COLOR_REMOVED;
|
|
|
|
private static int COLOR_NORMAL;
|
|
|
|
private static int COLOR_SELECTED;
|
|
|
|
private static int COLOR_FONT;
|
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
public DiffAdapter(Context context, FragmentManager fragmentManager, List<String> lines, IssueContext issue, String type) {
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
this.context = context;
|
|
|
|
this.fragmentManager = fragmentManager;
|
|
|
|
this.lines = lines;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
this.issue = issue;
|
2022-03-09 12:52:34 +01:00
|
|
|
this.type = type;
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
selectedLines = new ArrayList<>();
|
|
|
|
typeface = Typeface.createFromAsset(context.getAssets(), "fonts/sourcecodeproregular.ttf");
|
|
|
|
|
|
|
|
COLOR_ADDED = AppUtil.getColorFromAttribute(context, R.attr.diffAddedColor);
|
|
|
|
COLOR_REMOVED = AppUtil.getColorFromAttribute(context, R.attr.diffRemovedColor);
|
|
|
|
COLOR_NORMAL = AppUtil.getColorFromAttribute(context, R.attr.primaryBackgroundColor);
|
|
|
|
COLOR_SELECTED = AppUtil.getColorFromAttribute(context, R.attr.diffSelectedColor);
|
|
|
|
COLOR_FONT = AppUtil.getColorFromAttribute(context, R.attr.inputTextColor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return lines.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
|
|
|
return lines.get(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
|
|
|
|
if(convertView == null) {
|
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
|
|
|
|
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
|
textView.setTextColor(COLOR_FONT);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
2022-04-18 09:10:54 +02:00
|
|
|
textView.setPadding(32, 0, 32, 0);
|
2022-02-22 07:23:46 +01:00
|
|
|
textView.setTypeface(typeface);
|
|
|
|
|
|
|
|
convertView = textView;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-21 11:38:15 +02:00
|
|
|
if(type.equalsIgnoreCase("pull")) {
|
2022-03-09 12:52:34 +01:00
|
|
|
convertView.setOnClickListener(v -> {
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
if(selectedLines.contains(position)) {
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
selectedLines.remove((Object) position);
|
|
|
|
v.setBackgroundColor(getLineColor(lines.get(position)));
|
|
|
|
}
|
|
|
|
else {
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
selectedLines.add(position);
|
|
|
|
v.setBackgroundColor(COLOR_SELECTED);
|
|
|
|
}
|
|
|
|
});
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
convertView.setOnLongClickListener(v -> {
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
if(selectedLines.contains(position)) {
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
stringBuilder.append("```\n");
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
for(Integer selectedLine : selectedLines.stream().sorted().collect(Collectors.toList())) {
|
|
|
|
stringBuilder.append(lines.get(selectedLine));
|
|
|
|
stringBuilder.append("\n");
|
|
|
|
}
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
stringBuilder.append("```\n\n");
|
|
|
|
selectedLines.clear();
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putString("commentBody", stringBuilder.toString());
|
|
|
|
bundle.putBoolean("cursorToEnd", true);
|
2022-02-22 07:23:46 +01:00
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
BottomSheetReplyFragment.newInstance(bundle, issue).show(fragmentManager, "replyBottomSheet");
|
|
|
|
}
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
return true;
|
2022-02-22 07:23:46 +01:00
|
|
|
|
2022-03-09 12:52:34 +01:00
|
|
|
});
|
|
|
|
}
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
String line = lines.get(position);
|
|
|
|
|
|
|
|
int backgroundColor = selectedLines.contains(position) ? COLOR_SELECTED : getLineColor(line);
|
|
|
|
|
|
|
|
convertView.setBackgroundColor(backgroundColor);
|
|
|
|
((TextView) convertView).setText(line);
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getLineColor(String line) {
|
|
|
|
|
|
|
|
if(line.length() == 0) {
|
|
|
|
return COLOR_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(line.charAt(0)) {
|
|
|
|
case '+': return COLOR_ADDED;
|
|
|
|
case '-': return COLOR_REMOVED;
|
|
|
|
|
|
|
|
default: return COLOR_NORMAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|