Search in sources :

Example 1 with SimpleCallback

use of iknow.android.utils.callback.SimpleCallback in project Android-Video-Trimmer by iknow4.

the class VideoSelectActivity method initUI.

@SuppressLint("CheckResult")
@Override
public void initUI() {
    mVideoLoadManager = new VideoLoadManager();
    mVideoLoadManager.setLoader(new VideoCursorLoader());
    mBinding = DataBindingUtil.setContentView(this, R.layout.activity_video_select);
    mCameraSurfaceViewLy = findViewById(R.id.layout_surface_view);
    mBinding.mBtnBack.setOnClickListener(this);
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE).subscribe(granted -> {
        if (granted) {
            // Always true pre-M
            mVideoLoadManager.load(this, new SimpleCallback() {

                @Override
                public void success(Object obj) {
                    if (mVideoSelectAdapter == null) {
                        mVideoSelectAdapter = new VideoSelectAdapter(VideoSelectActivity.this, (Cursor) obj);
                    } else {
                        mVideoSelectAdapter.swapCursor((Cursor) obj);
                    }
                    if (mBinding.videoGridview.getAdapter() == null) {
                        mBinding.videoGridview.setAdapter(mVideoSelectAdapter);
                    }
                    mVideoSelectAdapter.notifyDataSetChanged();
                }
            });
        } else {
            finish();
        }
    });
    if (rxPermissions.isGranted(Manifest.permission.CAMERA)) {
        initCameraPreview();
    } else {
        mBinding.cameraPreviewLy.setVisibility(View.GONE);
        mBinding.openCameraPermissionLy.setVisibility(View.VISIBLE);
        mBinding.mOpenCameraPermission.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                rxPermissions.request(Manifest.permission.CAMERA).subscribe(granted -> {
                    if (granted) {
                        initCameraPreview();
                    }
                });
            }
        });
    }
}
Also used : VideoLoadManager(com.iknow.android.features.select.loader.VideoLoadManager) RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) R(com.iknow.android.R) SimpleCallback(iknow.android.utils.callback.SimpleCallback) Intent(android.content.Intent) VideoLoadManager(com.iknow.android.features.select.loader.VideoLoadManager) ViewGroup(android.view.ViewGroup) VideoRecordActivity(com.iknow.android.features.record.VideoRecordActivity) VideoCursorLoader(com.iknow.android.features.select.loader.VideoCursorLoader) Manifest(android.Manifest) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable) View(android.view.View) BaseActivity(com.iknow.android.features.common.ui.BaseActivity) PreviewSurfaceView(com.iknow.android.features.record.view.PreviewSurfaceView) ActivityVideoSelectBinding(com.iknow.android.databinding.ActivityVideoSelectBinding) Cursor(android.database.Cursor) DataBindingUtil(androidx.databinding.DataBindingUtil) RxPermissions(com.tbruyelle.rxpermissions2.RxPermissions) VideoCursorLoader(com.iknow.android.features.select.loader.VideoCursorLoader) Cursor(android.database.Cursor) View(android.view.View) PreviewSurfaceView(com.iknow.android.features.record.view.PreviewSurfaceView) SimpleCallback(iknow.android.utils.callback.SimpleCallback) SuppressLint(android.annotation.SuppressLint)

Aggregations

Manifest (android.Manifest)1 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Nullable (androidx.annotation.Nullable)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 R (com.iknow.android.R)1 ActivityVideoSelectBinding (com.iknow.android.databinding.ActivityVideoSelectBinding)1 BaseActivity (com.iknow.android.features.common.ui.BaseActivity)1 VideoRecordActivity (com.iknow.android.features.record.VideoRecordActivity)1 PreviewSurfaceView (com.iknow.android.features.record.view.PreviewSurfaceView)1 VideoCursorLoader (com.iknow.android.features.select.loader.VideoCursorLoader)1 VideoLoadManager (com.iknow.android.features.select.loader.VideoLoadManager)1 RxPermissions (com.tbruyelle.rxpermissions2.RxPermissions)1 SimpleCallback (iknow.android.utils.callback.SimpleCallback)1