diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-12-04 08:41:10 -0800 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-12-04 08:41:10 -0800 |
commit | 927dd580bce4a96ea83c194c988bcf0b4b1e0400 (patch) | |
tree | bbf9421a91498518cc7f4679e55ea6b366b5a34a /main | |
parent | 8bd5fd82a50259b148d08ec14b5db4327829eacd (diff) | |
parent | 4250bc50add8c08a71430585708833618bab3bd3 (diff) | |
download | cgeo-927dd580bce4a96ea83c194c988bcf0b4b1e0400.zip cgeo-927dd580bce4a96ea83c194c988bcf0b4b1e0400.tar.gz cgeo-927dd580bce4a96ea83c194c988bcf0b4b1e0400.tar.bz2 |
Merge pull request #2218 from marco-jacob/simpleDirChooserFix
fixes #2208 - corrected SimpleDirChooser selection
Diffstat (limited to 'main')
-rw-r--r-- | main/src/cgeo/geocaching/files/SimpleDirChooser.java | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java index 8deb741..4a4220c 100644 --- a/main/src/cgeo/geocaching/files/SimpleDirChooser.java +++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java @@ -36,9 +36,8 @@ public class SimpleDirChooser extends ListActivity { private static final String PARENT_DIR = ".. "; private File currentDir; private FileArrayAdapter adapter; - private CheckBox lastBoxChecked = null; private Button okButton = null; - private String checkedText = null; + private int lastPosition = -1; @Override public void onCreate(Bundle savedInstanceState) { @@ -68,7 +67,7 @@ public class SimpleDirChooser extends ListActivity { @Override public void onClick(View v) { Intent intent = new Intent(); - String chosenDirName = File.separator + checkedText; + String chosenDirName = File.separator + adapter.getItem(lastPosition).getName(); intent.putExtra(EXTRA_CHOSEN_DIR, currentDir.getAbsolutePath() + chosenDirName); setResult(RESULT_OK, intent); finish(); @@ -145,7 +144,8 @@ public class SimpleDirChooser extends ListActivity { } CheckBox check = (CheckBox) v.findViewById(R.id.CheckBox); if (check != null) { - check.setOnClickListener(new OnCheckBoxClickListener(option.getName())); + check.setOnClickListener(new OnCheckBoxClickListener(position)); + check.setChecked(option.isChecked()); } } return v; @@ -176,37 +176,37 @@ public class SimpleDirChooser extends ListActivity { } public class OnCheckBoxClickListener implements OnClickListener { - private String checkedText; + private int position; - OnCheckBoxClickListener(String checkedText) { - this.checkedText = checkedText; + OnCheckBoxClickListener(int position) { + this.position = position; } @Override public void onClick(View arg0) { - CheckBox check = (CheckBox) arg0; - if (lastBoxChecked == check) { - check.setChecked(false); - lastBoxChecked = null; - okButton.setEnabled(false); - okButton.setVisibility(View.INVISIBLE); - SimpleDirChooser.this.checkedText = ""; - } else { - if (lastBoxChecked != null) { - lastBoxChecked.setChecked(false); - } - check.setChecked(true); - lastBoxChecked = check; + Option lastOption = (lastPosition > -1) ? adapter.getItem(lastPosition) : null; + Option currentOption = adapter.getItem(position); + if (lastOption != null) { + lastOption.setChecked(false); + } + if (currentOption != lastOption) { + currentOption.setChecked(true); + lastPosition = position; okButton.setEnabled(true); okButton.setVisibility(View.VISIBLE); - SimpleDirChooser.this.checkedText = checkedText; + } else { + lastPosition = -1; + okButton.setEnabled(false); + okButton.setVisibility(View.INVISIBLE); } + arg0.refreshDrawableState(); } } public class Option implements Comparable<Option> { private final String name; private final String path; + private boolean checked = false; public Option(String name, String path) { this.name = name; @@ -221,6 +221,14 @@ public class SimpleDirChooser extends ListActivity { return path; } + public boolean isChecked() { + return this.checked; + } + + public void setChecked(boolean checked) { + this.checked = checked; + } + @Override public int compareTo(Option other) { if (other != null && this.name != null) { |