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
|
|
|
|
2014-01-02 15:10:08 -05:00
|
|
|
import se.emilsjolander.stickylistheaders.ApiLevelTooLowException;
|
|
|
|
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
|
|
|
import android.annotation.SuppressLint;
|
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;
|
2014-01-02 15:10:08 -05:00
|
|
|
import android.view.LayoutInflater;
|
2012-10-30 19:39:32 -04:00
|
|
|
import android.view.View;
|
2014-01-02 15:10:08 -05:00
|
|
|
import android.view.ViewGroup;
|
2014-01-01 16:26:19 -05:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
2014-01-02 15:10:08 -05:00
|
|
|
import com.actionbarsherlock.app.SherlockFragment;
|
|
|
|
|
|
|
|
/**
|
2014-01-03 12:07:42 -05:00
|
|
|
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
|
|
|
* StickyListHeaders library which does not extend upon ListView.
|
2014-01-02 15:10:08 -05:00
|
|
|
*/
|
|
|
|
public class KeyListPublicFragment extends SherlockFragment implements
|
|
|
|
AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> {
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2012-10-30 19:39:32 -04:00
|
|
|
private KeyListPublicActivity mKeyListPublicActivity;
|
2014-01-01 16:26:19 -05:00
|
|
|
private KeyListPublicAdapter mAdapter;
|
2014-01-02 16:36:57 -05:00
|
|
|
private StickyListHeadersListView mStickyList;
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
/**
|
|
|
|
* Load custom layout with StickyListView from library
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
View view = inflater.inflate(R.layout.key_list_public_fragment, container, false);
|
|
|
|
return view;
|
|
|
|
}
|
2014-01-02 15:10:08 -05:00
|
|
|
|
2012-10-28 18:51:03 -04:00
|
|
|
/**
|
|
|
|
* Define Adapter and Loader on create of Activity
|
|
|
|
*/
|
2014-01-02 15:10:08 -05:00
|
|
|
@SuppressLint("NewApi")
|
2012-10-28 18:51:03 -04:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
2012-10-30 19:39:32 -04:00
|
|
|
mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList.setOnItemClickListener(this);
|
|
|
|
mStickyList.setAreHeadersSticky(true);
|
|
|
|
mStickyList.setDrawingListUnderStickyHeader(false);
|
|
|
|
mStickyList.setFastScrollEnabled(true);
|
2014-01-02 15:10:08 -05:00
|
|
|
try {
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList.setFastScrollAlwaysVisible(true);
|
2014-01-02 15:10:08 -05:00
|
|
|
} catch (ApiLevelTooLowException e) {
|
|
|
|
}
|
2012-10-30 19:39:32 -04:00
|
|
|
|
2014-01-03 12:07:42 -05:00
|
|
|
// this view is made visible if no data is available
|
|
|
|
mStickyList.setEmptyView(getActivity().findViewById(R.id.empty));
|
2014-01-01 10:54:55 -05:00
|
|
|
|
2014-01-03 12:07:42 -05:00
|
|
|
// NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading
|
2014-01-01 16:26:19 -05:00
|
|
|
// Start out with a progress indicator.
|
2014-01-02 15:10:08 -05:00
|
|
|
// 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.
|
2014-01-03 12:07:42 -05:00
|
|
|
mAdapter = new KeyListPublicAdapter(mKeyListPublicActivity, null, Id.type.public_key,
|
|
|
|
USER_ID_INDEX);
|
|
|
|
mStickyList.setAdapter(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
|
|
|
|
2014-01-03 12:07:42 -05:00
|
|
|
static final int USER_ID_INDEX = 2;
|
|
|
|
|
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-03 12:07:42 -05:00
|
|
|
mAdapter.swapCursor(data);
|
2014-01-02 15:10:08 -05:00
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
mStickyList.setAdapter(mAdapter);
|
2012-10-28 18:51:03 -04:00
|
|
|
|
2014-01-03 12:07:42 -05:00
|
|
|
// NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading
|
2012-10-28 18:51:03 -04:00
|
|
|
// The list should now be shown.
|
2014-01-03 12:07:42 -05:00
|
|
|
// if (isResumed()) {
|
|
|
|
// setListShown(true);
|
|
|
|
// } else {
|
|
|
|
// setListShownNoAnimation(true);
|
|
|
|
// }
|
2012-10-28 18:51:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
2014-01-02 16:36:57 -05:00
|
|
|
/**
|
|
|
|
* On click on item, start key view activity
|
|
|
|
*/
|
2014-01-02 15:10:08 -05:00
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
Intent detailsIntent = new Intent(mKeyListPublicActivity, KeyViewActivity.class);
|
|
|
|
detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(id)));
|
|
|
|
startActivity(detailsIntent);
|
|
|
|
}
|
|
|
|
|
2012-10-28 18:51:03 -04:00
|
|
|
}
|