Skip to content

Commit

Permalink
Merge pull request #1019 from Phoenix09/patch-2
Browse files Browse the repository at this point in the history
Have separate source/target inputs for mounts so people actually know they can specify a target
  • Loading branch information
meefik authored Nov 25, 2018
2 parents aa0f246 + 2d22ba2 commit 00035cd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
53 changes: 42 additions & 11 deletions app/src/main/java/ru/meefik/linuxdeploy/MountsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,29 @@ public class MountsActivity extends AppCompatActivity {
private ArrayAdapter adapter;

private void addDialog() {
final EditText input = new EditText(this);
LayoutInflater layoutInflater = LayoutInflater.from(this);
View view = layoutInflater.inflate(R.layout.properties_mounts, null);
final EditText inputSrc = view.findViewById(R.id.editTextSrc);
final EditText inputTarget = view.findViewById(R.id.editTextTarget);
new AlertDialog.Builder(this)
.setTitle(R.string.new_mount_title)
.setView(input, 16, 32, 16, 0)
.setView(view)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
String text = input.getText().toString()
.replaceAll(" ", "_");
String text = "";
String src = inputSrc.getText().toString()
.replaceAll("[ :]", "_");
String target = inputTarget.getText().toString()
.replaceAll("[ :]", "_");
if (src.length() > 0) {
text = src;
if (target.length() > 0) {
text = text + ":" + target;
}
}
if (text.length() > 0) {
listItems.add(text);
adapter.notifyDataSetChanged();
Expand All @@ -52,21 +64,40 @@ public void onClick(DialogInterface dialog,
}

private void editDialog(final int position) {
final EditText input = new EditText(this);
LayoutInflater layoutInflater = LayoutInflater.from(this);
View view = layoutInflater.inflate(R.layout.properties_mounts, null);
final EditText inputSrc = view.findViewById(R.id.editTextSrc);
final EditText inputTarget = view.findViewById(R.id.editTextTarget);
if (position >= 0 && position < listItems.size()) {
input.setText(listItems.get(position));
input.setSelection(input.getText().length());
String text = listItems.get(position);
final String[] arr = text.split(":", 2);
try {
inputSrc.setText(arr[0]);
inputSrc.setSelection(arr[0].length());

inputTarget.setText(arr[1]);
inputTarget.setSelection(arr[1].length());
} catch (IndexOutOfBoundsException e) {}

new AlertDialog.Builder(this)
.setTitle(R.string.edit_mount_title)
.setView(input, 16, 32, 16, 0)
.setView(view)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
String text = input.getText()
.toString()
.replaceAll(" ", "_");
String text = "";
String src = inputSrc.getText().toString()
.replaceAll("[ :]", "_");
String target = inputTarget.getText().toString()
.replaceAll("[ :]", "_");
if (src.length() > 0) {
text = src;
if (target.length() > 0) {
text = text + ":" + target;
}
}
if (text.length() > 0) {
listItems.set(position, text);
adapter.notifyDataSetChanged();
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/properties_mounts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/editTextSrc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/hint_mounts_source"
android:inputType="textNoSuggestions" />

<EditText
android:id="@+id/editTextTarget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/hint_mounts_target"
android:inputType="textNoSuggestions" />
</LinearLayout>

2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
<string name="summary_is_mounts_preference">Allow to mount the Android resources</string>
<string name="title_mounts_editor_preference">Mount points</string>
<string name="summary_mounts_editor_preference">Edit the mount points list</string>
<string name="hint_mounts_source">Source</string>
<string name="hint_mounts_target">Target (optional)</string>

<!-- SSH -->
<string name="ssh_preferences">SSH</string>
Expand Down

0 comments on commit 00035cd

Please sign in to comment.