Update audio/video notes

This commit is contained in:
Victor Shcherb 2015-02-28 11:57:59 +02:00
parent ee09ccf41b
commit eb974df666
2 changed files with 12 additions and 18 deletions

View file

@ -178,12 +178,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
public boolean setName(String name) {
int index = file.getAbsolutePath().lastIndexOf("/") + 1;
if (index < 0) {
return false;
File directory = file.getParentFile();
String fileName = getFileName();
final String hashAndExtension;
int hashInd = fileName.lastIndexOf('_');
if (hashInd == -1) {
hashAndExtension = "_" + fileName;
} else {
hashAndExtension = fileName.substring(hashInd, fileName.length());
}
File directory = new File(file.getAbsolutePath().substring(0, index));
File to = new File(directory, name.trim());
File to = new File(directory, name+hashAndExtension);
if (file.renameTo(to)) {
file = to;
return true;
@ -198,9 +202,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public String getName(Context ctx) {
String fileName = file.getName();
int hashInd = fileName.lastIndexOf("_");
int hashInd = fileName.lastIndexOf('_');
if (hashInd != -1) {
return fileName.substring(0, hashInd - 1);
return fileName.substring(0, hashInd);
} else if (this.isAudio()) {
return ctx.getResources().getString(R.string.audio);
} else if (this.isVideo()) {

View file

@ -213,16 +213,6 @@ public class NotesFragment extends ListFragment {
getListView(), false);
final EditText editText = (EditText) v.findViewById(R.id.name);
builder.setView(v);
String fileName = recording.getFileName();
final String hash;
int hashInd = fileName.lastIndexOf("_");
if (hashInd == -1) {
hash = "_" + fileName;
} else {
hash = fileName.substring(hashInd, fileName.length());
}
editText.setText(recording.getName(getActivity()));
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
@ -230,7 +220,7 @@ public class NotesFragment extends ListFragment {
builder.setPositiveButton(R.string.default_buttons_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(!recording.setName(editText.getText().toString() + hash)) {
if(!recording.setName(editText.getText().toString())) {
Toast.makeText(getActivity(),R.string.rename_failed,Toast.LENGTH_SHORT).show();
}
recording.setDescription();