List fragment for trusted certificates can notify listeners about clicks
This commit is contained in:
+31
@@ -27,18 +27,29 @@ import org.strongswan.android.data.TrustedCertificateEntry;
|
||||
import org.strongswan.android.logic.TrustedCertificateManager;
|
||||
import org.strongswan.android.ui.adapter.TrustedCertificateAdapter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ListFragment;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.content.AsyncTaskLoader;
|
||||
import android.content.Context;
|
||||
import android.content.Loader;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class TrustedCertificateListFragment extends ListFragment implements LoaderCallbacks<List<TrustedCertificateEntry>>
|
||||
{
|
||||
private OnTrustedCertificateSelectedListener mListener;
|
||||
private TrustedCertificateAdapter mAdapter;
|
||||
private boolean mUser;
|
||||
|
||||
/**
|
||||
* The activity containing this fragment should implement this interface
|
||||
*/
|
||||
public interface OnTrustedCertificateSelectedListener {
|
||||
public void onTrustedCertificateSelected(TrustedCertificateEntry selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState)
|
||||
{
|
||||
@@ -63,6 +74,17 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity)
|
||||
{
|
||||
super.onAttach(activity);
|
||||
|
||||
if (activity instanceof OnTrustedCertificateSelectedListener)
|
||||
{
|
||||
mListener = (OnTrustedCertificateSelectedListener)activity;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<List<TrustedCertificateEntry>> onCreateLoader(int id, Bundle args)
|
||||
{ /* we don't need the id as we have only one loader */
|
||||
@@ -90,6 +112,15 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
||||
mAdapter.setData(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id)
|
||||
{
|
||||
if (mListener != null)
|
||||
{
|
||||
mListener.onTrustedCertificateSelected(mAdapter.getItem(position));
|
||||
}
|
||||
}
|
||||
|
||||
public static class CertificateListLoader extends AsyncTaskLoader<List<TrustedCertificateEntry>>
|
||||
{
|
||||
private List<TrustedCertificateEntry> mData;
|
||||
|
||||
Reference in New Issue
Block a user