From 2ca00265db9b7e3ec3c1f5cb0ed76d64841c1fdd Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 20 Oct 2021 09:52:10 +0200 Subject: [PATCH] bump speed dial version to something that uses AndroidX --- build.gradle | 2 +- .../ui/StartConversationActivity.java | 23 +++++++++++++++++-- .../menu/start_conversation_fab_submenu.xml | 20 ++++++++-------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index a51fb2f45..768837870 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ dependencies { implementation 'org.hsluv:hsluv:0.2' implementation 'org.conscrypt:conscrypt-android:2.5.2' implementation 'me.drakeet.support:toastcompat:1.1.0' - implementation "com.leinardi.android:speed-dial:2.0.1" + implementation "com.leinardi.android:speed-dial:3.2.0" implementation "com.squareup.retrofit2:retrofit:2.9.0" implementation "com.squareup.retrofit2:converter-gson:2.9.0" diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index e6d3ebf6e..994797779 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -37,11 +37,14 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.MenuRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.PopupMenu; +import androidx.core.content.ContextCompat; import androidx.databinding.DataBindingUtil; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -51,6 +54,8 @@ import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; import com.google.android.material.textfield.TextInputLayout; +import com.leinardi.android.speeddial.SpeedDialActionItem; +import com.leinardi.android.speeddial.SpeedDialView; import java.util.ArrayList; import java.util.Collections; @@ -266,8 +271,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne setSupportActionBar(binding.toolbar); configureActionBar(getSupportActionBar()); - binding.speedDial.inflate(R.menu.start_conversation_fab_submenu); - + inflateFab(binding.speedDial, R.menu.start_conversation_fab_submenu); binding.tabLayout.setupWithViewPager(binding.startConversationViewPager); binding.startConversationViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override @@ -338,6 +342,21 @@ public class StartConversationActivity extends XmppActivity implements XmppConne }); } + private void inflateFab(final SpeedDialView speedDialView, final @MenuRes int menuRes) { + speedDialView.clearActionItems(); + final PopupMenu popupMenu = new PopupMenu(this, new View(this)); + popupMenu.inflate(menuRes); + final Menu menu = popupMenu.getMenu(); + for (int i = 0; i < menu.size(); i++) { + final MenuItem menuItem = menu.getItem(i); + final SpeedDialActionItem actionItem = new SpeedDialActionItem.Builder(menuItem.getItemId(), menuItem.getIcon()) + .setLabel(menuItem.getTitle() != null ? menuItem.getTitle().toString() : null) + .setFabImageTintColor(ContextCompat.getColor(this, R.color.white)) + .create(); + speedDialView.addActionItem(actionItem); + } + } + public static boolean isValidJid(String input) { try { Jid jid = Jid.ofEscaped(input); diff --git a/src/main/res/menu/start_conversation_fab_submenu.xml b/src/main/res/menu/start_conversation_fab_submenu.xml index bfaca0727..2cf545d68 100644 --- a/src/main/res/menu/start_conversation_fab_submenu.xml +++ b/src/main/res/menu/start_conversation_fab_submenu.xml @@ -2,22 +2,22 @@ + android:icon="@drawable/ic_search_white_24dp" + android:title="@string/discover_channels" /> + android:icon="@drawable/ic_input_white_24dp" + android:title="@string/join_public_channel" /> + android:icon="@drawable/ic_public_white_24dp" + android:title="@string/create_public_channel" /> + android:icon="@drawable/ic_group_white_24dp" + android:title="@string/create_private_group_chat" /> + android:icon="@drawable/ic_person_white_48dp" + android:title="@string/add_contact" /> \ No newline at end of file -- 2.45.2