Merge pull request #4101 from ByteHamster/snackbars-covered

Fixed Snackbars being covered by audio player
This commit is contained in:
H. Lehmann 2020-05-03 16:51:01 +02:00 committed by GitHub
commit bf216cbfac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 62 additions and 39 deletions

View File

@ -415,12 +415,17 @@ public class MainActivity extends CastEnabledActivity {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(MessageEvent event) {
Log.d(TAG, "onEvent(" + event + ")");
View parentLayout = findViewById(R.id.drawer_layout);
Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT);
Snackbar snackbar;
if (getBottomSheet().getState() == BottomSheetBehavior.STATE_COLLAPSED) {
snackbar = showSnackbarAbovePlayer(event.message, Snackbar.LENGTH_SHORT);
} else {
snackbar = Snackbar.make(findViewById(android.R.id.content), event.message, Snackbar.LENGTH_SHORT);
snackbar.show();
}
if (event.action != null) {
snackbar.setAction(getString(R.string.undo), v -> event.action.run());
}
snackbar.show();
}
private void handleNavIntent() {
@ -454,4 +459,22 @@ public class MainActivity extends CastEnabledActivity {
super.onNewIntent(intent);
setIntent(intent);
}
public Snackbar showSnackbarAbovePlayer(int text, int duration) {
Snackbar s = Snackbar.make(findViewById(R.id.main_view), text, duration);
if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) {
s.setAnchorView(findViewById(R.id.audioplayerFragment));
}
s.show();
return s;
}
public Snackbar showSnackbarAbovePlayer(String text, int duration) {
Snackbar s = Snackbar.make(findViewById(R.id.main_view), text, duration);
if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) {
s.setAnchorView(findViewById(R.id.audioplayerFragment));
}
s.show();
return s;
}
}

View File

@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.snackbar.Snackbar;
import com.leinardi.android.speeddial.SpeedDialView;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.storage.DBWriter;
@ -313,8 +314,7 @@ public class EpisodesApplyActionFragment extends Fragment {
}
}
if (resId != 0) {
Snackbar.make(getActivity().findViewById(android.R.id.content), resId, Snackbar.LENGTH_SHORT)
.show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(resId, Snackbar.LENGTH_SHORT);
return true;
} else {
return false;
@ -470,12 +470,8 @@ public class EpisodesApplyActionFragment extends Fragment {
private void close(@PluralsRes int msgId, int numItems) {
if (numItems > 0) {
Snackbar.make(getActivity().findViewById(android.R.id.content),
getResources().getQuantityString(msgId, numItems, numItems),
Snackbar.LENGTH_LONG
)
.setAction(android.R.string.ok, v -> { })
.show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(
getResources().getQuantityString(msgId, numItems, numItems), Snackbar.LENGTH_LONG);
}
getActivity().getSupportFragmentManager().popBackStack();
}

View File

@ -10,6 +10,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder;
import org.greenrobot.eventbus.Subscribe;
@ -68,9 +69,8 @@ public class FavoriteEpisodesFragment extends EpisodesListFragment {
if (item != null) {
DBWriter.removeFavoriteItem(item);
Snackbar snackbar = Snackbar.make(root, getString(R.string.removed_item), Snackbar.LENGTH_LONG);
snackbar.setAction(getString(R.string.undo), v -> DBWriter.addFavoriteItem(item));
snackbar.show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.removed_item, Snackbar.LENGTH_LONG)
.setAction(getString(R.string.undo), v -> DBWriter.addFavoriteItem(item));
}
}
};

View File

@ -91,7 +91,7 @@ public class FeedInfoFragment extends Fragment {
android.content.ClipboardManager cm = (android.content.ClipboardManager) getContext()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
Snackbar.make(getView(), R.string.copied_url_msg, Snackbar.LENGTH_SHORT).show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.copied_url_msg, Snackbar.LENGTH_SHORT);
}
}
};

View File

