Extend Merge Options (#217)

Merge branch 'master' into extend-merge-dialog

Minor fixes

format

? an AndroidStudio suggestion ?

Signed-off-by: 6543 <6543@obermui.de>

add Title Text and some Fixes

add version check

Merge branch 'master' into extend-merge-dialog

Merge branch 'master' into extend-merge-dialog

use translation and revormat

make Merge Options Translateble
gitea locale revs:
* pulls.merge_pull_request
* pulls.rebase_merge_pull_request
* pulls.rebase_merge_commit_pull_request
* pulls.squash_merge_pull_request

Fix menu item

Make merge options work

Merge branch 'master' into merge-options

work - but UGLY UI

use enum for merge-modes

Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/217
This commit is contained in:
6543 2020-04-11 20:20:26 +00:00 committed by M M Arif
parent adb8a8bf04
commit 145043a515
6 changed files with 305 additions and 168 deletions

View File

@ -1,16 +1,20 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.hendraanggrian.appcompat.socialview.Mention;
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
@ -19,10 +23,13 @@ import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.VersionCheck;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.MergePullRequest;
import org.mian.gitnex.models.MergePullRequestSpinner;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import okhttp3.ResponseBody;
import retrofit2.Call;
@ -35,234 +42,267 @@ import retrofit2.Response;
public class MergePullRequestActivity extends BaseActivity {
public ImageView closeActivity;
private View.OnClickListener onClickListener;
public ImageView closeActivity;
private View.OnClickListener onClickListener;
final Context ctx = this;
final Context ctx = this;
private SocialAutoCompleteTextView mergePR;
private ArrayAdapter<Mention> defaultMentionAdapter;
private Button mergeButton;
private SocialAutoCompleteTextView mergeDescription;
private EditText mergeTitle;
private Spinner mergeModeSpinner;
private ArrayAdapter<Mention> defaultMentionAdapter;
private Button mergeButton;
private String Do;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_merge_pull_request;
}
@Override
protected int getLayoutResourceId() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return R.layout.activity_merge_pull_request;
}
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
TinyDB tinyDb = new TinyDB(getApplicationContext());
@SuppressLint("SetTextI18n")
@Override
public void onCreate(Bundle savedInstanceState) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
super.onCreate(savedInstanceState);
mergePR = findViewById(R.id.mergePR);
mergePR.setShowSoftInputOnFocus(true);
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
TinyDB tinyDb = new TinyDB(getApplicationContext());
mergePR.requestFocus();
assert imm != null;
imm.showSoftInput(mergePR, InputMethodManager.SHOW_IMPLICIT);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
defaultMentionAdapter = new MentionArrayAdapter<>(this);
loadCollaboratorsList();
mergeModeSpinner = findViewById(R.id.mergeSpinner);
mergeDescription = findViewById(R.id.mergeDescription);
mergeTitle = findViewById(R.id.mergeTitle);
mergePR.setMentionAdapter(defaultMentionAdapter);
mergeTitle.requestFocus();
assert imm != null;
imm.showSoftInput(mergeTitle, InputMethodManager.SHOW_IMPLICIT);
closeActivity = findViewById(R.id.close);
TextView toolbar_title = findViewById(R.id.toolbar_title);
setMergeAdapter();
if(!tinyDb.getString("issueTitle").isEmpty()) {
toolbar_title.setText(tinyDb.getString("issueTitle"));
}
mergeModeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mergeButton = findViewById(R.id.mergeButton);
MergePullRequestSpinner mergeId = (MergePullRequestSpinner) parent.getSelectedItem();
Do = mergeId.getId();
if(!connToInternet) {
}
disableProcessButton();
@Override
public void onNothingSelected(AdapterView<?> parent) {
} else {
}
mergeButton.setOnClickListener(mergePullRequest);
});
}
defaultMentionAdapter = new MentionArrayAdapter<>(this);
loadCollaboratorsList();
}
mergeDescription.setMentionAdapter(defaultMentionAdapter);
public void loadCollaboratorsList() {
closeActivity = findViewById(R.id.close);
TextView toolbar_title = findViewById(R.id.toolbar_title);
final TinyDB tinyDb = new TinyDB(getApplicationContext());
if(!tinyDb.getString("issueTitle").isEmpty()) {
toolbar_title.setText(tinyDb.getString("issueTitle"));
mergeTitle.setText(tinyDb.getString("issueTitle") + " (#" + tinyDb.getString("issueNumber")+ ")");
}
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
Call<List<Collaborators>> call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.getCollaborators(Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName);
mergeButton = findViewById(R.id.mergeButton);
call.enqueue(new Callback<List<Collaborators>>() {
if(!connToInternet) {
@Override
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
disableProcessButton();
if (response.isSuccessful()) {
}
else {
assert response.body() != null;
String fullName = "";
for (int i = 0; i < response.body().size(); i++) {
if(!response.body().get(i).getFull_name().equals("")) {
fullName = response.body().get(i).getFull_name();
}
defaultMentionAdapter.add(
new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
}
mergeButton.setOnClickListener(mergePullRequest);
}
else {
}
Log.i("onResponse", String.valueOf(response.code()));
}
}
private void setMergeAdapter() {
}
TinyDB tinyDb = new TinyDB(getApplicationContext());
@Override
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
Log.i("onFailure", t.toString());
}
ArrayList<MergePullRequestSpinner> mergeList = new ArrayList<>();
});
}
mergeList.add(new MergePullRequestSpinner("merge", getResources().getString(R.string.mergeOptionMerge)));
mergeList.add(new MergePullRequestSpinner("rebase", getResources().getString(R.string.mergeOptionRebase)));
mergeList.add(new MergePullRequestSpinner("rebase-merge", getResources().getString(R.string.mergeOptionRebaseCommit)));
//squash merge works only on gitea v1.11.5 and higher due to a bug
if(VersionCheck.compareVersion("1.11.5", tinyDb.getString("giteaVersion")) < 1) {
mergeList.add(new MergePullRequestSpinner("squash", getResources().getString(R.string.mergeOptionSquash)));
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
}
ArrayAdapter<MergePullRequestSpinner> adapter = new ArrayAdapter<>(ctx, R.layout.spinner_item, mergeList);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
mergeModeSpinner.setAdapter(adapter);
private View.OnClickListener mergePullRequest = new View.OnClickListener() {
public void onClick(View v) {
processMergePullRequest();
}
};
}
private void processMergePullRequest() {
public void loadCollaboratorsList() {
String mergePRDT = mergePR.getText().toString();
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
final TinyDB tinyDb = new TinyDB(getApplicationContext());
if(!connToInternet) {
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
Toasty.info(getApplicationContext(), getResources().getString(R.string.checkNetConnection));
return;
Call<List<Collaborators>> call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().getCollaborators(Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName);
}
call.enqueue(new Callback<List<Collaborators>>() {
disableProcessButton();
String doWhat = "merge";
mergeFunction(doWhat, mergePRDT);
@Override
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
}
if(response.isSuccessful()) {
private void mergeFunction(String doWhat, String mergePRDT) {
assert response.body() != null;
String fullName = "";
for(int i = 0; i < response.body().size(); i++) {
if(!response.body().get(i).getFull_name().equals("")) {
fullName = response.body().get(i).getFull_name();
}
defaultMentionAdapter.add(new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
}
final TinyDB tinyDb = new TinyDB(getApplicationContext());
}
else {
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final int prIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
Log.i("onResponse", String.valueOf(response.code()));
MergePullRequest mergePR = new MergePullRequest(doWhat, mergePRDT, null);
}
Call<ResponseBody> call = RetrofitClient
.getInstance(instanceUrl, getApplicationContext())
.getApiInterface()
.mergePullRequest(Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName, prIndex, mergePR);
}
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull retrofit2.Response<ResponseBody> response) {
Log.i("onFailure", t.toString());
}
if(response.code() == 200) {
});
}
Toasty.info(getApplicationContext(), getString(R.string.mergePRSuccessMsg));
tinyDb.putBoolean("prMerged", true);
tinyDb.putBoolean("resumePullRequests", true);
finish();
private void initCloseListener() {
}
else if(response.code() == 401) {
onClickListener = view -> finish();
}
enableProcessButton();
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
private View.OnClickListener mergePullRequest = v -> processMergePullRequest();
}
else if(response.code() == 404) {
private void processMergePullRequest() {
enableProcessButton();
Toasty.info(getApplicationContext(), getString(R.string.mergePR404ErrorMsg));
String mergePRDesc = mergeDescription.getText().toString();
String mergePRTitle = mergeTitle.getText().toString();
}
else {
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
enableProcessButton();
Toasty.info(getApplicationContext(), getString(R.string.genericError));
if(!connToInternet) {
}
Toasty.info(getApplicationContext(), getResources().getString(R.string.checkNetConnection));
return;
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
disableProcessButton();
mergeFunction(Do, mergePRDesc, mergePRTitle);
});
}
}
private void mergeFunction(String Do, String mergePRDT, String mergeTitle) {
private void disableProcessButton() {
final TinyDB tinyDb = new TinyDB(getApplicationContext());
mergeButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
mergeButton.setBackground(shape);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final int prIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
}
MergePullRequest mergePR = new MergePullRequest(Do, mergePRDT, mergeTitle);
private void enableProcessButton() {
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, getApplicationContext()).getApiInterface().mergePullRequest(Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName, prIndex, mergePR);
mergeButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
mergeButton.setBackground(shape);
call.enqueue(new Callback<ResponseBody>() {
}
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull retrofit2.Response<ResponseBody> response) {
if(response.code() == 200) {
Toasty.info(getApplicationContext(), getString(R.string.mergePRSuccessMsg));
tinyDb.putBoolean("prMerged", true);
tinyDb.putBoolean("resumePullRequests", true);
finish();
}
else if(response.code() == 401) {
enableProcessButton();
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() == 404) {
enableProcessButton();
Toasty.info(getApplicationContext(), getString(R.string.mergePR404ErrorMsg));
}
else {
enableProcessButton();
Toasty.info(getApplicationContext(), getString(R.string.genericError));
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
});
}
private void disableProcessButton() {
mergeButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(getResources().getColor(R.color.hintColor));
mergeButton.setBackground(shape);
}
private void enableProcessButton() {
mergeButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(getResources().getColor(R.color.btnBackground));
mergeButton.setBackground(shape);
}
}

