ReFormat activities #508

Open
6543 wants to merge 38 commits from 6543/GitNex:ReFormat_activities into master
39 changed files with 3939 additions and 4058 deletions

@ -18,15 +18,15 @@ _(This step is optional)_
---
_(This step is optional; an example is shown below)_
* The version of **Gitea** you are using:
* The version of **GitNex** you are using:
* Phone **OS** version and model:
* The type of certificate you are using (self-signed, signed):
* How you used to log in (via password or token):
* The version of **Gitea** you are using:
* The version of **GitNex** you are using:
* Phone **OS** version and model:
* The type of certificate you are using (self-signed, signed):
* How you used to log in (via password or token):
##### We would appreciate some screenshots or stacktrace's, but this is also not required.
---
_(Screenshots and stacktrace's can go here)_
#### Thank you for your time.
#### Thank you for your time.

@ -1,149 +1,148 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.UserSearchAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserSearch;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.models.UserSearch;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
*/
**/
public class AddCollaboratorToRepositoryActivity extends BaseActivity {
private View.OnClickListener onClickListener;
final Context ctx = this;
private Context appCtx;
private TextView addCollaboratorSearch;
private TextView noData;
private ProgressBar mProgressBar;
private View.OnClickListener onClickListener;
final Context ctx = this;
private Context appCtx;
private TextView addCollaboratorSearch;
private TextView noData;
private ProgressBar mProgressBar;
private RecyclerView mRecyclerView;
private RecyclerView mRecyclerView;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_add_collaborator_to_repository;
}
@Override
protected int getLayoutResourceId() {
@Override
public void onCreate(Bundle savedInstanceState) {
return R.layout.activity_add_collaborator_to_repository;
}
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
@Override
public void onCreate(Bundle savedInstanceState) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
ImageView closeActivity = findViewById(R.id.close);
addCollaboratorSearch = findViewById(R.id.addCollaboratorSearch);
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
mProgressBar = findViewById(R.id.progress_bar);
noData = findViewById(R.id.noData);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
addCollaboratorSearch.requestFocus();
assert imm != null;
imm.showSoftInput(addCollaboratorSearch, InputMethodManager.SHOW_IMPLICIT);
ImageView closeActivity = findViewById(R.id.close);
addCollaboratorSearch = findViewById(R.id.addCollaboratorSearch);
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
mProgressBar = findViewById(R.id.progress_bar);
noData = findViewById(R.id.noData);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
addCollaboratorSearch.requestFocus();
assert imm != null;
imm.showSoftInput(addCollaboratorSearch, InputMethodManager.SHOW_IMPLICIT);
addCollaboratorSearch.setOnEditorActionListener((v, actionId, event) -> {
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
if (actionId == EditorInfo.IME_ACTION_SEND) {
if(!addCollaboratorSearch.getText().toString().equals("")) {
loadUserSearchList(instanceUrl, instanceToken, addCollaboratorSearch.getText().toString(), loginUid);
}
}
addCollaboratorSearch.setOnEditorActionListener((v, actionId, event) -> {
return false;
if(actionId == EditorInfo.IME_ACTION_SEND) {
if(!addCollaboratorSearch.getText().toString().equals("")) {
loadUserSearchList(instanceUrl, instanceToken, addCollaboratorSearch.getText().toString(), loginUid);
}
}
});
return false;
}
});
public void loadUserSearchList(String instanceUrl, String token, String searchKeyword, String loginUid) {
}
Call<UserSearch> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
public void loadUserSearchList(String instanceUrl, String token, String searchKeyword, String loginUid) {
call.enqueue(new Callback<UserSearch>() {
Call<UserSearch> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
@Override
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
call.enqueue(new Callback<UserSearch>() {
if (response.isSuccessful()) {
assert response.body() != null;
getUsersList(response.body().getData(), ctx);
} else {
Log.i("onResponse", String.valueOf(response.code()));
}
@Override
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
}
if(response.code() == 200) {
assert response.body() != null;
getUsersList(response.body().getData(), ctx);
}
else {
Log.i("onResponse", String.valueOf(response.code()));
}
@Override
public void onFailure(@NonNull Call<UserSearch> call, @NonNull Throwable t) {
Log.i("onFailure", t.toString());
}
}
});
}
@Override
public void onFailure(@NonNull Call<UserSearch> call, @NonNull Throwable t) {
private void getUsersList(List<UserInfo> dataList, Context context) {
Log.i("onFailure", t.toString());
}
UserSearchAdapter adapter = new UserSearchAdapter(dataList, context);
});
}
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
DividerItemDecoration.VERTICAL);
mRecyclerView.addItemDecoration(dividerItemDecoration);
private void getUsersList(List<UserInfo> dataList, Context context) {
mProgressBar.setVisibility(View.VISIBLE);
UserSearchAdapter adapter = new UserSearchAdapter(dataList, context);
if(adapter.getItemCount() > 0) {
mRecyclerView.setAdapter(adapter);
noData.setVisibility(View.GONE);
mProgressBar.setVisibility(View.GONE);
}
else {
noData.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
mRecyclerView.addItemDecoration(dividerItemDecoration);
}
mProgressBar.setVisibility(View.VISIBLE);
private void initCloseListener() {
onClickListener = view -> finish();
}
if(adapter.getItemCount() > 0) {
mRecyclerView.setAdapter(adapter);
noData.setVisibility(View.GONE);
mProgressBar.setVisibility(View.GONE);
}
else {
noData.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
}
private void initCloseListener() {
onClickListener = view -> finish();
}
}

