Skip to content

Commit

Permalink
Fix some crashes. Reset toolbar when you tap an ayah.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedre committed Jun 13, 2014
1 parent b7ad10e commit 4e06a9a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
Expand Down Expand Up @@ -289,27 +290,28 @@ private void removeErrorPreferences(){
}

class CheckPagesAsyncTask extends AsyncTask<Void, Void, Boolean> {
private final Context mAppContext;
public CheckPagesAsyncTask() {
mAppContext = getApplicationContext();
}

@Override
protected Boolean doInBackground(Void... params) {
// intentionally not sleeping because waiting
// for the splash screen is not cool.
QuranFileUtils.migrateAudio(QuranDataActivity.this);
QuranFileUtils.migrateAudio(mAppContext);

if (QuranScreenInfo.getInstance().isTablet(QuranDataActivity.this)){
boolean haveLandscape = QuranFileUtils.haveAllImages(
QuranDataActivity.this,
if (QuranScreenInfo.getInstance().isTablet(mAppContext)){
boolean haveLandscape = QuranFileUtils.haveAllImages(mAppContext,
QuranScreenInfo.getInstance().getTabletWidthParam());
boolean havePortrait = QuranFileUtils.haveAllImages(
QuranDataActivity.this,
boolean havePortrait = QuranFileUtils.haveAllImages(mAppContext,
QuranScreenInfo.getInstance().getWidthParam());
mNeedPortraitImages = !havePortrait;
mNeedLandscapeImages = !haveLandscape;
return haveLandscape && havePortrait;
}
else {
boolean haveAll = QuranFileUtils.haveAllImages(
QuranDataActivity.this,
boolean haveAll = QuranFileUtils.haveAllImages(mAppContext,
QuranScreenInfo.getInstance().getWidthParam());
mNeedPortraitImages = !haveAll;
mNeedLandscapeImages = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ public boolean onPreferenceClick(Preference preference) {
s = new StorageUtils.Storage(
getString(R.string.prefs_sdcard_internal),
mInternalSdcardLocation);
} else {
} else if (mountPoints[i] != null) {
s = new StorageUtils.Storage(
getString(R.string.prefs_sdcard_external),
mountPoints[i].getAbsolutePath());
} else {
s = null;
}

if (s != null) {
mStorageList.add(s);
}
mStorageList.add(s);
}
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void onCreate() {
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction();

if (action.equals(ACTION_CONNECT)){
if (ACTION_CONNECT.equals(action)){
if (mState == State.Stopped){
processStopRequest(true);
}
Expand Down Expand Up @@ -317,7 +317,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
mBroadcastManager.sendBroadcast(updateIntent);
}
}
else if (action.equals(ACTION_PLAYBACK)){
else if (ACTION_PLAYBACK.equals(action)){
Serializable playInfo = intent.getSerializableExtra(EXTRA_PLAY_INFO);
if (playInfo != null && playInfo instanceof AudioRequest){
if (mState == State.Stopped ||
Expand All @@ -333,12 +333,12 @@ else if (action.equals(ACTION_PLAYBACK)){

processTogglePlaybackRequest();
}
else if (action.equals(ACTION_PLAY)){ processPlayRequest(); }
else if (action.equals(ACTION_PAUSE)){ processPauseRequest(); }
else if (action.equals(ACTION_SKIP)){ processSkipRequest(); }
else if (action.equals(ACTION_STOP)){ processStopRequest(); }
else if (action.equals(ACTION_REWIND)){ processRewindRequest(); }
else if (action.equals(ACTION_UPDATE_REPEAT)){
else if (ACTION_PLAY.equals(action)){ processPlayRequest(); }
else if (ACTION_PAUSE.equals(action)){ processPauseRequest(); }
else if (ACTION_SKIP.equals(action)){ processSkipRequest(); }
else if (ACTION_STOP.equals(action)){ processStopRequest(); }
else if (ACTION_REWIND.equals(action)){ processRewindRequest(); }
else if (ACTION_UPDATE_REPEAT.equals(action)){
Serializable repeatInfo = intent.getSerializableExtra(
EXTRA_REPEAT_INFO);
if (repeatInfo != null && mAudioRequest != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

package com.quran.labs.androidquran.service.util;

import com.quran.labs.androidquran.service.AudioService;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;

import com.quran.labs.androidquran.service.AudioService;

/**
* Receives broadcasted intents. In particular, we are interested in the
* android.media.AUDIO_BECOMING_NOISY and android.intent.action.MEDIA_BUTTON
Expand All @@ -48,7 +48,8 @@ public void onReceive(Context context, Intent intent) {
} else if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(
Intent.EXTRA_KEY_EVENT);
if (keyEvent.getAction() != KeyEvent.ACTION_DOWN){
if (keyEvent == null ||
keyEvent.getAction() != KeyEvent.ACTION_DOWN){
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,7 @@ public void updateAyahStartSelection(
clearAyahModeHighlights();
mStart = mEnd = suraAyah;
if (mAyahToolBar.isShowing()) {
mAyahToolBar.resetMenu();
updateToolbarPosition(suraAyah, tracker);
}
if (mSlidingPanel.isPaneVisible()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public boolean isShowing() {
return mIsShowing;
}

public void resetMenu() {
showMenu(mMenu);
}

public void showMenu() {
showMenu(mMenu);
setVisibility(VISIBLE);
Expand Down

0 comments on commit 4e06a9a

Please sign in to comment.