3838import android .view .MenuItem ;
3939import android .view .View ;
4040import android .view .ViewGroup ;
41+ import android .webkit .WebView ;
4142import android .widget .AdapterView ;
4243import android .widget .ArrayAdapter ;
4344import android .widget .FrameLayout ;
8889import org .schabi .newpipe .util .ServiceHelper ;
8990import org .schabi .newpipe .util .StateSaver ;
9091import org .schabi .newpipe .util .ThemeHelper ;
92+ import org .schabi .newpipe .util .external_communication .ShareUtils ;
9193import org .schabi .newpipe .views .FocusOverlayView ;
9294
9395import java .util .ArrayList ;
@@ -116,7 +118,8 @@ public class MainActivity extends AppCompatActivity {
116118 private static final int ITEM_ID_DOWNLOADS = -4 ;
117119 private static final int ITEM_ID_HISTORY = -5 ;
118120 private static final int ITEM_ID_SETTINGS = 0 ;
119- private static final int ITEM_ID_ABOUT = 1 ;
121+ private static final int ITEM_ID_DONATION = 1 ;
122+ private static final int ITEM_ID_ABOUT = 2 ;
120123
121124 private static final int ORDER = 0 ;
122125
@@ -134,6 +137,19 @@ protected void onCreate(final Bundle savedInstanceState) {
134137 ThemeHelper .setDayNightMode (this );
135138 ThemeHelper .setTheme (this , ServiceHelper .getSelectedServiceId (this ));
136139
140+ // Fixes text color turning black in dark/black mode:
141+ // https://github.com/TeamNewPipe/NewPipe/issues/12016
142+ // For further reference see: https://issuetracker.google.com/issues/37124582
143+ if (DeviceUtils .supportsWebView ()) {
144+ try {
145+ new WebView (this );
146+ } catch (final Throwable e ) {
147+ if (DEBUG ) {
148+ Log .e (TAG , "Failed to create WebView" , e );
149+ }
150+ }
151+ }
152+
137153 assureCorrectAppLanguage (this );
138154 super .onCreate (savedInstanceState );
139155
@@ -258,6 +274,10 @@ private void addDrawerMenuForCurrentService() throws ExtractionException {
258274 drawerLayoutBinding .navigation .getMenu ()
259275 .add (R .id .menu_options_about_group , ITEM_ID_SETTINGS , ORDER , R .string .settings )
260276 .setIcon (R .drawable .ic_settings );
277+ drawerLayoutBinding .navigation .getMenu ()
278+ .add (R .id .menu_options_about_group , ITEM_ID_DONATION , ORDER ,
279+ R .string .donation_title )
280+ .setIcon (R .drawable .volunteer_activism_ic );
261281 drawerLayoutBinding .navigation .getMenu ()
262282 .add (R .id .menu_options_about_group , ITEM_ID_ABOUT , ORDER , R .string .tab_about )
263283 .setIcon (R .drawable .ic_info_outline );
@@ -333,6 +353,9 @@ private void optionsAboutSelected(final MenuItem item) {
333353 case ITEM_ID_SETTINGS :
334354 NavigationHelper .openSettings (this );
335355 break ;
356+ case ITEM_ID_DONATION :
357+ ShareUtils .openUrlInBrowser (this , getString (R .string .donation_url ));
358+ break ;
336359 case ITEM_ID_ABOUT :
337360 NavigationHelper .openAbout (this );
338361 break ;
@@ -569,8 +592,8 @@ public void onBackPressed() {
569592 if (player instanceof BackPressable backPressable && !backPressable .onBackPressed ()) {
570593 BottomSheetBehavior .from (mainBinding .fragmentPlayerHolder )
571594 .setState (BottomSheetBehavior .STATE_COLLAPSED );
572- return ;
573595 }
596+ return ;
574597 }
575598
576599 if (fragmentManager .getBackStackEntryCount () == 1 ) {
@@ -817,7 +840,8 @@ private void openMiniPlayerUponPlayerStarted() {
817840 @ Override
818841 public void onReceive (final Context context , final Intent intent ) {
819842 if (Objects .equals (intent .getAction (),
820- VideoDetailFragment .ACTION_PLAYER_STARTED )) {
843+ VideoDetailFragment .ACTION_PLAYER_STARTED )
844+ && PlayerHolder .getInstance ().isPlayerOpen ()) {
821845 openMiniPlayerIfMissing ();
822846 // At this point the player is added 100%, we can unregister. Other actions
823847 // are useless since the fragment will not be removed after that.
@@ -829,6 +853,10 @@ public void onReceive(final Context context, final Intent intent) {
829853 final IntentFilter intentFilter = new IntentFilter ();
830854 intentFilter .addAction (VideoDetailFragment .ACTION_PLAYER_STARTED );
831855 registerReceiver (broadcastReceiver , intentFilter );
856+
857+ // If the PlayerHolder is not bound yet, but the service is running, try to bind to it.
858+ // Once the connection is established, the ACTION_PLAYER_STARTED will be sent.
859+ PlayerHolder .getInstance ().tryBindIfNeeded (this );
832860 }
833861 }
834862
@@ -840,4 +868,5 @@ private boolean bottomSheetHiddenOrCollapsed() {
840868 return sheetState == BottomSheetBehavior .STATE_HIDDEN
841869 || sheetState == BottomSheetBehavior .STATE_COLLAPSED ;
842870 }
871+
843872}
0 commit comments