parent
e2f7c1529a
commit
12dac6ccc3
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@color/conversation_list_item_background_read_light" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item android:left="73dp" android:right="10dp">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@color/conversation_list_divider_light" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@color/conversation_list_item_background_read_dark" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item android:left="73dp" android:right="10dp">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@color/conversation_list_divider_dark" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/drawer_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<fragment android:id="@+id/fragment_content"
|
||||||
|
android:name="org.thoughtcrime.securesms.ShareFragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ListView android:id="@android:id/list"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:drawSelectorOnTop="false"
|
||||||
|
android:scrollbarStyle="insideOverlay"
|
||||||
|
android:fadingEdgeLength="16dip"
|
||||||
|
android:divider="?share_list_item_divider"
|
||||||
|
android:dividerHeight="1px" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<org.thoughtcrime.securesms.ShareListItem
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.components.ForegroundImageView
|
||||||
|
android:id="@+id/contact_photo_image"
|
||||||
|
android:foreground="@drawable/contact_photo_background"
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:layout_marginBottom="3dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:cropToPadding="true"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:contentDescription="@string/SingleContactSelectionActivity_contact_photo" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dip"
|
||||||
|
android:layout_marginLeft="4dip"
|
||||||
|
android:layout_marginRight="8dip"
|
||||||
|
android:layout_marginBottom="4dip"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_toRightOf="@id/contact_photo_image"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView android:id="@+id/from"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textColor="?attr/conversation_list_item_contact_color"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:ellipsize="marquee" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</org.thoughtcrime.securesms.ShareListItem>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:title="@string/text_secure_normal__menu_new_message"
|
||||||
|
android:id="@+id/menu_new_message"
|
||||||
|
android:icon="?attr/menu_new_conversation_icon"
|
||||||
|
android:showAsAction="always" />
|
||||||
|
|
||||||
|
</menu>
|
@ -0,0 +1,173 @@
|
|||||||
|
/**
|
||||||
|
* 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.content.Intent;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
|
||||||
|
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||||
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An activity to quickly share content with contacts
|
||||||
|
*
|
||||||
|
* @author Jake McGinty
|
||||||
|
*/
|
||||||
|
public class ShareActivity extends PassphraseRequiredSherlockFragmentActivity
|
||||||
|
implements ShareFragment.ConversationSelectedListener
|
||||||
|
{
|
||||||
|
public final static String MASTER_SECRET_EXTRA = "master_secret";
|
||||||
|
|
||||||
|
private final DynamicTheme dynamicTheme = new DynamicTheme ();
|
||||||
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||||
|
|
||||||
|
private ShareFragment fragment;
|
||||||
|
private MasterSecret masterSecret;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
dynamicTheme.onCreate(this);
|
||||||
|
dynamicLanguage.onCreate(this);
|
||||||
|
super.onCreate(icicle);
|
||||||
|
|
||||||
|
setContentView(R.layout.share_activity);
|
||||||
|
ActionBarUtil.initializeDefaultActionBar(this, getSupportActionBar(), R.string.ShareActivity_share_with);
|
||||||
|
initializeResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
setIntent(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
dynamicTheme.onResume(this);
|
||||||
|
dynamicLanguage.onResume(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
if (!isFinishing()) finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
MemoryCleaner.clean(masterSecret);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = this.getSupportMenuInflater();
|
||||||
|
menu.clear();
|
||||||
|
|
||||||
|
inflater.inflate(R.menu.share, menu);
|
||||||
|
super.onPrepareOptionsMenu(menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
super.onOptionsItemSelected(item);
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_new_message: handleNewConversation(); return true;
|
||||||
|
case android.R.id.home: finish(); return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMasterSecretCleared() {
|
||||||
|
startActivity(new Intent(this, RoutingActivity.class));
|
||||||
|
super.onMasterSecretCleared();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNewConversation() {
|
||||||
|
Intent intent = getBaseShareIntent(NewConversationActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateConversation(long threadId, Recipients recipients, int distributionType) {
|
||||||
|
createConversation(threadId, recipients, distributionType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createConversation(long threadId, Recipients recipients, int distributionType) {
|
||||||
|
final Intent intent = getBaseShareIntent(ConversationActivity.class);
|
||||||
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.toIdString());
|
||||||
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
||||||
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType);
|
||||||
|
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeResources() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && TextSecurePreferences.isScreenSecurityEnabled(this)) {
|
||||||
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
|
||||||
|
WindowManager.LayoutParams.FLAG_SECURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
|
||||||
|
|
||||||
|
this.fragment = (ShareFragment)this.getSupportFragmentManager()
|
||||||
|
.findFragmentById(R.id.fragment_content);
|
||||||
|
|
||||||
|
this.fragment.setMasterSecret(masterSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent getBaseShareIntent(final Class<?> target) {
|
||||||
|
final Intent intent = new Intent(this, target);
|
||||||
|
final Intent originalIntent = getIntent();
|
||||||
|
final String draftText = originalIntent.getStringExtra(ConversationActivity.DRAFT_TEXT_EXTRA);
|
||||||
|
final Uri draftImage = originalIntent.getParcelableExtra(ConversationActivity.DRAFT_IMAGE_EXTRA);
|
||||||
|
final Uri draftAudio = originalIntent.getParcelableExtra(ConversationActivity.DRAFT_AUDIO_EXTRA);
|
||||||
|
final Uri draftVideo = originalIntent.getParcelableExtra(ConversationActivity.DRAFT_VIDEO_EXTRA);
|
||||||
|
|
||||||
|
intent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, draftText);
|
||||||
|
intent.putExtra(ConversationActivity.DRAFT_IMAGE_EXTRA, draftImage);
|
||||||
|
intent.putExtra(ConversationActivity.DRAFT_AUDIO_EXTRA, draftAudio);
|
||||||
|
intent.putExtra(ConversationActivity.DRAFT_VIDEO_EXTRA, draftVideo);
|
||||||
|
intent.putExtra(NewConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
|
||||||
|
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
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 com.actionbarsherlock.app.SherlockListFragment;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.database.loaders.ConversationListLoader;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A fragment to select and share to open conversations
|
||||||
|
*
|
||||||
|
* @author Jake McGinty
|
||||||
|
*/
|
||||||
|
public class ShareFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
|
|
||||||
|
private ConversationSelectedListener listener;
|
||||||
|
private MasterSecret masterSecret;
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMasterSecret(MasterSecret masterSecret) {
|
||||||
|
if (this.masterSecret != masterSecret) {
|
||||||
|
this.masterSecret = masterSecret;
|
||||||
|
initializeListAdapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* 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.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.support.v4.widget.CursorAdapter;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AbsListView;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterCipher;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A CursorAdapter for building a list of open conversations
|
||||||
|
*
|
||||||
|
* @author Jake McGinty
|
||||||
|
*/
|
||||||
|
public class ShareListAdapter extends CursorAdapter implements AbsListView.RecyclerListener {
|
||||||
|
|
||||||
|
private final ThreadDatabase threadDatabase;
|
||||||
|
private final MasterCipher masterCipher;
|
||||||
|
private final Context context;
|
||||||
|
private final LayoutInflater inflater;
|
||||||
|
|
||||||
|
public ShareListAdapter(Context context, Cursor cursor, MasterSecret masterSecret) {
|
||||||
|
super(context, cursor, 0);
|
||||||
|
|
||||||
|
if (masterSecret != null) this.masterCipher = new MasterCipher(masterSecret);
|
||||||
|
else this.masterCipher = null;
|
||||||
|
|
||||||
|
this.context = context;
|
||||||
|
this.threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
||||||
|
this.inflater = LayoutInflater.from(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||||
|
return inflater.inflate(R.layout.share_list_item_view, parent, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
|
if (masterCipher != null) {
|
||||||
|
ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, masterCipher);
|
||||||
|
ThreadRecord record = reader.getCurrent();
|
||||||
|
|
||||||
|
((ShareListItem)view).set(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMovedToScrapHeap(View view) {
|
||||||
|
((ShareListItem)view).unbind();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,155 @@
|
|||||||
|
/**
|
||||||
|
* 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.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.provider.Contacts.Intents;
|
||||||
|
import android.provider.ContactsContract.QuickContact;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.DateUtils;
|
||||||
|
import org.thoughtcrime.securesms.util.Emoji;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple view to show the recipients of an open conversation
|
||||||
|
*
|
||||||
|
* @author Jake McGinty
|
||||||
|
*/
|
||||||
|
public class ShareListItem extends RelativeLayout
|
||||||
|
implements Recipient.RecipientModifiedListener
|
||||||
|
{
|
||||||
|
private final static String TAG = ShareListItem.class.getSimpleName();
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private Recipients recipients;
|
||||||
|
private long threadId;
|
||||||
|
private TextView fromView;
|
||||||
|
|
||||||
|
private ImageView contactPhotoImage;
|
||||||
|
|
||||||
|
private final Handler handler = new Handler();
|
||||||
|
private int distributionType;
|
||||||
|
|
||||||
|
public ShareListItem(Context context) {
|
||||||
|
super(context);
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShareListItem(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinishInflate() {
|
||||||
|
this.fromView = (TextView) findViewById(R.id.from);
|
||||||
|
this.contactPhotoImage = (ImageView) findViewById(R.id.contact_photo_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(ThreadRecord thread) {
|
||||||
|
this.recipients = thread.getRecipients();
|
||||||
|
this.threadId = thread.getThreadId();
|
||||||
|
this.distributionType = thread.getDistributionType();
|
||||||
|
|
||||||
|
this.recipients.addListener(this);
|
||||||
|
this.fromView.setText(formatFrom(recipients));
|
||||||
|
|
||||||
|
setBackground();
|
||||||
|
setContactPhoto(this.recipients.getPrimaryRecipient());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unbind() {
|
||||||
|
if (this.recipients != null) this.recipients.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setContactPhoto(final Recipient recipient) {
|
||||||
|
if (recipient == null) return;
|
||||||
|
contactPhotoImage.setImageBitmap(BitmapUtil.getCircleCroppedBitmap(recipient.getContactPhoto()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBackground() {
|
||||||
|
int[] attributes = new int[]{R.attr.conversation_list_item_background_read};
|
||||||
|
TypedArray drawables = context.obtainStyledAttributes(attributes);
|
||||||
|
|
||||||
|
setBackgroundDrawable(drawables.getDrawable(0));
|
||||||
|
|
||||||
|
drawables.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CharSequence formatFrom(Recipients from) {
|
||||||
|
final String fromString;
|
||||||
|
final boolean isUnnamedGroup = from.isGroupRecipient() && TextUtils.isEmpty(from.getPrimaryRecipient().getName());
|
||||||
|
if (isUnnamedGroup) {
|
||||||
|
fromString = context.getString(R.string.ConversationActivity_unnamed_group);
|
||||||
|
} else {
|
||||||
|
fromString = from.toShortString();
|
||||||
|
}
|
||||||
|
SpannableStringBuilder builder = new SpannableStringBuilder(fromString);
|
||||||
|
|
||||||
|
final int typeface;
|
||||||
|
if (isUnnamedGroup) typeface = Typeface.ITALIC;
|
||||||
|
else typeface = Typeface.NORMAL;
|
||||||
|
|
||||||
|
builder.setSpan(new StyleSpan(typeface), 0, builder.length(),
|
||||||
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Recipients getRecipients() {
|
||||||
|
return recipients;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getThreadId() {
|
||||||
|
return threadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDistributionType() {
|
||||||
|
return distributionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onModified(Recipient recipient) {
|
||||||
|
handler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
fromView.setText(formatFrom(recipients));
|
||||||
|
setContactPhoto(recipients.getPrimaryRecipient());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,172 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (C) 2011 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.components;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
|
||||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
|
||||||
import org.thoughtcrime.securesms.contacts.RecipientsAdapter;
|
|
||||||
import org.thoughtcrime.securesms.contacts.RecipientsEditor;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Panel component combining both an editable field with a button for
|
|
||||||
* a list-based contact selector.
|
|
||||||
*
|
|
||||||
* @author Moxie Marlinspike
|
|
||||||
*/
|
|
||||||
public class RecipientsPanel extends RelativeLayout {
|
|
||||||
|
|
||||||
private RecipientsPanelChangedListener panelChangeListener;
|
|
||||||
private RecipientsEditor recipientsText;
|
|
||||||
private View panel;
|
|
||||||
|
|
||||||
private static final int RECIPIENTS_MAX_LENGTH = 312;
|
|
||||||
|
|
||||||
public RecipientsPanel(Context context) {
|
|
||||||
super(context);
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RecipientsPanel(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RecipientsPanel(Context context, AttributeSet attrs, int defStyle) {
|
|
||||||
super(context, attrs, defStyle);
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addRecipient(String name, String number) {
|
|
||||||
if (name != null) recipientsText.append(sanitizeRecipientName(name) + "< " + number + ">, ");
|
|
||||||
else recipientsText.append(number + ", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addContacts(List<ContactAccessor.ContactData> contacts) {
|
|
||||||
for (ContactAccessor.ContactData contact : contacts) {
|
|
||||||
for (ContactAccessor.NumberData number : contact.numbers) {
|
|
||||||
addRecipient(contact.name, number.number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addRecipients(Recipients recipients) {
|
|
||||||
Set<Recipient> panelRecipients;
|
|
||||||
|
|
||||||
try {
|
|
||||||
panelRecipients = new HashSet<Recipient>(getRecipients().getRecipientsList());
|
|
||||||
} catch (RecipientFormattingException e) {
|
|
||||||
Log.w("RecipientsPanel", e);
|
|
||||||
panelRecipients = new HashSet<Recipient>();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Recipient> recipientList = recipients.getRecipientsList();
|
|
||||||
Iterator<Recipient> iterator = recipientList.iterator();
|
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Recipient recipient = iterator.next();
|
|
||||||
if (!panelRecipients.contains(recipient)) {
|
|
||||||
addRecipient(recipient.getName(), recipient.getNumber());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Recipients getRecipients() throws RecipientFormattingException {
|
|
||||||
String rawText = recipientsText.getText().toString();
|
|
||||||
Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), rawText, false);
|
|
||||||
|
|
||||||
if (recipients.isEmpty())
|
|
||||||
throw new RecipientFormattingException("Recipient List Is Empty!");
|
|
||||||
|
|
||||||
return recipients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disable() {
|
|
||||||
recipientsText.setText("");
|
|
||||||
panel.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) {
|
|
||||||
this.panelChangeListener = panelChangeListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialize() {
|
|
||||||
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
inflater.inflate(R.layout.recipients_panel, this, true);
|
|
||||||
|
|
||||||
View imageButton = findViewById(R.id.contacts_button);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
||||||
((MarginLayoutParams) imageButton.getLayoutParams()).topMargin = 0;
|
|
||||||
|
|
||||||
panel = findViewById(R.id.recipients_panel);
|
|
||||||
initRecipientsEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initRecipientsEditor() {
|
|
||||||
Recipients recipients = null;
|
|
||||||
recipientsText = (RecipientsEditor)findViewById(R.id.recipients_text);
|
|
||||||
|
|
||||||
try {
|
|
||||||
recipients = getRecipients();
|
|
||||||
} catch (RecipientFormattingException e) {
|
|
||||||
recipients = new Recipients( new LinkedList<Recipient>() );
|
|
||||||
}
|
|
||||||
|
|
||||||
recipientsText.setAdapter(new RecipientsAdapter(this.getContext()));
|
|
||||||
recipientsText.populate(recipients);
|
|
||||||
recipientsText.setOnFocusChangeListener(new FocusChangedListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String sanitizeRecipientName(String name) {
|
|
||||||
return name.replaceAll("[,<>]", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FocusChangedListener implements View.OnFocusChangeListener {
|
|
||||||
public void onFocusChange(View v, boolean hasFocus) {
|
|
||||||
if (!hasFocus && (panelChangeListener != null)) {
|
|
||||||
try {
|
|
||||||
panelChangeListener.onRecipientsPanelUpdate(getRecipients());
|
|
||||||
} catch (RecipientFormattingException rfe) {
|
|
||||||
panelChangeListener.onRecipientsPanelUpdate(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface RecipientsPanelChangedListener {
|
|
||||||
public void onRecipientsPanelUpdate(Recipients recipients);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue