diff options
Diffstat (limited to 'src/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r-- | src/eu/siacs/conversations/ui/ConversationActivity.java | 164 |
1 files changed, 32 insertions, 132 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index 6504f056..17e410f2 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -1,10 +1,7 @@ package eu.siacs.conversations.ui; -import java.io.FileNotFoundException; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.RejectedExecutionException; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Contact; @@ -15,9 +12,8 @@ import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.UIHelper; import android.net.Uri; -import android.os.AsyncTask; import android.os.Bundle; -import android.preference.PreferenceManager; +import android.os.SystemClock; import android.provider.MediaStore; import android.app.ActionBar; import android.app.AlertDialog; @@ -27,14 +23,8 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.IntentSender.SendIntentException; import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; -import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -46,7 +36,6 @@ import android.widget.CheckBox; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; -import android.widget.ImageView; import android.widget.Toast; public class ConversationActivity extends XmppActivity { @@ -75,8 +64,6 @@ public class ConversationActivity extends XmppActivity { private ListView listView; private boolean paneShouldBeOpen = true; - private boolean useSubject = true; - private boolean showLastseen = false; private ArrayAdapter<Conversation> listAdapter; private OnConversationUpdate onConvChanged = new OnConversationUpdate() { @@ -108,7 +95,6 @@ public class ConversationActivity extends XmppActivity { }; protected ConversationActivity activity = this; - private DisplayMetrics metrics; private Toast prepareImageToast; private Uri pendingImageUri = null; @@ -139,9 +125,6 @@ public class ConversationActivity extends XmppActivity { @Override protected void onCreate(Bundle savedInstanceState) { - - metrics = getResources().getDisplayMetrics(); - super.onCreate(savedInstanceState); setContentView(R.layout.fragment_conversations_overview); @@ -196,8 +179,7 @@ public class ConversationActivity extends XmppActivity { if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); ab.setHomeButtonEnabled(true); - ab.setTitle(getSelectedConversation().getName( - useSubject)); + ab.setTitle(getSelectedConversation().getName()); } invalidateOptionsMenu(); if (!getSelectedConversation().isRead()) { @@ -233,6 +215,7 @@ public class ConversationActivity extends XmppActivity { MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add); MenuItem menuInviteContact = (MenuItem) menu .findItem(R.id.action_invite); + MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); if ((spl.isOpen() && (spl.isSlideable()))) { menuArchive.setVisible(false); @@ -242,6 +225,7 @@ public class ConversationActivity extends XmppActivity { menuInviteContact.setVisible(false); menuAttach.setVisible(false); menuClearHistory.setVisible(false); + menuMute.setVisible(false); } else { menuAdd.setVisible(!spl.isSlideable()); if (this.getSelectedConversation() != null) { @@ -482,6 +466,9 @@ public class ConversationActivity extends XmppActivity { case R.id.action_clear_history: clearHistoryDialog(getSelectedConversation()); break; + case R.id.action_mute: + muteConversationDialog(getSelectedConversation()); + break; default: break; } @@ -523,6 +510,31 @@ public class ConversationActivity extends XmppActivity { }); builder.create().show(); } + + protected void muteConversationDialog(final Conversation conversation) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.disable_notifications_for_this_conversation); + final int[] durations = getResources().getIntArray(R.array.mute_options_durations); + builder.setItems(R.array.mute_options_descriptions, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + long till; + if (durations[which]==-1) { + till = Long.MAX_VALUE; + } else { + till = SystemClock.elapsedRealtime() + (durations[which] * 1000); + } + conversation.setMutedTill(till); + ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() + .findFragmentByTag("conversation"); + if (selectedFragment!=null) { + selectedFragment.updateMessages(); + } + } + }); + builder.create().show(); + } protected ConversationFragment swapConversationFragment() { ConversationFragment selectedFragment = new ConversationFragment(); @@ -576,10 +588,6 @@ public class ConversationActivity extends XmppActivity { @Override public void onStart() { super.onStart(); - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(this); - this.useSubject = preferences.getBoolean("use_subject_in_muc", true); - this.showLastseen = preferences.getBoolean("show_last_seen", false); if (this.xmppConnectionServiceBound) { this.onBackendConnected(); } @@ -755,15 +763,6 @@ public class ConversationActivity extends XmppActivity { listView.invalidateViews(); } - public boolean showLastseen() { - if (getSelectedConversation() == null) { - return false; - } else { - return this.showLastseen - && getSelectedConversation().getMode() == Conversation.MODE_SINGLE; - } - } - public void runIntent(PendingIntent pi, int requestCode) { try { this.startIntentSenderForResult(pi.getIntentSender(), requestCode, @@ -772,105 +771,6 @@ public class ConversationActivity extends XmppActivity { } } - class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { - private final WeakReference<ImageView> imageViewReference; - private Message message = null; - - public BitmapWorkerTask(ImageView imageView) { - imageViewReference = new WeakReference<ImageView>(imageView); - } - - @Override - protected Bitmap doInBackground(Message... params) { - message = params[0]; - try { - return xmppConnectionService.getFileBackend().getThumbnail( - message, (int) (metrics.density * 288), false); - } catch (FileNotFoundException e) { - return null; - } - } - - @Override - protected void onPostExecute(Bitmap bitmap) { - if (imageViewReference != null && bitmap != null) { - final ImageView imageView = imageViewReference.get(); - if (imageView != null) { - imageView.setImageBitmap(bitmap); - imageView.setBackgroundColor(0x00000000); - } - } - } - } - - public void loadBitmap(Message message, ImageView imageView) { - Bitmap bm; - try { - bm = xmppConnectionService.getFileBackend().getThumbnail(message, - (int) (metrics.density * 288), true); - } catch (FileNotFoundException e) { - bm = null; - } - if (bm != null) { - imageView.setImageBitmap(bm); - imageView.setBackgroundColor(0x00000000); - } else { - if (cancelPotentialWork(message, imageView)) { - imageView.setBackgroundColor(0xff333333); - final BitmapWorkerTask task = new BitmapWorkerTask(imageView); - final AsyncDrawable asyncDrawable = new AsyncDrawable( - getResources(), null, task); - imageView.setImageDrawable(asyncDrawable); - try { - task.execute(message); - } catch (RejectedExecutionException e) { - return; - } - } - } - } - - public static boolean cancelPotentialWork(Message message, - ImageView imageView) { - final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); - - if (bitmapWorkerTask != null) { - final Message oldMessage = bitmapWorkerTask.message; - if (oldMessage == null || message != oldMessage) { - bitmapWorkerTask.cancel(true); - } else { - return false; - } - } - return true; - } - - private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { - if (imageView != null) { - final Drawable drawable = imageView.getDrawable(); - if (drawable instanceof AsyncDrawable) { - final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; - return asyncDrawable.getBitmapWorkerTask(); - } - } - return null; - } - - static class AsyncDrawable extends BitmapDrawable { - private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference; - - public AsyncDrawable(Resources res, Bitmap bitmap, - BitmapWorkerTask bitmapWorkerTask) { - super(res, bitmap); - bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>( - bitmapWorkerTask); - } - - public BitmapWorkerTask getBitmapWorkerTask() { - return bitmapWorkerTaskReference.get(); - } - } - public void encryptTextMessage(Message message) { xmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() { |