@ -45,6 +45,7 @@ public class AddNewTeamMemberActivity extends BaseActivity {
@Override
protected int getLayoutResourceId() {
return R.layout.activity_add_new_team_member;
}
@ -86,7 +87,7 @@ public class AddNewTeamMemberActivity extends BaseActivity {
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
mRecyclerView.addItemDecoration(dividerItemDecoration);
dataList = new ArrayList<>();
@ -107,10 +108,12 @@ public class AddNewTeamMemberActivity extends BaseActivity {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
@ -126,7 +129,7 @@ public class AddNewTeamMemberActivity extends BaseActivity {
@Override
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
if(response.isSuccessful()) {
if(response.code() == 200) {
assert response.body() != null;
if(response.body().getData().size() > 0) {
@ -151,6 +154,7 @@ public class AddNewTeamMemberActivity extends BaseActivity {
@Override
public void onFailure(@NonNull Call<UserSearch> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
@ -158,6 +162,7 @@ public class AddNewTeamMemberActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = view -> finish();
}

@ -1,11 +1,11 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
@ -25,270 +25,239 @@ import retrofit2.Callback;
/**
* Author M M Arif
*/
**/
public class AddRemoveAssigneesActivity extends BaseActivity {
private ArrayList<MultiSelectModel> listOfCollaborators = new ArrayList<>();
private ArrayList<Integer> issueAssigneesIds = new ArrayList<>();
private Boolean assigneesFlag = false;
private MultiSelectDialog multiSelectDialogAssignees;
final Context ctx = this;
private Context appCtx;
private ArrayList<MultiSelectModel> listOfCollaborators = new ArrayList<>();
private ArrayList<Integer> issueAssigneesIds = new ArrayList<>();
private Boolean assigneesFlag = false;
private MultiSelectDialog multiSelectDialogAssignees;
final Context ctx = this;
private Context appCtx;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_add_remove_assignees;
}
@Override
protected int getLayoutResourceId() {
@Override
public void onCreate(Bundle savedInstanceState) {
return R.layout.activity_add_remove_assignees;
}
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
getAssignees(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
}
getAssignees(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
private void getAssignees(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, final int issueIndex, final String loginUid) {
final TinyDB tinyDb = new TinyDB(appCtx);
Call<List<Collaborators>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
call.enqueue(new Callback<List<Collaborators>>() {
}
@Override
public void onResponse(@NonNull final Call<List<Collaborators>> call, @NonNull final retrofit2.Response<List<Collaborators>> response) {
if(response.isSuccessful()) {
if(response.code() == 200) {
final List<Collaborators> collaboratorsList_ = response.body();
private void getAssignees(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, final int issueIndex, final String loginUid) {
assert collaboratorsList_ != null;
if(collaboratorsList_.size() > 0) {
for (int i = 0; i < collaboratorsList_.size(); i++) {
final TinyDB tinyDb = new TinyDB(appCtx);
listOfCollaborators.add(new MultiSelectModel(collaboratorsList_.get(i).getId(), collaboratorsList_.get(i).getUsername().trim()));
Call<List<Collaborators>> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
}
}
call.enqueue(new Callback<List<Collaborators>>() {
// get current issue assignees
Call<Issues> callSingleIssueAssignees = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
@Override
public void onResponse(@NonNull final Call<List<Collaborators>> call, @NonNull final retrofit2.Response<List<Collaborators>> response) {
callSingleIssueAssignees.enqueue(new Callback<Issues>() {
switch(response.code()) {
case 200:
final List<Collaborators> collaboratorsList_ = response.body();
@Override
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
assert collaboratorsList_ != null;
if(collaboratorsList_.size() > 0) {
for(int i = 0; i < collaboratorsList_.size(); i++) {
if(response.code() == 200) {
listOfCollaborators.add(new MultiSelectModel(collaboratorsList_.get(i).getId(), collaboratorsList_.get(i).getUsername().trim()));
Issues issueAssigneesList = response.body();
}
}
assert issueAssigneesList != null;
if (issueAssigneesList.getAssignees() != null) {
if (issueAssigneesList.getAssignees().size() > 0) {
for (int i = 0; i < issueAssigneesList.getAssignees().size(); i++) {
// get current issue assignees
Call<Issues> callSingleIssueAssignees = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
issueAssigneesIds.add(issueAssigneesList.getAssignees().get(i).getId());
callSingleIssueAssignees.enqueue(new Callback<Issues>() {
if(issueAssigneesList.getAssignees().get(i).getUsername().equals(loginUid)) {
listOfCollaborators.add(new MultiSelectModel(issueAssigneesList.getAssignees().get(i).getId(), issueAssigneesList.getAssignees().get(i).getUsername().trim()));
}
@Override
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
}
assigneesFlag = true;
}
}
else {
listOfCollaborators.add(new MultiSelectModel(tinyDb.getInt("userId"), loginUid));
}
if(response.code() == 200) {
if(assigneesFlag) {
Issues issueAssigneesList = response.body();
multiSelectDialogAssignees = new MultiSelectDialog()
.title(getResources().getString(R.string.newIssueSelectAssigneesListTitle))
.titleSize(25)
.positiveText(getResources().getString(R.string.saveButton))
.negativeText(getResources().getString(R.string.cancelButton))
.setMinSelectionLimit(0)
.preSelectIDsList(issueAssigneesIds)
.setMaxSelectionLimit(listOfCollaborators.size())
.multiSelectList(listOfCollaborators)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
assert issueAssigneesList != null;
if(issueAssigneesList.getAssignees() != null) {
if(issueAssigneesList.getAssignees().size() > 0) {
for(int i = 0; i < issueAssigneesList.getAssignees().size(); i++) {
Log.i("selectedNames", String.valueOf(selectedNames));
issueAssigneesIds.add(issueAssigneesList.getAssignees().get(i).getId());
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
}
if(issueAssigneesList.getAssignees().get(i).getUsername().equals(loginUid)) {
listOfCollaborators.add(new MultiSelectModel(issueAssigneesList.getAssignees().get(i).getId(), issueAssigneesList.getAssignees().get(i).getUsername().trim()));
}
@Override
public void onCancel() {
CloseActivity();
}
});
}
assigneesFlag = true;
}
}
else {
listOfCollaborators.add(new MultiSelectModel(tinyDb.getInt("userId"), loginUid));
}
}
else {
if(assigneesFlag) {
multiSelectDialogAssignees = new MultiSelectDialog()
.title(getResources().getString(R.string.newIssueSelectAssigneesListTitle))
.titleSize(25)
.positiveText(getResources().getString(R.string.saveButton))
.negativeText(getResources().getString(R.string.cancelButton))
.setMinSelectionLimit(0)
.setMaxSelectionLimit(listOfCollaborators.size())
.multiSelectList(listOfCollaborators)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
multiSelectDialogAssignees = new MultiSelectDialog().title(getResources().getString(R.string.newIssueSelectAssigneesListTitle)).titleSize(25).positiveText(getResources().getString(R.string.saveButton)).negativeText(getResources().getString(R.string.cancelButton)).setMinSelectionLimit(0).preSelectIDsList(issueAssigneesIds).setMaxSelectionLimit(listOfCollaborators.size()).multiSelectList(listOfCollaborators).onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
}
Log.i("selectedNames", String.valueOf(selectedNames));
@Override
public void onCancel() {
CloseActivity();
}
});
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
}
}
@Override
public void onCancel() {
multiSelectDialogAssignees.show(getSupportFragmentManager(), "issueMultiSelectDialog");
CloseActivity();
}
});
}
}
}
else {
@Override
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
multiSelectDialogAssignees = new MultiSelectDialog().title(getResources().getString(R.string.newIssueSelectAssigneesListTitle)).titleSize(25).positiveText(getResources().getString(R.string.saveButton)).negativeText(getResources().getString(R.string.cancelButton)).setMinSelectionLimit(0).setMaxSelectionLimit(listOfCollaborators.size()).multiSelectList(listOfCollaborators).onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
});
// get current issue assignees
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
}
else if(response.code() == 401) {
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
}
else if(response.code() == 403) {
@Override
public void onCancel() {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
CloseActivity();
}
});
}
else if(response.code() == 404) {
}
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
multiSelectDialogAssignees.show(getSupportFragmentManager(), "issueMultiSelectDialog");
}
else {
}
}
Toasty.info(ctx, getString(R.string.genericError));
@Override
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
}
}
Log.e("onFailure", t.toString());
}
}
});
break;
@Override
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
});
case 401:
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
break;
}
case 403:
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
break;
private void CloseActivity() {
this.finish();
}
case 404:
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
break;
private void updateIssueAssignees(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String loginUid, int issueIndex, List<String> issueAssigneesList) {
default:
Toasty.info(ctx, getString(R.string.genericError));
UpdateIssueAssignees updateAssigneeJson = new UpdateIssueAssignees(issueAssigneesList);
}
}
Call<JsonElement> call3;
@Override
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
call3 = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.patchIssueAssignees(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, updateAssigneeJson);
Log.e("onFailure", t.toString());
}
});
call3.enqueue(new Callback<JsonElement>() {
}
@Override
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
private void CloseActivity() {
if(response2.code() == 201) {
this.finish();
}
Toasty.info(ctx, ctx.getString(R.string.assigneesUpdated));
private void updateIssueAssignees(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String loginUid, int issueIndex, List<String> issueAssigneesList) {
}
else if(response2.code() == 401) {
UpdateIssueAssignees updateAssigneeJson = new UpdateIssueAssignees(issueAssigneesList);
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
Call<JsonElement> call3;
}
else if(response2.code() == 403) {
call3 = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().patchIssueAssignees(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, updateAssigneeJson);
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
call3.enqueue(new Callback<JsonElement>() {
}
else if(response2.code() == 404) {
@Override
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
if(response2.code() == 201) {
}
else {
Toasty.info(ctx, ctx.getString(R.string.assigneesUpdated));
Toasty.info(ctx, getString(R.string.genericError));
}
else if(response2.code() == 401) {
}
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
}
else if(response2.code() == 403) {
@Override
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
});
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
}
}
else if(response2.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.genericError));
}
}
@Override
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
});
}
}

