2012-10-30 19:39:32 -04:00
|
|
|
/*
|
2014-01-01 16:26:19 -05:00
|
|
|
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
2012-10-30 19:39:32 -04:00
|
|
|
*
|
2013-09-06 10:17:01 -04:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2012-10-30 19:39:32 -04:00
|
|
|
*
|
2013-09-06 10:17:01 -04:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-10-30 19:39:32 -04:00
|
|
|
*
|
2013-09-06 10:17:01 -04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-10-30 19:39:32 -04:00
|
|
|
*/
|
|
|
|
|
2013-01-16 08:31:16 -05:00
|
|
|
package org.sufficientlysecure.keychain.ui;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2013-01-16 08:31:16 -05:00
|
|
|
import org.sufficientlysecure.keychain.Id;
|
2014-01-01 16:26:19 -05:00
|
|
|
import org.sufficientlysecure.keychain.R;
|
2014-01-01 10:54:55 -05:00
|
|
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
2013-01-16 08:31:16 -05:00
|
|
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|
|
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
|
2014-01-01 16:26:19 -05:00
|
|
|
import org.sufficientlysecure.keychain.ui.adapter.KeyListPublicAdapter;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2012-10-30 19:39:32 -04:00
|
|
|
import android.content.Intent;
|
2012-10-28 18:51:03 -04:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2014-01-01 16:26:19 -05:00
|
|
|
import android.support.v4.app.LoaderManager;
|
2012-10-28 18:51:03 -04:00
|
|
|
import android.support.v4.content.CursorLoader;
|
|
|
|
import android.support.v4.content.Loader;
|
2012-10-30 19:39:32 -04:00
|
|
|
import android.view.View;
|
2014-01-01 16:26:19 -05:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
|
|
|
|
|
|
import com.actionbarsherlock.app.SherlockListFragment;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
public class KeyListPublicFragment extends SherlockListFragment implements
|
2012-10-28 18:51:03 -04:00
|
|
|
LoaderManager.LoaderCallbacks<Cursor> {
|
|
|
|
|
2012-10-30 19:39:32 -04:00
|
|
|
private KeyListPublicActivity mKeyListPublicActivity;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
private KeyListPublicAdapter mAdapter;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define Adapter and Loader on create of Activity
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
2012-10-30 19:39:32 -04:00
|
|
|
mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
getListView().setOnItemClickListener(new OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
// start key view on click
|
|
|
|
Intent detailsIntent = new Intent(mKeyListPublicActivity, KeyViewActivity.class);
|
|
|
|
detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long
|
|
|
|
.toString(id)));
|
|
|
|
startActivity(detailsIntent);
|
2012-10-30 19:39:32 -04:00
|
|
|
}
|
2014-01-01 16:26:19 -05:00
|
|
|
});
|
2012-10-30 19:39:32 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// Give some text to display if there is no data. In a real
|
|
|
|
// application this would come from a resource.
|
|
|
|
setEmptyText(getString(R.string.list_empty));
|
2012-10-30 19:39:32 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// We have a menu item to show in action bar.
|
|
|
|
setHasOptionsMenu(true);
|
2014-01-01 10:54:55 -05:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// Start out with a progress indicator.
|
|
|
|
setListShown(false);
|
2013-01-08 16:12:23 -05:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// Create an empty adapter we will use to display the loaded data.
|
|
|
|
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key);
|
|
|
|
setListAdapter(mAdapter);
|
2012-10-30 19:39:32 -04:00
|
|
|
|
2014-01-01 16:26:19 -05:00
|
|
|
// Prepare the loader. Either re-connect with an existing one,
|
|
|
|
// or start a new one.
|
|
|
|
getLoaderManager().initLoader(0, null, this);
|
2012-10-30 19:39:32 -04:00
|
|
|
}
|
|
|
|
|
2012-10-28 18:51:03 -04:00
|
|
|
// These are the rows that we will retrieve.
|
2012-10-29 19:15:08 -04:00
|
|
|
static final String[] PROJECTION = new String[] { KeyRings._ID, KeyRings.MASTER_KEY_ID,
|
|
|
|
UserIds.USER_ID };
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2012-10-29 19:15:08 -04:00
|
|
|
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
2012-10-28 18:51:03 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
|
|
|
// This is called when a new Loader needs to be created. This
|
|
|
|
// sample only has one Loader, so we don't care about the ID.
|
2012-10-29 19:15:08 -04:00
|
|
|
Uri baseUri = KeyRings.buildPublicKeyRingsUri();
|
2012-10-28 18:51:03 -04:00
|
|
|
|
|
|
|
// Now create and return a CursorLoader that will take care of
|
|
|
|
// creating a Cursor for the data being displayed.
|
|
|
|
return new CursorLoader(getActivity(), baseUri, PROJECTION, null, null, SORT_ORDER);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
|
|
|
// Swap the new cursor in. (The framework will take care of closing the
|
|
|
|
// old cursor once we return.)
|
2014-01-01 16:26:19 -05:00
|
|
|
mAdapter.swapCursor(data);
|
2012-10-28 18:51:03 -04:00
|
|
|
|
|
|
|
// The list should now be shown.
|
|
|
|
if (isResumed()) {
|
|
|
|
setListShown(true);
|
|
|
|
} else {
|
|
|
|
setListShownNoAnimation(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> loader) {
|
|
|
|
// This is called when the last Cursor provided to onLoadFinished()
|
|
|
|
// above is about to be closed. We need to make sure we are no
|
|
|
|
// longer using it.
|
2014-01-01 16:26:19 -05:00
|
|
|
mAdapter.swapCursor(null);
|
2012-10-28 18:51:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|