Browse Source

Fix null pointer exception caused by activity not being ready

master
Anthony Restaino 8 years ago
parent
commit
6b69eb6edd
  1. 11
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  2. 15
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

11
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -127,6 +127,13 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -127,6 +127,13 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
ThemeUtils.getIconLightThemeColor(context);
}
private TabsManager getTabsManager() {
if (mTabsManager == null) {
mTabsManager = mUiController.getTabModel();
}
return mTabsManager;
}
// Handle bookmark click
private final OnItemClickListener mItemClickListener = new OnItemClickListener() {
@Override
@ -311,7 +318,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -311,7 +318,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mUiController.bookmarkButtonClicked();
break;
case R.id.action_reading:
LightningView currentTab = mTabsManager.getCurrentTab();
LightningView currentTab = getTabsManager().getCurrentTab();
if (currentTab != null) {
Intent read = new Intent(getActivity(), ReadingActivity.class);
read.putExtra(Constants.LOAD_READING_URL, currentTab.getUrl());
@ -319,7 +326,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -319,7 +326,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
}
break;
case R.id.action_toggle_desktop:
LightningView current = mTabsManager.getCurrentTab();
LightningView current = getTabsManager().getCurrentTab();
if (current != null) {
current.toggleDesktopUA(getActivity());
current.reload();

15
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -147,6 +147,13 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -147,6 +147,13 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
return view;
}
private TabsManager getTabsManager() {
if (mTabsManager == null) {
mTabsManager = mUiController.getTabModel();
}
return mTabsManager;
}
private void setupFrameLayoutButton(@NonNull final View root, @IdRes final int buttonId,
@IdRes final int imageId) {
final View frameButton = root.findViewById(buttonId);
@ -210,7 +217,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -210,7 +217,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
public void onClick(@NonNull View v) {
switch (v.getId()) {
case R.id.tab_header_button:
mUiController.showCloseDialog(mTabsManager.indexOfCurrentTab());
mUiController.showCloseDialog(getTabsManager().indexOfCurrentTab());
break;
case R.id.new_tab_button:
mUiController.newTabButtonClicked();
@ -243,7 +250,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -243,7 +250,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
@Override
public void tabAdded() {
if (mTabsAdapter != null) {
mTabsAdapter.notifyItemInserted(mTabsManager.last());
mTabsAdapter.notifyItemInserted(getTabsManager().last());
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
@ -315,7 +322,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -315,7 +322,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
ViewCompat.jumpDrawablesToCurrentState(holder.exitButton);
LightningView web = mTabsManager.getTabAtPosition(position);
LightningView web = getTabsManager().getTabAtPosition(position);
if (web == null) {
return;
}
@ -360,7 +367,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View @@ -360,7 +367,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
@Override
public int getItemCount() {
return mTabsManager.size();
return getTabsManager().size();
}
public Bitmap getDesaturatedBitmap(@NonNull Bitmap favicon) {

Loading…
Cancel
Save