add fab to start conversations activity

This commit is contained in:
Daniel Gultsch 2018-02-18 20:01:01 +01:00
parent 2df1aaaed2
commit c0b95a9d1c
4 changed files with 60 additions and 59 deletions

View file

@ -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;

View file

@ -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<ListItem> 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();
}

View file

@ -1,8 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/start_conversation_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_primary" >
</android.support.v4.view.ViewPager>
android:background="?attr/color_background_primary"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="?attr/icon_add_person"
android:layout_margin="16dp" />
</FrameLayout>
</layout>

View file

@ -4,51 +4,35 @@
<item
android:id="@+id/action_search"
app:actionLayout="@layout/actionview_search"
android:icon="?attr/icon_search"
app:showAsAction="collapseActionView|always"
android:title="@string/search" />
<item
android:id="@+id/action_create_contact"
android:icon="?attr/icon_add_person"
app:showAsAction="always"
android:title="@string/create_contact" />
<item
android:id="@+id/action_conference"
android:icon="?attr/icon_add_group"
app:showAsAction="always"
android:title="@string/join_or_create_conference">
<menu>
android:title="@string/search"
app:actionLayout="@layout/actionview_search"
app:showAsAction="collapseActionView|always"/>
<item
android:id="@+id/action_join_conference"
android:title="@string/join_conference"/>
<item
android:id="@+id/action_create_conference"
android:title="@string/create_conference"/>
</menu>
</item>
android:title="@string/join_conference"
app:showAsAction="never"/>
<item
android:id="@+id/action_scan_qr_code"
app:showAsAction="never"
android:title="@string/scan_qr_code" />
android:title="@string/scan_qr_code"
app:showAsAction="never"/>
<item
android:id="@+id/action_hide_offline"
android:checkable="true"
android:checked="false"
android:orderInCategory="85"
app:showAsAction="never"
android:title="@string/hide_offline"/>
android:title="@string/hide_offline"
app:showAsAction="never"/>
<item
android:id="@+id/action_accounts"
android:orderInCategory="90"
app:showAsAction="never"
android:title="@string/action_accounts" />
android:title="@string/action_accounts"
app:showAsAction="never"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
app:showAsAction="never"
android:title="@string/action_settings" />
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>