Prevent NPE

This commit is contained in:
Martin Fietz 2016-02-23 08:27:09 +01:00
parent b1df272797
commit 4366e134cf
2 changed files with 17 additions and 5 deletions

View File

@ -139,7 +139,9 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig); if(drawerToggle != null) {
drawerToggle.onConfigurationChanged(newConfig);
}
} }
private void loadLastFragment() { private void loadLastFragment() {
@ -283,7 +285,10 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
} }
public void notifyMediaPositionChanged() { public void notifyMediaPositionChanged() {
ChaptersFragment chaptersFragment = mPagerAdapter.getChaptersFragment(); if(pagerAdapter == null) {
return;
}
ChaptersFragment chaptersFragment = pagerAdapter.getChaptersFragment();
if(chaptersFragment != null) { if(chaptersFragment != null) {
ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter(); ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter();
if (adapter != null) { if (adapter != null) {

View File

@ -206,8 +206,10 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
controller.reinitServiceIfPaused(); if(controller != null) {
controller.pause(); controller.reinitServiceIfPaused();
controller.pause();
}
} }
/** /**
@ -582,7 +584,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
super.onResume(); super.onResume();
Log.d(TAG, "onResume()"); Log.d(TAG, "onResume()");
StorageUtils.checkStorageAvailability(this); StorageUtils.checkStorageAvailability(this);
controller.init(); if(controller != null) {
controller.init();
}
} }
/** /**
@ -618,6 +622,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O
private void updateProgressbarPosition(int position, int duration) { private void updateProgressbarPosition(int position, int duration) {
Log.d(TAG, "updateProgressbarPosition(" + position + ", " + duration + ")"); Log.d(TAG, "updateProgressbarPosition(" + position + ", " + duration + ")");
if(sbPosition == null) {
return;
}
float progress = ((float) position) / duration; float progress = ((float) position) / duration;
sbPosition.setProgress((int) (progress * sbPosition.getMax())); sbPosition.setProgress((int) (progress * sbPosition.getMax()));
} }