Merge pull request #3322 from Stypox/fix-mute-button

Fix mute button causing crashes on API 19
This commit is contained in:
Tobias Groza 2020-04-01 18:30:10 +02:00 committed by GitHub
commit 06a897fba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 15 deletions

View File

@ -3,17 +3,9 @@ package org.schabi.newpipe.player;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.provider.Settings; import android.provider.Settings;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -26,6 +18,12 @@ import android.widget.ProgressBar;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
@ -698,13 +696,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
item.setTitle(player.isMuted() ? R.string.unmute : R.string.mute); item.setTitle(player.isMuted() ? R.string.unmute : R.string.mute);
//2) Icon change accordingly to current App Theme //2) Icon change accordingly to current App Theme
item.setIcon(player.isMuted() ? getThemedDrawable(R.attr.volume_off) : getThemedDrawable(R.attr.volume_on)); // using rootView.getContext() because getApplicationContext() didn't work
item.setIcon(player.isMuted()
? ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), R.attr.volume_off)
: ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), R.attr.volume_on));
} }
} }
private Drawable getThemedDrawable(int attribute) {
return getResources().getDrawable(
getTheme().obtainStyledAttributes(R.style.Theme_AppCompat, new int[]{attribute})
.getResourceId(0, 0));
}
} }