From c0b95a9d1c9a504f95f3d7750d4917292be883e4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 18 Feb 2018 20:01:01 +0100 Subject: [PATCH] add fab to start conversations activity --- .../siacs/conversations/ui/OmemoActivity.java | 4 +- .../ui/StartConversationActivity.java | 46 +++++++++++-------- .../layout/activity_start_conversation.xml | 25 +++++++--- src/main/res/menu/start_conversation.xml | 44 ++++++------------ 4 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java b/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java index 50ce5ae21..3b5f5e2f1 100644 --- a/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/OmemoActivity.java @@ -5,13 +5,11 @@ import android.support.v7.app.AlertDialog; import android.content.Intent; import android.os.Bundle; import android.support.v4.content.ContextCompat; -import android.support.v7.widget.SwitchCompat; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; import android.widget.CompoundButton; -import android.widget.ImageButton; -import android.widget.ImageView; + import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 4bba90dd4..2d5809691 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -2,7 +2,14 @@ package eu.siacs.conversations.ui; import android.Manifest; import android.annotation.SuppressLint; +import android.content.res.TypedArray; +import android.databinding.DataBindingUtil; +import android.databinding.ViewDataBinding; +import android.graphics.drawable.Drawable; +import android.support.annotation.AttrRes; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.app.Dialog; import android.app.PendingIntent; @@ -58,6 +65,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; +import eu.siacs.conversations.databinding.ActivityStartConversationBinding; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; @@ -78,7 +86,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU public int conference_context_id; public int contact_context_id; - private ViewPager mViewPager; private ListPagerAdapter mListPagerAdapter; private List contacts = new ArrayList<>(); private ListItemAdapter mContactsAdapter; @@ -125,7 +132,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { - mViewPager.setCurrentItem(tab.getPosition()); + binding.startConversationViewPager.setCurrentItem(tab.getPosition()); onTabChanged(); } @@ -215,6 +222,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } }; private Toast mToast; + private ActivityStartConversationBinding binding; protected void hideToast() { if (mToast != null) { @@ -237,8 +245,14 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new EmojiService(this).init(); - setContentView(R.layout.activity_start_conversation); - mViewPager = findViewById(R.id.start_conversation_view_pager); + this.binding = DataBindingUtil.setContentView(this,R.layout.activity_start_conversation); + this.binding.fab.setOnClickListener((v) -> { + if (getSupportActionBar().getSelectedNavigationIndex() == 0) { + showCreateContactDialog(null, null); + } else { + showCreateConferenceDialog(); + } + }); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); @@ -247,9 +261,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU actionBar.addTab(mContactsTab); actionBar.addTab(mConferencesTab); - mViewPager.setOnPageChangeListener(mOnPageChangeListener); + binding.startConversationViewPager.setOnPageChangeListener(mOnPageChangeListener); mListPagerAdapter = new ListPagerAdapter(getSupportFragmentManager()); - mViewPager.setAdapter(mListPagerAdapter); + binding.startConversationViewPager.setAdapter(mListPagerAdapter); mConferenceAdapter = new ListItemAdapter(this, conferences); mContactsAdapter = new ListItemAdapter(this, contacts); @@ -589,8 +603,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.start_conversation, menu); - MenuItem menuCreateContact = menu.findItem(R.id.action_create_contact); - MenuItem menuCreateConference = menu.findItem(R.id.action_conference); MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline); menuHideOffline.setChecked(this.mHideOfflineContacts); mMenuSearchView = menu.findItem(R.id.action_search); @@ -599,11 +611,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU mSearchEditText = mSearchView.findViewById(R.id.search_field); mSearchEditText.addTextChangedListener(mSearchTextWatcher); mSearchEditText.setOnEditorActionListener(mSearchDone); - if (getSupportActionBar().getSelectedNavigationIndex() == 0) { - menuCreateConference.setVisible(false); - } else { - menuCreateContact.setVisible(false); - } if (mInitialJid != null) { MenuItemCompat.expandActionView(mMenuSearchView); mSearchEditText.append(mInitialJid); @@ -615,15 +622,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.action_create_contact: - showCreateContactDialog(null, null); - return true; case R.id.action_join_conference: showJoinConferenceDialog(null); return true; - case R.id.action_create_conference: - showCreateConferenceDialog(); - return true; case R.id.action_scan_qr_code: Intent intent = new Intent(this, UriHandlerActivity.class); intent.setAction(UriHandlerActivity.ACTION_SCAN_QR_CODE); @@ -932,6 +933,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } private void onTabChanged() { + @DrawableRes final int fabDrawable; + if (getSupportActionBar().getSelectedNavigationIndex() == 0) { + fabDrawable = R.drawable.ic_person_add_white_24dp; + } else { + fabDrawable = R.drawable.ic_group_add_white_24dp; + } + binding.fab.setImageResource(fabDrawable); invalidateOptionsMenu(); } diff --git a/src/main/res/layout/activity_start_conversation.xml b/src/main/res/layout/activity_start_conversation.xml index b10777279..1c489a522 100644 --- a/src/main/res/layout/activity_start_conversation.xml +++ b/src/main/res/layout/activity_start_conversation.xml @@ -1,8 +1,19 @@ - - - \ No newline at end of file + + + + + + diff --git a/src/main/res/menu/start_conversation.xml b/src/main/res/menu/start_conversation.xml index e32869d6c..4e3998c18 100644 --- a/src/main/res/menu/start_conversation.xml +++ b/src/main/res/menu/start_conversation.xml @@ -4,51 +4,35 @@ + android:title="@string/search" + app:actionLayout="@layout/actionview_search" + app:showAsAction="collapseActionView|always"/> - - - - - - - + android:id="@+id/action_join_conference" + android:title="@string/join_conference" + app:showAsAction="never"/> + android:title="@string/scan_qr_code" + app:showAsAction="never"/> + android:title="@string/hide_offline" + app:showAsAction="never"/> + android:title="@string/action_accounts" + app:showAsAction="never"/> + android:title="@string/action_settings" + app:showAsAction="never"/> \ No newline at end of file