@ -142,7 +142,8 @@ public class ItemFragment extends Fragment {
&& ObjectsCompat.equals(item.getMedia().getIdentifier(), controller.getMedia().getIdentifier())) {
controller.seekTo(time);
} else {
Snackbar.make(getView(), R.string.play_this_to_seek_position, Snackbar.LENGTH_LONG).show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.play_this_to_seek_position,
Snackbar.LENGTH_LONG);
}
});
registerForContextMenu(webvDescription);

View File

@ -16,6 +16,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
@ -388,11 +389,9 @@ public class QueueFragment extends Fragment {
recyclerAdapter.setLocked(locked);
}
if (locked) {
Snackbar.make(getActivity().findViewById(android.R.id.content),
R.string.queue_locked, Snackbar.LENGTH_SHORT).show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.queue_locked, Snackbar.LENGTH_SHORT);
} else {
Snackbar.make(getActivity().findViewById(android.R.id.content),
R.string.queue_unlocked, Snackbar.LENGTH_SHORT).show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.queue_unlocked, Snackbar.LENGTH_SHORT);
}
}
@ -497,16 +496,16 @@ public class QueueFragment extends Fragment {
final boolean isRead = item.isPlayed();
DBWriter.markItemPlayed(FeedItem.PLAYED, false, item.getId());
DBWriter.removeQueueItem(getActivity(), true, item);
Snackbar snackbar = Snackbar.make(root, getString(item.hasMedia()
? R.string.marked_as_read_label : R.string.marked_as_read_no_media_label),
Snackbar.LENGTH_LONG);
snackbar.setAction(getString(R.string.undo), v -> {
DBWriter.addQueueItemAt(getActivity(), item.getId(), position, false);
if(!isRead) {
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
}
});
snackbar.show();
((MainActivity) getActivity()).showSnackbarAbovePlayer(
item.hasMedia() ? R.string.marked_as_read_label : R.string.marked_as_read_no_media_label,
Snackbar.LENGTH_LONG)
.setAction(getString(R.string.undo), v -> {
DBWriter.addQueueItemAt(getActivity(), item.getId(), position, false);
if (!isRead) {
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
}
});
}
@Override

View File

@ -10,6 +10,7 @@ import android.view.Menu;
import android.view.MenuItem;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
@ -290,14 +291,14 @@ public class FeedItemMenuHandler {
}
};
Snackbar snackbar = Snackbar.make(fragment.getView(), fragment.getString(R.string.removed_new_flag_label),
Snackbar.LENGTH_LONG);
snackbar.setAction(fragment.getString(R.string.undo), v -> {
DBWriter.markItemPlayed(FeedItem.NEW, item.getId());
// don't forget to cancel the thing that's going to remove the media
h.removeCallbacks(r);
});
snackbar.show();
Snackbar snackbar = ((MainActivity) fragment.getActivity()).showSnackbarAbovePlayer(
R.string.removed_new_flag_label, Snackbar.LENGTH_LONG)
.setAction(fragment.getString(R.string.undo), v -> {
DBWriter.markItemPlayed(FeedItem.NEW, item.getId());
// don't forget to cancel the thing that's going to remove the media
h.removeCallbacks(r);
});
h.postDelayed(r, (int) Math.ceil(snackbar.getDuration() * 1.05f));
}

View File

@ -16,6 +16,7 @@ import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.core.util.Consumer;
import androidx.core.view.ViewCompat;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.util.Converter;
@ -115,7 +116,9 @@ public class ShownotesWebView extends WebView implements View.OnLongClickListene
android.content.ClipboardManager cm = (android.content.ClipboardManager) getContext()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
Snackbar.make(this, R.string.copied_url_msg, Snackbar.LENGTH_LONG).show();
Snackbar s = Snackbar.make(this, R.string.copied_url_msg, Snackbar.LENGTH_LONG);
ViewCompat.setElevation(s.getView(), 100);
s.show();
break;
case R.id.go_to_position_item:
if (Timeline.isTimecodeLink(selectedUrl) && timecodeSelectedListener != null) {