diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/ConversationActivity.java | 197 |
1 files changed, 145 insertions, 52 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 920c07af1..ea3cf627a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -6,10 +6,12 @@ import android.app.AlertDialog; import android.app.FragmentTransaction; import android.app.PendingIntent; 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.PackageManager; import android.net.Uri; import android.os.Build; @@ -32,6 +34,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; @@ -53,6 +56,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; @@ -61,12 +65,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"; @@ -92,11 +98,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; @@ -117,6 +122,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; } @@ -179,6 +202,8 @@ public class ConversationActivity extends XmppActivity } } + AppUpdate(); + setContentView(R.layout.fragment_conversations_overview); this.mConversationFragment = new ConversationFragment(); @@ -276,8 +301,9 @@ public class ConversationActivity extends XmppActivity 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) { @@ -318,6 +344,32 @@ public class ConversationActivity extends XmppActivity } } + protected void AppUpdate() { + String PREFS_NAME = "UpdateTimeStamp"; + SharedPreferences UpdateTimeStamp = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + long lastUpdateTime = UpdateTimeStamp.getLong("lastUpdateTime", 0); + + 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); @@ -335,24 +387,69 @@ 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.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,19 +473,16 @@ public class ConversationActivity extends XmppActivity 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 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); menuSecure.setVisible(false); menuInviteContact.setVisible(false); menuAttach.setVisible(false); @@ -397,6 +491,9 @@ 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().getNextEncryption() != Message.ENCRYPTION_NONE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -406,13 +503,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()) { @@ -629,6 +723,7 @@ public class ConversationActivity extends XmppActivity case R.id.action_archive: this.endConversation(getSelectedConversation()); break; +/* case R.id.action_contact_details: switchToContactDetails(getSelectedConversation().getContact()); break; @@ -639,6 +734,7 @@ public class ConversationActivity extends XmppActivity intent.putExtra("uuid", getSelectedConversation().getUuid()); startActivity(intent); break; +*/ case R.id.action_invite: inviteToConversation(getSelectedConversation()); break; @@ -955,8 +1051,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()) { @@ -1085,6 +1180,8 @@ public class ConversationActivity extends XmppActivity sendReadMarkerIfNecessary(getSelectedConversation()); } + AppUpdate(); + } @Override @@ -1245,24 +1342,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); @@ -1414,7 +1493,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) { @@ -1553,7 +1632,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) { @@ -1643,6 +1722,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(); |