mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-26 16:04:07 +08:00
finished work on creating new file
This commit is contained in:
parent
8d1b47de8e
commit
742b1894e6
@ -6,6 +6,7 @@ import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@ -82,6 +83,27 @@ public class NewFileActivity extends AppCompatActivity {
|
||||
newFileBranchesSpinner.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
|
||||
getBranches(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
|
||||
|
||||
newFileBranchesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
|
||||
{
|
||||
public void onItemSelected(AdapterView<?> arg0,
|
||||
View arg1, int arg2, long arg3)
|
||||
{
|
||||
Branches bModelValue = (Branches) newFileBranchesSpinner.getSelectedItem();
|
||||
Log.i("bModelSelected", bModelValue.toString());
|
||||
|
||||
if(bModelValue.toString().equals("No branch")) {
|
||||
newFileBranchName.setEnabled(true);
|
||||
}
|
||||
else {
|
||||
newFileBranchName.setEnabled(false);
|
||||
newFileBranchName.setText("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> arg0) {}
|
||||
});
|
||||
|
||||
disableProcessButton();
|
||||
|
||||
if(!connToInternet) {
|
||||
@ -124,9 +146,7 @@ public class NewFileActivity extends AppCompatActivity {
|
||||
String newFileBranchName_ = newFileBranchName.getText().toString();
|
||||
String newFileCommitMessage_ = newFileCommitMessage.getText().toString();
|
||||
|
||||
Branches bModel = (Branches) newFileBranchesSpinner.getSelectedItem();
|
||||
|
||||
Log.i("bModel", bModel.toString());
|
||||
Branches currentBranch = (Branches) newFileBranchesSpinner.getSelectedItem();
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
@ -142,10 +162,20 @@ public class NewFileActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
|
||||
if(!appUtil.checkStringsWithDash(newFileBranchName_)) {
|
||||
if(currentBranch.toString().equals("No branch")) {
|
||||
|
||||
Toasty.info(getApplicationContext(), getString(R.string.newFileInvalidBranchName));
|
||||
return;
|
||||
if(newFileBranchName_.equals("")) {
|
||||
Toasty.info(getApplicationContext(), getString(R.string.newFileRequiredFieldNewBranchName));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if(!appUtil.checkStringsWithDash(newFileBranchName_)) {
|
||||
|
||||
Toasty.info(getApplicationContext(), getString(R.string.newFileInvalidBranchName));
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -157,16 +187,21 @@ public class NewFileActivity extends AppCompatActivity {
|
||||
else {
|
||||
|
||||
disableProcessButton();
|
||||
//Log.i("base64", appUtil.encodeBase64(newFileContent_));
|
||||
createNewFile(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName, newFileName_, appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_);
|
||||
createNewFile(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName, newFileName_, appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createNewFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage) {
|
||||
private void createNewFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage, String currentBranch) {
|
||||
|
||||
NewFile createNewFileJsonStr = new NewFile(fileContent, fileCommitMessage, fileBranchName);
|
||||
NewFile createNewFileJsonStr;
|
||||
if(currentBranch.equals("No branch")) {
|
||||
createNewFileJsonStr = new NewFile("", fileContent, fileCommitMessage, fileBranchName);
|
||||
}
|
||||
else {
|
||||
createNewFileJsonStr = new NewFile(currentBranch, fileContent, fileCommitMessage, "");
|
||||
}
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl)
|
||||
|
@ -90,7 +90,8 @@ public class NewFile {
|
||||
}
|
||||
}
|
||||
|
||||
public NewFile(String content, String message, String new_branch) {
|
||||
public NewFile(String branch, String content, String message, String new_branch) {
|
||||
this.branch = branch;
|
||||
this.content = content;
|
||||
this.message = message;
|
||||
this.new_branch = new_branch;
|
||||
|
@ -134,6 +134,16 @@
|
||||
android:paddingRight="5dp"
|
||||
android:paddingStart="5dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newFileCurrentBranchMessage"
|
||||
android:textColor="@color/hintColor"
|
||||
android:textSize="12sp"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:gravity="end" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -157,6 +167,16 @@
|
||||
android:inputType="textCapSentences|text"
|
||||
android:textColorHighlight="@color/colorWhite"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/newFileNewBranchMessage"
|
||||
android:textColor="@color/hintColor"
|
||||
android:textSize="12sp"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:gravity="end" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -420,6 +420,9 @@
|
||||
<string name="newFileSuccessMessage">New file created</string>
|
||||
<string name="newFileOldBranches">Current Branches</string>
|
||||
<string name="newFileRequiredFields">Fields like filename, contents and commit message are required.</string>
|
||||
<string name="newFileCurrentBranchMessage">Selecting current branch will disable new branch</string>
|
||||
<string name="newFileNewBranchMessage">e.g: new-branch</string>
|
||||
<string name="newFileRequiredFieldNewBranchName">New branch name cannot be empty if current branch is not selected</string>
|
||||
|
||||
<!-- generic copy -->
|
||||
<string name="okButton">OK</string>
|
||||
|
@ -420,6 +420,9 @@
|
||||
<string name="newFileSuccessMessage">New file created</string>
|
||||
<string name="newFileOldBranches">Current Branches</string>
|
||||
<string name="newFileRequiredFields">Fields like filename, contents and commit message are required.</string>
|
||||
<string name="newFileCurrentBranchMessage">Selecting current branch will disable new branch</string>
|
||||
<string name="newFileNewBranchMessage">e.g: new-branch</string>
|
||||
<string name="newFileRequiredFieldNewBranchName">New branch name cannot be empty if current branch is not selected</string>
|
||||
|
||||
<!-- generic copy -->
|
||||
<string name="okButton">OK</string>
|
||||
|
@ -420,6 +420,9 @@
|
||||
<string name="newFileSuccessMessage">New file created</string>
|
||||
<string name="newFileOldBranches">Current Branches</string>
|
||||
<string name="newFileRequiredFields">Fields like filename, contents and commit message are required.</string>
|
||||
<string name="newFileCurrentBranchMessage">Selecting current branch will disable new branch</string>
|
||||
<string name="newFileNewBranchMessage">e.g: new-branch</string>
|
||||
<string name="newFileRequiredFieldNewBranchName">New branch name cannot be empty if current branch is not selected</string>
|
||||
|
||||
<!-- generic copy -->
|
||||
<string name="okButton">OK</string>
|
||||
|
@ -457,7 +457,10 @@
|
||||
<string name="newFileCommitMessageError">Commit message is too long</string>
|
||||
<string name="newFileSuccessMessage">New file created</string>
|
||||
<string name="newFileOldBranches">Current Branches</string>
|
||||
<string name="newFileRequiredFields">Fields like filename, contents and commit message are required.</string>
|
||||
<string name="newFileRequiredFields">Fields like filename, content and commit message are required</string>
|
||||
<string name="newFileCurrentBranchMessage">Selecting current branch will disable new branch</string>
|
||||
<string name="newFileNewBranchMessage">e.g: new-branch</string>
|
||||
<string name="newFileRequiredFieldNewBranchName">New branch name cannot be empty if current branch is not selected</string>
|
||||
|
||||
<!-- generic copy -->
|
||||
<string name="okButton">OK</string>
|
||||
|
Loading…
Reference in New Issue
Block a user