aboutsummaryrefslogtreecommitdiffstats
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/org/connectbot/EditHostActivity.java69
-rw-r--r--app/src/main/res/drawable-hdpi/ic_save.pngbin0 -> 247 bytes
-rw-r--r--app/src/main/res/drawable-mdpi/ic_save.pngbin0 -> 168 bytes
-rw-r--r--app/src/main/res/drawable-xhdpi/ic_save.pngbin0 -> 273 bytes
-rw-r--r--app/src/main/res/drawable-xxhdpi/ic_save.pngbin0 -> 391 bytes
-rw-r--r--app/src/main/res/drawable-xxxhdpi/ic_save.pngbin0 -> 504 bytes
-rw-r--r--app/src/main/res/menu/edit_host_activity_edit_menu.xml2
-rw-r--r--app/src/main/res/values/strings.xml6
8 files changed, 65 insertions, 12 deletions
diff --git a/app/src/main/java/org/connectbot/EditHostActivity.java b/app/src/main/java/org/connectbot/EditHostActivity.java
index f61924f..d5e2458 100644
--- a/app/src/main/java/org/connectbot/EditHostActivity.java
+++ b/app/src/main/java/org/connectbot/EditHostActivity.java
@@ -24,6 +24,7 @@ import java.util.Map;
import android.content.ComponentName;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.TypedArray;
@@ -46,6 +47,8 @@ public class EditHostActivity extends AppCompatActivity implements HostEditorFra
private static final String EXTRA_EXISTING_HOST_ID = "org.connectbot.existing_host_id";
private static final long NO_HOST_ID = -1;
+ private static final int ENABLED_ALPHA = 255;
+ private static final int DISABLED_ALPHA = 130;
private HostDatabase mHostDb;
private PubkeyDatabase mPubkeyDb;
@@ -135,7 +138,7 @@ public class EditHostActivity extends AppCompatActivity implements HostEditorFra
mSaveHostButton = menu.getItem(0);
// If the new host is being created, it can't be added until modifications have been made.
- mSaveHostButton.setEnabled(!mIsCreating);
+ setAddSaveButtonEnabled(!mIsCreating);
return super.onCreateOptionsMenu(menu);
}
@@ -144,14 +147,8 @@ public class EditHostActivity extends AppCompatActivity implements HostEditorFra
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.save:
- mHostDb.saveHost(mHost);
-
- if (mBridge != null) {
- // If the console is already open, apply the new encoding now. If the console
- // was not yet opened, this will be applied automatically when it is opened.
- mBridge.setCharset(mHost.getEncoding());
- }
- finish();
+ case android.R.id.home:
+ attemptSaveAndExit();
return true;
default:
return super.onOptionsItemSelected(item);
@@ -200,14 +197,64 @@ public class EditHostActivity extends AppCompatActivity implements HostEditorFra
public void onValidHostConfigured(HostBean host) {
mHost = host;
if (mSaveHostButton != null)
- mSaveHostButton.setEnabled(true);
+ setAddSaveButtonEnabled(true);
}
@Override
public void onHostInvalidated() {
mHost = null;
if (mSaveHostButton != null)
- mSaveHostButton.setEnabled(false);
+ setAddSaveButtonEnabled(false);
+ }
+
+ @Override
+ public void onBackPressed() {
+ attemptSaveAndExit();
+ }
+
+ /**
+ * If the host represents a valid URI, save it and exit; otherwise, pop up a dialog asking
+ * the user if he/she wants to discard the changes.
+ */
+ private void attemptSaveAndExit() {
+ if (mHost == null) {
+ showDiscardDialog();
+ return;
+ }
+
+ mHostDb.saveHost(mHost);
+
+ if (mBridge != null) {
+ // If the console is already open, apply the new encoding now. If the console
+ // was not yet opened, this will be applied automatically when it is opened.
+ mBridge.setCharset(mHost.getEncoding());
+ }
+ finish();
+ }
+
+ private void showDiscardDialog() {
+ android.support.v7.app.AlertDialog.Builder builder =
+ new android.support.v7.app.AlertDialog.Builder(this);
+ builder.setMessage(R.string.discard_host_changes_message)
+ .setPositiveButton(R.string.discard_host_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Do not save to the database - just exit.
+ finish();
+ }
+ })
+ .setNegativeButton(R.string.discard_host_cancel_button, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Do nothing.
+ }
+ });
+ builder.show();
+ }
+
+ private void setAddSaveButtonEnabled(boolean enabled) {
+ mSaveHostButton.setEnabled(enabled);
+ mSaveHostButton.getIcon().setAlpha(enabled ? ENABLED_ALPHA : DISABLED_ALPHA);
}
// Private static class used to generate a list of available Charsets. Note that this class
diff --git a/app/src/main/res/drawable-hdpi/ic_save.png b/app/src/main/res/drawable-hdpi/ic_save.png
new file mode 100644
index 0000000..dd3f106
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_save.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_save.png b/app/src/main/res/drawable-mdpi/ic_save.png
new file mode 100644
index 0000000..015062e
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_save.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_save.png b/app/src/main/res/drawable-xhdpi/ic_save.png
new file mode 100644
index 0000000..adda095
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_save.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_save.png b/app/src/main/res/drawable-xxhdpi/ic_save.png
new file mode 100644
index 0000000..3e0ce1a
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_save.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_save.png b/app/src/main/res/drawable-xxxhdpi/ic_save.png
new file mode 100644
index 0000000..bd80bf1
--- /dev/null
+++ b/app/src/main/res/drawable-xxxhdpi/ic_save.png
Binary files differ
diff --git a/app/src/main/res/menu/edit_host_activity_edit_menu.xml b/app/src/main/res/menu/edit_host_activity_edit_menu.xml
index 564e211..ecc8171 100644
--- a/app/src/main/res/menu/edit_host_activity_edit_menu.xml
+++ b/app/src/main/res/menu/edit_host_activity_edit_menu.xml
@@ -22,7 +22,7 @@
>
<item android:id="@+id/save"
- android:icon="@drawable/ic_add"
+ android:icon="@drawable/ic_save"
android:title="@string/hostpref_edit_host"
connectbot:showAsAction="always|withText"
/>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 445d894..b087bfd 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -655,5 +655,11 @@
<string name="pubkey_add_new">Add new pubkey</string>
<!-- Text for button which, when clicked, brings up picker to import an existing pubkey. -->
<string name="pubkey_import_existing">Import existing pubkey</string>
+ <!-- Text for dialog which explains that the host URI is invalid and asks to discard. -->
+ <string name="discard_host_changes_message">Host URI is invalid. Would you like to discard changes?</string>
+ <!-- Text for button which discards changes to the host. -->
+ <string name="discard_host_button">Discard</string>
+ <!-- Text for button which does not discard changes and keeps editing. -->
+ <string name="discard_host_cancel_button">Keep editing</string>
</resources>