summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohamed Zenadi <zeapo@users.noreply.github.com>2014-11-26 20:50:44 +0100
committerMohamed Zenadi <zeapo@users.noreply.github.com>2014-11-26 20:50:44 +0100
commit244b7194665bc484b8db07d4ddd1f885af12878c (patch)
tree65370849a603f1227b2f2c3d2f2e1920254f4872
parent8076ef89f48f0d92e098f5fb64baed4d6f17f34f (diff)
parentf28065662a7556ec6948bfd23672716a1cf71dde (diff)
Merge pull request #44 from zeapo/feature/httpsv1.2-a6
Add https support
-rw-r--r--app/app-release.apkbin2016049 -> 2020143 bytes
-rw-r--r--app/build.gradle4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/GitHandler.java202
-rw-r--r--app/src/main/res/values/arrays.xml1
-rw-r--r--app/src/main/res/values/strings.xml2
5 files changed, 119 insertions, 90 deletions
diff --git a/app/app-release.apk b/app/app-release.apk
index b0ec4ad8..eca5db41 100644
--- a/app/app-release.apk
+++ b/app/app-release.apk
Binary files differ
diff --git a/app/build.gradle b/app/build.gradle
index 2510f89a..0662e235 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -9,8 +9,8 @@ android {
applicationId "com.zeapo.pwdstore"
minSdkVersion 15
targetSdkVersion 21
- versionCode 24
- versionName "1.2-a5"
+ versionCode 25
+ versionName "1.2-a6"
}
compileOptions {
diff --git a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java
index 1393d053..79dec904 100644
--- a/app/src/main/java/com/zeapo/pwdstore/GitHandler.java
+++ b/app/src/main/java/com/zeapo/pwdstore/GitHandler.java
@@ -97,8 +97,30 @@ public class GitHandler extends ActionBarActivity {
case REQUEST_CLONE:
setContentView(R.layout.activity_git_clone);
+ final Spinner protcol_spinner = (Spinner) findViewById(R.id.clone_protocol);
+ final Spinner connection_mode_spinner = (Spinner) findViewById(R.id.connection_mode);
+
+
+ // init the spinner for connection modes
+ final ArrayAdapter<CharSequence> connection_mode_adapter = ArrayAdapter.createFromResource(this,
+ R.array.connection_modes, android.R.layout.simple_spinner_item);
+ connection_mode_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ connection_mode_spinner.setAdapter(connection_mode_adapter);
+ connection_mode_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
+ String selection = ((Spinner) findViewById(R.id.connection_mode)).getSelectedItem().toString();
+ connectionMode = selection;
+ settings.edit().putString("git_remote_auth", selection).apply();
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> adapterView) {
+
+ }
+ });
+
// init the spinner for protocols
- Spinner protcol_spinner = (Spinner) findViewById(R.id.clone_protocol);
ArrayAdapter<CharSequence> protocol_adapter = ArrayAdapter.createFromResource(this,
R.array.clone_protocols, android.R.layout.simple_spinner_item);
protocol_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@@ -110,17 +132,20 @@ public class GitHandler extends ActionBarActivity {
protocol = ((Spinner)findViewById(R.id.clone_protocol)).getSelectedItem().toString();
if (protocol.equals("ssh://")) {
((EditText)findViewById(R.id.clone_uri)).setHint("user@hostname:path");
+
+ ((EditText) findViewById(R.id.server_port)).setHint(R.string.default_ssh_port);
+
+ // select ssh-key auth mode as default and enable the spinner in case it was disabled
+ connection_mode_spinner.setSelection(0);
+ connection_mode_spinner.setEnabled(true);
} else {
((EditText)findViewById(R.id.clone_uri)).setHint("hostname/path");
- new AlertDialog.Builder(activity).
- setMessage(activity.getResources().getString(R.string.read_only_dialog_text)).
- setCancelable(true).
- setPositiveButton(activity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
-
- }
- }).show();
+
+ ((EditText) findViewById(R.id.server_port)).setHint(R.string.default_https_port);
+
+ // select user/pwd auth-mode and disable the spinner
+ connection_mode_spinner.setSelection(1);
+ connection_mode_spinner.setEnabled(false);
}
}
@@ -131,25 +156,6 @@ public class GitHandler extends ActionBarActivity {
}
);
- // init the spinner for connection modes
- Spinner connection_mode_spinner = (Spinner) findViewById(R.id.connection_mode);
- ArrayAdapter<CharSequence> connection_mode_adapter = ArrayAdapter.createFromResource(this,
- R.array.connection_modes, android.R.layout.simple_spinner_item);
- connection_mode_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- connection_mode_spinner.setAdapter(connection_mode_adapter);
- connection_mode_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
- String selection = ((Spinner) findViewById(R.id.connection_mode)).getSelectedItem().toString();
- connectionMode = selection;
- settings.edit().putString("git_remote_auth", selection).apply();
- }
-
- @Override
- public void onNothingSelected(AdapterView<?> adapterView) {
-
- }
- });
// init the server information
final EditText server_url = ((EditText) findViewById(R.id.server_url));
@@ -259,30 +265,57 @@ public class GitHandler extends ActionBarActivity {
EditText server_port = ((EditText) findViewById(R.id.server_port));
EditText server_path = ((EditText) findViewById(R.id.server_path));
EditText server_user = ((EditText) findViewById(R.id.server_user));
- Log.i("GIT", "key entred");
-
- if (uri != null) {
- String hostname =
- server_user.getText()
- + "@" +
- server_url.getText().toString().trim()
- + ":";
- if (server_port.getText().toString().equals("22")) {
- hostname += server_path.getText().toString();
-
- ((TextView) findViewById(R.id.warn_url)).setVisibility(View.GONE);
- } else {
- TextView warn_url = (TextView) findViewById(R.id.warn_url);
- if (!server_path.getText().toString().matches("/.*") && !server_port.getText().toString().isEmpty()) {
- warn_url.setText(R.string.warn_malformed_url_port);
- warn_url.setVisibility(View.VISIBLE);
- } else {
- warn_url.setVisibility(View.GONE);
+
+ if (uri != null) {
+ switch (protocol)
+ {
+ case "ssh://":
+ {
+ String hostname =
+ server_user.getText()
+ + "@" +
+ server_url.getText().toString().trim()
+ + ":";
+ if (server_port.getText().toString().equals("22")) {
+ hostname += server_path.getText().toString();
+
+ ((TextView) findViewById(R.id.warn_url)).setVisibility(View.GONE);
+ } else {
+ TextView warn_url = (TextView) findViewById(R.id.warn_url);
+ if (!server_path.getText().toString().matches("/.*") && !server_port.getText().toString().isEmpty()) {
+ warn_url.setText(R.string.warn_malformed_url_port);
+ warn_url.setVisibility(View.VISIBLE);
+ } else {
+ warn_url.setVisibility(View.GONE);
+ }
+ hostname += server_port.getText().toString() + server_path.getText().toString();
+ }
+
+ if (!hostname.equals("@:")) uri.setText(hostname);
+ }
+ break;
+ case "https://":
+ {
+ StringBuilder hostname = new StringBuilder();
+ hostname.append(server_url.getText().toString().trim());
+
+ if (server_port.getText().toString().equals("443")) {
+ hostname.append(server_path.getText().toString());
+
+ ((TextView) findViewById(R.id.warn_url)).setVisibility(View.GONE);
+ } else {
+ hostname.append("/");
+ hostname.append(server_port.getText().toString())
+ .append(server_path.getText().toString());
+ }
+
+ if (!hostname.toString().equals("@/")) uri.setText(hostname);
}
- hostname += server_port.getText().toString() + server_path.getText().toString();
+ break;
+ default:
+ break;
}
- if (!hostname.equals("@:")) uri.setText(hostname);
}
}
@@ -439,8 +472,6 @@ public class GitHandler extends ActionBarActivity {
if (!port.isEmpty())
hostname = protocol + hostname;
- Log.i("GIT", "> " + port);
-
// did he forget the username?
if (!hostname.matches("^.+@.+")) {
new AlertDialog.Builder(this).
@@ -506,10 +537,9 @@ public class GitHandler extends ActionBarActivity {
// remember the settings
SharedPreferences.Editor editor = settings.edit();
- // TODO this is not pretty, use the information obtained earlier
- editor.putString("git_remote_server", hostname.split("@")[1].split(":")[0]);
- editor.putString("git_remote_location", hostname.split("@")[1].split(":")[1]);
- editor.putString("git_remote_username", hostname.split("@")[0]);
+ editor.putString("git_remote_server", ((EditText) findViewById(R.id.server_url)).getText().toString());
+ editor.putString("git_remote_location", ((EditText) findViewById(R.id.server_path)).getText().toString());
+ editor.putString("git_remote_username", ((EditText) findViewById(R.id.server_user)).getText().toString());
editor.putString("git_remote_protocol", protocol);
editor.putString("git_remote_auth", connectionMode);
editor.putString("git_remote_port", port);
@@ -700,39 +730,35 @@ public class GitHandler extends ActionBarActivity {
}).show();
}
} else {
- if (protocol.equals("ssh://")) {
- final EditText password = new EditText(activity);
- password.setHint("Password");
- password.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
- password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
-
- new AlertDialog.Builder(activity)
- .setTitle(activity.getResources().getString(R.string.passphrase_dialog_title))
- .setMessage(activity.getResources().getString(R.string.password_dialog_text))
- .setView(password)
- .setPositiveButton(activity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
-
- SshSessionFactory.setInstance(new GitConfigSessionFactory());
- try {
- method.invoke(activity,
- new UsernamePasswordCredentialsProvider(
- settings.getString("git_remote_username", "git"),
- password.getText().toString())
- );
- } catch (Exception e){
- e.printStackTrace();
- }
-
+ final EditText password = new EditText(activity);
+ password.setHint("Password");
+ password.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
+ password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+
+ new AlertDialog.Builder(activity)
+ .setTitle(activity.getResources().getString(R.string.passphrase_dialog_title))
+ .setMessage(activity.getResources().getString(R.string.password_dialog_text))
+ .setView(password)
+ .setPositiveButton(activity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+
+ SshSessionFactory.setInstance(new GitConfigSessionFactory());
+ try {
+ method.invoke(activity,
+ new UsernamePasswordCredentialsProvider(
+ settings.getString("git_remote_username", "git"),
+ password.getText().toString())
+ );
+ } catch (Exception e){
+ e.printStackTrace();
}
- }).setNegativeButton(activity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // Do nothing.
- }
- }).show();
- } else {
- // BUG: we do not support HTTP yet...
- }
+
+ }
+ }).setNegativeButton(activity.getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ // Do nothing.
+ }
+ }).show();
}
}
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 49be6e77..3fc10c7f 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -6,5 +6,6 @@
</string-array>
<string-array name="clone_protocols">
<item>ssh://</item>
+ <item>https://</item>
</string-array>
</resources> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 91b4e49a..05b8bbd4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -63,6 +63,8 @@
<string name="server_url">Server URL</string>
<string name="server_url_hint">server.com</string>
<string name="server_port_hint">22</string>
+ <string name="default_ssh_port">22</string>
+ <string name="default_https_port">443</string>
<string name="server_path">Repo path</string>
<string name="server_path_hint">path/to/pass</string>
<string name="server_user">Username</string>