Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored MainActivity... #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions app/src/main/java/io/microshow/rxffmpegdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import io.microshow.rxffmpegdemo.databinding.ActivityMainBinding;
import io.reactivex.functions.Consumer;

import java.util.Optional;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

private static final String TAG = MainActivity.class.getSimpleName();
Expand Down Expand Up @@ -45,7 +47,7 @@ public void onClick(View view) {
rxPermissions.request(PERMISSIONS_STORAGE).subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
if (aBoolean) {// 用户同意了权限
if (aBoolean == Boolean.TRUE) {// 用户同意了权限
runFFmpegRxJava();
} else {//用户拒绝了权限
Toast.makeText(MainActivity.this,"您拒绝了权限,请往设置里开启权限",Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -78,28 +80,28 @@ private void runFFmpegRxJava () {
RxFFmpegInvoke.getInstance().runCommandRxJava(commands).subscribe(new RxFFmpegSubscriber() {
@Override
public void onFinish() {
if (mProgressDialog != null)
mProgressDialog.cancel();
Optional.ofNullable(mProgressDialog)
.ifPresent(ProgressDialog::cancel);
showDialog("处理成功");
}

@Override
public void onProgress(int progress) {
if (mProgressDialog != null)
mProgressDialog.setProgress(progress);
Optional.ofNullable(mProgressDialog)
.ifPresent(pd -> pd.setProgress(progress));
}

@Override
public void onCancel() {
if (mProgressDialog != null)
mProgressDialog.cancel();
Optional.ofNullable(mProgressDialog)
.ifPresent(ProgressDialog::cancel);
showDialog("已取消");
}

@Override
public void onError(String message) {
if (mProgressDialog != null)
mProgressDialog.cancel();
Optional.ofNullable(mProgressDialog)
.ifPresent(ProgressDialog::cancel);
showDialog("出错了 onError:" + message);
}
});
Expand All @@ -115,4 +117,4 @@ private void showDialog (String message) {
Utils.showDialog(this, message, Utils.convertUsToTime((endTime-startTime)/1000, false));
}

}
}