Search in sources :

Example 1 with IFileAdapter

use of group.pals.android.lib.ui.filechooser.IFileAdapter in project FBReaderJ by geometer.

the class ViewFilesContextMenuUtils method doShowHistoryContents.

/**
     * Shows history contents to the user. He can clear all items.
     * 
     * @param context
     *            {@link Context}
     * @param fileProvider
     *            {@link IFileProvider}
     * @param history
     *            {@link History} of {@link IFile}.
     * @param currentLocation
     *            current location, will not be shown.
     * @param listener
     *            will be notified after the user closed the dialog, or when the
     *            user selects an item.
     */
public static void doShowHistoryContents(final Context context, final IFileProvider fileProvider, final History<IFile> history, IFile currentLocation, final TaskListener listener) {
    if (history.isEmpty())
        return;
    final AlertDialog _dialog = Dlg.newDlg(context);
    // don't use Cancel button
    _dialog.setButton(DialogInterface.BUTTON_NEGATIVE, null, (DialogInterface.OnClickListener) null);
    _dialog.setIcon(android.R.drawable.ic_dialog_info);
    _dialog.setTitle(R.string.afc_title_history);
    List<IFileDataModel> data = new ArrayList<IFileDataModel>();
    ArrayList<IFile> items = history.items();
    for (int i = items.size() - 1; i >= 0; i--) {
        IFile f = items.get(i);
        if (f == currentLocation)
            continue;
        // check for duplicates
        boolean duplicated = false;
        for (int j = 0; j < data.size(); j++) {
            if (f.equalsToPath(data.get(j).getFile())) {
                duplicated = true;
                break;
            }
        }
        if (!duplicated)
            data.add(new IFileDataModel(f));
    }
    final IFileAdapter _adapter = new IFileAdapter(context, data, FilterMode.DirectoriesOnly, null, false);
    ListView listView = (ListView) LayoutInflater.from(context).inflate(R.layout.afc_listview_files, null);
    listView.setBackgroundResource(0);
    listView.setFastScrollEnabled(true);
    listView.setAdapter(_adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (listener != null) {
                _dialog.dismiss();
                listener.onFinish(true, _adapter.getItem(position).getFile());
            }
        }
    });
    // OnItemClickListener
    _dialog.setView(listView);
    _dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.afc_cmd_clear), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            history.clear();
        }
    });
    _dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (listener != null)
                listener.onFinish(true, null);
        }
    });
    _dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) IFileAdapter(group.pals.android.lib.ui.filechooser.IFileAdapter) IFile(group.pals.android.lib.ui.filechooser.io.IFile) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) IFileDataModel(group.pals.android.lib.ui.filechooser.IFileDataModel) AdapterView(android.widget.AdapterView)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 IFileAdapter (group.pals.android.lib.ui.filechooser.IFileAdapter)1 IFileDataModel (group.pals.android.lib.ui.filechooser.IFileDataModel)1 IFile (group.pals.android.lib.ui.filechooser.io.IFile)1 ArrayList (java.util.ArrayList)1