View File

@ -151,6 +151,7 @@ public class PullRequestsFragment extends Fragment {
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, prState, resultLimit);
tinyDb.putBoolean("resumePullRequests", false);
tinyDb.putBoolean("prMerged", false);
}

View File

@ -11,9 +11,11 @@ public class MergePullRequest {
private String MergeTitleField;
public MergePullRequest(String Do, String MergeMessageField, String MergeTitleField) {
this.Do = Do;
this.MergeMessageField = MergeMessageField;
this.MergeTitleField = MergeTitleField;
}
}

View File

@ -0,0 +1,55 @@
package org.mian.gitnex.models;
import androidx.annotation.NonNull;
/**
* Author M M Arif
*/
public class MergePullRequestSpinner {
private String id;
private String mergerMethod;
public MergePullRequestSpinner(String id, String mergerMethod) {
this.id = id;
this.mergerMethod = mergerMethod;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
private String getMergerMethod() {
return mergerMethod;
}
public void setName(String mergerMethod) {
this.mergerMethod = mergerMethod;
}
@NonNull
@Override
public String toString() {
return mergerMethod;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof MergePullRequestSpinner){
MergePullRequestSpinner spinner = (MergePullRequestSpinner )obj;
return spinner.getMergerMethod().equals(mergerMethod) && spinner.getId().equals(id);
}
return false;
}
}