@ -1,13 +1,11 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
@ -20,289 +18,258 @@ import org.mian.gitnex.models.MultiSelectModel;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
*/
**/
public class AddRemoveLabelsActivity extends BaseActivity {
private ArrayList<MultiSelectModel> listOfLabels = new ArrayList<>();
private ArrayList<Integer> issueLabelIds = new ArrayList<>();
private Boolean labelsFlag = false;
private MultiSelectDialog multiSelectDialogLabels;
final Context ctx = this;
private Context appCtx;
private ArrayList<MultiSelectModel> listOfLabels = new ArrayList<>();
private ArrayList<Integer> issueLabelIds = new ArrayList<>();
private Boolean labelsFlag = false;
private MultiSelectDialog multiSelectDialogLabels;
final Context ctx = this;
private Context appCtx;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_add_remove_labels;
}
@Override
protected int getLayoutResourceId() {
@Override
public void onCreate(Bundle savedInstanceState) {
return R.layout.activity_add_remove_labels;
}
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
getLabels(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
}
getLabels(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
private void getLabels(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, final int issueIndex, final String loginUid) {
}
final TinyDB tinyDb = new TinyDB(appCtx);
private void getLabels(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, final int issueIndex, final String loginUid) {
Call<List<Labels>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getlabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
call.enqueue(new Callback<List<Labels>>() {
@Override
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
if(response.isSuccessful()) {
if(response.code() == 200) {
List<Labels> labelsList_ = response.body();
assert labelsList_ != null;
if(labelsList_.size() > 0) {
for (int i = 0; i < labelsList_.size(); i++) {
listOfLabels.add(new MultiSelectModel(labelsList_.get(i).getId(), labelsList_.get(i).getName().trim()));
}
}
// get current issue labels
Call<List<Labels>> callSingleIssueLabels = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
callSingleIssueLabels.enqueue(new Callback<List<Labels>>() {
@Override
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
if(response.code() == 200) {
List<Labels> issueLabelsList = response.body();
final TinyDB tinyDb = new TinyDB(appCtx);
assert issueLabelsList != null;
if(issueLabelsList.size() > 0) {
for (int i = 0; i < issueLabelsList.size(); i++) {
issueLabelIds.add(issueLabelsList.get(i).getId());
}
labelsFlag = true;
}
if(labelsFlag) {
Call<List<Labels>> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getlabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
multiSelectDialogLabels = new MultiSelectDialog()
.title(getResources().getString(R.string.newIssueSelectLabelsListTitle))
.titleSize(25)
.positiveText(getResources().getString(R.string.saveButton))
.negativeText(getResources().getString(R.string.cancelButton))
.setMinSelectionLimit(0)
.preSelectIDsList(issueLabelIds)
.setMaxSelectionLimit(listOfLabels.size())
.multiSelectList(listOfLabels)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
call.enqueue(new Callback<List<Labels>>() {
String labelIds = selectedIds.toString();
int[] integers;
if (selectedIds.size() > 0) {
@Override
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
String[] items = labelIds.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
integers = new int[items.length];
for (int i = 0; i < integers.length; i++) {
integers[i] = Integer.parseInt(items[i]);
}
switch(response.code()) {
case 200:
}
else {
integers = new int[0];
}
List<Labels> labelsList_ = response.body();
updateIssueLabels(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, integers, loginUid);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
}
assert labelsList_ != null;
if(labelsList_.size() > 0) {
for(int i = 0; i < labelsList_.size(); i++) {
@Override
public void onCancel() {
CloseActivity();
}
});
listOfLabels.add(new MultiSelectModel(labelsList_.get(i).getId(), labelsList_.get(i).getName().trim()));
}
else {
}
}
multiSelectDialogLabels = new MultiSelectDialog()
.title(getResources().getString(R.string.newIssueSelectLabelsListTitle))
.titleSize(25)
.positiveText(getResources().getString(R.string.saveButton))
.negativeText(getResources().getString(R.string.cancelButton))
.setMinSelectionLimit(0)
.setMaxSelectionLimit(listOfLabels.size())
.multiSelectList(listOfLabels)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
// get current issue labels
Call<List<Labels>> callSingleIssueLabels = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
String labelIds = selectedIds.toString();
int[] integers;
if (selectedIds.size() > 0) {
callSingleIssueLabels.enqueue(new Callback<List<Labels>>() {
String[] items = labelIds.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
integers = new int[items.length];
for (int i = 0; i < integers.length; i++) {
integers[i] = Integer.parseInt(items[i]);
}
@Override
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
}
else {
integers = new int[0];
}
if(response.code() == 200) {
updateIssueLabels(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, integers, loginUid);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
List<Labels> issueLabelsList = response.body();
}
assert issueLabelsList != null;
if(issueLabelsList.size() > 0) {
for(int i = 0; i < issueLabelsList.size(); i++) {
@Override
public void onCancel() {
CloseActivity();
}
});
issueLabelIds.add(issueLabelsList.get(i).getId());
}
}
labelsFlag = true;
}
multiSelectDialogLabels.show(getSupportFragmentManager(), "issueMultiSelectDialog");
if(labelsFlag) {
}
}
multiSelectDialogLabels = new MultiSelectDialog().title(getResources().getString(R.string.newIssueSelectLabelsListTitle)).titleSize(25).positiveText(getResources().getString(R.string.saveButton)).negativeText(getResources().getString(R.string.cancelButton)).setMinSelectionLimit(0).preSelectIDsList(issueLabelIds).setMaxSelectionLimit(listOfLabels.size()).multiSelectList(listOfLabels).onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
});
// get current issue labels
String labelIds = selectedIds.toString();
int[] integers;
if(selectedIds.size() > 0) {
}
else if(response.code() == 401) {
String[] items = labelIds.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
integers = new int[items.length];
for(int i = 0; i < integers.length; i++) {
integers[i] = Integer.parseInt(items[i]);
}
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else {
integers = new int[0];
}
}
else if(response.code() == 403) {
updateIssueLabels(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, integers, loginUid);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
}
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
@Override
public void onCancel() {
}
else if(response.code() == 404) {
CloseActivity();
}
});
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
}
else {
}
else {
multiSelectDialogLabels = new MultiSelectDialog().title(getResources().getString(R.string.newIssueSelectLabelsListTitle)).titleSize(25).positiveText(getResources().getString(R.string.saveButton)).negativeText(getResources().getString(R.string.cancelButton)).setMinSelectionLimit(0).setMaxSelectionLimit(listOfLabels.size()).multiSelectList(listOfLabels).onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
Toasty.info(ctx, getString(R.string.genericError));
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
}
}
String labelIds = selectedIds.toString();
int[] integers;
if(selectedIds.size() > 0) {
}
String[] items = labelIds.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
integers = new int[items.length];
for(int i = 0; i < integers.length; i++) {
integers[i] = Integer.parseInt(items[i]);
}
@Override
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
});
}
else {
integers = new int[0];
}
}
updateIssueLabels(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, integers, loginUid);
tinyDb.putBoolean("singleIssueUpdate", true);
CloseActivity();
private void updateIssueLabels(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, int issueIndex, int[] issueLabels, String loginUid) {
}
Labels patchIssueLabels = new Labels(issueLabels);
@Override
public void onCancel() {
Call<JsonElement> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.updateIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, patchIssueLabels);
CloseActivity();
}
});
call.enqueue(new Callback<JsonElement>() {
}
@Override
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
multiSelectDialogLabels.show(getSupportFragmentManager(), "issueMultiSelectDialog");
if(response.code() == 200) {
}
}
Toasty.info(ctx, ctx.getString(R.string.labelsUpdated));
@Override
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
}
else if(response.code() == 401) {
Log.e("onFailure", t.toString());
}
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
});
break;
}
else if(response.code() == 403) {
case 401:
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
break;
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
case 403:
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
break;
}
else if(response.code() == 404) {
case 404:
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
break;
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
default:
Toasty.info(ctx, getString(R.string.genericError));
}
}
else {
}
Toasty.info(ctx, getString(R.string.genericError));
@Override
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
}
Log.e("onFailure", t.toString());
}
});
}
}
@Override
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
});
private void updateIssueLabels(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, int issueIndex, int[] issueLabels, String loginUid) {
}
Labels patchIssueLabels = new Labels(issueLabels);
Call<JsonElement> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().updateIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, patchIssueLabels);
call.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
switch(response.code()) {
case 200:
Toasty.info(ctx, ctx.getString(R.string.labelsUpdated));
break;
case 401:
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
break;
case 403:
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
break;
case 404:
Toasty.info(ctx, ctx.getString(R.string.apiNotFound)