version:1.4.0
fix: update:闹钟提醒循环播放,优化sos和提醒页面
This commit is contained in:
@@ -12,7 +12,7 @@ import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.xxpatx.os.R;
|
||||
import com.xxpatx.os.adapter.SosNnmberAdapter;
|
||||
import com.xxpatx.os.adapter.EmergencyContactAdapter;
|
||||
import com.xxpatx.os.base.mvvm.BaseMvvmActivity;
|
||||
import com.xxpatx.os.bean.BaseResponse;
|
||||
import com.xxpatx.os.bean.Contact;
|
||||
@@ -32,16 +32,18 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, ActivityEmergencyBinding> {
|
||||
private String TAG = "EmergencyActivity";
|
||||
private static final String TAG = "EmergencyActivity";
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private SosNnmberAdapter mSosNnmberAdapter;
|
||||
// private SosNnmberAdapter mSosNnmberAdapter;
|
||||
private EmergencyContactAdapter mEmergencyContactAdapter;
|
||||
|
||||
private Disposable subscribe;
|
||||
private boolean needDial = false;
|
||||
private boolean isCalling = false;
|
||||
private List<Contact> phoneList;
|
||||
|
||||
private Disposable mDisposable;
|
||||
private boolean mNeedDial = false;
|
||||
private boolean mCalling = false;
|
||||
private List<Contact> mContactList;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -62,22 +64,23 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
// Intent bootIntent = new Intent(BootReceiver.SOS);
|
||||
// bootIntent.setComponent(new ComponentName("com.xxpatx.sn", "com.xxpatx.sn.receiver.BootReceiver"));
|
||||
// sendBroadcast(bootIntent);
|
||||
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
mViewDataBinding.rvContact.setLayoutManager(linearLayoutManager);
|
||||
mSosNnmberAdapter = new SosNnmberAdapter();
|
||||
mViewDataBinding.rvContact.setAdapter(mSosNnmberAdapter);
|
||||
mEmergencyContactAdapter = new EmergencyContactAdapter();
|
||||
mViewDataBinding.rvContact.setAdapter(mEmergencyContactAdapter);
|
||||
|
||||
AmapManager.getInstance().startLocation();
|
||||
|
||||
final Long time = 3L;
|
||||
subscribe = Observable.interval(1, TimeUnit.SECONDS)
|
||||
mDisposable = Observable.interval(1, TimeUnit.SECONDS)
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycleSubject(), ActivityEvent.DESTROY))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> {
|
||||
Log.e("TAG", "倒计时:" + aLong);
|
||||
if (aLong < time && !subscribe.isDisposed()) {
|
||||
if (aLong < time && !mDisposable.isDisposed()) {
|
||||
mViewDataBinding.tvCountdown.setText("倒计时(" + (time - aLong - 1) + ")秒");
|
||||
Log.e(TAG, "accept: " + (time - aLong - 1));
|
||||
} else {
|
||||
@@ -109,22 +112,22 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
}
|
||||
});
|
||||
|
||||
needDial = true;
|
||||
mNeedDial = true;
|
||||
|
||||
if (phoneList == null || phoneList.isEmpty()) {
|
||||
if (mContactList == null || mContactList.isEmpty()) {
|
||||
Toaster.showLong("没有设置紧急联系人");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phoneList.get(0).getMobile());
|
||||
Uri data = Uri.parse("tel:" + mContactList.get(0).getMobile());
|
||||
intent.setData(data);
|
||||
startActivity(intent);
|
||||
phoneList.remove(0);
|
||||
mSosNnmberAdapter.notifyDataSetChanged();
|
||||
isCalling = true;
|
||||
subscribe.dispose();
|
||||
mContactList.remove(0);
|
||||
mEmergencyContactAdapter.notifyDataSetChanged();
|
||||
mCalling = true;
|
||||
mDisposable.dispose();
|
||||
}
|
||||
});
|
||||
mViewDataBinding.ivFinish.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -155,8 +158,8 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
mViewModel.mContactListData.observe(this, new androidx.lifecycle.Observer<List<Contact>>() {
|
||||
@Override
|
||||
public void onChanged(List<Contact> contacts) {
|
||||
phoneList = contacts;
|
||||
mSosNnmberAdapter.setPhoneNumberList(phoneList);
|
||||
mContactList = contacts;
|
||||
mEmergencyContactAdapter.setContactList(mContactList);
|
||||
}
|
||||
});
|
||||
mViewModel.getCacheContact();
|
||||
@@ -167,10 +170,10 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Log.e(TAG, "onStart: ");
|
||||
Log.e(TAG, "onStart: phoneList = " + phoneList);
|
||||
Log.e(TAG, "onStart: needDial = " + needDial);
|
||||
if (needDial) {
|
||||
if (phoneList != null && !phoneList.isEmpty()) {
|
||||
Log.e(TAG, "onStart: phoneList = " + mContactList);
|
||||
Log.e(TAG, "onStart: needDial = " + mNeedDial);
|
||||
if (mNeedDial) {
|
||||
if (mContactList != null && !mContactList.isEmpty()) {
|
||||
Observable.timer(3, TimeUnit.SECONDS)
|
||||
.compose(RxLifecycle.bindUntilEvent(getLifecycleSubject(), ActivityEvent.DESTROY))
|
||||
.subscribeOn(Schedulers.io())
|
||||
@@ -185,10 +188,10 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
public void onNext(@NonNull Long aLong) {
|
||||
Log.e(TAG, "timer onNext: " + aLong);
|
||||
Intent intent = new Intent(Intent.ACTION_CALL);
|
||||
String phone = phoneList.get(0).getMobile();
|
||||
isCalling = true;
|
||||
phoneList.remove(0);
|
||||
mSosNnmberAdapter.notifyDataSetChanged();
|
||||
String phone = mContactList.get(0).getMobile();
|
||||
mCalling = true;
|
||||
mContactList.remove(0);
|
||||
mEmergencyContactAdapter.notifyDataSetChanged();
|
||||
Uri data = Uri.parse("tel:" + phone);
|
||||
intent.setData(data);
|
||||
startActivity(intent);
|
||||
@@ -220,9 +223,9 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.e(TAG, "onDestroy: ");
|
||||
if (subscribe != null && !subscribe.isDisposed()) {
|
||||
subscribe.dispose();
|
||||
subscribe = null;
|
||||
if (mDisposable != null && !mDisposable.isDisposed()) {
|
||||
mDisposable.dispose();
|
||||
mDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,22 +283,22 @@ public class EmergencyActivity extends BaseMvvmActivity<EmergencyViewModel, Acti
|
||||
|
||||
public class BtnClick{
|
||||
public void call(View view){
|
||||
needDial = true;
|
||||
mNeedDial = true;
|
||||
|
||||
if (phoneList == null || phoneList.isEmpty()) {
|
||||
if (mContactList == null || mContactList.isEmpty()) {
|
||||
Toaster.showLong("没有设置紧急联系人");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + phoneList.get(0).getMobile());
|
||||
Uri data = Uri.parse("tel:" + mContactList.get(0).getMobile());
|
||||
intent.setData(data);
|
||||
startActivity(intent);
|
||||
phoneList.remove(0);
|
||||
mSosNnmberAdapter.notifyDataSetChanged();
|
||||
isCalling = true;
|
||||
subscribe.dispose();
|
||||
mContactList.remove(0);
|
||||
mEmergencyContactAdapter.notifyDataSetChanged();
|
||||
mCalling = true;
|
||||
mDisposable.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ public class NoticeActivity extends BaseDataBindingActivity {
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, AudioManager.FLAG_PLAY_SOUND);
|
||||
|
||||
mMediaPlayer = MediaPlayer.create(this, R.raw.ni);
|
||||
mMediaPlayer.setLooping(true);
|
||||
// 开始播放
|
||||
mMediaPlayer.start();
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.xxpatx.os.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.xxpatx.os.R;
|
||||
import com.xxpatx.os.bean.Contact;
|
||||
import com.xxpatx.os.utils.GlideLoadUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EmergencyContactAdapter extends RecyclerView.Adapter<EmergencyContactAdapter.EmergencyContactHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<Contact> mContactList;
|
||||
|
||||
public void setContactList(List<Contact> contactList) {
|
||||
mContactList = contactList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public EmergencyContactHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new EmergencyContactHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_emergency_contact, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull EmergencyContactHolder holder, int position) {
|
||||
Contact contact = mContactList.get(position);
|
||||
GlideLoadUtils.getInstance().glideLoad(mContext, contact.getAvatar(), holder.iv_avatar, R.drawable.default_avatar);
|
||||
holder.tv_name.setText(contact.getName());
|
||||
holder.tv_phone.setText(contact.getMobile());
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_CALL);
|
||||
Uri data = Uri.parse("tel:" + contact.getMobile());
|
||||
intent.setData(data);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mContactList == null ? 0 : mContactList.size();
|
||||
}
|
||||
|
||||
public class EmergencyContactHolder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
NiceImageView iv_avatar;
|
||||
TextView tv_name, tv_phone;
|
||||
|
||||
public EmergencyContactHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
iv_avatar = itemView.findViewById(R.id.iv_avatar);
|
||||
tv_name = itemView.findViewById(R.id.tv_name);
|
||||
tv_phone = itemView.findViewById(R.id.tv_phone);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user