|
1 | 1 | package com.paulds.simpleftp.presentation.model; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import android.content.DialogInterface; |
4 | 5 | import android.content.Intent; |
5 | 6 | import android.databinding.BaseObservable; |
6 | 7 | import android.databinding.Bindable; |
7 | 8 | import android.databinding.Observable; |
8 | 9 | import android.databinding.ObservableArrayList; |
9 | 10 | import android.databinding.ObservableBoolean; |
10 | 11 | import android.databinding.ObservableField; |
| 12 | +import android.support.v7.app.AlertDialog; |
11 | 13 | import android.view.View; |
| 14 | +import android.widget.EditText; |
12 | 15 | import android.widget.Toast; |
13 | 16 |
|
14 | 17 | import com.paulds.simpleftp.BR; |
@@ -81,6 +84,7 @@ public void updateList() { |
81 | 84 | if(servers != null) { |
82 | 85 | for (FtpServer server : serverEntities) { |
83 | 86 | FtpServerViewModel viewModel = new FtpServerViewModel(this); |
| 87 | + viewModel.setId(server.getId()); |
84 | 88 | viewModel.setName(server.getName()); |
85 | 89 | viewModel.setHost(server.getHost()); |
86 | 90 | viewModel.setPort(server.getPort()); |
@@ -108,6 +112,37 @@ public void closeServer(View view) { |
108 | 112 | selectedServerVisible.set(false); |
109 | 113 | } |
110 | 114 |
|
| 115 | + /** |
| 116 | + * Delete the selected server. |
| 117 | + * @param view The current view. |
| 118 | + */ |
| 119 | + public void deleteServer(View view) { |
| 120 | + if(selectedServer.get() != null) { |
| 121 | + AlertDialog.Builder builder = new AlertDialog.Builder(this.context); |
| 122 | + |
| 123 | + builder.setMessage(R.string.dialog_delete_server_message); |
| 124 | + |
| 125 | + builder.setPositiveButton(R.string.dialog_delete_server_positive_button, new DialogInterface.OnClickListener() { |
| 126 | + @Override |
| 127 | + public void onClick(DialogInterface dialog, int which) { |
| 128 | + AndroidApplication.getRepository().getServerRepository().deleteServer(selectedServer.get().getId()); |
| 129 | + selectedServerVisible.set(false); |
| 130 | + updateList(); |
| 131 | + } |
| 132 | + }); |
| 133 | + |
| 134 | + builder.setNegativeButton(R.string.dialog_delete_server_negative_button, new DialogInterface.OnClickListener() { |
| 135 | + @Override |
| 136 | + public void onClick(DialogInterface dialog, int which) { |
| 137 | + dialog.cancel(); |
| 138 | + } |
| 139 | + }); |
| 140 | + |
| 141 | + AlertDialog dialog = builder.create(); |
| 142 | + dialog.show(); |
| 143 | + } |
| 144 | + } |
| 145 | + |
111 | 146 | /** |
112 | 147 | * Add a new FTP server. |
113 | 148 | * @param view The current view. |
|
0 commit comments