2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
2020-10-30 08:00:52 +01:00
|
|
|
import android.view.MotionEvent;
|
2019-06-03 23:25:05 +02:00
|
|
|
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.Button;
|
|
|
|
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.UserOrganizations;
|
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.ActivityCreateOrganizationBinding;
|
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.fragments.OrganizationsFragment;
|
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 retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-17 11:32:03 +01:00
|
|
|
public class CreateOrganizationActivity extends BaseActivity {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
public ImageView closeActivity;
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private Button createOrganizationButton;
|
|
|
|
|
|
|
|
private EditText orgName;
|
|
|
|
private EditText orgDesc;
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
2020-03-04 20:37:28 +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
|
|
|
ActivityCreateOrganizationBinding activityCreateOrganizationBinding = ActivityCreateOrganizationBinding.inflate(getLayoutInflater());
|
2021-01-26 18:43:25 +01:00
|
|
|
setContentView(activityCreateOrganizationBinding.getRoot());
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
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 = activityCreateOrganizationBinding.close;
|
|
|
|
orgName = activityCreateOrganizationBinding.newOrganizationName;
|
|
|
|
orgDesc = activityCreateOrganizationBinding.newOrganizationDescription;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-03-29 16:24:38 +02:00
|
|
|
orgName.requestFocus();
|
|
|
|
assert imm != null;
|
|
|
|
imm.showSoftInput(orgName, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
|
2020-10-30 08:00:52 +01:00
|
|
|
orgDesc.setOnTouchListener((touchView, motionEvent) -> {
|
|
|
|
|
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
|
|
|
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
|
|
|
|
|
|
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
2021-01-26 16:10:31 +01:00
|
|
|
createOrganizationButton = activityCreateOrganizationBinding.createNewOrganizationButton;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
if(!connToInternet) {
|
|
|
|
|
|
|
|
createOrganizationButton.setEnabled(false);
|
2020-08-06 17:16:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
createOrganizationButton.setOnClickListener(createOrgListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
|
|
|
onClickListener = view -> finish();
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 14:13:19 +01:00
|
|
|
private final View.OnClickListener createOrgListener = v -> processNewOrganization();
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
private void processNewOrganization() {
|
|
|
|
|
2020-06-28 17:11:59 +02:00
|
|
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
String newOrgName = orgName.getText().toString();
|
|
|
|
String newOrgDesc = orgDesc.getText().toString();
|
|
|
|
|
|
|
|
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(!newOrgDesc.equals("")) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2021-02-01 19:13:48 +01:00
|
|
|
if (newOrgDesc.length() > 255) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.orgDescError));
|
2019-06-03 23:25:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newOrgName.equals("")) {
|
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.error(ctx, getString(R.string.orgNameErrorEmpty));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
2021-02-13 20:31:38 +01:00
|
|
|
else if(!AppUtil.checkStrings(newOrgName)) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.orgNameErrorInvalid));
|
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
|
|
|
createNewOrganization(getAccount().getAuthorization(), newOrgName, newOrgDesc);
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:17:00 +01:00
|
|
|
private void createNewOrganization(final String token, String orgName, String orgDesc) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
UserOrganizations createOrganization = new UserOrganizations(orgName, null, orgDesc, null, null);
|
|
|
|
|
|
|
|
Call<UserOrganizations> call = RetrofitClient
|
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
|
|
|
.getApiInterface(ctx)
|
2019-06-03 23:25:05 +02:00
|
|
|
.createNewOrganization(token, createOrganization);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<UserOrganizations>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserOrganizations> call, @NonNull retrofit2.Response<UserOrganizations> 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
|
|
|
OrganizationsFragment.orgCreated = true;
|
2019-06-03 23:25:05 +02:00
|
|
|
enableProcessButton();
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.success(ctx, getString(R.string.orgCreated));
|
2019-06-03 23:25:05 +02:00
|
|
|
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.orgExistsError));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
else if(response.code() == 422) {
|
|
|
|
|
|
|
|
enableProcessButton();
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
if(response.code() == 404) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
enableProcessButton();
|
2020-08-06 17:16:51 +02:00
|
|
|
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
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<UserOrganizations> call, @NonNull Throwable t) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
enableProcessButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void disableProcessButton() {
|
|
|
|
|
|
|
|
createOrganizationButton.setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableProcessButton() {
|
|
|
|
|
|
|
|
createOrganizationButton.setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|