Fixed #2597. If there are no file found showing "Data is not available message" and removing marker.
This commit is contained in:
parent
21b73be257
commit
72a92d4899
1 changed files with 86 additions and 67 deletions
|
@ -18,23 +18,25 @@ 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();
|
||||||
|
|
||||||
|
if (mIsFileAvailable) {
|
||||||
leftTitleButtonController = new TitleButtonController() {
|
leftTitleButtonController = new TitleButtonController() {
|
||||||
@Override
|
@Override
|
||||||
public void buttonPressed() {
|
public void buttonPressed() {
|
||||||
if (plugin != null) {
|
if (mPlugin != null) {
|
||||||
if (plugin.isPlaying(getRecording())) {
|
if (mPlugin.isPlaying(getRecording())) {
|
||||||
plugin.stopPlaying();
|
mPlugin.stopPlaying();
|
||||||
} else {
|
} else {
|
||||||
plugin.playRecording(getMapActivity(), getRecording());
|
mPlugin.playRecording(getMapActivity(), getRecording());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +51,8 @@ public class AudioVideoNoteMenuController extends MenuController {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (plugin != null) {
|
if (mPlugin != null) {
|
||||||
plugin.deleteRecording(getRecording(), true);
|
mPlugin.deleteRecording(getRecording(), true);
|
||||||
getMapActivity().getContextMenu().close();
|
getMapActivity().getContextMenu().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +63,7 @@ public class AudioVideoNoteMenuController extends MenuController {
|
||||||
};
|
};
|
||||||
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
|
rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete);
|
||||||
rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
|
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,17 +160,18 @@ 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) {
|
||||||
|
String path = mRecording.getFile().getAbsolutePath();
|
||||||
MediaScannerConnection.scanFile(getMapActivity(), new String[]{path},
|
MediaScannerConnection.scanFile(getMapActivity(), new String[]{path},
|
||||||
null, new MediaScannerConnection.OnScanCompletedListener() {
|
null, new MediaScannerConnection.OnScanCompletedListener() {
|
||||||
public void onScanCompleted(String path, Uri uri) {
|
public void onScanCompleted(String path, Uri uri) {
|
||||||
Intent shareIntent = new Intent(
|
Intent shareIntent = new Intent(
|
||||||
android.content.Intent.ACTION_SEND);
|
android.content.Intent.ACTION_SEND);
|
||||||
if (recording.isPhoto()) {
|
if (mRecording.isPhoto()) {
|
||||||
shareIntent.setType("image/*");
|
shareIntent.setType("image/*");
|
||||||
} else if (recording.isAudio()) {
|
} else if (mRecording.isAudio()) {
|
||||||
shareIntent.setType("audio/*");
|
shareIntent.setType("audio/*");
|
||||||
} else if (recording.isVideo()) {
|
} else if (mRecording.isVideo()) {
|
||||||
shareIntent.setType("video/*");
|
shareIntent.setType("video/*");
|
||||||
}
|
}
|
||||||
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||||
|
@ -165,5 +181,8 @@ public class AudioVideoNoteMenuController extends MenuController {
|
||||||
getMapActivity().getString(R.string.share_note)));
|
getMapActivity().getString(R.string.share_note)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
super.share(latLon, title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue