mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-30 20:52:21 -05:00
added some key binding
* ctrl + tab will open the conversations overview (when available) * ctrl + up / down will navigate between conversations
This commit is contained in:
parent
88cdd03f0f
commit
6308dcfdd4
@ -17,6 +17,7 @@ import android.provider.MediaStore;
|
|||||||
import android.support.v4.widget.SlidingPaneLayout;
|
import android.support.v4.widget.SlidingPaneLayout;
|
||||||
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -88,6 +89,8 @@ public class ConversationActivity extends XmppActivity
|
|||||||
private Uri mPendingGeoUri = null;
|
private Uri mPendingGeoUri = null;
|
||||||
private boolean forbidProcessingPendings = false;
|
private boolean forbidProcessingPendings = false;
|
||||||
|
|
||||||
|
private boolean conversationWasSelectedByKeyboard = false;
|
||||||
|
|
||||||
private View mContentView;
|
private View mContentView;
|
||||||
|
|
||||||
private List<Conversation> conversationList = new ArrayList<>();
|
private List<Conversation> conversationList = new ArrayList<>();
|
||||||
@ -190,6 +193,7 @@ public class ConversationActivity extends XmppActivity
|
|||||||
if (getSelectedConversation() != conversationList.get(position)) {
|
if (getSelectedConversation() != conversationList.get(position)) {
|
||||||
setSelectedConversation(conversationList.get(position));
|
setSelectedConversation(conversationList.get(position));
|
||||||
ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
|
ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
|
||||||
|
conversationWasSelectedByKeyboard = false;
|
||||||
}
|
}
|
||||||
hideConversationsOverview();
|
hideConversationsOverview();
|
||||||
openConversation();
|
openConversation();
|
||||||
@ -856,6 +860,76 @@ public class ConversationActivity extends XmppActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyUp(int key, KeyEvent event) {
|
||||||
|
final boolean modifier = event.isCtrlPressed();
|
||||||
|
final boolean upKey = key == KeyEvent.KEYCODE_DPAD_UP || key == KeyEvent.KEYCODE_DPAD_LEFT;
|
||||||
|
final boolean downKey = key == KeyEvent.KEYCODE_DPAD_DOWN || key == KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||||
|
if (modifier && key == KeyEvent.KEYCODE_TAB && isConversationsOverviewHideable()) {
|
||||||
|
toggleConversationsOverview();
|
||||||
|
return true;
|
||||||
|
} else if (modifier && downKey) {
|
||||||
|
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
|
||||||
|
showConversationsOverview();;
|
||||||
|
}
|
||||||
|
selectDownConversation();
|
||||||
|
return true;
|
||||||
|
} else if (modifier && upKey) {
|
||||||
|
if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
|
||||||
|
showConversationsOverview();;
|
||||||
|
}
|
||||||
|
selectUpConversation();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return super.onKeyUp(key, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleConversationsOverview() {
|
||||||
|
if (isConversationsOverviewVisable()) {
|
||||||
|
hideConversationsOverview();
|
||||||
|
if (mConversationFragment != null) {
|
||||||
|
mConversationFragment.setFocusOnInputField();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showConversationsOverview();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectUpConversation() {
|
||||||
|
Log.d(Config.LOGTAG,"select up conversation");
|
||||||
|
if (this.mSelectedConversation != null) {
|
||||||
|
int index = this.conversationList.indexOf(this.mSelectedConversation);
|
||||||
|
if (index > 0) {
|
||||||
|
int next = index - 1;
|
||||||
|
this.conversationWasSelectedByKeyboard = true;
|
||||||
|
setSelectedConversation(this.conversationList.get(next));
|
||||||
|
this.mConversationFragment.reInit(getSelectedConversation());
|
||||||
|
if (next > listView.getLastVisiblePosition() -1 || next < listView.getFirstVisiblePosition() + 1) {
|
||||||
|
this.listView.setSelection(next);
|
||||||
|
}
|
||||||
|
openConversation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectDownConversation() {
|
||||||
|
Log.d(Config.LOGTAG, "select down conversation");
|
||||||
|
if (this.mSelectedConversation != null) {
|
||||||
|
int index = this.conversationList.indexOf(this.mSelectedConversation);
|
||||||
|
if (index != -1 && index < this.conversationList.size() - 1) {
|
||||||
|
int next = index + 1;
|
||||||
|
this.conversationWasSelectedByKeyboard = true;
|
||||||
|
setSelectedConversation(this.conversationList.get(next));
|
||||||
|
this.mConversationFragment.reInit(getSelectedConversation());
|
||||||
|
if (next > listView.getLastVisiblePosition() -1 || next < listView.getFirstVisiblePosition() + 1) {
|
||||||
|
this.listView.setSelection(next);
|
||||||
|
}
|
||||||
|
openConversation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(final Intent intent) {
|
protected void onNewIntent(final Intent intent) {
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
@ -1349,4 +1423,8 @@ public class ConversationActivity extends XmppActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean highlightSelectedConversations() {
|
||||||
|
return !isConversationsOverviewHideable() || this.conversationWasSelectedByKeyboard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -857,6 +857,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
|||||||
updateChatMsgHint();
|
updateChatMsgHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFocusOnInputField() {
|
||||||
|
mEditMessage.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
|
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
|
||||||
|
|
||||||
private int getSendButtonImageResource(SendButtonAction action, int status) {
|
private int getSendButtonImageResource(SendButtonAction action, int status) {
|
||||||
|
@ -47,7 +47,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|
|||||||
if (this.activity instanceof ConversationActivity) {
|
if (this.activity instanceof ConversationActivity) {
|
||||||
View swipeableItem = view.findViewById(R.id.swipeable_item);
|
View swipeableItem = view.findViewById(R.id.swipeable_item);
|
||||||
ConversationActivity a = (ConversationActivity) this.activity;
|
ConversationActivity a = (ConversationActivity) this.activity;
|
||||||
int c = !a.isConversationsOverviewHideable() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
|
int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
|
||||||
swipeableItem.setBackgroundColor(c);
|
swipeableItem.setBackgroundColor(c);
|
||||||
}
|
}
|
||||||
TextView convName = (TextView) view.findViewById(R.id.conversation_name);
|
TextView convName = (TextView) view.findViewById(R.id.conversation_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user