Skip to content

Commit

Permalink
fix: snackbars were not dismissable
Browse files Browse the repository at this point in the history
ensure a coordinatorlayout is at the top of the view hierarchy and make sure proper view is supplied to snackbar.make()
  • Loading branch information
Ben Sandee committed Sep 9, 2022
1 parent 231fd78 commit 3403b1c
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 58 deletions.
Expand Up @@ -98,7 +98,7 @@ abstract class DrawerActivity : SBActivity() {
super.onCreate(savedInstanceState)
drawerBinding = DrawerBinding.inflate(layoutInflater)
toolbarBinding = ToolbarBinding.bind(drawerBinding.root)
contentView = drawerBinding.root
setContentView(drawerBinding.root)

drawerBinding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GRAVITY_BROWSE_DRAWER)
drawerBinding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GRAVITY_PLAYER_DRAWER)
Expand Down Expand Up @@ -198,6 +198,10 @@ abstract class DrawerActivity : SBActivity() {
}
}

override fun getSnackbarView(): View? {
return drawerBinding.drawerLayout
}

override fun onStart() {
super.onStart()

Expand Down
Expand Up @@ -235,10 +235,6 @@ protected void onStop() {
super.onStop();
}

protected View getContentView() {
return findViewById(android.R.id.content);
}

@Override
protected void onRestart() {
logVerbose("onRestart");
Expand Down Expand Up @@ -311,6 +307,9 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
return handled;
}

@Nullable
protected abstract View getSnackbarView();

private boolean handleVolumeKeycodes(int keyCode) {
boolean handled = false;

Expand Down Expand Up @@ -446,7 +445,7 @@ protected void setWindowFlags() {

protected void showPlayerSnackbar(PlayerStatus status) {
OSAssert.assertMainThread();
if (!mStarted || isFinishing() || !allowSnackbarDisplay() || getContentView() == null) {
if (!mStarted || isFinishing() || !allowSnackbarDisplay() || getSnackbarView() == null) {
sDeferredPlayerSnackbar = status;
return;
}
Expand All @@ -455,7 +454,7 @@ protected void showPlayerSnackbar(PlayerStatus status) {
if (!status.getId().equals(mLastShownPlayerSnackbar)) {
mLastShownPlayerSnackbar = status.getId();
String text = getString(R.string.change_player_snackbar, status.getName());
Snackbar.make(getContentView(), HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_COMPACT), Snackbar.LENGTH_SHORT).show();
Snackbar.make(getSnackbarView(), HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_COMPACT), Snackbar.LENGTH_SHORT).show();
}
}

Expand Down
Expand Up @@ -15,6 +15,7 @@
import androidx.appcompat.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.orangebikelabs.orangesqueeze.R;
import com.orangebikelabs.orangesqueeze.app.SBActivity;
Expand Down Expand Up @@ -104,6 +105,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}
}

@Nullable
@Override
protected View getSnackbarView() {
return findViewById(R.id.toolbar_content);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
Expand Down
Expand Up @@ -12,6 +12,8 @@ import android.content.Intent
import com.orangebikelabs.orangesqueeze.ui.MainActivity
import androidx.core.app.NavUtils
import android.view.MenuItem
import android.view.View
import android.widget.FrameLayout
import androidx.appcompat.widget.Toolbar
import androidx.core.app.TaskStackBuilder
import androidx.fragment.app.commitNow
Expand All @@ -32,6 +34,10 @@ class PrepareDownloadActivity : SBActivity() {
}
}

override fun getSnackbarView(): View? {
return findViewById<FrameLayout>(R.id.toolbar_content)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.toolbar_activity)
Expand Down
Expand Up @@ -7,6 +7,7 @@

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

Expand Down Expand Up @@ -44,6 +45,12 @@ public void onDestroy() {
mBus.unregister(mEventReceiver);
}

@Nullable
@Override
protected View getSnackbarView() {
return findViewById(R.id.noplayer_server_label);
}

@Override
protected boolean isSupportedConnectionState(ConnectionInfo ci) {
return ci.isConnected() && mContext.getServerStatus().getAvailablePlayerIds().isEmpty();
Expand Down
Expand Up @@ -5,6 +5,8 @@
package com.orangebikelabs.orangesqueeze.startup

import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import androidx.fragment.app.commitNow
import com.orangebikelabs.orangesqueeze.R
import com.orangebikelabs.orangesqueeze.app.SBActivity
Expand All @@ -23,7 +25,7 @@ open class ConnectActivity : SBActivity() {

val binding = ToolbarActivityBinding.inflate(layoutInflater)
val toolbarBinding = ToolbarBinding.bind(binding.root)
contentView = binding.root
setContentView(binding.root)

setSupportActionBar(toolbarBinding.toolbar)
supportActionBar?.hide()
Expand All @@ -35,6 +37,10 @@ open class ConnectActivity : SBActivity() {
}
}

override fun getSnackbarView(): View? {
return findViewById<FrameLayout>(R.id.toolbar_content)
}

override fun isSupportedConnectionState(ci: ConnectionInfo): Boolean {
return !ci.isConnected
}
Expand Down
Expand Up @@ -7,6 +7,7 @@

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.orangebikelabs.orangesqueeze.R;
Expand Down Expand Up @@ -55,6 +56,12 @@ protected void onDestroy() {
mBus.unregister(mEventReceiver);
}

@Nullable
@Override
protected View getSnackbarView() {
return findViewById(R.id.connecting_text);
}

/**
* make sure that we're only in this activity if connection state is disconnected or while connecting
*/
Expand Down
Expand Up @@ -7,6 +7,9 @@ package com.orangebikelabs.orangesqueeze.startup

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import com.orangebikelabs.orangesqueeze.R
import com.orangebikelabs.orangesqueeze.app.SBActivity
import com.orangebikelabs.orangesqueeze.common.ConnectionInfo
import com.orangebikelabs.orangesqueeze.common.LaunchFlags
Expand Down Expand Up @@ -39,6 +42,10 @@ class StartupActivity : SBActivity() {
checkConnectionState()
}

override fun getSnackbarView(): View? {
return null
}

override fun checkConnectionState(): Boolean {
val ci = mContext.connectionInfo

Expand Down
Expand Up @@ -11,6 +11,7 @@ import android.view.Menu
import androidx.core.app.NavUtils
import androidx.core.app.TaskStackBuilder
import android.view.MenuItem
import android.view.View

import com.orangebikelabs.orangesqueeze.app.SBActivity
import com.orangebikelabs.orangesqueeze.common.BusProvider
Expand All @@ -31,14 +32,18 @@ abstract class AbsPreferenceActivity : SBActivity() {

val activityBinding = ToolbarActivityBinding.inflate(layoutInflater)
val toolbar = ToolbarBinding.bind(activityBinding.root)
contentView = activityBinding.root
setContentView(activityBinding.root)

setSupportActionBar(toolbar.toolbar)

supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

override fun getSnackbarView(): View? {
return null
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
return true
}
Expand Down
102 changes: 53 additions & 49 deletions app/src/main/res/layout/drawer.xml
Expand Up @@ -2,67 +2,71 @@
~ Copyright (c) 2020-2022 The OpenSqueeze Authors. All Rights Reserved.
~ Use of this source code is governed by the license that can be found in the LICENSE file.
-->

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">

<include
layout="@layout/toolbar"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="?android:attr/colorBackground" />
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<FrameLayout
android:id="@+id/tinynowplaying_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp" />
</LinearLayout>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="?android:attr/colorBackground" />

<!-- The browse drawer -->
<FrameLayout
android:id="@+id/browse_drawer"
android:layout_width="@dimen/drawer_size"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/tinynowplaying_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp" />
</LinearLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/browse_drawer_fragment"
android:name="com.orangebikelabs.orangesqueeze.browse.BrowseDrawerFragment"
android:layout_width="match_parent"
<!-- The browse drawer -->
<FrameLayout
android:id="@+id/browse_drawer"
android:layout_width="@dimen/drawer_size"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
tools:layout="@layout/browsedrawer_fragment" />
</FrameLayout>
android:layout_gravity="start"
android:fitsSystemWindows="true">

<!-- The player drawer -->
<FrameLayout
android:id="@+id/player_drawer"
android:layout_width="@dimen/drawer_size"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="?android:attr/colorBackground">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/browse_drawer_fragment"
android:name="com.orangebikelabs.orangesqueeze.browse.BrowseDrawerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
tools:layout="@layout/browsedrawer_fragment" />
</FrameLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/player_drawer_fragment"
android:name="com.orangebikelabs.orangesqueeze.players.PlayerDrawerFragment"
android:layout_width="match_parent"
<!-- The player drawer -->
<FrameLayout
android:id="@+id/player_drawer"
android:layout_width="@dimen/drawer_size"
android:layout_height="match_parent"
tools:layout="@layout/manageplayers" />
</FrameLayout>
</androidx.drawerlayout.widget.DrawerLayout>
android:layout_gravity="end"
android:background="?android:attr/colorBackground">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/player_drawer_fragment"
android:name="com.orangebikelabs.orangesqueeze.players.PlayerDrawerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/manageplayers" />
</FrameLayout>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit 3403b1c

Please sign in to comment.