2014-02-28 06:44:02 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2014 Open Whisper Systems
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.os.Bundle;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.support.v4.app.ListFragment;
|
2014-02-28 06:44:02 +00:00
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.content.Loader;
|
|
|
|
import android.support.v4.widget.CursorAdapter;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.database.loaders.ConversationListLoader;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2014-02-28 06:44:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A fragment to select and share to open conversations
|
|
|
|
*
|
|
|
|
* @author Jake McGinty
|
|
|
|
*/
|
2014-06-29 03:40:57 +00:00
|
|
|
public class ShareFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
2014-02-28 06:44:02 +00:00
|
|
|
|
|
|
|
private ConversationSelectedListener listener;
|
|
|
|
private MasterSecret masterSecret;
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
masterSecret = getArguments().getParcelable("master_secret");
|
|
|
|
}
|
|
|
|
|
2014-02-28 06:44:02 +00:00
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
|
|
|
return inflater.inflate(R.layout.share_fragment, container, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
|
|
|
|
initializeListAdapter();
|
|
|
|
getLoaderManager().initLoader(0, null, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
this.listener = (ConversationSelectedListener) activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
|
|
|
if (v instanceof ShareListItem) {
|
|
|
|
ShareListItem headerView = (ShareListItem) v;
|
|
|
|
|
|
|
|
handleCreateConversation(headerView.getThreadId(), headerView.getRecipients(),
|
|
|
|
headerView.getDistributionType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeListAdapter() {
|
|
|
|
this.setListAdapter(new ShareListAdapter(getActivity(), null, masterSecret));
|
|
|
|
getListView().setRecyclerListener((ShareListAdapter) getListAdapter());
|
|
|
|
getLoaderManager().restartLoader(0, null, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCreateConversation(long threadId, Recipients recipients, int distributionType) {
|
|
|
|
listener.onCreateConversation(threadId, recipients, distributionType);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
|
|
|
return new ConversationListLoader(getActivity(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
|
|
|
((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> arg0) {
|
|
|
|
((CursorAdapter)getListAdapter()).changeCursor(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface ConversationSelectedListener {
|
|
|
|
public void onCreateConversation(long threadId, Recipients recipients, int distributionType);
|
|
|
|
}
|
|
|
|
}
|