Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 053b9c7a authored by Andrew Lee's avatar Andrew Lee
Browse files

Rewrite of MediaPlayer logic.

+ Control MediaPlayer instance more tightly. Wait until
prepareContent to initialize instance. Release MediaPlayer when it
is no longer needed.
+ Instead of using isFinishing, check explicitly for orientation
change to know whether to release MediaPlayer.
+ Change Presenter to singleton, to address audio change wonkiness.
+ Only create a Presenter if the call log fragment shows voicemail.
+ ... fixing a variety of cases.

- Temporarily disable proximity sensor until blocking issue is fixed.

Bug: 21856243
Change-Id: Ic06e98bb5278467c3cce726a06b6cf3d855861a2
parent b67f24eb
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -116,8 +116,10 @@ public class CallLogAdapter extends GroupingListAdapter
                return;
            }

            if (mVoicemailPlaybackPresenter != null) {
                // Always reset the voicemail playback state on expand or collapse.
                mVoicemailPlaybackPresenter.reset();
            }

            if (viewHolder.getAdapterPosition() == mCurrentlyExpandedPosition) {
                // Hide actions, if the clicked item is the expanded item.
+17 −6
Original line number Diff line number Diff line
@@ -187,7 +187,10 @@ public class CallLogFragment extends Fragment
        resolver.registerContentObserver(Status.CONTENT_URI, true, mVoicemailStatusObserver);
        setHasOptionsMenu(true);

        mVoicemailPlaybackPresenter = new VoicemailPlaybackPresenter(activity, state);
        if (mCallTypeFilter == Calls.VOICEMAIL_TYPE) {
            mVoicemailPlaybackPresenter = VoicemailPlaybackPresenter
                    .getInstance(activity, state);
        }
    }

    /** Called by the CallLogQueryHandler when the list of calls has been fetched or updated. */
@@ -321,23 +324,28 @@ public class CallLogFragment extends Fragment

    @Override
    public void onPause() {
        mVoicemailPlaybackPresenter.onPause(getActivity().isFinishing());
        if (mVoicemailPlaybackPresenter != null) {
            mVoicemailPlaybackPresenter.onPause();
        }
        mAdapter.pauseCache();
        super.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();

        updateOnTransition(false /* onEntry */);

        super.onStop();
    }

    @Override
    public void onDestroy() {
        mAdapter.pauseCache();
        mAdapter.changeCursor(null);
        mVoicemailPlaybackPresenter.onDestroy(getActivity().isFinishing());

        if (mVoicemailPlaybackPresenter != null) {
            mVoicemailPlaybackPresenter.onDestroy();
        }

        getActivity().getContentResolver().unregisterContentObserver(mCallLogObserver);
        getActivity().getContentResolver().unregisterContentObserver(mContactsObserver);
@@ -353,8 +361,11 @@ public class CallLogFragment extends Fragment
        outState.putLong(KEY_DATE_LIMIT, mDateLimit);

        mAdapter.onSaveInstanceState(outState);

        if (mVoicemailPlaybackPresenter != null) {
            mVoicemailPlaybackPresenter.onSaveInstanceState(outState);
        }
    }

    @Override
    public void fetchCalls() {
+8 −7
Original line number Diff line number Diff line
@@ -50,8 +50,9 @@ import javax.annotation.concurrent.NotThreadSafe;
import javax.annotation.concurrent.ThreadSafe;

/**
 * Displays and plays a single voicemail.
 * <p>
 * Displays and plays a single voicemail. See {@link VoicemailPlaybackPresenter} for
 * details on the voicemail playback implementation.
 *
 * This class is not thread-safe, it is thread-confined. All calls to all public
 * methods on this class are expected to come from the main ui thread.
 */
@@ -178,12 +179,13 @@ public class VoicemailPlaybackLayout extends LinearLayout
            if (mPresenter == null) {
                return;
            }
            CallLogAsyncTaskUtil.deleteVoicemail(mContext, mPresenter.getVoicemailUri(), null);
            CallLogAsyncTaskUtil.deleteVoicemail(mContext, mVoicemailUri, null);
        }
    };

    private Context mContext;
    private VoicemailPlaybackPresenter mPresenter;
    private Uri mVoicemailUri;

    private boolean mIsPlaying = false;

@@ -209,8 +211,9 @@ public class VoicemailPlaybackLayout extends LinearLayout
    }

    @Override
    public void setPresenter(VoicemailPlaybackPresenter presenter) {
    public void setPresenter(VoicemailPlaybackPresenter presenter, Uri voicemailUri) {
        mPresenter = presenter;
        mVoicemailUri = voicemailUri;
    }

    @Override
@@ -256,15 +259,13 @@ public class VoicemailPlaybackLayout extends LinearLayout
    }

    @Override
    public void onPlaybackError(Exception e) {
    public void onPlaybackError() {
        if (mPositionUpdater != null) {
            mPositionUpdater.stopUpdating();
        }

        disableUiElements();
        mPlaybackPosition.setText(getString(R.string.voicemail_playback_error));

        Log.e(TAG, "Could not play voicemail", e);
    }


+169 −115

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public class VoicemailPlaybackTest extends ActivityInstrumentationTestCase2<Call
        mLayout = new VoicemailPlaybackLayout(mActivity);
        mLayout.onFinishInflate();

        mPresenter = new VoicemailPlaybackPresenter(mActivity, null);
        mPresenter = VoicemailPlaybackPresenter.getInstance(mActivity, null);
    }

    @Override