aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java330
1 files changed, 260 insertions, 70 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index c7fa2d288..9e8c7f6f6 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -7,11 +7,16 @@ import android.app.FragmentTransaction;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
+import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -33,6 +38,7 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
+import android.widget.TextView;
import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
@@ -54,6 +60,7 @@ import eu.siacs.conversations.entities.Blockable;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.XmppConnectionService;
@@ -62,12 +69,14 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper;
+import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
+import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
public class ConversationActivity extends XmppActivity
- implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
+ implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast, View.OnClickListener {
public static final String ACTION_DOWNLOAD = "eu.siacs.conversations.action.DOWNLOAD";
@@ -93,11 +102,10 @@ public class ConversationActivity extends XmppActivity
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
private static final String STATE_PANEL_OPEN = "state_panel_open";
private static final String STATE_PENDING_URI = "state_pending_uri";
-
- private String mOpenConverstaion = null;
- private boolean mPanelOpen = true;
final private List<Uri> mPendingImageUris = new ArrayList<>();
final private List<Uri> mPendingFileUris = new ArrayList<>();
+ private String mOpenConverstaion = null;
+ private boolean mPanelOpen = true;
private Uri mPendingGeoUri = null;
private boolean forbidProcessingPendings = false;
private Message mPendingDownloadableMessage = null;
@@ -118,6 +126,24 @@ public class ConversationActivity extends XmppActivity
private AtomicBoolean mRedirected = new AtomicBoolean(false);
private Pair<Integer, Intent> mPostponedActivityResult;
+ @SuppressLint("NewApi")
+ private static List<Uri> extractUriFromIntent(final Intent intent) {
+ List<Uri> uris = new ArrayList<>();
+ if (intent == null) {
+ return uris;
+ }
+ Uri uri = intent.getData();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
+ ClipData clipData = intent.getClipData();
+ for (int i = 0; i < clipData.getItemCount(); ++i) {
+ uris.add(clipData.getItemAt(i).getUri());
+ }
+ } else {
+ uris.add(uri);
+ }
+ return uris;
+ }
+
public Conversation getSelectedConversation() {
return this.mSelectedConversation;
}
@@ -274,11 +300,12 @@ public class ConversationActivity extends XmppActivity
};
}
});
- listView.enableSwipeToDismiss();
+ //listView.enableSwipeToDismiss();
listView.setSwipingLayout(R.id.swipeable_item);
listView.setUndoStyle(EnhancedListView.UndoStyle.SINGLE_POPUP);
- listView.setUndoHideDelay(5000);
+ listView.setUndoHideDelay(10000);
listView.setRequireTouchBeforeDismiss(false);
+ listView.setSwipeDirection(EnhancedListView.SwipeDirection.START); // swipe to left to close conversation
mContentView = findViewById(R.id.content_view_spl);
if (mContentView == null) {
@@ -319,6 +346,99 @@ public class ConversationActivity extends XmppActivity
}
}
+ public boolean isPackageInstalled(String targetPackage){
+ List<ApplicationInfo> packages;
+ PackageManager pm;
+ pm = getPackageManager();
+ packages = pm.getInstalledApplications(0);
+ for (ApplicationInfo packageInfo : packages) {
+ if(packageInfo.packageName.equals(targetPackage)) return true;
+ }
+ return false;
+ }
+
+ protected void AppUpdate() {
+ String PREFS_NAME = "UpdateTimeStamp";
+ SharedPreferences UpdateTimeStamp = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+ long lastUpdateTime = UpdateTimeStamp.getLong("lastUpdateTime", 0);
+
+ //detect installed plugins and deinstall them
+ PackageInfo pInfo = null;
+ try {
+ pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ }
+ //get the app version Name for display
+ final int versionCode = pInfo.versionCode;
+ // delete voice recorder and location plugin for versions >= 142 (1.12.1)
+ if (versionCode >= 142) {
+ Log.d(Config.LOGTAG, "New Features - Uninstall plugins");
+ if (isPackageInstalled("eu.siacs.conversations.voicerecorder") || isPackageInstalled("eu.siacs.conversations.sharelocation") || isPackageInstalled("com.samwhited.opensharelocationplugin")) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this);
+ builder.setMessage(R.string.uninstall_plugins)
+ .setPositiveButton(R.string.uninstall, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialogInterface, int i) {
+ //start the deinstallation of voice recorder
+ if (isPackageInstalled("eu.siacs.conversations.voicerecorder")) {
+ Uri packageURI_VR = Uri.parse("package:eu.siacs.conversations.voicerecorder");
+ Intent uninstallIntent_VR = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_VR);
+ if (uninstallIntent_VR.resolveActivity(getPackageManager()) != null) {
+ Log.d(Config.LOGTAG, "New Features - Uninstall voice recorder");
+ startActivity(uninstallIntent_VR);
+ }
+ }
+ //start the deinstallation of share location
+ if (isPackageInstalled("eu.siacs.conversations.sharelocation")) {
+ Uri packageURI_SL = Uri.parse("package:eu.siacs.conversations.sharelocation");
+ Intent uninstallIntent_SL = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_SL);
+ if (uninstallIntent_SL.resolveActivity(getPackageManager()) != null) {
+ Log.d(Config.LOGTAG, "New Features - Uninstall share location");
+ startActivity(uninstallIntent_SL);
+ }
+ }
+ //start the deinstallation of open share location
+ if (isPackageInstalled("com.samwhited.opensharelocationplugin")) {
+ Uri packageURI_SL = Uri.parse("package:com.samwhited.opensharelocationplugin");
+ Intent uninstallIntent_SL = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_SL);
+ if (uninstallIntent_SL.resolveActivity(getPackageManager()) != null) {
+ Log.d(Config.LOGTAG, "New Features - Uninstall open share location");
+ startActivity(uninstallIntent_SL);
+ }
+ }
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialogInterface, int i) {
+ Log.d(Config.LOGTAG, "New Features - Uninstall cancled");
+
+ }
+ });
+ builder.create().show();
+ }
+ }
+
+ Log.d(Config.LOGTAG, "AppUpdater - LastUpdateTime: " + lastUpdateTime);
+
+ if ((lastUpdateTime + (Config.UPDATE_CHECK_TIMER * 1000)) < System.currentTimeMillis()) {
+ lastUpdateTime = System.currentTimeMillis();
+ SharedPreferences.Editor editor = UpdateTimeStamp.edit();
+ editor.putLong("lastUpdateTime", lastUpdateTime);
+ editor.commit();
+
+ // run AppUpdater
+ Log.d(Config.LOGTAG, "AppUpdater - CurrentTime: " + lastUpdateTime);
+ Intent AppUpdater = new Intent(this, UpdaterActivity.class);
+ startActivity(AppUpdater);
+ Log.d(Config.LOGTAG, "AppUpdater started");
+
+ } else {
+
+ Log.d(Config.LOGTAG, "AppUpdater stopped");
+ return;
+ }
+ }
+
@Override
public void switchToConversation(Conversation conversation) {
setSelectedConversation(conversation);
@@ -336,24 +456,70 @@ public class ConversationActivity extends XmppActivity
}
private void updateActionBarTitle(boolean titleShouldBeName) {
- final ActionBar ab = getActionBar();
- final Conversation conversation = getSelectedConversation();
- if (ab != null) {
- if (titleShouldBeName && conversation != null) {
- ab.setDisplayHomeAsUpEnabled(true);
- ab.setHomeButtonEnabled(true);
- if (conversation.getMode() == Conversation.MODE_SINGLE || useSubjectToIdentifyConference()) {
- ab.setTitle(conversation.getName());
- } else {
- ab.setTitle(conversation.getJid().toBareJid().toString());
- }
- } else {
- ab.setDisplayHomeAsUpEnabled(false);
- ab.setHomeButtonEnabled(false);
- ab.setTitle(R.string.app_name);
- }
- }
- }
+ final ActionBar ab = getActionBar();
+ final Conversation conversation = getSelectedConversation();
+ if (ab != null) {
+ if (titleShouldBeName && conversation != null) {
+ ab.setDisplayHomeAsUpEnabled(true);
+ ab.setHomeButtonEnabled(true);
+ ab.setDisplayShowTitleEnabled(false);
+ ab.setDisplayShowCustomEnabled(true);
+ ab.setCustomView(R.layout.ab_title);
+ if (conversation.getMode() == Conversation.MODE_SINGLE || useSubjectToIdentifyConference()) {
+ TextView abtitle = (TextView) findViewById(android.R.id.text1);
+ abtitle.setText(conversation.getName());
+ abtitle.setOnClickListener(this);
+ if (conversation.getMode() == Conversation.MODE_SINGLE && !this.getSelectedConversation().withSelf()) {
+ if (conversation.getContact().getMostAvailableStatus() == Presence.Status.OFFLINE) {
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(getString(R.string.account_status_offline));
+ absubtitle.setOnClickListener(this);
+ } else {
+ ChatState state = conversation.getIncomingChatState();
+ if (state == ChatState.COMPOSING) {
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(getString(R.string.is_typing));
+ absubtitle.setTypeface(null, Typeface.BOLD_ITALIC);
+ absubtitle.setOnClickListener(this);
+ } else if (state == ChatState.PAUSED) {
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().lastseen.time));
+ absubtitle.setOnClickListener(this);
+ } else {
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().lastseen.time));
+ absubtitle.setOnClickListener(this);
+ }
+ }
+ } else if (useSubjectToIdentifyConference()) {
+ if (conversation.getParticipants() != null) {
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(conversation.getParticipants());
+ absubtitle.setOnClickListener(this);
+ } else {
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(R.string.no_participants);
+ absubtitle.setOnClickListener(this);
+ }
+ }
+ } else {
+ TextView abtitle = (TextView) findViewById(android.R.id.text1);
+ abtitle.setText(conversation.getJid().toBareJid().toString());
+ abtitle.setOnClickListener(this);
+ TextView absubtitle = (TextView) findViewById(android.R.id.text2);
+ absubtitle.setText(null);
+ absubtitle.setOnClickListener(this);
+ }
+ } else {
+ ab.setDisplayHomeAsUpEnabled(false);
+ ab.setHomeButtonEnabled(false);
+ ab.setDisplayShowTitleEnabled(true);
+ ab.setDisplayShowCustomEnabled(false);
+ ab.setTitle(R.string.app_name);
+ ab.setSubtitle(null);
+ }
+ }
+ }
private void openConversation() {
this.updateActionBarTitle();
@@ -376,20 +542,19 @@ public class ConversationActivity extends XmppActivity
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.conversations, menu);
final MenuItem menuSecure = menu.findItem(R.id.action_security);
- final MenuItem menuArchive = menu.findItem(R.id.action_archive);
- final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
- final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
+ final MenuItem menuArchiveChat = menu.findItem(R.id.action_archive_chat);
+ final MenuItem menuArchiveMuc = menu.findItem(R.id.action_archive_muc);
final MenuItem menuAttach = menu.findItem(R.id.action_attach_file);
final MenuItem menuClearHistory = menu.findItem(R.id.action_clear_history);
final MenuItem menuAdd = menu.findItem(R.id.action_add);
final MenuItem menuInviteContact = menu.findItem(R.id.action_invite);
final MenuItem menuMute = menu.findItem(R.id.action_mute);
final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
+ final MenuItem menuUpdater = menu.findItem(R.id.action_check_updates);
if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
- menuArchive.setVisible(false);
- menuMucDetails.setVisible(false);
- menuContactDetails.setVisible(false);
+ menuArchiveChat.setVisible(false);
+ menuArchiveMuc.setVisible(false);
menuSecure.setVisible(false);
menuInviteContact.setVisible(false);
menuAttach.setVisible(false);
@@ -398,7 +563,15 @@ public class ConversationActivity extends XmppActivity
menuUnmute.setVisible(false);
} else {
menuAdd.setVisible(!isConversationsOverviewHideable());
+ //hide settings, accounts and updater in all menus except in main window
+ menuUpdater.setVisible(false);
+
if (this.getSelectedConversation() != null) {
+ if (this.getSelectedConversation().getMode() == Conversation.MODE_SINGLE) {
+ menuArchiveMuc.setVisible(false);
+ } else {
+ menuArchiveChat.setVisible(false);
+ }
if (this.getSelectedConversation().getNextEncryption() != Message.ENCRYPTION_NONE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
menuSecure.setIcon(R.drawable.ic_lock_white_24dp);
@@ -407,13 +580,10 @@ public class ConversationActivity extends XmppActivity
}
}
if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) {
- menuContactDetails.setVisible(false);
menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable() && getSelectedConversation().getMucOptions().participating());
menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite());
menuSecure.setVisible((Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices()); //only if pgp is supported we have a choice
} else {
- menuContactDetails.setVisible(!this.getSelectedConversation().withSelf());
- menuMucDetails.setVisible(false);
menuSecure.setVisible(Config.multipleEncryptionChoices());
}
if (this.getSelectedConversation().isMuted()) {
@@ -458,11 +628,11 @@ public class ConversationActivity extends XmppActivity
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setAction(Intent.ACTION_GET_CONTENT);
break;
- case ATTACHMENT_CHOICE_RECORD_VOICE:
- intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
- fallbackPackageId = "eu.siacs.conversations.voicerecorder";
- break;
- case ATTACHMENT_CHOICE_LOCATION:
+ case ATTACHMENT_CHOICE_RECORD_VOICE:
+ intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
+ intent.setPackage("eu.siacs.conversations");
+ break;
+ case ATTACHMENT_CHOICE_LOCATION:
intent.setAction("eu.siacs.conversations.location.request");
fallbackPackageId = "eu.siacs.conversations.sharelocation";
break;
@@ -627,10 +797,24 @@ public class ConversationActivity extends XmppActivity
case R.id.action_attach_file:
attachFileDialog();
break;
- case R.id.action_archive:
+ case R.id.action_archive_chat:
this.endConversation(getSelectedConversation());
break;
- case R.id.action_contact_details:
+ case R.id.action_archive_muc:
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(getString(R.string.action_end_conversation_muc));
+ builder.setMessage(getString(R.string.leave_conference_warning));
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton(getString(R.string.action_end_conversation_muc),
+ new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ endConversation(getSelectedConversation());
+ }
+ });
+ builder.create().show();
+ break;
+/* case R.id.action_contact_details:
switchToContactDetails(getSelectedConversation().getContact());
break;
case R.id.action_muc_details:
@@ -640,6 +824,7 @@ public class ConversationActivity extends XmppActivity
intent.putExtra("uuid", getSelectedConversation().getUuid());
startActivity(intent);
break;
+*/
case R.id.action_invite:
inviteToConversation(getSelectedConversation());
break;
@@ -701,8 +886,11 @@ public class ConversationActivity extends XmppActivity
builder.setTitle(getString(R.string.clear_conversation_history));
View dialogView = getLayoutInflater().inflate(
R.layout.dialog_clear_history, null);
- final CheckBox endConversationCheckBox = (CheckBox) dialogView
- .findViewById(R.id.end_conversation_checkbox);
+ final CheckBox endConversationCheckBox = (CheckBox) dialogView
+ .findViewById(R.id.end_conversation_checkbox);
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ endConversationCheckBox.setVisibility(View.VISIBLE);
+ }
builder.setView(dialogView);
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.delete_messages),
@@ -711,12 +899,17 @@ public class ConversationActivity extends XmppActivity
@Override
public void onClick(DialogInterface dialog, int which) {
ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation);
- if (endConversationCheckBox.isChecked()) {
- endConversation(conversation);
- } else {
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- }
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ if (endConversationCheckBox.isChecked()) {
+ endConversation(conversation);
+ } else {
+ updateConversationList();
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ }
+ } else {
+ updateConversationList();
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ }
}
});
builder.create().show();
@@ -959,8 +1152,7 @@ public class ConversationActivity extends XmppActivity
} else if (modifier && key == downKey) {
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
showConversationsOverview();
- ;
- }
+ }
return selectDownConversation();
} else if (modifier && key == upKey) {
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
@@ -1089,6 +1281,8 @@ public class ConversationActivity extends XmppActivity
sendReadMarkerIfNecessary(getSelectedConversation());
}
+ AppUpdate();
+
}
@Override
@@ -1256,24 +1450,6 @@ public class ConversationActivity extends XmppActivity
xmppConnectionService.getNotificationService().setOpenConversation(null);
}
- @SuppressLint("NewApi")
- private static List<Uri> extractUriFromIntent(final Intent intent) {
- List<Uri> uris = new ArrayList<>();
- if (intent == null) {
- return uris;
- }
- Uri uri = intent.getData();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
- ClipData clipData = intent.getClipData();
- for (int i = 0; i < clipData.getItemCount(); ++i) {
- uris.add(clipData.getItemAt(i).getUri());
- }
- } else {
- uris.add(uri);
- }
- return uris;
- }
-
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -1429,7 +1605,7 @@ public class ConversationActivity extends XmppActivity
if (conversation == null) {
return;
}
- xmppConnectionService.attachLocationToConversation(conversation,uri, new UiCallback<Message>() {
+ xmppConnectionService.attachLocationToConversation(conversation, uri, new UiCallback<Message>() {
@Override
public void success(Message message) {
@@ -1568,7 +1744,7 @@ public class ConversationActivity extends XmppActivity
}
public boolean useWhiteBackground() {
- return getPreferences().getBoolean("use_white_background",false);
+ return getPreferences().getBoolean("use_white_background", false);
}
protected boolean trustKeysIfNeeded(int requestCode) {
@@ -1658,6 +1834,20 @@ public class ConversationActivity extends XmppActivity
return !isConversationsOverviewHideable() || this.conversationWasSelectedByKeyboard;
}
+ @Override
+ public void onClick(View view) {
+ final Conversation conversation = getSelectedConversation();
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ switchToContactDetails(getSelectedConversation().getContact());
+ } else if (conversation.getMode() == Conversation.MODE_MULTI) {
+ Intent intent = new Intent(this,
+ ConferenceDetailsActivity.class);
+ intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
+ intent.putExtra("uuid", getSelectedConversation().getUuid());
+ startActivity(intent);
+ }
+ }
+
public void setMessagesLoaded() {
if (mConversationFragment != null) {
mConversationFragment.setMessagesLoaded();