Fixed #2597. If there are no file found showing "Data is not available message" and removing marker.

This commit is contained in:
GaidamakUA 2016-06-02 14:15:37 +03:00
parent 21b73be257
commit 72a92d4899

View file

@ -18,49 +18,52 @@ import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
public class AudioVideoNoteMenuController extends MenuController { public class AudioVideoNoteMenuController extends MenuController {
private Recording recording; private Recording mRecording;
private AudioVideoNotesPlugin mPlugin;
private AudioVideoNotesPlugin plugin; private boolean mIsFileAvailable;
public AudioVideoNoteMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, final Recording recording) { public AudioVideoNoteMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, final Recording recording) {
super(new AudioVideoNoteMenuBuilder(app, recording), pointDescription, mapActivity); super(new AudioVideoNoteMenuBuilder(app, recording), pointDescription, mapActivity);
this.recording = recording; this.mRecording = recording;
plugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class); mPlugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
mIsFileAvailable = mRecording.getFile().exists();
leftTitleButtonController = new TitleButtonController() { if (mIsFileAvailable) {
@Override leftTitleButtonController = new TitleButtonController() {
public void buttonPressed() { @Override
if (plugin != null) { public void buttonPressed() {
if (plugin.isPlaying(getRecording())) { if (mPlugin != null) {
plugin.stopPlaying(); if (mPlugin.isPlaying(getRecording())) {
} else { mPlugin.stopPlaying();
plugin.playRecording(getMapActivity(), getRecording()); } else {
} mPlugin.playRecording(getMapActivity(), getRecording());
}
}
};
rightTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
AlertDialog.Builder bld = new AlertDialog.Builder(getMapActivity());
bld.setMessage(R.string.recording_delete_confirm);
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (plugin != null) {
plugin.deleteRecording(getRecording(), true);
getMapActivity().getContextMenu().close();
} }
} }
}); }
bld.setNegativeButton(R.string.shared_string_no, null); };
bld.show();
} rightTitleButtonController = new TitleButtonController() {
}; @Override
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete); public void buttonPressed() {
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; AlertDialog.Builder bld = new AlertDialog.Builder(getMapActivity());
bld.setMessage(R.string.recording_delete_confirm);
bld.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mPlugin != null) {
mPlugin.deleteRecording(getRecording(), true);
getMapActivity().getContextMenu().close();
}
}
});
bld.setNegativeButton(R.string.shared_string_no, null);
bld.show();
}
};
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
}
updateData(); updateData();
} }
@ -68,12 +71,13 @@ public class AudioVideoNoteMenuController extends MenuController {
@Override @Override
protected void setObject(Object object) { protected void setObject(Object object) {
if (object instanceof Recording) { if (object instanceof Recording) {
this.recording = (Recording) object; this.mRecording = (Recording) object;
mIsFileAvailable = mRecording.getFile().exists();
} }
} }
public Recording getRecording() { public Recording getRecording() {
return recording; return mRecording;
} }
@Override @Override
@ -83,9 +87,9 @@ public class AudioVideoNoteMenuController extends MenuController {
@Override @Override
public Drawable getLeftIcon() { public Drawable getLeftIcon() {
if (recording.isPhoto()) { if (mRecording.isPhoto()) {
return getIcon(R.drawable.ic_action_photo_dark, R.color.audio_video_icon_color); return getIcon(R.drawable.ic_action_photo_dark, R.color.audio_video_icon_color);
} else if (recording.isAudio()) { } else if (mRecording.isAudio()) {
return getIcon(R.drawable.ic_action_micro_dark, R.color.audio_video_icon_color); return getIcon(R.drawable.ic_action_micro_dark, R.color.audio_video_icon_color);
} else { } else {
return getIcon(R.drawable.ic_action_video_dark, R.color.audio_video_icon_color); return getIcon(R.drawable.ic_action_video_dark, R.color.audio_video_icon_color);
@ -94,12 +98,20 @@ public class AudioVideoNoteMenuController extends MenuController {
@Override @Override
public String getNameStr() { public String getNameStr() {
return recording.getName(getMapActivity(), false); if (mIsFileAvailable) {
return mRecording.getName(getMapActivity(), false);
} else {
return getMapActivity().getString(R.string.data_is_not_available);
}
} }
@Override @Override
public String getTypeStr() { public String getTypeStr() {
return recording.getType(getMapActivity()); if (mIsFileAvailable) {
return mRecording.getType(getMapActivity());
} else {
return super.getTypeStr();
}
} }
@Override @Override
@ -114,16 +126,19 @@ public class AudioVideoNoteMenuController extends MenuController {
@Override @Override
public void updateData() { public void updateData() {
if (!mIsFileAvailable) {
return;
}
boolean accessibilityEnabled = getMapActivity().getMyApplication().accessibilityEnabled(); boolean accessibilityEnabled = getMapActivity().getMyApplication().accessibilityEnabled();
rightTitleButtonController.visible = true; rightTitleButtonController.visible = true;
if (!recording.isPhoto()) { if (!mRecording.isPhoto()) {
if (plugin.isPlaying(recording)) { if (mPlugin.isPlaying(mRecording)) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_control_stop); leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_control_stop);
leftTitleButtonController.leftIconId = R.drawable.ic_action_rec_stop; leftTitleButtonController.leftIconId = R.drawable.ic_action_rec_stop;
int pos = plugin.getPlayingPosition(); int pos = mPlugin.getPlayingPosition();
String durationStr; String durationStr;
if (pos == -1) { if (pos == -1) {
durationStr = recording.getPlainDuration(accessibilityEnabled); durationStr = mRecording.getPlainDuration(accessibilityEnabled);
} else { } else {
durationStr = Algorithms.formatDuration(pos / 1000, accessibilityEnabled); durationStr = Algorithms.formatDuration(pos / 1000, accessibilityEnabled);
} }
@ -133,7 +148,7 @@ public class AudioVideoNoteMenuController extends MenuController {
} else { } else {
leftTitleButtonController.caption = getMapActivity().getString(R.string.recording_context_menu_play); leftTitleButtonController.caption = getMapActivity().getString(R.string.recording_context_menu_play);
leftTitleButtonController.leftIconId = R.drawable.ic_play_dark; leftTitleButtonController.leftIconId = R.drawable.ic_play_dark;
String durationStr = recording.getPlainDuration(accessibilityEnabled); String durationStr = mRecording.getPlainDuration(accessibilityEnabled);
leftTitleButtonController.needRightText = true; leftTitleButtonController.needRightText = true;
leftTitleButtonController.rightTextCaption = "" + durationStr; leftTitleButtonController.rightTextCaption = "" + durationStr;
} }
@ -145,25 +160,29 @@ public class AudioVideoNoteMenuController extends MenuController {
@Override @Override
public void share(LatLon latLon, String title) { public void share(LatLon latLon, String title) {
String path = recording.getFile().getAbsolutePath(); if (mIsFileAvailable) {
MediaScannerConnection.scanFile(getMapActivity(), new String[]{path}, String path = mRecording.getFile().getAbsolutePath();
null, new MediaScannerConnection.OnScanCompletedListener() { MediaScannerConnection.scanFile(getMapActivity(), new String[]{path},
public void onScanCompleted(String path, Uri uri) { null, new MediaScannerConnection.OnScanCompletedListener() {
Intent shareIntent = new Intent( public void onScanCompleted(String path, Uri uri) {
android.content.Intent.ACTION_SEND); Intent shareIntent = new Intent(
if (recording.isPhoto()) { android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*"); if (mRecording.isPhoto()) {
} else if (recording.isAudio()) { shareIntent.setType("image/*");
shareIntent.setType("audio/*"); } else if (mRecording.isAudio()) {
} else if (recording.isVideo()) { shareIntent.setType("audio/*");
shareIntent.setType("video/*"); } else if (mRecording.isVideo()) {
shareIntent.setType("video/*");
}
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
getMapActivity().startActivity(Intent.createChooser(shareIntent,
getMapActivity().getString(R.string.share_note)));
} }
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); });
shareIntent } else {
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); super.share(latLon, title);
getMapActivity().startActivity(Intent.createChooser(shareIntent, }
getMapActivity().getString(R.string.share_note)));
}
});
} }
} }