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

Commit 7341f1d3 authored by Diksha Gohlyan's avatar Diksha Gohlyan
Browse files

Listen to media mount unmount broadcast

Test: manual testing

Bug: 137509246

Change-Id: I75b118f74a0f168901e9d8b839ab50cf11faa160
parent d2db36ca
Loading
Loading
Loading
Loading
+45 −15
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface RequestCode {}

    public static final int REQUEST_COPY_DESTINATION = 1;

    static final String TAG = "DirectoryFragment";
@@ -140,6 +141,9 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
    private static final int REFRESH_SPINNER_TIMEOUT = 500;
    private static final int PROVIDER_MAX_RETRIES = 10;
    private static final long PROVIDER_TEST_DELAY = 4000;
    private static final String ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
    private static final String ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
    private static final String ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";

    private BaseActivity mActivity;

@@ -257,6 +261,22 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        }
    };

    private final BroadcastReceiver mSdCardBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            onRefresh();
        }
    };

    private IntentFilter getSdCardStateChangeFilter() {
        IntentFilter sdCardStateChangeFilter = new IntentFilter();
        sdCardStateChangeFilter.addAction(ACTION_MEDIA_REMOVED);
        sdCardStateChangeFilter.addAction(ACTION_MEDIA_MOUNTED);
        sdCardStateChangeFilter.addAction(ACTION_MEDIA_EJECT);
        sdCardStateChangeFilter.addDataScheme("file");
        return sdCardStateChangeFilter;
    }

    private void checkUriAndScheduleCheckIfNeeded(UserId userId) {
        RootInfo currentRoot = mActivity.getCurrentRoot();
        DocumentInfo currentDoc = mActivity.getDisplayState().stack.peek();
@@ -390,6 +410,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
                mHandler.removeCallbacks(mProviderTestRunnable);
            }
        }
        getContext().unregisterReceiver(mSdCardBroadcastReceiver);

        // Cancel any outstanding thumbnail requests
        final int count = mRecView.getChildCount();
@@ -555,6 +576,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
            // roots are updated.
            LocalBroadcastManager.getInstance(mActivity).registerReceiver(mReceiver, filter);
        }
        getContext().registerReceiver(mSdCardBroadcastReceiver, getSdCardStateChangeFilter());
    }

    @Override
@@ -672,6 +694,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On

    /**
     * Updates the layout after the view mode switches.
     *
     * @param mode The new view mode.
     */
    private void updateLayout(@ViewMode int mode) {
@@ -705,21 +728,26 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On

    /**
     * Updates the layout after the view mode switches.
     *
     * @param mode The new view mode.
     */
    private void scaleLayout(float scale) {
        assert DEBUG;

        if (VERBOSE) Log.v(
        if (VERBOSE) {
            Log.v(
                    TAG, "Handling scale event: " + scale + ", existing scale: " + mLiveScale);
        }

        if (mMode == MODE_GRID) {
            float minScale = getFraction(R.fraction.grid_scale_min);
            float maxScale = getFraction(R.fraction.grid_scale_max);
            float nextScale = mLiveScale * scale;

            if (VERBOSE) Log.v(TAG,
            if (VERBOSE) {
                Log.v(TAG,
                        "Next scale " + nextScale + ", Min/max scale " + minScale + "/" + maxScale);
            }

            if (nextScale > minScale && nextScale < maxScale) {
                if (DEBUG) {
@@ -1170,6 +1198,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On

    /**
     * Gets the model ID for a given RecyclerView item.
     *
     * @param view A View that is a document item view, or a child of a document item view.
     * @return The Model ID for the given document, or null if the given view is not associated with
     * a document item view.
@@ -1250,6 +1279,7 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
        ft.commitAllowingStateLoss();
    }

    /** Gets the fragment from the fragment manager. */
    public static @Nullable DirectoryFragment get(FragmentManager fm) {
        // TODO: deal with multiple directories shown at once
        Fragment fragment = fm.findFragmentById(getFragmentId());