Refactored dashaudiovideonotesactivity. Added delete recording function

This commit is contained in:
Denis 2014-12-25 15:37:51 +02:00
parent 30b2a79b60
commit 83af9ac052
5 changed files with 148 additions and 61 deletions

View file

@ -5,11 +5,4 @@
android:id="@+id/main_scroll"
android:background="@color/dashboard_background" >
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="net.osmand.plus.dashboard.DashAudioVideoNotesFragment"
android:layout_marginTop="@dimen/dashCardMargin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>

View file

@ -6,6 +6,7 @@
android:background="@drawable/dashboard_button"
android:layout_height="@dimen/dashListItemHeight">
<View android:layout_width="match_parent"
android:id="@+id/divider"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"

View file

@ -1019,9 +1019,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
recordings.unregisterObject(r.lat, r.lon, r);
recordingByFileName.remove(r.file.getName());
Algorithms.removeAllFiles(r.file);
if (activity != null) {
activity.getMapLayers().getContextMenuLayer().setLocation(null, "");
activity.getMapView().refreshMap();
}
}
@Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {

View file

@ -1,22 +1,45 @@
package net.osmand.plus.dashboard;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.internal.widget.IcsAdapterView;
import com.actionbarsherlock.view.MenuItem;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MainMenuActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Denis on 23.12.2014.
*/
public class DashAudioVideoNotesActivity extends SherlockFragmentActivity {
public class DashAudioVideoNotesActivity extends SherlockListActivity {
AudioVideoNotesPlugin plugin;
List<AudioVideoNotesPlugin.Recording> items;
NotesAdapter listAdapter;
@Override
protected void onResume() {
super.onResume();
setContentView(R.layout.audio_video_notes_all);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editing_poi_filter);
plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
ColorDrawable color = new ColorDrawable(getResources().getColor(R.color.actionbar_color));
ActionBar actionBar = getSupportActionBar();
@ -25,6 +48,52 @@ public class DashAudioVideoNotesActivity extends SherlockFragmentActivity {
actionBar.setIcon(android.R.color.transparent);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
getListView().setBackgroundColor(getResources().getColor(R.color.dashboard_background));
}
@Override
protected void onResume() {
super.onResume();
items = new ArrayList<AudioVideoNotesPlugin.Recording>(plugin.getAllRecordings());
listAdapter = new NotesAdapter(items);
setListAdapter(listAdapter);
}
private void showContextMenu(final AudioVideoNotesPlugin.Recording recording){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final ContextMenuAdapter adapter = new ContextMenuAdapter(this);
ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
if (resId == R.string.local_index_mi_delete) {
AlertDialog.Builder confirm = new AlertDialog.Builder(DashAudioVideoNotesActivity.this);
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
plugin.deleteRecording(recording);
items.remove(recording);
listAdapter.notifyDataSetChanged();
}
});
confirm.setNegativeButton(R.string.default_buttons_no, null);
confirm.setMessage(getString(R.string.delete_confirmation_msg, recording.file.getName()));
confirm.show();
}
return true;
}
};
adapter.item(R.string.local_index_mi_delete).listen(listener).position(0).reg();
builder.setItems(adapter.getItemNames(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ContextMenuAdapter.OnContextMenuClick clk = adapter.getClickAdapter(which);
if (clk != null){
clk.onContextMenuClick(null, adapter.getElementId(which), which, false);
}
}
});
builder.show();
}
@Override
@ -36,4 +105,32 @@ public class DashAudioVideoNotesActivity extends SherlockFragmentActivity {
return super.onOptionsItemSelected(item);
}
}
class NotesAdapter extends ArrayAdapter<AudioVideoNotesPlugin.Recording> {
NotesAdapter(List<AudioVideoNotesPlugin.Recording> recordingList) {
super(DashAudioVideoNotesActivity.this, R.layout.dash_note_item, recordingList);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = convertView;
if (row == null){
row = inflater.inflate(R.layout.dash_note_item, parent, false);
row.findViewById(R.id.divider).setVisibility(View.GONE);
}
final AudioVideoNotesPlugin.Recording recording = getItem(position);
DashAudioVideoNotesFragment.getNoteView(recording, row, DashAudioVideoNotesActivity.this, plugin);
row.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showContextMenu(recording);
return true;
}
});
return row;
}
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.dashboard;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
@ -28,17 +29,12 @@ import java.util.List;
*/
public class DashAudioVideoNotesFragment extends DashBaseFragment {
AudioVideoNotesPlugin plugin;
boolean allNotes;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_audio_video_notes_plugin, container, false);
allNotes = getActivity() instanceof DashAudioVideoNotesActivity;
if (allNotes) {
view.findViewById(R.id.header_layout).setVisibility(View.GONE);
} else {
Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.notes_text)).setTypeface(typeface);
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);
@ -52,8 +48,6 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
activity.startActivity(favorites);
}
});
}
return view;
}
@ -92,7 +86,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
LinearLayout notesLayout = (LinearLayout) mainView.findViewById(R.id.notes);
notesLayout.removeAllViews();
if (notes.size() > 3 && !allNotes){
if (notes.size() > 3){
while (notes.size() != 3){
notes.remove(3);
}
@ -102,11 +96,27 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dash_note_item, null, false);
getNoteView(recording, view, getActivity(), plugin);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15, null,
recording.name != null ? recording.name : recording.getDescription(getActivity()),
recording); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
notesLayout.addView(view);
}
}
public static void getNoteView(final AudioVideoNotesPlugin.Recording recording, View view,
final Context ctx, final AudioVideoNotesPlugin plugin) {
if (recording.name != null){
((TextView) view.findViewById(R.id.name)).setText(recording.name);
((TextView) view.findViewById(R.id.descr)).setText(recording.getDescription(getActivity()));
((TextView) view.findViewById(R.id.descr)).setText(recording.getDescription(ctx));
} else {
((TextView) view.findViewById(R.id.name)).setText(recording.getDescription(getActivity()));
((TextView) view.findViewById(R.id.name)).setText(recording.getDescription(ctx));
view.findViewById(R.id.descr).setVisibility(View.GONE);
}
@ -119,28 +129,12 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
icon.setImageResource(R.drawable.ic_type_img);
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15, null,
recording.name != null ? recording.name : recording.getDescription(getActivity()),
recording); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
view.findViewById(R.id.play).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.playRecording(getActivity(), recording);
plugin.playRecording(ctx, recording);
}
});
//int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
//LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
//view.setLayoutParams(lp);
notesLayout.addView(view);
}
}
}