Search in sources :

Example 1 with LocalIndexOperationTask

use of net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask in project Osmand by osmandapp.

the class ItemViewHolder method contextMenu.

protected void contextMenu(View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) {
    final PopupMenu optionsMenu = new PopupMenu(context, v);
    MenuItem item;
    final File fl = indexItem.getTargetFile(context.getMyApplication());
    if (fl.exists()) {
        item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                LocalIndexType tp = LocalIndexType.MAP_DATA;
                if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
                    tp = LocalIndexType.TILES_DATA;
                } else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
                    tp = LocalIndexType.MAP_DATA;
                } else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
                    tp = LocalIndexType.SRTM_DATA;
                } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
                    tp = LocalIndexType.MAP_DATA;
                } else if (indexItem.getType() == DownloadActivityType.FONT_FILE) {
                    tp = LocalIndexType.FONT_DATA;
                } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
                    tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA : LocalIndexType.VOICE_DATA;
                }
                final LocalIndexInfo info = new LocalIndexInfo(tp, fl, false, context.getMyApplication());
                AlertDialog.Builder confirm = new AlertDialog.Builder(context);
                confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        new LocalIndexOperationTask(context, null, LocalIndexOperationTask.DELETE_OPERATION).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info);
                    }
                });
                confirm.setNegativeButton(R.string.shared_string_no, null);
                String fn = FileNameTranslationHelper.getFileName(context, context.getMyApplication().getRegions(), indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
                confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn));
                confirm.show();
                return true;
            }
        });
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_download).setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_import));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            download(indexItem, parentOptional);
            return true;
        }
    });
    optionsMenu.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LocalIndexOperationTask(net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask) MenuItem(android.view.MenuItem) LocalIndexType(net.osmand.plus.activities.LocalIndexHelper.LocalIndexType) OnClickListener(android.view.View.OnClickListener) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 PopupMenu (android.support.v7.widget.PopupMenu)1 MenuItem (android.view.MenuItem)1 OnClickListener (android.view.View.OnClickListener)1 File (java.io.File)1 LocalIndexType (net.osmand.plus.activities.LocalIndexHelper.LocalIndexType)1 LocalIndexInfo (net.osmand.plus.activities.LocalIndexInfo)1 LocalIndexOperationTask (net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask)1