2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Bundle;
|
2020-10-20 20:09:07 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.View;
|
2020-03-29 16:24:38 +02:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2020-10-20 20:09:07 +02:00
|
|
|
import android.widget.AutoCompleteTextView;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2021-02-11 11:23:35 +01:00
|
|
|
import org.gitnex.tea4j.models.OrgOwner;
|
|
|
|
import org.gitnex.tea4j.models.OrganizationRepository;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivityCreateRepoBinding;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.AlertDialogs;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.AppUtil;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.helpers.Toasty;
|
|
|
|
import java.util.ArrayList;
|
2020-03-29 20:57:19 +02:00
|
|
|
import java.util.Arrays;
|
2019-06-03 23:25:05 +02:00
|
|
|
import java.util.List;
|
2020-03-29 20:57:19 +02:00
|
|
|
import java.util.regex.Pattern;
|
2019-06-03 23:25:05 +02:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-17 11:32:03 +01:00
|
|
|
public class CreateRepoActivity extends BaseActivity {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
public ImageView closeActivity;
|
|
|
|
private View.OnClickListener onClickListener;
|
2020-10-20 20:09:07 +02:00
|
|
|
private AutoCompleteTextView spinner;
|
2019-06-03 23:25:05 +02:00
|
|
|
private Button createRepo;
|
|
|
|
private EditText repoName;
|
|
|
|
private EditText repoDesc;
|
|
|
|
private CheckBox repoAccess;
|
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
private String loginUid;
|
|
|
|
|
|
|
|
private String selectedOwner;
|
|
|
|
|
|
|
|
List<OrgOwner> organizationsList = new ArrayList<>();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-03-29 20:57:19 +02:00
|
|
|
//https://github.com/go-gitea/gitea/blob/52cfd2743c0e85b36081cf80a850e6a5901f1865/models/repo.go#L964-L967
|
|
|
|
final List<String> reservedRepoNames = Arrays.asList(".", "..");
|
|
|
|
final Pattern reservedRepoPatterns = Pattern.compile("\\.(git|wiki)$");
|
|
|
|
|
2020-01-07 13:27:05 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2020-04-28 15:47:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
ActivityCreateRepoBinding activityCreateRepoBinding = ActivityCreateRepoBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(activityCreateRepoBinding.getRoot());
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(ctx);
|
2019-06-03 23:25:05 +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
|
|
|
loginUid = getAccount().getAccount().getUserName();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
closeActivity = activityCreateRepoBinding.close;
|
|
|
|
repoName = activityCreateRepoBinding.newRepoName;
|
|
|
|
repoDesc = activityCreateRepoBinding.newRepoDescription;
|
|
|
|
repoAccess = activityCreateRepoBinding.newRepoPrivate;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
repoName.requestFocus();
|
|
|
|
assert imm != null;
|
|
|
|
imm.showSoftInput(repoName, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
spinner = activityCreateRepoBinding.ownerSpinner;
|
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
|
|
|
getOrganizations(getAccount().getAuthorization(), loginUid);
|
2020-08-20 18:21:55 +02:00
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
createRepo = activityCreateRepoBinding.createNewRepoButton;
|
2019-06-03 23:25:05 +02:00
|
|
|
disableProcessButton();
|
|
|
|
|
|
|
|
if(!connToInternet) {
|
|
|
|
|
|
|
|
disableProcessButton();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
createRepo.setOnClickListener(createRepoListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
private final View.OnClickListener createRepoListener = v -> processNewRepo();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
private void processNewRepo() {
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
String newRepoName = repoName.getText().toString();
|
|
|
|
String newRepoDesc = repoDesc.getText().toString();
|
|
|
|
boolean newRepoAccess = repoAccess.isChecked();
|
|
|
|
|
|
|
|
if(!connToInternet) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
2019-06-03 23:25:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!newRepoDesc.equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2021-02-01 19:13:48 +01:00
|
|
|
if (newRepoDesc.length() > 255) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.repoDescError));
|
2019-06-03 23:25:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newRepoName.equals("")) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.repoNameErrorEmpty));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
2021-02-13 20:31:38 +01:00
|
|
|
else if(!AppUtil.checkStrings(newRepoName)) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.repoNameErrorInvalid));
|
2020-03-29 20:57:19 +02:00
|
|
|
}
|
|
|
|
else if (reservedRepoNames.contains(newRepoName)) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedName));
|
2020-03-29 20:57:19 +02:00
|
|
|
}
|
|
|
|
else if (reservedRepoPatterns.matcher(newRepoName).find()) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedPatterns));
|
2020-10-20 20:09:07 +02:00
|
|
|
}
|
|
|
|
else if(selectedOwner == null) {
|
|
|
|
|
|
|
|
Toasty.error(ctx, getString(R.string.repoOwnerError));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
disableProcessButton();
|
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
|
|
|
createNewRepository(getAccount().getAuthorization(), loginUid, newRepoName, newRepoDesc, selectedOwner, newRepoAccess);
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
private void createNewRepository(final String token, String loginUid, String repoName, String repoDesc, String selectedOwner, boolean isPrivate) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
OrganizationRepository createRepository = new OrganizationRepository(true, repoDesc, null, null, repoName, isPrivate, "Default");
|
|
|
|
|
|
|
|
Call<OrganizationRepository> call;
|
2020-10-20 20:09:07 +02:00
|
|
|
if(selectedOwner.equals(loginUid)) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.createNewUserRepository(token, createRepository);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(ctx)
|
2020-10-20 20:09:07 +02:00
|
|
|
.createNewUserOrgRepository(token, selectedOwner, createRepository);
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
call.enqueue(new Callback<OrganizationRepository>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<OrganizationRepository> call, @NonNull retrofit2.Response<OrganizationRepository> response) {
|
|
|
|
|
|
|
|
if(response.code() == 201) {
|
|
|
|
|
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
|
|
|
MainActivity.repoCreated = true;
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(ctx, getString(R.string.repoCreated));
|
2019-06-03 23:25:05 +02:00
|
|
|
enableProcessButton();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
else if(response.code() == 401) {
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
|
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
2021-12-15 20:37:53 +01:00
|
|
|
getResources().getString(R.string.cancelButton),
|
|
|
|
getResources().getString(R.string.navLogout));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 409) {
|
|
|
|
|
|
|
|
enableProcessButton();
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.repoExistsError));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
enableProcessButton();
|
2022-03-18 09:56:49 +01:00
|
|
|
Toasty.error(ctx, getString(R.string.genericError));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<OrganizationRepository> call, @NonNull Throwable t) {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
private void getOrganizations(String instanceToken, final String userLogin) {
|
2020-03-17 11:32:03 +01:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
Call<List<OrgOwner>> call = RetrofitClient
|
2020-11-02 16:17:00 +01:00
|
|
|
.getApiInterface(ctx)
|
2021-08-02 20:04:33 +02:00
|
|
|
.getOrgOwners(instanceToken, 1, 50);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
call.enqueue(new Callback<List<OrgOwner>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<OrgOwner>> call, @NonNull retrofit2.Response<List<OrgOwner>> response) {
|
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
if(response.code() == 200) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
int organizationId = 0;
|
2020-03-17 11:32:03 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
List<OrgOwner> organizationsList_ = response.body();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
organizationsList.add(new OrgOwner(userLogin));
|
|
|
|
assert organizationsList_ != null;
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
if(organizationsList_.size() > 0) {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
for(int i = 0; i < organizationsList_.size(); i++) {
|
2019-06-03 23:25:05 +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
|
|
|
if(!getIntent().getStringExtra("orgName").equals("")) {
|
|
|
|
if(getIntent().getStringExtra("orgName").equals(organizationsList_.get(i).getUsername())) {
|
2020-10-20 20:09:07 +02:00
|
|
|
organizationId = i + 1;
|
|
|
|
}
|
|
|
|
}
|
2020-08-06 17:16:51 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
OrgOwner data = new OrgOwner(organizationsList_.get(i).getUsername());
|
|
|
|
organizationsList.add(data);
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
ArrayAdapter<OrgOwner> adapter = new ArrayAdapter<>(CreateRepoActivity.this, R.layout.list_spinner_items, organizationsList);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
spinner.setAdapter(adapter);
|
2020-03-17 11:32:03 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
spinner.setOnItemClickListener ((parent, view, position, id) -> selectedOwner = organizationsList.get(position).getUsername());
|
2020-08-06 17:16:51 +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
|
|
|
if(getIntent().getBooleanExtra("organizationAction", false) && organizationId != 0) {
|
2020-03-17 11:32:03 +01:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
int selectOwnerById = organizationId;
|
|
|
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
spinner.setText(organizationsList.get(selectOwnerById).getUsername(), false);
|
|
|
|
selectedOwner = organizationsList.get(selectOwnerById).getUsername();
|
|
|
|
}, 500);
|
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
|
|
|
getIntent().removeExtra("organizationAction");
|
2020-10-20 20:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(response.code() == 401) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-10-20 20:09:07 +02:00
|
|
|
enableProcessButton();
|
|
|
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
2021-12-15 20:37:53 +01:00
|
|
|
getResources().getString(R.string.cancelButton), getResources().getString(R.string.navLogout));
|
2020-10-20 20:09:07 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<OrgOwner>> call, @NonNull Throwable t) {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
|
|
|
onClickListener = view -> finish();
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void disableProcessButton() {
|
|
|
|
|
|
|
|
createRepo.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableProcessButton() {
|
|
|
|
|
|
|
|
createRepo.setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|