2022-02-22 07:23:46 +01:00
|
|
|
package org.mian.gitnex.fragments;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
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 org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.adapters.DiffFilesAdapter;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
|
|
|
import org.mian.gitnex.databinding.FragmentDiffFilesBinding;
|
2022-03-28 19:57:47 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
2022-04-18 09:10:54 +02:00
|
|
|
import org.mian.gitnex.helpers.FileDiffView;
|
2022-03-28 19:57:47 +02:00
|
|
|
import org.mian.gitnex.helpers.ParseDiff;
|
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
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.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author opyale
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class DiffFilesFragment extends Fragment {
|
|
|
|
|
|
|
|
private FragmentDiffFilesBinding binding;
|
|
|
|
private Context ctx;
|
|
|
|
|
|
|
|
public DiffFilesFragment() {}
|
|
|
|
|
|
|
|
public static DiffFilesFragment newInstance() {
|
|
|
|
return new DiffFilesFragment();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
2022-05-19 09:06:11 +02:00
|
|
|
if(binding != null) {
|
|
|
|
ctx = requireContext();
|
|
|
|
return binding.getRoot();
|
|
|
|
}
|
|
|
|
|
2022-02-22 07:23:46 +01:00
|
|
|
binding = FragmentDiffFilesBinding.inflate(inflater, container, false);
|
|
|
|
ctx = requireContext();
|
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
|
|
|
IssueContext issue = IssueContext.fromIntent(requireActivity().getIntent());
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
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()
|
2022-05-21 11:38:15 +02:00
|
|
|
.replace(R.id.fragment_container, DiffFragment.newInstance((FileDiffView) parent.getItemAtPosition(position), issue))
|
2022-02-22 07:23:46 +01:00
|
|
|
.commit());
|
|
|
|
|
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
|
|
|
getPullDiffFiles(issue.getRepository().getOwner(), issue.getRepository().getName(), String.valueOf(issue.getIssueIndex()));
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
return binding.getRoot();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getPullDiffFiles(String owner, String repo, String pullIndex) {
|
|
|
|
|
|
|
|
Thread thread = new Thread(() -> {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
Call<String> call = RetrofitClient.getApiInterface(ctx).repoDownloadPullDiffOrPatch(owner, repo, Long.valueOf(pullIndex), "diff", null);
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
Response<String> response = call.execute();
|
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
|
|
|
if(response.body() == null) {
|
|
|
|
Toasty.error(requireContext(), getString(R.string.genericError));
|
|
|
|
requireActivity().finish();
|
|
|
|
return;
|
|
|
|
}
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
switch(response.code()) {
|
|
|
|
|
|
|
|
case 200:
|
2022-04-18 09:10:54 +02:00
|
|
|
List<FileDiffView> fileDiffViews = ParseDiff.getFileDiffViewArray(response.body());
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
int filesCount = fileDiffViews.size();
|
|
|
|
|
|
|
|
String toolbarTitleText = (filesCount > 1) ?
|
|
|
|
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.progressBar.setVisibility(View.GONE);
|
|
|
|
binding.diffFiles.setAdapter(adapter);
|
|
|
|
binding.toolbarTitle.setText(toolbarTitleText);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 401:
|
2022-05-01 12:35:50 +02:00
|
|
|
requireActivity().runOnUiThread(() -> AlertDialogs.authorizationTokenRevokedDialog(ctx));
|
2022-02-22 07:23:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 403:
|
|
|
|
requireActivity().runOnUiThread(() -> Toasty.error(ctx, ctx.getString(R.string.authorizeError)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 404:
|
|
|
|
requireActivity().runOnUiThread(() -> Toasty.warning(ctx, ctx.getString(R.string.apiNotFound)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-03-18 09:56:49 +01:00
|
|
|
requireActivity().runOnUiThread(() -> Toasty.error(ctx, getString(R.string.genericError)));
|
2022-02-22 07:23:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
} catch(IOException ignored) {}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
thread.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|