Improved fab speed dial
This commit is contained in:
@ -36,11 +36,12 @@ import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
||||
import ch.dissem.apps.abit.repository.AndroidAddressRepository;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.apps.abit.util.FabUtils;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu;
|
||||
|
||||
/**
|
||||
* Fragment that shows a list of all contacts, the ones we subscribed to first.
|
||||
@ -119,8 +120,31 @@ public class AddressListFragment extends AbstractItemListFragment<Void, Bitmessa
|
||||
@Override
|
||||
public void onAttach(Context ctx) {
|
||||
super.onAttach(ctx);
|
||||
if (ctx instanceof ActionBarListener) {
|
||||
((ActionBarListener) ctx).updateTitle(getString(R.string.contacts_and_subscriptions));
|
||||
if (ctx instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) ctx;
|
||||
activity.updateTitle(getString(R.string.contacts_and_subscriptions));
|
||||
FabSpeedDialMenu menu = new FabSpeedDialMenu(ctx);
|
||||
menu.add(R.string.scan_qr_code).setIcon(R.drawable.ic_action_qr_code);
|
||||
menu.add(R.string.create_contact).setIcon(R.drawable.ic_action_create_contact);
|
||||
FabUtils.initFab(activity, R.drawable.ic_action_add_contact, menu)
|
||||
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
switch (itemId) {
|
||||
case 1:
|
||||
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
||||
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
||||
.initiateScan();
|
||||
break;
|
||||
case 2:
|
||||
Intent intent = new Intent(getActivity(), CreateAddressActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,29 +152,7 @@ public class AddressListFragment extends AbstractItemListFragment<Void, Bitmessa
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
|
||||
savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_address_list, container, false);
|
||||
|
||||
FabSpeedDial fabSpeedDial = (FabSpeedDial) view.findViewById(R.id.fab_add_contact);
|
||||
fabSpeedDial.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
switch (itemId) {
|
||||
case R.id.action_read_qr_code:
|
||||
IntentIntegrator.forSupportFragment(AddressListFragment.this)
|
||||
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES)
|
||||
.initiateScan();
|
||||
break;
|
||||
case R.id.action_create_contact:
|
||||
Intent intent = new Intent(getActivity(), CreateAddressActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
return inflater.inflate(R.layout.fragment_address_list, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,6 @@ import java.util.List;
|
||||
import ch.dissem.apps.abit.dialog.FullNodeDialogActivity;
|
||||
import ch.dissem.apps.abit.drawer.ProfileImageListener;
|
||||
import ch.dissem.apps.abit.drawer.ProfileSelectionListener;
|
||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
||||
import ch.dissem.apps.abit.listener.ListSelectionListener;
|
||||
import ch.dissem.apps.abit.service.BitmessageService;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
@ -67,6 +66,7 @@ import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||
|
||||
import static ch.dissem.apps.abit.ComposeMessageActivity.launchReplyTo;
|
||||
import static ch.dissem.apps.abit.repository.AndroidMessageRepository.LABEL_ARCHIVE;
|
||||
@ -91,7 +91,7 @@ import static ch.dissem.apps.abit.service.BitmessageService.isRunning;
|
||||
* </p>
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements ListSelectionListener<Serializable>, ActionBarListener {
|
||||
implements ListSelectionListener<Serializable> {
|
||||
public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
|
||||
public static final String EXTRA_SHOW_LABEL = "ch.dissem.abit.ShowLabel";
|
||||
public static final String EXTRA_REPLY_TO_MESSAGE = "ch.dissem.abit.ReplyToMessage";
|
||||
@ -120,13 +120,17 @@ public class MainActivity extends AppCompatActivity
|
||||
private Drawer drawer;
|
||||
private SwitchDrawerItem nodeSwitch;
|
||||
|
||||
private FabSpeedDial fab;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
instance = new WeakReference<>(this);
|
||||
bmc = Singleton.getBitmessageContext(this);
|
||||
|
||||
setContentView(R.layout.activity_message_list);
|
||||
setContentView(R.layout.activity_main);
|
||||
fab = (FabSpeedDial) findViewById(R.id.fab);
|
||||
fab.hide();
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
@ -487,7 +491,6 @@ public class MainActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUnread() {
|
||||
for (IDrawerItem item : drawer.getDrawerItems()) {
|
||||
if (item.getTag() instanceof Label) {
|
||||
@ -573,7 +576,6 @@ public class MainActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTitle(CharSequence title) {
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setTitle(title);
|
||||
@ -584,6 +586,10 @@ public class MainActivity extends AppCompatActivity
|
||||
return selectedLabel;
|
||||
}
|
||||
|
||||
public FabSpeedDial getFloatingActionButton() {
|
||||
return fab;
|
||||
}
|
||||
|
||||
public static MainActivity getInstance() {
|
||||
if (instance == null) return null;
|
||||
return instance.get();
|
||||
|
@ -43,7 +43,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.apps.abit.util.Assets;
|
||||
import ch.dissem.apps.abit.util.Drawables;
|
||||
@ -142,8 +141,8 @@ public class MessageDetailFragment extends Fragment {
|
||||
}
|
||||
MessageRepository messageRepo = Singleton.getMessageRepository(inflater.getContext());
|
||||
if (removed) {
|
||||
if (getActivity() instanceof ActionBarListener) {
|
||||
((ActionBarListener) getActivity()).updateUnread();
|
||||
if (getActivity() instanceof MainActivity) {
|
||||
((MainActivity) getActivity()).updateUnread();
|
||||
}
|
||||
messageRepo.save(item);
|
||||
}
|
||||
@ -200,13 +199,13 @@ public class MessageDetailFragment extends Fragment {
|
||||
case R.id.mark_unread:
|
||||
item.addLabels(messageRepo.getLabels(Label.Type.UNREAD));
|
||||
messageRepo.save(item);
|
||||
if (getActivity() instanceof ActionBarListener) {
|
||||
((ActionBarListener) getActivity()).updateUnread();
|
||||
if (getActivity() instanceof MainActivity) {
|
||||
((MainActivity) getActivity()).updateUnread();
|
||||
}
|
||||
return true;
|
||||
case R.id.archive:
|
||||
if (item.isUnread() && getActivity() instanceof ActionBarListener) {
|
||||
((ActionBarListener) getActivity()).updateUnread();
|
||||
if (item.isUnread() && getActivity() instanceof MainActivity) {
|
||||
((MainActivity) getActivity()).updateUnread();
|
||||
}
|
||||
item.getLabels().clear();
|
||||
messageRepo.save(item);
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@ -45,14 +46,15 @@ import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import ch.dissem.apps.abit.adapter.SwipeableMessageAdapter;
|
||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
||||
import ch.dissem.apps.abit.listener.ListSelectionListener;
|
||||
import ch.dissem.apps.abit.repository.AndroidMessageRepository;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.apps.abit.util.FabUtils;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu;
|
||||
|
||||
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_BROADCAST;
|
||||
import static ch.dissem.apps.abit.ComposeMessageActivity.EXTRA_IDENTITY;
|
||||
@ -119,8 +121,8 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
||||
private void doUpdateList(final Label label) {
|
||||
adapter.clear(label);
|
||||
if (label == null) {
|
||||
if (getActivity() instanceof ActionBarListener) {
|
||||
((ActionBarListener) getActivity()).updateTitle(getString(R.string.app_name));
|
||||
if (getActivity() instanceof MainActivity) {
|
||||
((MainActivity) getActivity()).updateTitle(getString(R.string.app_name));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
return;
|
||||
@ -129,8 +131,8 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
||||
if (emptyTrashMenuItem != null) {
|
||||
emptyTrashMenuItem.setVisible(label.getType() == Label.Type.TRASH);
|
||||
}
|
||||
if (getActivity() instanceof ActionBarListener) {
|
||||
ActionBarListener actionBarListener = (ActionBarListener) getActivity();
|
||||
if (getActivity() instanceof MainActivity) {
|
||||
MainActivity actionBarListener = (MainActivity) getActivity();
|
||||
if ("archive".equals(label.toString())) {
|
||||
actionBarListener.updateTitle(getString(R.string.archive));
|
||||
} else {
|
||||
@ -167,38 +169,6 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
||||
recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
|
||||
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
|
||||
|
||||
// Show the dummy content as text in a TextView.
|
||||
FabSpeedDial fab = (FabSpeedDial) rootView.findViewById(R.id
|
||||
.fab_compose_message);
|
||||
fab.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
BitmessageAddress identity = Singleton.getIdentity(getActivity());
|
||||
if (identity == null) {
|
||||
Toast.makeText(getActivity(), R.string.no_identity_warning,
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
switch (itemId) {
|
||||
case R.id.action_compose_message: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case R.id.action_compose_broadcast: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
intent.putExtra(EXTRA_BROADCAST, true);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// touch guard manager (this class is required to suppress scrolling while swipe-dismiss
|
||||
// animation is running)
|
||||
recyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
|
||||
@ -269,6 +239,45 @@ public class MessageListFragment extends Fragment implements ListHolder<Label> {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
if (context instanceof MainActivity) {
|
||||
FabSpeedDialMenu menu = new FabSpeedDialMenu(context);
|
||||
menu.add(R.string.broadcast).setIcon(R.drawable.ic_action_broadcast);
|
||||
menu.add(R.string.personal_message).setIcon(R.drawable.ic_action_personal);
|
||||
FabUtils.initFab((MainActivity) context, R.drawable.ic_action_compose_message, menu)
|
||||
.addOnMenuItemClickListener(new FabSpeedDial.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onMenuItemClick(FloatingActionButton floatingActionButton, @Nullable TextView textView, int itemId) {
|
||||
BitmessageAddress identity = Singleton.getIdentity(getActivity());
|
||||
if (identity == null) {
|
||||
Toast.makeText(getActivity(), R.string.no_identity_warning,
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
switch (itemId) {
|
||||
case 1: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
Intent intent = new Intent(getActivity(), ComposeMessageActivity.class);
|
||||
intent.putExtra(EXTRA_IDENTITY, identity);
|
||||
intent.putExtra(EXTRA_BROADCAST, true);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (recyclerViewSwipeManager != null) {
|
||||
|
@ -24,12 +24,12 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mikepenz.aboutlibraries.Libs;
|
||||
import com.mikepenz.aboutlibraries.LibsBuilder;
|
||||
|
||||
import ch.dissem.apps.abit.listener.ActionBarListener;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.apps.abit.synchronization.SyncAdapter;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
@ -121,11 +121,14 @@ public class SettingsFragment
|
||||
@Override
|
||||
public void onAttach(Context ctx) {
|
||||
super.onAttach(ctx);
|
||||
if (ctx instanceof MainActivity){
|
||||
((MainActivity) ctx).getFloatingActionButton().hide();
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(ctx)
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
if (ctx instanceof ActionBarListener) {
|
||||
((ActionBarListener) ctx).updateTitle(getString(R.string.settings));
|
||||
if (ctx instanceof MainActivity) {
|
||||
((MainActivity) ctx).updateTitle(getString(R.string.settings));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Christian Basler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package ch.dissem.apps.abit.listener;
|
||||
|
||||
/**
|
||||
* @author Christian Basler
|
||||
*/
|
||||
public interface ActionBarListener {
|
||||
void updateTitle(CharSequence title);
|
||||
|
||||
void updateUnread();
|
||||
}
|
35
app/src/main/java/ch/dissem/apps/abit/util/FabUtils.java
Normal file
35
app/src/main/java/ch/dissem/apps/abit/util/FabUtils.java
Normal file
@ -0,0 +1,35 @@
|
||||
package ch.dissem.apps.abit.util;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
||||
import ch.dissem.apps.abit.MainActivity;
|
||||
import ch.dissem.apps.abit.R;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDial;
|
||||
import io.github.kobakei.materialfabspeeddial.FabSpeedDialMenu;
|
||||
|
||||
/**
|
||||
* Utilities to work with the common floating action button in the main activity
|
||||
*/
|
||||
public class FabUtils {
|
||||
public static FabSpeedDial initFab(MainActivity activity, final @DrawableRes int drawableRes, FabSpeedDialMenu menu) {
|
||||
FabSpeedDial fab = activity.getFloatingActionButton();
|
||||
fab.show();
|
||||
fab.closeMenu();
|
||||
final FloatingActionButton mainFab = fab.getMainFab();
|
||||
mainFab.setImageResource(drawableRes);
|
||||
fab.setMenu(menu);
|
||||
fab.addOnStateChangeListener(new FabSpeedDial.OnStateChangeListener() {
|
||||
@Override
|
||||
public void onStateChange(boolean isOpened) {
|
||||
if (isOpened) {
|
||||
// It will be turned 45 degrees, which makes an x out of the +
|
||||
mainFab.setImageResource(R.drawable.ic_action_add);
|
||||
} else {
|
||||
mainFab.setImageResource(drawableRes);
|
||||
}
|
||||
}
|
||||
});
|
||||
return fab;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user