revised tablet ui. fixed #423

This commit is contained in:
iNPUTmice 2014-10-03 15:00:29 +02:00
parent 335152b191
commit 9ae52a235f
9 changed files with 177 additions and 119 deletions

View file

@ -1,11 +1,11 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <eu.siacs.conversations.ui.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="240dp" android:layout_width="300dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primarybackground" android:background="@color/primarybackground"
android:orientation="vertical" > android:orientation="vertical" >
@ -27,4 +27,4 @@
android:orientation="vertical" > android:orientation="vertical" >
</LinearLayout> </LinearLayout>
</android.support.v4.widget.SlidingPaneLayout> </eu.siacs.conversations.ui.SlidingPaneLayout>

View file

@ -1,5 +1,5 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >

View file

@ -1,11 +1,11 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="324dp" android:layout_width="400dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primarybackground" android:background="@color/primarybackground"
android:orientation="vertical" > android:orientation="vertical" >

View file

@ -1,11 +1,11 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_ll"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="320dp"
android:layout_width="288dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primarybackground" android:background="@color/primarybackground"
android:orientation="vertical" > android:orientation="vertical" >
@ -23,8 +23,7 @@
android:id="@+id/selected_conversation" android:id="@+id/selected_conversation"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" > android:orientation="vertical" >
</LinearLayout> </LinearLayout>
</android.support.v4.widget.SlidingPaneLayout> </LinearLayout>

View file

@ -1,5 +1,5 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >

View file

