import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public void removeItemWithSnackbar(Activity activity, final int position, final SnackbarListener listener)
{
getSwipeManager().performFakeSwipe(mVHs.get(position), SwipeableItemConstants.RESULT_SWIPED_LEFT);
if (mChatroomObjects.get(position) != null)
{
final ChatroomRecyclerObject huehuehue = removeItem(position);
if (huehuehue != null)
{
final SharedPreferences mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
huehuehue.setIsPinned(false);
String chatroomName = huehuehue.getName();
String snackTextDel = "Deleted " + chatroomName;
final String snackTextRestore = "Chatroom restored!";
final SpannableStringBuilder snackTextDelSSB = new SpannableStringBuilder().append(snackTextDel);
final SpannableStringBuilder snackTextRestoreSSB = new SpannableStringBuilder().append(snackTextRestore);
if (mSharedPrefs.getBoolean("darkTheme", false))
{
snackTextDelSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.colorDark)), 0, snackTextDel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
snackTextRestoreSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.colorDark)), 0, snackTextRestore.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else
{
snackTextDelSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.white)), 0, snackTextDel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
snackTextRestoreSSB.setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.white)), 0, snackTextRestore.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
final View parentLayout = activity.findViewById(android.R.id.content);
Snackbar snackbar = Snackbar
.make(parentLayout, snackTextDelSSB, Snackbar.LENGTH_LONG)
.setAction("UNDO", new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Snackbar hue = Snackbar.make(parentLayout, snackTextRestoreSSB, Snackbar.LENGTH_SHORT);
if (mSharedPrefs.getBoolean("darkTheme", false))
{
hue.getView().setBackgroundColor(Color.WHITE);
}
hue.show();
addItem(huehuehue);
listener.onUndo();
}
});
if (mSharedPrefs.getBoolean("darkTheme", false))
{
snackbar.getView().setBackgroundColor(activity.getResources().getColor(R.color.white));
}
snackbar.show();
snackbar.addCallback(new BaseTransientBottomBar.BaseCallback()
{
@Override
public void onDismissed(Snackbar transientBottomBar, int event)
{
switch (event)
{
case DISMISS_EVENT_TIMEOUT:
listener.onUndoExpire(huehuehue.getUrl());
break;
}
}
});
}
}
}