aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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>
d='n474' href='#n474'>474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864