@ -59,8 +59,13 @@ public class ConversationActivity extends XmppActivity implements
private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303; private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303;
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
private static final String STATE_PANEL_OPEN = "state_panel_open";
protected SlidingPaneLayout spl; private String mOpenConverstaion = null;
private boolean mPanelOpen = true;
private View mContentView;
private List<Conversation> conversationList = new ArrayList<Conversation>(); private List<Conversation> conversationList = new ArrayList<Conversation>();
private Conversation selectedConversation = null; private Conversation selectedConversation = null;
@ -90,18 +95,52 @@ public class ConversationActivity extends XmppActivity implements
return this.listView; return this.listView;
} }
public SlidingPaneLayout getSlidingPaneLayout() {
return this.spl;
}
public boolean shouldPaneBeOpen() { public boolean shouldPaneBeOpen() {
return paneShouldBeOpen; return paneShouldBeOpen;
} }
public void showConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.openPane();
}
}
public void hideConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.closePane();
}
}
public boolean isConversationsOverviewHideable() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
return mSlidingPaneLayout.isSlideable();
} else {
return false;
}
}
public boolean isConversationsOverviewVisable() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
return mSlidingPaneLayout.isOpen();
} else {
return true;
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mOpenConverstaion = savedInstanceState.getString(
STATE_OPEN_CONVERSATION, null);
mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true);
}
setContentView(R.layout.fragment_conversations_overview); setContentView(R.layout.fragment_conversations_overview);
listView = (ListView) findViewById(R.id.list); listView = (ListView) findViewById(R.id.list);
@ -122,15 +161,20 @@ public class ConversationActivity extends XmppActivity implements
setSelectedConversation(conversationList.get(position)); setSelectedConversation(conversationList.get(position));
swapConversationFragment(); swapConversationFragment();
} else { } else {
spl.closePane(); hideConversationsOverview();
} }
} }
}); });
spl = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout); mContentView = findViewById(R.id.content_view_spl);
spl.setParallaxDistance(150); if (mContentView==null) {
spl.setShadowResource(R.drawable.es_slidingpane_shadow); mContentView = findViewById(R.id.content_view_ll);
spl.setSliderFadeColor(0); }
spl.setPanelSlideListener(new PanelSlideListener() { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.setParallaxDistance(150);
mSlidingPaneLayout.setShadowResource(R.drawable.es_slidingpane_shadow);
mSlidingPaneLayout.setSliderFadeColor(0);
mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() {
@Override @Override
public void onPanelOpened(View arg0) { public void onPanelOpened(View arg0) {
@ -144,7 +188,8 @@ public class ConversationActivity extends XmppActivity implements
invalidateOptionsMenu(); invalidateOptionsMenu();
hideKeyboard(); hideKeyboard();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.getNotificationService().setOpenConversation(null); xmppConnectionService.getNotificationService()
.setOpenConversation(null);
} }
} }
@ -155,8 +200,8 @@ public class ConversationActivity extends XmppActivity implements
&& (getSelectedConversation() != null)) { && (getSelectedConversation() != null)) {
openConversation(getSelectedConversation()); openConversation(getSelectedConversation());
if (!getSelectedConversation().isRead()) { if (!getSelectedConversation().isRead()) {
xmppConnectionService xmppConnectionService.markRead(
.markRead(getSelectedConversation(),true); getSelectedConversation(), true);
listView.invalidateViews(); listView.invalidateViews();
} }
} }
@ -169,6 +214,7 @@ public class ConversationActivity extends XmppActivity implements
} }
}); });
} }
}
public void openConversation(Conversation conversation) { public void openConversation(Conversation conversation) {
ActionBar ab = getActionBar(); ActionBar ab = getActionBar();
@ -179,13 +225,14 @@ public class ConversationActivity extends XmppActivity implements
|| activity.useSubjectToIdentifyConference()) { || activity.useSubjectToIdentifyConference()) {
ab.setTitle(getSelectedConversation().getName()); ab.setTitle(getSelectedConversation().getName());
} else { } else {
ab.setTitle(getSelectedConversation() ab.setTitle(getSelectedConversation().getContactJid()
.getContactJid().split("/")[0]); .split("/")[0]);
} }
} }
invalidateOptionsMenu(); invalidateOptionsMenu();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.getNotificationService().setOpenConversation(conversation); xmppConnectionService.getNotificationService().setOpenConversation(
conversation);
} }
} }
@ -206,7 +253,7 @@ public class ConversationActivity extends XmppActivity implements
.findItem(R.id.action_invite); .findItem(R.id.action_invite);
MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute);
if ((spl.isOpen() && (spl.isSlideable()))) { if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
menuArchive.setVisible(false); menuArchive.setVisible(false);
menuMucDetails.setVisible(false); menuMucDetails.setVisible(false);
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
@ -216,7 +263,7 @@ public class ConversationActivity extends XmppActivity implements
menuClearHistory.setVisible(false); menuClearHistory.setVisible(false);
menuMute.setVisible(false); menuMute.setVisible(false);
} else { } else {
menuAdd.setVisible(!spl.isSlideable()); menuAdd.setVisible(!isConversationsOverviewHideable());
if (this.getSelectedConversation() != null) { if (this.getSelectedConversation() != null) {
if (this.getSelectedConversation().getLatestMessage() if (this.getSelectedConversation().getLatestMessage()
.getEncryption() != Message.ENCRYPTION_NONE) { .getEncryption() != Message.ENCRYPTION_NONE) {
@ -325,7 +372,7 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {
spl.openPane(); showConversationsOverview();
return true; return true;
} else if (item.getItemId() == R.id.action_add) { } else if (item.getItemId() == R.id.action_add) {
startActivity(new Intent(this, StartConversationActivity.class)); startActivity(new Intent(this, StartConversationActivity.class));
@ -377,7 +424,7 @@ public class ConversationActivity extends XmppActivity implements
public void endConversation(Conversation conversation) { public void endConversation(Conversation conversation) {
conversation.setStatus(Conversation.STATUS_ARCHIVED); conversation.setStatus(Conversation.STATUS_ARCHIVED);
paneShouldBeOpen = true; paneShouldBeOpen = true;
spl.openPane(); showConversationsOverview();
xmppConnectionService.archiveConversation(conversation); xmppConnectionService.archiveConversation(conversation);
if (conversationList.size() > 0) { if (conversationList.size() > 0) {
setSelectedConversation(conversationList.get(0)); setSelectedConversation(conversationList.get(0));
@ -563,8 +610,8 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
if (!spl.isOpen()) { if (!isConversationsOverviewVisable()) {
spl.openPane(); showConversationsOverview();
return false; return false;
} }
} }
@ -612,64 +659,72 @@ public class ConversationActivity extends XmppActivity implements
xmppConnectionService.removeOnConversationListChangedListener(); xmppConnectionService.removeOnConversationListChangedListener();
xmppConnectionService.removeOnAccountListChangedListener(); xmppConnectionService.removeOnAccountListChangedListener();
xmppConnectionService.removeOnRosterUpdateListener(); xmppConnectionService.removeOnRosterUpdateListener();
xmppConnectionService.getNotificationService().setOpenConversation(null); xmppConnectionService.getNotificationService().setOpenConversation(
null);
} }
super.onStop(); super.onStop();
} }
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString(STATE_OPEN_CONVERSATION,
getSelectedConversation().getUuid());
savedInstanceState.putBoolean(STATE_PANEL_OPEN, isConversationsOverviewVisable());
super.onSaveInstanceState(savedInstanceState);
}
@Override @Override
void onBackendConnected() { void onBackendConnected() {
this.registerListener(); this.registerListener();
if (conversationList.size() == 0) {
updateConversationList(); updateConversationList();
}
if (getSelectedConversation() != null && pendingImageUri != null) {
attachImageToConversation(getSelectedConversation(),
pendingImageUri);
pendingImageUri = null;
} else {
pendingImageUri = null;
}
if ((getIntent().getAction() != null)
&& (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) {
if (getIntent().getType().equals(
ConversationActivity.VIEW_CONVERSATION)) {
handledViewIntent = true;
String convToView = (String) getIntent().getExtras().get(
CONVERSATION);
for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(convToView)) {
setSelectedConversation(conversationList.get(i));
}
}
paneShouldBeOpen = false;
String text = getIntent().getExtras().getString(TEXT, null);
swapConversationFragment().setText(text);
}
} else {
if (xmppConnectionService.getAccounts().size() == 0) { if (xmppConnectionService.getAccounts().size() == 0) {
startActivity(new Intent(this, EditAccountActivity.class)); startActivity(new Intent(this, EditAccountActivity.class));
} else if (conversationList.size() <= 0) { } else if (conversationList.size() <= 0) {
// add no history
startActivity(new Intent(this, StartConversationActivity.class)); startActivity(new Intent(this, StartConversationActivity.class));
finish(); finish();
} else if (mOpenConverstaion != null) {
selectConversationByUuid(mOpenConverstaion);
paneShouldBeOpen = mPanelOpen;
if (paneShouldBeOpen) {
showConversationsOverview();
}
swapConversationFragment();
mOpenConverstaion = null;
} else if (getIntent() != null
&& VIEW_CONVERSATION.equals(getIntent().getType())) {
String uuid = (String) getIntent().getExtras().get(CONVERSATION);
String text = getIntent().getExtras().getString(TEXT, null);
selectConversationByUuid(uuid);
paneShouldBeOpen = false;
swapConversationFragment().setText(text);
setIntent(null);
} else { } else {
spl.openPane(); showConversationsOverview();
// find currently loaded fragment
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager() ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation"); .findFragmentByTag("conversation");
if (selectedFragment != null) { if (selectedFragment != null) {
selectedFragment.onBackendConnected(); selectedFragment.onBackendConnected();
} else { } else {
pendingImageUri = null;
setSelectedConversation(conversationList.get(0)); setSelectedConversation(conversationList.get(0));
swapConversationFragment(); swapConversationFragment();
} }
}
if (pendingImageUri != null) {
attachImageToConversation(getSelectedConversation(),
pendingImageUri);
pendingImageUri = null;
}
ExceptionHelper.checkForCrash(this, this.xmppConnectionService); ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
} }
private void selectConversationByUuid(String uuid) {
for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(uuid)) {
setSelectedConversation(conversationList.get(i));
}
} }
} }