View File

@ -68,32 +68,67 @@
android:paddingBottom="30dp"
android:orientation="vertical">
<com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView
android:id="@+id/mergePR"
<EditText
android:id="@+id/mergeTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:padding="10dp"
android:textSize="14sp"
tools:ignore="Autofill"
android:background="@drawable/shape_inputs"
android:textColor="?attr/inputTextColor"
android:textColorHint="?attr/hintColor"
android:textColorHighlight="?attr/primaryTextColor"
android:inputType="textCapSentences|text" />
<com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView
android:id="@+id/mergeDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:completionThreshold="1"
android:background="@drawable/shape_inputs"
android:maxLines="12"
android:minLines="10"
tools:ignore="Autofill"
android:labelFor="@+id/mergePR"
android:labelFor="@+id/mergeDescription"
android:scrollbars="vertical"
android:gravity="top|start"
android:textSize="14sp"
android:textColor="@color/white"
android:textColor="?attr/inputTextColor"
android:hint="@string/mergeCommentText"
android:textColorHint="@color/colorAccent"
android:textColorHint="?attr/hintColor"
android:inputType="textCapSentences|textMultiLine"
android:textColorHighlight="@color/white" />
android:textColorHighlight="?attr/primaryTextColor" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_dropdown"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" >
<Spinner
android:id="@+id/mergeSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingStart="5dp" />
</RelativeLayout>
<TextView
android:id="@+id/mergeInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mergeNoteText"
android:textColor="?attr/primaryTextColor"
android:textColor="?attr/hintColor"
android:textSize="12sp"
android:gravity="start"
android:layout_marginTop="10dp" />

View File

@ -566,6 +566,10 @@
<string name="mergeCommentText">Merge comment</string>
<string name="mergePRSuccessMsg">Pull Request was merged successfully</string>
<string name="mergePR404ErrorMsg">Pull Request is not available for merge</string>
<string name="mergeOptionMerge">Merge Pull Request</string>
<string name="mergeOptionRebase">Rebase and Merge</string>
<string name="mergeOptionRebaseCommit">Rebase and Merge (&#45;&#45;no-ff)</string>
<string name="mergeOptionSquash">Squash and Merge</string>
<string name="downloadFile">Download This File</string>
<string name="waitLoadingDownloadFile">Please wait for the file to load to memory</string>