3131import android .util .Log ;
3232import android .view .LayoutInflater ;
3333import android .view .Menu ;
34- import android .view .MenuInflater ;
3534import android .view .MenuItem ;
3635import android .view .View ;
3736import android .view .Window ;
5655import com .google .android .material .navigation .NavigationView ;
5756
5857import org .schabi .newpipe .extractor .NewPipe ;
59- import org .schabi .newpipe .extractor .ServiceList ;
6058import org .schabi .newpipe .extractor .StreamingService ;
6159import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
6260import org .schabi .newpipe .extractor .services .peertube .PeertubeInstance ;
6765import org .schabi .newpipe .report .ErrorActivity ;
6866import org .schabi .newpipe .util .Constants ;
6967import org .schabi .newpipe .util .KioskTranslator ;
68+ import org .schabi .newpipe .util .Localization ;
7069import org .schabi .newpipe .util .NavigationHelper ;
7170import org .schabi .newpipe .util .PeertubeHelper ;
7271import org .schabi .newpipe .util .PermissionHelper ;
7877import java .util .ArrayList ;
7978import java .util .List ;
8079
80+ import static org .schabi .newpipe .util .Localization .assureCorrectAppLanguage ;
81+
8182public class MainActivity extends AppCompatActivity {
8283 private static final String TAG = "MainActivity" ;
8384 public static final boolean DEBUG = !BuildConfig .BUILD_TYPE .equals ("release" );
@@ -113,9 +114,9 @@ protected void onCreate(Bundle savedInstanceState) {
113114 if (Build .VERSION .SDK_INT == Build .VERSION_CODES .KITKAT ) {
114115 TLSSocketFactoryCompat .setAsDefault ();
115116 }
116-
117117 ThemeHelper .setTheme (this , ServiceHelper .getSelectedServiceId (this ));
118118
119+ assureCorrectAppLanguage (this );
119120 super .onCreate (savedInstanceState );
120121 setContentView (R .layout .activity_main );
121122
@@ -419,6 +420,8 @@ protected void onDestroy() {
419420
420421 @ Override
421422 protected void onResume () {
423+ assureCorrectAppLanguage (this );
424+ Localization .init (getApplicationContext ()); //change the date format to match the selected language on resume
422425 super .onResume ();
423426
424427 // close drawer on return, and don't show animation, so its looks like the drawer isn't open
@@ -449,6 +452,16 @@ protected void onResume() {
449452 sharedPreferences .edit ().putBoolean (Constants .KEY_MAIN_PAGE_CHANGE , false ).apply ();
450453 NavigationHelper .openMainActivity (this );
451454 }
455+
456+ if (sharedPreferences .getBoolean (Constants .KEY_ENABLE_WATCH_HISTORY , true )) {
457+ if (DEBUG ) Log .d (TAG , "do not show History-menu as its disabled in settings" );
458+ drawerItems .getMenu ().findItem (ITEM_ID_HISTORY ).setVisible (true );
459+ }
460+
461+ if (!sharedPreferences .getBoolean (Constants .KEY_ENABLE_WATCH_HISTORY , true )) {
462+ if (DEBUG ) Log .d (TAG , "show History-menu as its enabled in settings" );
463+ drawerItems .getMenu ().findItem (ITEM_ID_HISTORY ).setVisible (false );
464+ }
452465 }
453466
454467 @ Override
@@ -551,8 +564,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
551564 if (!(fragment instanceof SearchFragment )) {
552565 findViewById (R .id .toolbar ).findViewById (R .id .toolbar_search_container ).setVisibility (View .GONE );
553566
554- MenuInflater inflater = getMenuInflater ();
555- inflater .inflate (R .menu .main_menu , menu );
556567 }
557568
558569 ActionBar actionBar = getSupportActionBar ();
@@ -574,14 +585,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
574585 case android .R .id .home :
575586 onHomeButtonPressed ();
576587 return true ;
577- case R .id .action_show_downloads :
578- return NavigationHelper .openDownloads (this );
579- case R .id .action_history :
580- NavigationHelper .openStatisticFragment (getSupportFragmentManager ());
581- return true ;
582- case R .id .action_settings :
583- NavigationHelper .openSettings (this );
584- return true ;
585588 default :
586589 return super .onOptionsItemSelected (item );
587590 }
0 commit comments