| 105 | import java.util.Objects; |
| 106 | |
| 107 | public class MainActivity extends AppCompatActivity { |
| 108 | private static final String TAG = "MainActivity"; |
| 109 | @SuppressWarnings("ConstantConditions") |
| 110 | public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); |
| 111 | |
| 112 | private ActivityMainBinding mainBinding; |
| 113 | private DrawerHeaderBinding drawerHeaderBinding; |
| 114 | private DrawerLayoutBinding drawerLayoutBinding; |
| 115 | private ToolbarLayoutBinding toolbarLayoutBinding; |
| 116 | |
| 117 | private ActionBarDrawerToggle toggle; |
| 118 | |
| 119 | private boolean servicesShown = false; |
| 120 | |
| 121 | private BroadcastReceiver broadcastReceiver; |
| 122 | |
| 123 | private static final int ITEM_ID_SUBSCRIPTIONS = -1; |
| 124 | private static final int ITEM_ID_FEED = -2; |
| 125 | private static final int ITEM_ID_BOOKMARKS = -3; |
| 126 | private static final int ITEM_ID_DOWNLOADS = -4; |
| 127 | private static final int ITEM_ID_HISTORY = -5; |
| 128 | private static final int ITEM_ID_SETTINGS = 0; |
| 129 | private static final int ITEM_ID_DONATION = 1; |
| 130 | private static final int ITEM_ID_ABOUT = 2; |
| 131 | |
| 132 | private static final int ORDER = 0; |
| 133 | public static final String KEY_IS_IN_BACKGROUND = "is_in_background"; |
| 134 | |
| 135 | private SharedPreferences sharedPreferences; |
| 136 | private SharedPreferences.Editor sharedPrefEditor; |
| 137 | /*////////////////////////////////////////////////////////////////////////// |
| 138 | // Activity's LifeCycle |
| 139 | //////////////////////////////////////////////////////////////////////////*/ |
| 140 | |
| 141 | @Override |
| 142 | protected void onCreate(final Bundle savedInstanceState) { |
| 143 | if (DEBUG) { |
| 144 | Log.d(TAG, "onCreate() called with: " |
| 145 | + "savedInstanceState = [" + savedInstanceState + "]"); |
| 146 | } |
| 147 | |
| 148 | Localization.migrateAppLanguageSettingIfNecessary(getApplicationContext()); |
| 149 | ThemeHelper.setDayNightMode(this); |
| 150 | ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); |
| 151 | |
| 152 | // Fixes text color turning black in dark/black mode: |
| 153 | // https://github.com/TeamNewPipe/NewPipe/issues/12016 |
| 154 | // For further reference see: https://issuetracker.google.com/issues/37124582 |
| 155 | if (DeviceUtils.supportsWebView()) { |
| 156 | try { |
| 157 | new WebView(this); |
| 158 | } catch (final Throwable e) { |
| 159 | if (DEBUG) { |
| 160 | Log.e(TAG, "Failed to create WebView", e); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |