diff --git a/app/app-release.apk b/app/app-release.apk index b0ec4ad8..eca5db41 100644 Binary files a/app/app-release.apk and b/app/app-release.apk 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,43 +97,12 @@ public class GitHandler extends ActionBarActivity { case REQUEST_CLONE: setContentView(R.layout.activity_git_clone); - // init the spinner for protocols - Spinner protcol_spinner = (Spinner) findViewById(R.id.clone_protocol); - ArrayAdapter 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); - protcol_spinner.setAdapter(protocol_adapter); - protcol_spinner.setOnItemSelectedListener( - new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int i, long l) { - protocol = ((Spinner)findViewById(R.id.clone_protocol)).getSelectedItem().toString(); - if (protocol.equals("ssh://")) { - ((EditText)findViewById(R.id.clone_uri)).setHint("user@hostname:path"); - } 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) { + final Spinner protcol_spinner = (Spinner) findViewById(R.id.clone_protocol); + final Spinner connection_mode_spinner = (Spinner) findViewById(R.id.connection_mode); - } - }).show(); - } - } - - @Override - public void onNothingSelected(AdapterView adapterView) { - - } - } - ); // init the spinner for connection modes - Spinner connection_mode_spinner = (Spinner) findViewById(R.id.connection_mode); - ArrayAdapter connection_mode_adapter = ArrayAdapter.createFromResource(this, + final ArrayAdapter 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); @@ -151,6 +120,43 @@ public class GitHandler extends ActionBarActivity { } }); + // init the spinner for protocols + ArrayAdapter 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); + protcol_spinner.setAdapter(protocol_adapter); + protcol_spinner.setOnItemSelectedListener( + new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + 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"); + + ((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); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + } + ); + + // init the server information final EditText server_url = ((EditText) findViewById(R.id.server_url)); final EditText server_port = ((EditText) findViewById(R.id.server_port)); @@ -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(); + 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); + ((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); } - hostname += server_port.getText().toString() + server_path.getText().toString(); + 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); + } + 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); + 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(); - } + 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 @@ ssh:// + https:// \ 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 @@ Server URL server.com 22 + 22 + 443 Repo path path/to/pass Username