View file

@ -245,9 +245,7 @@ public class ConversationFragment extends Fragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (activity.getSlidingPaneLayout().isSlideable()) { activity.hideConversationsOverview();
activity.getSlidingPaneLayout().closePane();
}
} }
}); });
mEditMessage.setOnEditorActionListener(mEditorActionListener); mEditMessage.setOnEditorActionListener(mEditorActionListener);
@ -376,9 +374,9 @@ public class ConversationFragment extends Fragment {
int position = mEditMessage.length(); int position = mEditMessage.length();
Editable etext = mEditMessage.getText(); Editable etext = mEditMessage.getText();
Selection.setSelection(etext, position); Selection.setSelection(etext, position);
if (activity.getSlidingPaneLayout().isSlideable()) { if (activity.isConversationsOverviewHideable()) {
if (!activity.shouldPaneBeOpen()) { if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane(); activity.hideConversationsOverview();
activity.openConversation(conversation); activity.openConversation(conversation);
} }
} }

View file

@ -59,6 +59,7 @@ public abstract class XmppActivity extends Activity {
protected int mPrimaryTextColor; protected int mPrimaryTextColor;
protected int mSecondaryTextColor; protected int mSecondaryTextColor;
protected int mSecondaryBackgroundColor;
protected int mColorRed; protected int mColorRed;
protected int mColorOrange; protected int mColorOrange;
protected int mColorGreen; protected int mColorGreen;
@ -207,6 +208,7 @@ public abstract class XmppActivity extends Activity {
mColorOrange = getResources().getColor(R.color.orange); mColorOrange = getResources().getColor(R.color.orange);
mColorGreen = getResources().getColor(R.color.green); mColorGreen = getResources().getColor(R.color.green);
mPrimaryColor = getResources().getColor(R.color.primary); mPrimaryColor = getResources().getColor(R.color.primary);
mSecondaryBackgroundColor = getResources().getColor(R.color.secondarybackground);
if (getPreferences().getBoolean("use_larger_font", false)) { if (getPreferences().getBoolean("use_larger_font", false)) {
setTheme(R.style.ConversationsTheme_LargerText); setTheme(R.style.ConversationsTheme_LargerText);
} }
@ -519,6 +521,10 @@ public abstract class XmppActivity extends Activity {
return this.mPrimaryColor; return this.mPrimaryColor;
} }
public int getSecondaryBackgroundColor() {
return this.mSecondaryBackgroundColor;
}
class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference; private final WeakReference<ImageView> imageViewReference;
private Message message = null; private Message message = null;

View file

@ -40,9 +40,9 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
Conversation conv = getItem(position); Conversation conv = getItem(position);
if (this.activity instanceof ConversationActivity) { if (this.activity instanceof ConversationActivity) {
ConversationActivity activity = (ConversationActivity) this.activity; ConversationActivity activity = (ConversationActivity) this.activity;
if (!activity.getSlidingPaneLayout().isSlideable()) { if (!activity.isConversationsOverviewHideable()) {
if (conv == activity.getSelectedConversation()) { if (conv == activity.getSelectedConversation()) {
view.setBackgroundColor(0xffdddddd); view.setBackgroundColor(activity.getSecondaryBackgroundColor());
} else { } else {
view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.TRANSPARENT);
} }