2019-09-17 08:17:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2022-08-14 08:44:04 +02:00
|
|
|
import android.app.Activity;
|
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 android.content.Intent;
|
2019-09-17 08:17:05 +02:00
|
|
|
import android.os.Bundle;
|
2024-02-11 14:20:23 +01:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.view.MenuItem;
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.view.MotionEvent;
|
2019-09-18 10:25:49 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ArrayAdapter;
|
2022-08-14 08:44:04 +02:00
|
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
2019-09-18 10:25:49 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2022-09-21 07:43:00 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
2022-08-14 08:44:04 +02:00
|
|
|
import org.apache.commons.io.FilenameUtils;
|
2022-09-14 20:40:44 +02:00
|
|
|
import org.gitnex.tea4j.v2.models.Branch;
|
|
|
|
import org.gitnex.tea4j.v2.models.CreateFileOptions;
|
|
|
|
import org.gitnex.tea4j.v2.models.DeleteFileOptions;
|
|
|
|
import org.gitnex.tea4j.v2.models.FileDeleteResponse;
|
|
|
|
import org.gitnex.tea4j.v2.models.FileResponse;
|
|
|
|
import org.gitnex.tea4j.v2.models.UpdateFileOptions;
|
2019-09-17 08:17:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
2019-09-18 10:25:49 +02:00
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivityCreateFileBinding;
|
2019-09-18 10:25:49 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2024-02-11 14:20:23 +01:00
|
|
|
import org.mian.gitnex.helpers.SnackBar;
|
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.RepositoryContext;
|
2019-09-18 10:25:49 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2019-09-17 08:17:05 +02:00
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2019-09-17 08:17:05 +02:00
|
|
|
*/
|
2020-03-17 11:32:03 +01:00
|
|
|
public class CreateFileActivity extends BaseActivity {
|
2019-09-17 08:17:05 +02:00
|
|
|
|
2021-02-01 19:13:48 +01:00
|
|
|
public static final int FILE_ACTION_CREATE = 0;
|
|
|
|
public static final int FILE_ACTION_DELETE = 1;
|
|
|
|
public static final int FILE_ACTION_EDIT = 2;
|
2022-08-15 16:26:02 +02:00
|
|
|
private final List<String> branches = new ArrayList<>();
|
|
|
|
private ActivityCreateFileBinding binding;
|
2022-09-21 07:43:00 +02:00
|
|
|
ActivityResultLauncher<Intent> codeEditorActivityResultLauncher =
|
|
|
|
registerForActivityResult(
|
|
|
|
new ActivityResultContracts.StartActivityForResult(),
|
|
|
|
result -> {
|
|
|
|
if (result.getResultCode() == Activity.RESULT_OK) {
|
|
|
|
Intent data = result.getData();
|
|
|
|
assert data != null;
|
|
|
|
binding.newFileContent.setText(
|
|
|
|
data.getStringExtra("fileContentFromActivity"));
|
|
|
|
}
|
|
|
|
});
|
2021-02-01 19:13:48 +01:00
|
|
|
private int fileAction = FILE_ACTION_CREATE;
|
2021-03-21 16:56:54 +01:00
|
|
|
private String filePath;
|
|
|
|
private String fileSha;
|
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 RepositoryContext repository;
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
binding = ActivityCreateFileBinding.inflate(getLayoutInflater());
|
|
|
|
setContentView(binding.getRoot());
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
repository = RepositoryContext.fromIntent(getIntent());
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setNavigationOnClickListener(v -> finish());
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
MenuItem create = binding.topAppBar.getMenu().getItem(0);
|
|
|
|
MenuItem update = binding.topAppBar.getMenu().getItem(1);
|
|
|
|
MenuItem delete = binding.topAppBar.getMenu().getItem(2);
|
|
|
|
update.setVisible(false);
|
|
|
|
delete.setVisible(false);
|
2020-03-29 16:24:38 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
binding.newFileContent.setOnTouchListener(
|
|
|
|
(touchView, motionEvent) -> {
|
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
2020-10-30 08:00:52 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0
|
|
|
|
&& (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
2020-10-30 08:00:52 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
|
|
|
}
|
2021-03-21 16:56:54 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
return false;
|
|
|
|
});
|
2021-03-21 16:56:54 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (getIntent().getStringExtra("filePath") != null
|
|
|
|
&& getIntent().getIntExtra("fileAction", FILE_ACTION_DELETE)
|
|
|
|
== FILE_ACTION_DELETE) {
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
fileAction = getIntent().getIntExtra("fileAction", FILE_ACTION_DELETE);
|
|
|
|
filePath = getIntent().getStringExtra("filePath");
|
|
|
|
fileSha = getIntent().getStringExtra("fileSha");
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setTitle(getString(R.string.deleteGenericTitle, filePath));
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
binding.newFileNameLayout.setVisibility(View.GONE);
|
|
|
|
binding.newFileContentLayout.setVisibility(View.GONE);
|
2024-02-11 14:20:23 +01:00
|
|
|
delete.setVisible(true);
|
|
|
|
create.setVisible(false);
|
|
|
|
update.setVisible(false);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (getIntent().getStringExtra("filePath") != null
|
|
|
|
&& getIntent().getIntExtra("fileAction", FILE_ACTION_EDIT) == FILE_ACTION_EDIT) {
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
fileAction = getIntent().getIntExtra("fileAction", FILE_ACTION_EDIT);
|
|
|
|
filePath = getIntent().getStringExtra("filePath");
|
|
|
|
fileSha = getIntent().getStringExtra("fileSha");
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setTitle(getString(R.string.editFileText, filePath));
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
binding.newFileName.setText(filePath);
|
|
|
|
binding.newFileName.setEnabled(false);
|
|
|
|
binding.newFileName.setFocusable(false);
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
binding.newFileContent.setText(getIntent().getStringExtra("fileContents"));
|
2024-02-11 14:20:23 +01:00
|
|
|
update.setVisible(true);
|
|
|
|
create.setVisible(false);
|
|
|
|
delete.setVisible(false);
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
getBranches(repository.getOwner(), repository.getName());
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
binding.openCodeEditor.setOnClickListener(
|
2022-09-21 07:43:00 +02:00
|
|
|
v ->
|
|
|
|
launchCodeEditorActivityForResult(
|
|
|
|
Objects.requireNonNull(binding.newFileContent.getText()).toString(),
|
|
|
|
FilenameUtils.getExtension(
|
|
|
|
String.valueOf(binding.newFileName.getText()))));
|
2022-08-14 08:44:04 +02:00
|
|
|
|
2024-02-11 14:20:23 +01:00
|
|
|
binding.topAppBar.setOnMenuItemClickListener(
|
|
|
|
menuItem -> {
|
|
|
|
int id = menuItem.getItemId();
|
|
|
|
|
|
|
|
if (id == R.id.create) {
|
|
|
|
processNewFile();
|
|
|
|
return true;
|
|
|
|
} else if (id == R.id.update) {
|
|
|
|
processNewFile();
|
|
|
|
return true;
|
|
|
|
} else if (id == R.id.delete) {
|
|
|
|
processNewFile();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return super.onOptionsItemSelected(menuItem);
|
|
|
|
}
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-08-14 08:44:04 +02:00
|
|
|
public void launchCodeEditorActivityForResult(String fileContent, String fileExtension) {
|
|
|
|
Intent intent = new Intent(this, CodeEditorActivity.class);
|
|
|
|
intent.putExtra("fileExtension", fileExtension);
|
|
|
|
intent.putExtra("fileContent", fileContent);
|
|
|
|
codeEditorActivityResultLauncher.launch(intent);
|
|
|
|
}
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void processNewFile() {
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
String newFileName =
|
|
|
|
binding.newFileName.getText() != null
|
|
|
|
? binding.newFileName.getText().toString()
|
|
|
|
: "";
|
|
|
|
String newFileContent =
|
|
|
|
binding.newFileContent.getText() != null
|
|
|
|
? binding.newFileContent.getText().toString()
|
|
|
|
: "";
|
|
|
|
String newFileBranchName =
|
|
|
|
binding.newFileBranches.getText() != null
|
|
|
|
? binding.newFileBranches.getText().toString()
|
|
|
|
: "";
|
|
|
|
String newFileCommitMessage =
|
|
|
|
binding.newFileCommitMessage.getText() != null
|
|
|
|
? binding.newFileCommitMessage.getText().toString()
|
|
|
|
: "";
|
|
|
|
|
|
|
|
if (!AppUtil.hasNetworkConnection(appCtx)) {
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.checkNetConnection));
|
2022-08-15 16:26:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (((newFileName.isEmpty() || newFileContent.isEmpty())
|
|
|
|
&& fileAction != FILE_ACTION_DELETE)
|
|
|
|
|| newFileCommitMessage.isEmpty()) {
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.newFileRequiredFields));
|
2022-08-15 16:26:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (!AppUtil.checkStringsWithDash(newFileBranchName)) {
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.newFileInvalidBranchName));
|
2022-08-15 16:26:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (newFileCommitMessage.length() > 255) {
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.newFileCommitMessageError));
|
2022-08-15 16:26:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
switch (fileAction) {
|
2022-08-15 16:26:02 +02:00
|
|
|
case FILE_ACTION_CREATE:
|
2022-09-21 07:43:00 +02:00
|
|
|
createNewFile(
|
|
|
|
repository.getOwner(),
|
|
|
|
repository.getName(),
|
|
|
|
newFileName,
|
|
|
|
AppUtil.encodeBase64(newFileContent),
|
|
|
|
newFileCommitMessage,
|
|
|
|
newFileBranchName);
|
2022-08-15 16:26:02 +02:00
|
|
|
break;
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
case FILE_ACTION_DELETE:
|
2022-09-21 07:43:00 +02:00
|
|
|
deleteFile(
|
|
|
|
repository.getOwner(),
|
|
|
|
repository.getName(),
|
|
|
|
filePath,
|
|
|
|
newFileCommitMessage,
|
|
|
|
newFileBranchName,
|
|
|
|
fileSha);
|
2022-08-15 16:26:02 +02:00
|
|
|
break;
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
case FILE_ACTION_EDIT:
|
2022-09-21 07:43:00 +02:00
|
|
|
editFile(
|
|
|
|
repository.getOwner(),
|
|
|
|
repository.getName(),
|
|
|
|
filePath,
|
|
|
|
AppUtil.encodeBase64(newFileContent),
|
|
|
|
newFileCommitMessage,
|
|
|
|
newFileBranchName,
|
|
|
|
fileSha);
|
2022-08-15 16:26:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void createNewFile(
|
|
|
|
String repoOwner,
|
|
|
|
String repoName,
|
|
|
|
String fileName,
|
|
|
|
String fileContent,
|
|
|
|
String fileCommitMessage,
|
|
|
|
String branchName) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
CreateFileOptions createNewFileJsonStr = new CreateFileOptions();
|
2022-04-18 09:10:54 +02:00
|
|
|
createNewFileJsonStr.setContent(fileContent);
|
|
|
|
createNewFileJsonStr.setMessage(fileCommitMessage);
|
2022-08-14 08:44:04 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (branches.contains(branchName)) {
|
2022-04-18 09:10:54 +02:00
|
|
|
createNewFileJsonStr.setBranch(branchName);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2022-04-18 09:10:54 +02:00
|
|
|
createNewFileJsonStr.setNewBranch(branchName);
|
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<FileResponse> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoCreateFile(createNewFileJsonStr, repoOwner, repoName, fileName);
|
|
|
|
|
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<FileResponse> call,
|
|
|
|
@NonNull retrofit2.Response<FileResponse> response) {
|
|
|
|
|
|
|
|
switch (response.code()) {
|
|
|
|
case 201:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.success(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.newFileSuccessMessage));
|
2022-09-21 07:43:00 +02:00
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("fileModified", true);
|
|
|
|
result.putExtra("fileAction", fileAction);
|
|
|
|
setResult(200, result);
|
2023-03-26 08:11:59 +02:00
|
|
|
RepoDetailActivity.updateFABActions = true;
|
2024-02-11 14:20:23 +01:00
|
|
|
new Handler().postDelayed(() -> finish(), 3000);
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 401:
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 404:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.apiNotFound));
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.genericError));
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-11 14:20:23 +01:00
|
|
|
public void onFailure(@NonNull Call<FileResponse> call, @NonNull Throwable t) {}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void deleteFile(
|
|
|
|
String repoOwner,
|
|
|
|
String repoName,
|
|
|
|
String fileName,
|
|
|
|
String fileCommitMessage,
|
|
|
|
String branchName,
|
|
|
|
String fileSha) {
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
DeleteFileOptions deleteFileJsonStr = new DeleteFileOptions();
|
2022-04-18 09:10:54 +02:00
|
|
|
deleteFileJsonStr.setMessage(fileCommitMessage);
|
|
|
|
deleteFileJsonStr.setSha(fileSha);
|
2022-08-14 08:44:04 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (branches.contains(branchName)) {
|
2022-04-18 09:10:54 +02:00
|
|
|
deleteFileJsonStr.setBranch(branchName);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2022-04-18 09:10:54 +02:00
|
|
|
deleteFileJsonStr.setNewBranch(branchName);
|
|
|
|
}
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<FileDeleteResponse> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoDeleteFileWithBody(repoOwner, repoName, fileName, deleteFileJsonStr);
|
|
|
|
|
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<FileDeleteResponse> call,
|
|
|
|
@NonNull retrofit2.Response<FileDeleteResponse> response) {
|
|
|
|
|
|
|
|
switch (response.code()) {
|
|
|
|
case 200:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.success(
|
2022-09-21 07:43:00 +02:00
|
|
|
ctx,
|
2024-02-11 14:20:23 +01:00
|
|
|
findViewById(android.R.id.content),
|
2022-09-21 07:43:00 +02:00
|
|
|
getString(
|
|
|
|
R.string.deleteFileMessage,
|
|
|
|
repository.getBranchRef()));
|
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("fileModified", true);
|
|
|
|
result.putExtra("fileAction", fileAction);
|
|
|
|
setResult(200, result);
|
2024-02-11 14:20:23 +01:00
|
|
|
new Handler().postDelayed(() -> finish(), 3000);
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 401:
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 404:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.apiNotFound));
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.genericError));
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(
|
2024-02-11 14:20:23 +01:00
|
|
|
@NonNull Call<FileDeleteResponse> call, @NonNull Throwable t) {}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2020-08-18 16:37:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
private void editFile(
|
|
|
|
String repoOwner,
|
|
|
|
String repoName,
|
|
|
|
String fileName,
|
|
|
|
String fileContent,
|
|
|
|
String fileCommitMessage,
|
|
|
|
String branchName,
|
|
|
|
String fileSha) {
|
2020-08-18 16:37:10 +02:00
|
|
|
|
2022-04-18 09:10:54 +02:00
|
|
|
UpdateFileOptions editFileJsonStr = new UpdateFileOptions();
|
|
|
|
editFileJsonStr.setContent(fileContent);
|
|
|
|
editFileJsonStr.setMessage(fileCommitMessage);
|
|
|
|
editFileJsonStr.setSha(fileSha);
|
2022-08-14 08:44:04 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (branches.contains(branchName)) {
|
2022-04-18 09:10:54 +02:00
|
|
|
editFileJsonStr.setBranch(branchName);
|
2022-09-21 07:43:00 +02:00
|
|
|
} else {
|
2022-04-18 09:10:54 +02:00
|
|
|
editFileJsonStr.setNewBranch(branchName);
|
|
|
|
}
|
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<FileResponse> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoUpdateFile(editFileJsonStr, repoOwner, repoName, fileName);
|
|
|
|
|
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<FileResponse> call,
|
|
|
|
@NonNull retrofit2.Response<FileResponse> response) {
|
|
|
|
|
|
|
|
switch (response.code()) {
|
|
|
|
case 200:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.success(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.editFileMessage, branchName));
|
2022-09-21 07:43:00 +02:00
|
|
|
Intent result = new Intent();
|
|
|
|
result.putExtra("fileModified", true);
|
|
|
|
result.putExtra("fileAction", fileAction);
|
|
|
|
setResult(200, result);
|
2024-02-11 14:20:23 +01:00
|
|
|
new Handler().postDelayed(() -> finish(), 3000);
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 401:
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 404:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.apiNotFound));
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-02-11 14:20:23 +01:00
|
|
|
SnackBar.error(
|
|
|
|
ctx,
|
|
|
|
findViewById(android.R.id.content),
|
|
|
|
getString(R.string.genericError));
|
2022-09-21 07:43:00 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-11 14:20:23 +01:00
|
|
|
public void onFailure(@NonNull Call<FileResponse> call, @NonNull Throwable t) {}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2020-08-18 16:37:10 +02:00
|
|
|
}
|
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void getBranches(String repoOwner, String repoName) {
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
Call<List<Branch>> call =
|
|
|
|
RetrofitClient.getApiInterface(ctx)
|
|
|
|
.repoListBranches(repoOwner, repoName, null, null);
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
call.enqueue(
|
|
|
|
new Callback<>() {
|
2022-08-15 16:26:02 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void onResponse(
|
|
|
|
@NonNull Call<List<Branch>> call,
|
|
|
|
@NonNull retrofit2.Response<List<Branch>> response) {
|
2019-09-18 10:25:49 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (response.code() == 200) {
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
assert response.body() != null;
|
|
|
|
for (Branch branch : response.body()) branches.add(branch.getName());
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ArrayAdapter<String> adapter =
|
|
|
|
new ArrayAdapter<>(
|
|
|
|
CreateFileActivity.this,
|
|
|
|
R.layout.list_spinner_items,
|
|
|
|
branches);
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
binding.newFileBranches.setAdapter(adapter);
|
|
|
|
binding.newFileBranches.setText(repository.getBranchRef(), false);
|
|
|
|
}
|
|
|
|
}
|
2020-10-20 20:09:07 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
@Override
|
2024-02-11 14:20:23 +01:00
|
|
|
public void onFailure(@NonNull Call<List<Branch>> call, @NonNull Throwable t) {}
|
2022-09-21 07:43:00 +02:00
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2020-10-20 20:09:07 +02: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
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
repository.checkAccountSwitch(this);
|
|
|
|
}
|
2019-09-17 08:17:05 +02:00
|
|
|
}
|