aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/ui/ConversationActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java224
1 files changed, 66 insertions, 158 deletions
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index c68063d2..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,15 +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.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -47,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 {
@@ -76,12 +64,10 @@ 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() {
-
+
@Override
public void onConversationUpdate() {
runOnUiThread(new Runnable() {
@@ -109,9 +95,8 @@ public class ConversationActivity extends XmppActivity {
};
protected ConversationActivity activity = this;
- private DisplayMetrics metrics;
private Toast prepareImageToast;
-
+
private Uri pendingImageUri = null;
public List<Conversation> getConversationList() {
@@ -140,15 +125,12 @@ public class ConversationActivity extends XmppActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
-
- metrics = getResources().getDisplayMetrics();
-
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_conversations_overview);
listView = (ListView) findViewById(R.id.list);
-
+
getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setHomeButtonEnabled(false);
@@ -179,7 +161,7 @@ public class ConversationActivity extends XmppActivity {
public void onPanelOpened(View arg0) {
paneShouldBeOpen = true;
ActionBar ab = getActionBar();
- if (ab!=null) {
+ if (ab != null) {
ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false);
ab.setTitle(R.string.app_name);
@@ -194,11 +176,10 @@ public class ConversationActivity extends XmppActivity {
if ((conversationList.size() > 0)
&& (getSelectedConversation() != null)) {
ActionBar ab = getActionBar();
- if (ab!=null) {
+ if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeButtonEnabled(true);
- ab.setTitle(
- getSelectedConversation().getName(useSubject));
+ ab.setTitle(getSelectedConversation().getName());
}
invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) {
@@ -232,7 +213,9 @@ public class ConversationActivity extends XmppActivity {
MenuItem menuClearHistory = (MenuItem) menu
.findItem(R.id.action_clear_history);
MenuItem menuAdd = (MenuItem) menu.findItem(R.id.action_add);
- MenuItem menuInviteContact = (MenuItem) menu.findItem(R.id.action_invite);
+ 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) {
@@ -267,11 +251,12 @@ public class ConversationActivity extends XmppActivity {
@Override
public void onPresenceSelected() {
if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) {
- pendingImageUri = xmppConnectionService.getFileBackend().getTakePhotoUri();
- Log.d("xmppService",pendingImageUri.toString());
+ pendingImageUri = xmppConnectionService.getFileBackend()
+ .getTakePhotoUri();
Intent takePictureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,pendingImageUri);
+ takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
+ pendingImageUri);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent,
REQUEST_IMAGE_CAPTURE);
@@ -353,7 +338,7 @@ public class ConversationActivity extends XmppActivity {
return true;
case R.id.action_attach_file:
View menuAttachFile = findViewById(R.id.action_attach_file);
- if (menuAttachFile==null) {
+ if (menuAttachFile == null) {
break;
}
PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
@@ -405,7 +390,7 @@ public class ConversationActivity extends XmppActivity {
case R.id.action_security:
final Conversation conversation = getSelectedConversation();
View menuItemView = findViewById(R.id.action_security);
- if (menuItemView==null) {
+ if (menuItemView == null) {
break;
}
PopupMenu popup = new PopupMenu(this, menuItemView);
@@ -481,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;
}
@@ -522,16 +510,41 @@ 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();
if (!isFinishing()) {
- FragmentTransaction transaction = getFragmentManager()
- .beginTransaction();
- transaction.replace(R.id.selected_conversation, selectedFragment,
- "conversation");
-
+ FragmentTransaction transaction = getFragmentManager()
+ .beginTransaction();
+ transaction.replace(R.id.selected_conversation, selectedFragment,
+ "conversation");
+
transaction.commitAllowingStateLoss();
}
return selectedFragment;
@@ -553,7 +566,8 @@ public class ConversationActivity extends XmppActivity {
if (xmppConnectionServiceBound) {
if ((Intent.ACTION_VIEW.equals(intent.getAction()) && (VIEW_CONVERSATION
.equals(intent.getType())))) {
- String convToView = (String) intent.getExtras().get(CONVERSATION);
+ String convToView = (String) intent.getExtras().get(
+ CONVERSATION);
updateConversationList();
for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(convToView)) {
@@ -574,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();
}
@@ -600,9 +610,10 @@ public class ConversationActivity extends XmppActivity {
if (conversationList.size() == 0) {
updateConversationList();
}
-
- if (getSelectedConversation()!=null && pendingImageUri !=null) {
- attachImageToConversation(getSelectedConversation(), pendingImageUri);
+
+ if (getSelectedConversation() != null && pendingImageUri != null) {
+ attachImageToConversation(getSelectedConversation(),
+ pendingImageUri);
pendingImageUri = null;
} else {
pendingImageUri = null;
@@ -670,7 +681,8 @@ public class ConversationActivity extends XmppActivity {
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
pendingImageUri = data.getData();
if (xmppConnectionServiceBound) {
- attachImageToConversation(getSelectedConversation(),pendingImageUri);
+ attachImageToConversation(getSelectedConversation(),
+ pendingImageUri);
pendingImageUri = null;
}
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
@@ -686,10 +698,12 @@ public class ConversationActivity extends XmppActivity {
// encryptTextMessage();
} else if (requestCode == REQUEST_IMAGE_CAPTURE) {
if (xmppConnectionServiceBound) {
- attachImageToConversation(getSelectedConversation(), pendingImageUri);
+ attachImageToConversation(getSelectedConversation(),
+ pendingImageUri);
pendingImageUri = null;
}
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ Intent intent = new Intent(
+ Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(pendingImageUri);
sendBroadcast(intent);
} else if (requestCode == REQUEST_RECORD_AUDIO) {
@@ -700,7 +714,7 @@ public class ConversationActivity extends XmppActivity {
}
private void attachAudioToConversation(Conversation conversation, Uri uri) {
-
+
}
private void attachImageToConversation(Conversation conversation, Uri uri) {
@@ -744,122 +758,16 @@ public class ConversationActivity extends XmppActivity {
}
public void updateConversationList() {
- xmppConnectionService.populateWithOrderedConversations(conversationList);
+ xmppConnectionService
+ .populateWithOrderedConversations(conversationList);
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,
null, 0, 0, 0);
- } catch (SendIntentException e1) {}
- }
-
- 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();
+ } catch (SendIntentException e1) {
}
}