Skip to content

Commit

Permalink
转发到其他手机短信取消延时重试(没有实际意义)
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Oct 24, 2021
1 parent 447b164 commit c4effff
Showing 1 changed file with 9 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
import android.util.Log;

import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import com.idormy.sms.forwarder.utils.SimUtil;
import com.idormy.sms.forwarder.utils.SmsUtil;

import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;

@SuppressWarnings("ResultOfMethodCallIgnored")
public class SenderSmsMsg extends SenderBaseMsg {

static final String TAG = "SenderSmsMsg";
Expand All @@ -23,35 +16,16 @@ public static void sendMsg(final long logId, final Handler handError, int simSlo

//TODO:simSlot转subId
final int subId = SimUtil.getSubscriptionIdBySimId(simSlot);
String res = SmsUtil.sendSms(subId, mobiles, text);

//TODO:粗略解析是否发送成功
if (res == null) {
LogUtil.updateLog(logId, 1, "发送成功");
} else {
LogUtil.updateLog(logId, 0, res);
Toast(handError, TAG, "短信发送失败");
}

Observable
.create((ObservableEmitter<Object> emitter) -> {
Toast(handError, TAG, "开始发送短信...");

String res = SmsUtil.sendSms(subId, mobiles, text);

//TODO:粗略解析是否发送成功
if (res == null) {
LogUtil.updateLog(logId, 1, "发送成功");
} else {
LogUtil.updateLog(logId, 0, res);
Toast(handError, TAG, "短信发送失败");
emitter.onError(new RuntimeException("短信发送异常..."));
}

}).retryWhen((Observable<Throwable> errorObservable) -> errorObservable
.zipWith(Observable.just(
SettingUtil.getRetryDelayTime(1),
SettingUtil.getRetryDelayTime(2),
SettingUtil.getRetryDelayTime(3),
SettingUtil.getRetryDelayTime(4),
SettingUtil.getRetryDelayTime(5)
), (Throwable e, Integer time) -> time)
.flatMap((Integer delay) -> {
Toast(handError, TAG, "短信发送异常," + delay + "秒后重试");
return Observable.timer(delay, TimeUnit.SECONDS);
}))
.subscribe(System.out::println);
}

}

0 comments on commit c4effff

Please sign in to comment.