version:4.4
fix: update:优化闹钟页面,优化日常应用
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.InformationAdapter;
|
||||
import com.uiuios.aios.adapter.TitleAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.ArticleInfo;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.bean.CategoryBean;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class InformationActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.rv_title)
|
||||
RecyclerView rv_title;
|
||||
@BindView(R.id.rv_video)
|
||||
RecyclerView rv_video;
|
||||
@BindView(R.id.cl_nodata)
|
||||
ConstraintLayout cl_nodata;
|
||||
|
||||
private TitleAdapter mTitleAdapter;
|
||||
private InformationAdapter mInformationAdapter;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_information;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mTitleAdapter = new TitleAdapter();
|
||||
mTitleAdapter.setTitleChangeCallback(new TitleAdapter.TitleChangeCallback() {
|
||||
@Override
|
||||
public void onTitleChange(CategoryBean categoryBean) {
|
||||
int id = categoryBean.getId();
|
||||
if (id == -100) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
||||
rv_title.setLayoutManager(linearLayoutManager);
|
||||
rv_title.setAdapter(mTitleAdapter);
|
||||
|
||||
mInformationAdapter =new InformationAdapter();
|
||||
LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(this);
|
||||
linearLayoutManager1.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
rv_video.setLayoutManager(linearLayoutManager1);
|
||||
rv_video.setAdapter(mInformationAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
getCategorys();
|
||||
getArticleList();
|
||||
}
|
||||
|
||||
private void getCategorys() {
|
||||
NetInterfaceManager.getInstance().getCategorysObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<CategoryBean>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getCategorys", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<CategoryBean>> listBaseResponse) {
|
||||
Log.e("getCategorys", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
mTitleAdapter.setCategoryList(listBaseResponse.data);
|
||||
} else {
|
||||
mTitleAdapter.setCategoryList(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getCategorys", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getCategorys", "onComplete: ");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void getArticleList() {
|
||||
NetInterfaceManager.getInstance().getArticleListObservable()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<ArticleInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getArticle", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<ArticleInfo>> listBaseResponse) {
|
||||
Log.e("getArticle", "onNext: " + listBaseResponse);
|
||||
List<ArticleInfo> articleInfoList = listBaseResponse.data;
|
||||
if (articleInfoList != null && articleInfoList.size() != 0) {
|
||||
mInformationAdapter.setArticleInfos(articleInfoList);
|
||||
rv_video.setVisibility(View.VISIBLE);
|
||||
cl_nodata.setVisibility(android.view.View.GONE);
|
||||
} else {
|
||||
rv_video.setVisibility(android.view.View.GONE);
|
||||
cl_nodata.setVisibility(android.view.View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getArticle", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getArticle", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.uiuios.aios.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.base.BaseDataBindingActivity;
|
||||
import com.uiuios.aios.bean.ArticleInfo;
|
||||
import com.uiuios.aios.databinding.ActivityInfoDetailsBinding;
|
||||
|
||||
public class InformationDetailsActivity extends BaseDataBindingActivity {
|
||||
|
||||
// @BindView(R.id.tv_title)
|
||||
// TextView tv_title;
|
||||
// @BindView(R.id.tv_time)
|
||||
// TextView tv_time;
|
||||
// @BindView(R.id.niceImageView)
|
||||
// NiceImageView niceImageView;
|
||||
// @BindView(R.id.tv_content)
|
||||
// TextView tv_content;
|
||||
|
||||
private ActivityInfoDetailsBinding mBinding;
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_info_details);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
Intent intent = getIntent();
|
||||
ArticleInfo articleInfo = (ArticleInfo) intent.getSerializableExtra("articleInfo");
|
||||
mBinding.setArticleInfo(articleInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.alarmclock.AlarmClockAddActivity;
|
||||
import com.uiuios.aios.alarm.AlarmAdapter;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.dialog.DeleteDialog;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
|
||||
public class AlarmActivity extends BaseActivity implements AlarmContact.AlarmView {
|
||||
private static final String TAG = AlarmActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.cl_exit)
|
||||
ConstraintLayout cl_exit;
|
||||
@BindView(R.id.cl_all)
|
||||
ConstraintLayout cl_all;
|
||||
@BindView(R.id.cl_medicine)
|
||||
ConstraintLayout cl_medicine;
|
||||
@BindView(R.id.cl_look)
|
||||
ConstraintLayout cl_look;
|
||||
@BindView(R.id.cl_reserve)
|
||||
ConstraintLayout cl_reserve;
|
||||
@BindView(R.id.imageView1)
|
||||
ImageView imageView1;
|
||||
@BindView(R.id.imageView3)
|
||||
ImageView imageView3;
|
||||
@BindView(R.id.imageView5)
|
||||
ImageView imageView5;
|
||||
@BindView(R.id.imageView7)
|
||||
ImageView imageView7;
|
||||
|
||||
@BindView(R.id.rv_data)
|
||||
RecyclerView rv_data;
|
||||
@BindView(R.id.cl_nodata)
|
||||
ConstraintLayout cl_nodata;
|
||||
|
||||
@BindView(R.id.imageView2)
|
||||
ImageView imageView2;
|
||||
@BindView(R.id.imageView4)
|
||||
ImageView imageView4;
|
||||
@BindView(R.id.imageView6)
|
||||
ImageView imageView6;
|
||||
@BindView(R.id.imageView8)
|
||||
ImageView imageView8;
|
||||
|
||||
@BindView(R.id.iv_add)
|
||||
ImageView iv_add;
|
||||
|
||||
private AlarmPresenter mPresenter;
|
||||
private AlarmAdapter mAlarmAdapter;
|
||||
private int mType = 0;
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_alarm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new AlarmPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
|
||||
mAlarmAdapter = new AlarmAdapter();
|
||||
mAlarmAdapter.setOnLongClickListener(new AlarmAdapter.OnLongClickListener() {
|
||||
@Override
|
||||
public void onLongClick(AlarmClockData alarmClockData) {
|
||||
showDialog(alarmClockData);
|
||||
}
|
||||
});
|
||||
rv_data.setLayoutManager(new LinearLayoutManager(AlarmActivity.this));
|
||||
rv_data.setAdapter(mAlarmAdapter);
|
||||
switchItem(0);
|
||||
cl_exit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
cl_all.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(0);
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
});
|
||||
cl_medicine.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(1);
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
});
|
||||
cl_look.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(2);
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
});
|
||||
cl_reserve.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switchItem(3);
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
});
|
||||
|
||||
iv_add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(AlarmActivity.this, AlarmClockAddActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
|
||||
private void switchItem(int position) {
|
||||
mType = position;
|
||||
cl_all.setBackground(null);
|
||||
cl_medicine.setBackground(null);
|
||||
cl_look.setBackground(null);
|
||||
cl_reserve.setBackground(null);
|
||||
|
||||
imageView2.setImageDrawable(null);
|
||||
imageView4.setImageDrawable(null);
|
||||
imageView6.setImageDrawable(null);
|
||||
imageView8.setImageDrawable(null);
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
default:
|
||||
// cl_all.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView2.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
imageView1.setImageDrawable(getDrawable(R.drawable.icon_alarm_all_pressed));
|
||||
imageView3.setImageDrawable(getDrawable(R.drawable.icon_alarm_medicine));
|
||||
imageView5.setImageDrawable(getDrawable(R.drawable.icon_alarm_look));
|
||||
imageView7.setImageDrawable(getDrawable(R.drawable.icon_alarm_reserve));
|
||||
break;
|
||||
case 1:
|
||||
// cl_medicine.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView4.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
imageView1.setImageDrawable(getDrawable(R.drawable.icon_alarm_all));
|
||||
imageView3.setImageDrawable(getDrawable(R.drawable.icon_alarm_medicine_pressed));
|
||||
imageView5.setImageDrawable(getDrawable(R.drawable.icon_alarm_look));
|
||||
imageView7.setImageDrawable(getDrawable(R.drawable.icon_alarm_reserve));
|
||||
break;
|
||||
case 2:
|
||||
// cl_look.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView6.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
imageView1.setImageDrawable(getDrawable(R.drawable.icon_alarm_all));
|
||||
imageView3.setImageDrawable(getDrawable(R.drawable.icon_alarm_medicine));
|
||||
imageView5.setImageDrawable(getDrawable(R.drawable.icon_alarm_look_pressed));
|
||||
imageView7.setImageDrawable(getDrawable(R.drawable.icon_alarm_reserve));
|
||||
break;
|
||||
case 3:
|
||||
// cl_reserve.setBackground(getDrawable(R.drawable.alarm_pressed_background));
|
||||
imageView8.setImageDrawable(getDrawable(R.drawable.icon_touch));
|
||||
imageView1.setImageDrawable(getDrawable(R.drawable.icon_alarm_all));
|
||||
imageView3.setImageDrawable(getDrawable(R.drawable.icon_alarm_medicine));
|
||||
imageView5.setImageDrawable(getDrawable(R.drawable.icon_alarm_look));
|
||||
imageView7.setImageDrawable(getDrawable(R.drawable.icon_alarm_reserve_pressed));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void showDialog(AlarmClockData alarmClockData) {
|
||||
DeleteDialog dialog = new DeleteDialog(this);
|
||||
dialog.setTitle("提醒")
|
||||
.setMessage("是否要删除本次闹钟")
|
||||
.setPositive("确定")
|
||||
.setNegtive("取消")
|
||||
.setOnClickBottomListener(new DeleteDialog.OnClickBottomListener() {
|
||||
@Override
|
||||
public void onPositiveClick() {
|
||||
deleteAlarm(alarmClockData);
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegtiveClick() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void deleteAlarm(AlarmClockData alarmClockData) {
|
||||
if (alarmClockData.isIs_local()) {
|
||||
alarmClockData.setDeleted(true);
|
||||
AlarmUtils.getInstance().deleteAlarmClock(alarmClockData);
|
||||
mPresenter.getAlarmClock(mType);
|
||||
} else {
|
||||
NetInterfaceManager.getInstance().deleteAlarmClockObservable(alarmClockData.getId())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("deleteAlarm", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("deleteAlarm", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
AlarmUtils.getInstance().deleteAlarmClock(alarmClockData);
|
||||
ToastUtil.show("删除成功");
|
||||
} else {
|
||||
ToastUtil.show("删除失败:" + baseResponse.msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("deleteAlarm", "onError: " + e.getMessage());
|
||||
alarmClockData.setDeleted(true);
|
||||
AlarmUtils.getInstance().updateAlarmClock(alarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("deleteAlarm", "onComplete: ");
|
||||
mPresenter.getAlarmClock(mType);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> alarmClockData) {
|
||||
List<AlarmClockData> localAddAlarm = AlarmUtils.getInstance().getLocalAddAlarm();
|
||||
Log.e(TAG, "setAlarmClock: localAddAlarm size = " + localAddAlarm);
|
||||
if (alarmClockData != null) {
|
||||
localAddAlarm.addAll(alarmClockData);
|
||||
}
|
||||
if (localAddAlarm.size() == 0) {
|
||||
mAlarmAdapter.setAlarmClockData(null);
|
||||
// swipeRefreshLayout.setRefreshing(false);
|
||||
cl_nodata.setVisibility(View.VISIBLE);
|
||||
rv_data.setVisibility(View.GONE);
|
||||
ToastUtil.show("没有数据");
|
||||
} else {
|
||||
mAlarmAdapter.setAlarmClockData(localAddAlarm);
|
||||
// swipeRefreshLayout.setRefreshing(false);
|
||||
cl_nodata.setVisibility(View.GONE);
|
||||
rv_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AlarmContact {
|
||||
public interface Presenter extends BasePresenter<AlarmView> {
|
||||
void getAlarmClock();
|
||||
|
||||
void getAlarmClock(int type);
|
||||
}
|
||||
|
||||
public interface AlarmView extends BaseView {
|
||||
void setAlarmClock(List<AlarmClockData> alarmClockData);
|
||||
|
||||
void setAlarmClockEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class AlarmPresenter implements AlarmContact.Presenter {
|
||||
private static final String TAG = AlarmPresenter.class.getSimpleName();
|
||||
|
||||
private AlarmContact.AlarmView mView;
|
||||
private Context mContext;
|
||||
|
||||
AlarmPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(@NonNull AlarmContact.AlarmView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getAlarmClock() {
|
||||
NetInterfaceManager.getInstance().getAlarmClock(true, getLifecycle(), new NetInterfaceManager.AlarmClockCallback() {
|
||||
@Override
|
||||
public void setAlarmClock(List<AlarmClockData> alarmClockList) {
|
||||
if (alarmClockList.size() == 0) {
|
||||
setAlarmClockEmpty();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmClockEmpty() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAlarmClock(int type) {
|
||||
Log.e(TAG, "getAlarmClock: " + type);
|
||||
NetInterfaceManager.getInstance().getAlarmClockObservable(type)
|
||||
.subscribe(new Observer<BaseResponse<List<AlarmClockData>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAlarmClock", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<List<AlarmClockData>> listBaseResponse) {
|
||||
Log.e("getAlarmClock", "onNext: " + listBaseResponse);
|
||||
mView.setAlarmClock(listBaseResponse.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClock", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAlarmClock", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
package com.uiuios.aios.activity.alarmclock;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -56,7 +56,7 @@ public class AlarmClockActivity extends BaseLifecycleActivity implements AlarmCl
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_alarm_clock;
|
||||
return R.layout.activity_alarm;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
package com.uiuios.aios.activity.alarmclock;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
@@ -7,7 +8,6 @@ import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
@@ -30,33 +30,19 @@ import com.luck.picture.lib.config.SelectMimeType;
|
||||
import com.luck.picture.lib.entity.LocalMedia;
|
||||
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseLifecycleActivity;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.service.main.MainService;
|
||||
import com.uiuios.aios.utils.FFmpegUtils;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ScreenUtil;
|
||||
import com.uiuios.aios.utils.TimeUtils;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.BaseLifecycleActivity;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.AlarmClockId;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.utils.Utils;
|
||||
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;
|
||||
import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX;
|
||||
|
||||
import java.io.File;
|
||||
@@ -96,10 +82,6 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
NiceImageView nv_pic;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.bt_confirm)
|
||||
Button bt_confirm;
|
||||
@BindView(R.id.bt_cancel)
|
||||
Button bt_cancel;
|
||||
@BindView(R.id.tv_duration)
|
||||
TextView tv_duration;
|
||||
|
||||
@@ -107,10 +89,15 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
RadioButton rb1;
|
||||
@BindView(R.id.rb2)
|
||||
RadioButton rb2;
|
||||
@BindView(R.id.rb3)
|
||||
RadioButton rb3;
|
||||
@BindView(R.id.rb4)
|
||||
RadioButton rb4;
|
||||
@BindView(R.id.rb_all)
|
||||
RadioButton rb_all;
|
||||
@BindView(R.id.rb_look)
|
||||
RadioButton rb_look;
|
||||
@BindView(R.id.rb_reserve)
|
||||
RadioButton rb_reserve;
|
||||
|
||||
@BindView(R.id.iv_add)
|
||||
ImageView iv_add;
|
||||
|
||||
private PopupWindow mPopupWindow;
|
||||
|
||||
@@ -118,11 +105,13 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
private String mPictrueFilePath;
|
||||
private Date mDate;
|
||||
/*类型 1一次性 2每天 3周一到周五 4周六周日*/
|
||||
private int mType = 1;
|
||||
private int mDayType = 1;
|
||||
private int mClockType = 1;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_add_alarm_clock;
|
||||
return R.layout.activity_add_alarm;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,14 +125,14 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
ButterKnife.bind(this);
|
||||
initTimePicker();
|
||||
|
||||
|
||||
rb1.setChecked(true);
|
||||
rb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb1.setTextColor(colorStateList);
|
||||
mType = 1;
|
||||
mDayType = 1;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb1.setTextColor(colorStateList);
|
||||
@@ -152,45 +141,50 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
});
|
||||
rb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb2.setTextColor(colorStateList);
|
||||
mType = 2;
|
||||
mDayType = 2;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb2.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
rb_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb3.setTextColor(colorStateList);
|
||||
mType = 3;
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mClockType = 1;
|
||||
et_activation.setText("用药闹钟");
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb3.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb4.setTextColor(colorStateList);
|
||||
mType = 4;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb4.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rb1.setChecked(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb_look.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mClockType = 2;
|
||||
et_activation.setText("接送闹钟");
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
rb_reserve.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mClockType = 3;
|
||||
et_activation.setText("预约闹钟");
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cl_pic.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -210,18 +204,12 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
openSelector();
|
||||
}
|
||||
});
|
||||
bt_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
iv_add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkContent();
|
||||
}
|
||||
});
|
||||
bt_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -247,7 +235,7 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
tvMenuOne.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 1;
|
||||
mDayType = 1;
|
||||
tv_type.setText("只响一次");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
@@ -255,7 +243,7 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
tvMenuTwo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 2;
|
||||
mDayType = 2;
|
||||
tv_type.setText("每天");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
@@ -263,7 +251,7 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
tvMenuThree.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 3;
|
||||
mDayType = 3;
|
||||
tv_type.setText("周一至周五");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
@@ -271,7 +259,7 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
tvMenuFour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 4;
|
||||
mDayType = 4;
|
||||
tv_type.setText("周六至周日");
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
@@ -288,7 +276,7 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
}
|
||||
}
|
||||
|
||||
LoadingDialog mLoadingDialog;
|
||||
// LoadingDialog mLoadingDialog;
|
||||
|
||||
private void checkContent() {
|
||||
|
||||
@@ -310,80 +298,83 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
MediaType mediaType = MediaType.Companion.parse("image/png");
|
||||
RequestBody requestBody = RequestBody.Companion.create(picFile, mediaType);
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("file", picFile.getName(), requestBody);
|
||||
|
||||
AlarmClockData alarmClockData = new AlarmClockData();
|
||||
alarmClockData.setFile(mPictrueFilePath);
|
||||
alarmClockData.setType(mType);
|
||||
alarmClockData.setType(mDayType);
|
||||
alarmClockData.setTime(timeStamp);
|
||||
alarmClockData.setTitle(et_activation.getText().toString());
|
||||
alarmClockData.setRemind_type(0);
|
||||
alarmClockData.setIs_onoff(1);
|
||||
alarmClockData.setClazz(mClockType);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", RemoteManager.getInstance().getSerial());
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("time", timeStamp);
|
||||
params.put("type", String.valueOf(mType));
|
||||
params.put("type", String.valueOf(mDayType));
|
||||
params.put("title", et_activation.getText().toString());
|
||||
params.put("remind_type", "0");
|
||||
params.put("is_onoff", "1");
|
||||
params.put("class", String.valueOf(mClockType));
|
||||
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.setLoadingText("正在上传")
|
||||
.setSuccessText("添加成功")
|
||||
.setFailedText("添加失败")
|
||||
.setInterceptBack(true)
|
||||
.setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
|
||||
.closeSuccessAnim()
|
||||
.show();
|
||||
// mLoadingDialog = new LoadingDialog(this);
|
||||
// mLoadingDialog.setLoadingText("正在上传")
|
||||
// .setSuccessText("添加成功")
|
||||
// .setFailedText("添加失败")
|
||||
// .setInterceptBack(true)
|
||||
// .setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
|
||||
// .closeSuccessAnim()
|
||||
// .show();
|
||||
|
||||
NetInterfaceManager.getInstance().getAlarmClockAddObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<AlarmClockId>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkContent", "onSubscribe: ");
|
||||
bt_confirm.setEnabled(false);
|
||||
}
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
int fakeId = random.nextInt(Integer.MAX_VALUE);
|
||||
Log.e(TAG, "checkContent: fakeId = " + fakeId);
|
||||
alarmClockData.setId(fakeId);
|
||||
alarmClockData.setIs_local(true);
|
||||
Log.e(TAG, "checkContent: addAlarmClock = " + AlarmUtils.getInstance().addAlarmClock(alarmClockData));
|
||||
ToastUtil.show("添加成功");
|
||||
Intent intent = new Intent(MainService.uploadAlarmClockReceiver.UPLOAD_ALARM_RECEIVER_ACTION);
|
||||
sendBroadcast(intent);
|
||||
finish();
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AlarmClockId> baseResponse) {
|
||||
Log.e("checkContent", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ToastUtil.show("添加成功");
|
||||
// int id = baseResponse.data.getId();
|
||||
// alarmClockData.setId(id);
|
||||
// AlarmUtils.getInstance().addAlarmClock(alarmClockData);
|
||||
mLoadingDialog.loadSuccess();
|
||||
mLoadingDialog.close();
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show("添加失败:" + baseResponse.msg);
|
||||
bt_confirm.setEnabled(true);
|
||||
mLoadingDialog.loadFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkContent", "onError: " + e.getMessage());
|
||||
ToastUtil.show("已保存到本地");
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
int fakeId = random.nextInt(Integer.MAX_VALUE);
|
||||
Log.e(TAG, "onError: fakeId = " + fakeId);
|
||||
alarmClockData.setId(fakeId);
|
||||
alarmClockData.setIs_local(true);
|
||||
Log.e(TAG, "onError: addAlarmClock = " + AlarmUtils.getInstance().addAlarmClock(alarmClockData));
|
||||
|
||||
onComplete();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkContent", "onComplete: ");
|
||||
mLoadingDialog.close();
|
||||
bt_confirm.setEnabled(true);
|
||||
}
|
||||
});
|
||||
// NetInterfaceManager.getInstance().getAlarmClockAddObservable(params, body)
|
||||
// .compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
// .subscribe(new Observer<BaseResponse<AlarmClockId>>() {
|
||||
// @Override
|
||||
// public void onSubscribe(@NonNull Disposable d) {
|
||||
// Log.e("addAlarmClock", "onSubscribe: ");
|
||||
// iv_add.setEnabled(false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNext(@NonNull BaseResponse<AlarmClockId> baseResponse) {
|
||||
// Log.e("addAlarmClock", "onNext: " + baseResponse);
|
||||
// if (baseResponse.code == 200) {
|
||||
// ToastUtil.show("添加成功");
|
||||
//// int id = baseResponse.data.getId();
|
||||
//// alarmClockData.setId(id);
|
||||
//// AlarmUtils.getInstance().addAlarmClock(alarmClockData);
|
||||
// finish();
|
||||
// } else {
|
||||
// ToastUtil.show("添加失败:" + baseResponse.msg);
|
||||
// iv_add.setEnabled(true);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(@NonNull Throwable e) {
|
||||
// Log.e("addAlarmClock", "onError: " + e.getMessage());
|
||||
// ToastUtil.show("已保存到本地");
|
||||
// onComplete();
|
||||
// finish();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onComplete() {
|
||||
// Log.e("addAlarmClock", "onComplete: ");
|
||||
// iv_add.setEnabled(true);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void openSelector() {
|
||||
@@ -485,7 +476,7 @@ public class AlarmClockAddActivity extends BaseLifecycleActivity {
|
||||
|
||||
private String getTime(Date date) {
|
||||
SimpleDateFormat format;
|
||||
if (mType == 1) {
|
||||
if (mDayType == 1) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
} else {
|
||||
format = new SimpleDateFormat("HH:mm");
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
package com.uiuios.aios.activity.alarmclock;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
package com.uiuios.aios.activity.alarmclock;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
@@ -9,7 +9,6 @@ import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
@@ -46,7 +45,6 @@ import com.uiuios.aios.alarm.AlarmClockData;
|
||||
import com.uiuios.aios.alarm.AlarmUtils;
|
||||
import com.uiuios.aios.base.GlideEngine;
|
||||
import com.uiuios.aios.bean.BaseResponse;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
import com.uiuios.aios.utils.FFmpegUtils;
|
||||
import com.uiuios.aios.utils.FileUtil;
|
||||
@@ -99,12 +97,6 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
NiceImageView nv_pic;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.bt_confirm)
|
||||
Button bt_confirm;
|
||||
@BindView(R.id.bt_cancel)
|
||||
Button bt_cancel;
|
||||
@BindView(R.id.tv_title)
|
||||
TextView tv_title;
|
||||
@BindView(R.id.tv_duration)
|
||||
TextView tv_duration;
|
||||
|
||||
@@ -112,10 +104,15 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
RadioButton rb1;
|
||||
@BindView(R.id.rb2)
|
||||
RadioButton rb2;
|
||||
@BindView(R.id.rb3)
|
||||
RadioButton rb3;
|
||||
@BindView(R.id.rb4)
|
||||
RadioButton rb4;
|
||||
@BindView(R.id.rb_all)
|
||||
RadioButton rb_all;
|
||||
@BindView(R.id.rb_look)
|
||||
RadioButton rb_look;
|
||||
@BindView(R.id.rb_reserve)
|
||||
RadioButton rb_reserve;
|
||||
|
||||
@BindView(R.id.iv_add)
|
||||
ImageView iv_add;
|
||||
|
||||
private PopupWindow mMenuPopupWindow;
|
||||
|
||||
@@ -124,7 +121,8 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
|
||||
private Date mDate;
|
||||
/*类型 1一次性 2每天 3周一到周五 4周六周日*/
|
||||
private int mType = 1;
|
||||
private int mDayType = 1;
|
||||
private int mClockType = 1;
|
||||
private int mId;
|
||||
private AlarmClockData mAlarmClockData;
|
||||
|
||||
@@ -187,7 +185,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_add_alarm_clock);
|
||||
setContentView(R.layout.activity_add_alarm);
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
UltimateBarX.statusBarOnly(this)
|
||||
.colorRes(R.color.default_blue)
|
||||
@@ -199,7 +197,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
|
||||
private void initView() {
|
||||
ButterKnife.bind(this);
|
||||
tv_title.setText("编辑闹钟");
|
||||
// tv_title.setText("编辑闹钟");
|
||||
initTimePicker();
|
||||
|
||||
cl_pic.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -220,18 +218,6 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
openSelector();
|
||||
}
|
||||
});
|
||||
bt_confirm.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkContent();
|
||||
}
|
||||
});
|
||||
bt_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
iv_back.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -244,7 +230,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb1.setTextColor(colorStateList);
|
||||
mType = 1;
|
||||
mDayType = 1;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb1.setTextColor(colorStateList);
|
||||
@@ -257,39 +243,50 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb2.setTextColor(colorStateList);
|
||||
mType = 2;
|
||||
mDayType = 2;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb2.setTextColor(colorStateList);
|
||||
}
|
||||
}
|
||||
});
|
||||
rb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
|
||||
rb_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb3.setTextColor(colorStateList);
|
||||
mType = 3;
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mClockType = 1;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb3.setTextColor(colorStateList);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
rb4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
rb_look.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (b) {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.white);
|
||||
rb4.setTextColor(colorStateList);
|
||||
mType = 4;
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mClockType = 2;
|
||||
} else {
|
||||
ColorStateList colorStateList = getResources().getColorStateList(R.color.radio_botton_gray);
|
||||
rb4.setTextColor(colorStateList);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
rb_reserve.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mClockType = 3;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
iv_add.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkContent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
@@ -305,38 +302,45 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
NetInterfaceManager.getInstance().getAlarmClockByIdObservable(mId)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<AlarmClockData>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAlarmClockById", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AlarmClockData> alarmClockDatabaseResponse) {
|
||||
Log.e("getAlarmClockById", "onNext: " + alarmClockDatabaseResponse);
|
||||
if (alarmClockDatabaseResponse.code == 200) {
|
||||
AlarmClockData alarmClockData = alarmClockDatabaseResponse.data;
|
||||
mAlarmClockData = alarmClockData;
|
||||
setAlarmClockInfo(alarmClockData);
|
||||
HashMap<Integer, AlarmClockData> clockDataHashMap = AlarmUtils.getInstance().getOldDataMap();
|
||||
AlarmClockData alarmClockData = clockDataHashMap.get(mId);
|
||||
if (alarmClockData == null || !alarmClockData.isIs_local()) {
|
||||
NetInterfaceManager.getInstance().getAlarmClockByIdObservable(mId)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<AlarmClockData>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("getAlarmClockById", "onSubscribe: ");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClockById", "onError: " + e.getMessage());
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldDataMap();
|
||||
mAlarmClockData = oldData.get(mId);
|
||||
setAlarmClockInfo(mAlarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse<AlarmClockData> alarmClockDatabaseResponse) {
|
||||
Log.e("getAlarmClockById", "onNext: " + alarmClockDatabaseResponse);
|
||||
if (alarmClockDatabaseResponse.code == 200) {
|
||||
AlarmClockData alarmClockData = alarmClockDatabaseResponse.data;
|
||||
mAlarmClockData = alarmClockData;
|
||||
setAlarmClockInfo(alarmClockData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAlarmClockById", "onComplete: ");
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("getAlarmClockById", "onError: " + e.getMessage());
|
||||
HashMap<Integer, AlarmClockData> oldData = AlarmUtils.getInstance().getOldDataMap();
|
||||
mAlarmClockData = oldData.get(mId);
|
||||
setAlarmClockInfo(mAlarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAlarmClockById", "onComplete: ");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mAlarmClockData = alarmClockData;
|
||||
setAlarmClockInfo(mAlarmClockData);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAlarmClockInfo(AlarmClockData alarmClockData) {
|
||||
@@ -345,24 +349,37 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "setAlarmClockInfo: " + alarmClockData);
|
||||
mType = alarmClockData.getType();
|
||||
switch (mType) {
|
||||
mDayType = alarmClockData.getType();
|
||||
switch (mDayType) {
|
||||
default:
|
||||
case AlarmUtils.ONCE:
|
||||
rb1.setChecked(true);
|
||||
tv_type.setText("只响一次");
|
||||
// tv_type.setText("只响一次");
|
||||
break;
|
||||
case AlarmUtils.LOOP:
|
||||
rb2.setChecked(true);
|
||||
tv_type.setText("每天");
|
||||
// tv_type.setText("每天");
|
||||
break;
|
||||
case AlarmUtils.WORKING_DAY:
|
||||
rb3.setChecked(true);
|
||||
tv_type.setText("周一至周五");
|
||||
// case AlarmUtils.WORKING_DAY:
|
||||
// rb3.setChecked(true);
|
||||
// tv_type.setText("周一至周五");
|
||||
// break;
|
||||
// case AlarmUtils.OFF_DAY:
|
||||
// rb4.setChecked(true);
|
||||
// tv_type.setText("周六至周日");
|
||||
// break;
|
||||
}
|
||||
mClockType = alarmClockData.getClazz();
|
||||
switch (mClockType) {
|
||||
case 1:
|
||||
default:
|
||||
rb_all.setChecked(true);
|
||||
break;
|
||||
case AlarmUtils.OFF_DAY:
|
||||
rb4.setChecked(true);
|
||||
tv_type.setText("周六至周日");
|
||||
case 2:
|
||||
rb_look.setChecked(true);
|
||||
break;
|
||||
case 3:
|
||||
rb_reserve.setChecked(true);
|
||||
break;
|
||||
}
|
||||
String time = alarmClockData.getTime();
|
||||
@@ -423,23 +440,26 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
}
|
||||
|
||||
mAlarmClockData.setId(mId);
|
||||
mAlarmClockData.setType(mType);
|
||||
mAlarmClockData.setType(mDayType);
|
||||
mAlarmClockData.setTime(timeStamp);
|
||||
mAlarmClockData.setTitle(et_activation.getText().toString());
|
||||
mAlarmClockData.setFile(mPictrueFilePath);
|
||||
mAlarmClockData.setRemind_type(0);
|
||||
mAlarmClockData.setIs_onoff(1);
|
||||
mAlarmClockData.setFinished(false);
|
||||
mAlarmClockData.setClazz(mClockType);
|
||||
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", RemoteManager.getInstance().getSerial());
|
||||
params.put("sn", Utils.getSerial());
|
||||
params.put("id", String.valueOf(mId));
|
||||
params.put("type", String.valueOf(mType));
|
||||
params.put("type", String.valueOf(mDayType));
|
||||
params.put("time", timeStamp);
|
||||
params.put("title", et_activation.getText().toString());
|
||||
params.put("remind_type", "0");
|
||||
params.put("is_onoff", "1");
|
||||
params.put("class", String.valueOf(mClockType));
|
||||
|
||||
|
||||
mLoadingDialog = new LoadingDialog(this);
|
||||
mLoadingDialog.setLoadingText("正在上传")
|
||||
@@ -450,48 +470,57 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
.closeSuccessAnim()
|
||||
.show();
|
||||
|
||||
NetInterfaceManager.getInstance().getAlarmClockEditObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkContent", "onSubscribe: ");
|
||||
ToastUtil.show("正在上传");
|
||||
bt_confirm.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("checkContent", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ToastUtil.show("编辑成功");
|
||||
mLoadingDialog.loadSuccess();
|
||||
mLoadingDialog.close();
|
||||
mAlarmClockData.setEdited(false);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show("编辑失败:" + baseResponse.msg);
|
||||
mLoadingDialog.loadFailed();
|
||||
if (mAlarmClockData.isIs_local()) {
|
||||
ToastUtil.show("编辑成功");
|
||||
mLoadingDialog.loadSuccess();
|
||||
mLoadingDialog.close();
|
||||
mAlarmClockData.setEdited(false);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
finish();
|
||||
} else {
|
||||
NetInterfaceManager.getInstance().getAlarmClockEditObservable(params, body)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("checkContent", "onSubscribe: ");
|
||||
ToastUtil.show("正在上传");
|
||||
iv_add.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkContent", "onError: " + e.getMessage());
|
||||
mAlarmClockData.setEdited(true);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e("checkContent", "onNext: " + baseResponse);
|
||||
if (baseResponse.code == 200) {
|
||||
ToastUtil.show("编辑成功");
|
||||
mLoadingDialog.loadSuccess();
|
||||
mLoadingDialog.close();
|
||||
mAlarmClockData.setEdited(false);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
finish();
|
||||
} else {
|
||||
ToastUtil.show("编辑失败:" + baseResponse.msg);
|
||||
mLoadingDialog.loadFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkContent", "onComplete: ");
|
||||
bt_confirm.setEnabled(true);
|
||||
finish();
|
||||
mLoadingDialog.close();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("checkContent", "onError: " + e.getMessage());
|
||||
mAlarmClockData.setEdited(true);
|
||||
AlarmUtils.getInstance().updateAlarmClock(mAlarmClockData);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("checkContent", "onComplete: ");
|
||||
iv_add.setEnabled(true);
|
||||
finish();
|
||||
mLoadingDialog.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -507,7 +536,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
tvMenuOne.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 1;
|
||||
mDayType = 1;
|
||||
tv_type.setText("只响一次");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
@@ -515,7 +544,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
tvMenuTwo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 2;
|
||||
mDayType = 2;
|
||||
tv_type.setText("每天");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
@@ -523,7 +552,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
tvMenuThree.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 3;
|
||||
mDayType = 3;
|
||||
tv_type.setText("周一至周五");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
@@ -531,7 +560,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
tvMenuFour.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mType = 4;
|
||||
mDayType = 4;
|
||||
tv_type.setText("周六至周日");
|
||||
mMenuPopupWindow.dismiss();
|
||||
}
|
||||
@@ -612,7 +641,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
startDate.set(2013, 0, 23);
|
||||
|
||||
Calendar endDate = Calendar.getInstance();
|
||||
endDate.set(2019, 11, 28);
|
||||
endDate.set(2099, 11, 28);
|
||||
|
||||
//时间选择器
|
||||
pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
|
||||
@@ -647,7 +676,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
|
||||
private String getTime(Date date) {
|
||||
SimpleDateFormat format;
|
||||
if (mType == 1) {
|
||||
if (mDayType == 1) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
} else {
|
||||
format = new SimpleDateFormat("HH:mm");
|
||||
@@ -658,7 +687,7 @@ public class AlarmClockEditActivity extends AppCompatActivity implements Lifecyc
|
||||
private Calendar getTime(String timeString) {
|
||||
SimpleDateFormat sdf;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
if (mType == 1) {
|
||||
if (mDayType == 1) {
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
} else {
|
||||
sdf = new SimpleDateFormat("HH:mm");
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.uiuios.aios.activity.alarm;
|
||||
package com.uiuios.aios.activity.alarmclock;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package com.uiuios.aios.activity.location;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.adapter.CityAdapter;
|
||||
import com.uiuios.aios.adapter.DistrictAdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.AddressBean;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.view.RecyclerViewSpacesItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class LocationAcivity extends BaseActivity implements LocationContact.LocationView, CityAdapter.CityCallback, DistrictAdapter.DistrictCallback {
|
||||
|
||||
@BindView(R.id.bg)
|
||||
ConstraintLayout bg;
|
||||
@BindView(R.id.root)
|
||||
ConstraintLayout root;
|
||||
@BindView(R.id.rv_area)
|
||||
RecyclerView rv_area;
|
||||
|
||||
@BindView(R.id.edit_search)
|
||||
EditText edit_search;
|
||||
@BindView(R.id.rv_city)
|
||||
RecyclerView rv_city;
|
||||
@BindView(R.id.cl_location)
|
||||
ConstraintLayout cl_location;
|
||||
|
||||
private List<AddressBean> popularCities = new ArrayList<AddressBean>() {{
|
||||
this.add(new AddressBean("北京"));
|
||||
this.add(new AddressBean("上海"));
|
||||
this.add(new AddressBean("深圳"));
|
||||
this.add(new AddressBean("广州"));
|
||||
this.add(new AddressBean("武汉"));
|
||||
this.add(new AddressBean("长沙"));
|
||||
this.add(new AddressBean("南京"));
|
||||
this.add(new AddressBean("苏州"));
|
||||
this.add(new AddressBean("西安"));
|
||||
this.add(new AddressBean("济南"));
|
||||
this.add(new AddressBean("青岛"));
|
||||
this.add(new AddressBean("沈阳"));
|
||||
this.add(new AddressBean("重庆"));
|
||||
this.add(new AddressBean("郑州"));
|
||||
this.add(new AddressBean("成都"));
|
||||
this.add(new AddressBean("杭州"));
|
||||
this.add(new AddressBean("厦门"));
|
||||
}};
|
||||
|
||||
private LocationPresenter mPresenter;
|
||||
private CityAdapter mCityAdapter;
|
||||
private DistrictAdapter mDistrictAdapter;
|
||||
|
||||
private List<AddressBean> mDistrict;
|
||||
private AddressBean mAddressBean;
|
||||
|
||||
/**
|
||||
* 设置布局
|
||||
*/
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.activity_location;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化视图
|
||||
*/
|
||||
@Override
|
||||
public void initView() {
|
||||
ButterKnife.bind(this);
|
||||
mPresenter = new LocationPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
bg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
rv_area.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
cl_location.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mAddressBean = new AddressBean(RemoteManager.getInstance().getDistrict());
|
||||
setIntent();
|
||||
}
|
||||
});
|
||||
edit_search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
|
||||
edit_search.setInputType(EditorInfo.TYPE_CLASS_TEXT);
|
||||
edit_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND ||
|
||||
(event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
|
||||
switch (event.getAction()) {
|
||||
case KeyEvent.ACTION_UP:
|
||||
//do it
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
|
||||
//do something;
|
||||
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
|
||||
.hideSoftInputFromWindow(LocationAcivity.this.getCurrentFocus()
|
||||
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
String text = edit_search.getText().toString();
|
||||
checkContent(text);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkContent(String text) {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
rv_area.setVisibility(View.GONE);
|
||||
} else {
|
||||
rv_area.setVisibility(View.VISIBLE);
|
||||
List<AddressBean> area = mDistrict.stream().filter(new Predicate<AddressBean>() {
|
||||
@Override
|
||||
public boolean test(AddressBean addressBean) {
|
||||
return addressBean.toString().contains(text);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
mDistrictAdapter.setDistrict(area);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据
|
||||
*/
|
||||
@Override
|
||||
public void initData() {
|
||||
HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
|
||||
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getRealMetrics(dm);
|
||||
float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.TOP_DECORATION, (int) (density * 4));//top间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, (int) (density * 4));//底部间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.LEFT_DECORATION, (int) (density * 30));//左间距
|
||||
stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.RIGHT_DECORATION, (int) (density * 30));//右间距
|
||||
rv_city.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
|
||||
mCityAdapter = new CityAdapter();
|
||||
mCityAdapter.setCityList(popularCities);
|
||||
mCityAdapter.setCityCallback(this::onCitySelected);
|
||||
rv_city.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
rv_city.setAdapter(mCityAdapter);
|
||||
|
||||
mDistrictAdapter = new DistrictAdapter();
|
||||
mDistrictAdapter.setDistrictCallback(this::onDistrictSelected);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
rv_area.setLayoutManager(linearLayoutManager);
|
||||
rv_area.setAdapter(mDistrictAdapter);
|
||||
|
||||
mPresenter.initJsonData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPresenter.detachView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJsonData(List<AddressBean> area) {
|
||||
this.mDistrict = area;
|
||||
mDistrictAdapter.setDistrict(area);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDistrictSelected(AddressBean addressBean) {
|
||||
mAddressBean = addressBean;
|
||||
setIntent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCitySelected(AddressBean addressBean) {
|
||||
mAddressBean = addressBean;
|
||||
setIntent();
|
||||
}
|
||||
|
||||
private void setIntent() {
|
||||
Intent intent = new Intent();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("address", mAddressBean.toString());
|
||||
bundle.putString("district", mAddressBean.getDistrict());
|
||||
intent.putExtras(bundle);
|
||||
// 携带意图返回上一个页面 RESULT_OK代表处理成功了
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
// 结束当前页面
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.uiuios.aios.activity.location;
|
||||
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.AddressBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LocationContact {
|
||||
interface Presenter extends BasePresenter<LocationView> {
|
||||
void initJsonData();
|
||||
}
|
||||
|
||||
public interface LocationView extends BaseView {
|
||||
void setJsonData(List<AddressBean> area);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.uiuios.aios.activity.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.AddressBean;
|
||||
import com.uiuios.aios.bean.JsonBean;
|
||||
import com.uiuios.aios.gson.GetJsonDataUtil;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.ObservableEmitter;
|
||||
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
public class LocationPresenter implements LocationContact.Presenter {
|
||||
private Context mContext;
|
||||
|
||||
|
||||
LocationPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
private LocationContact.LocationView mView;
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(LocationContact.LocationView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initJsonData() {
|
||||
long time = System.currentTimeMillis();
|
||||
Observable.create(new ObservableOnSubscribe<List<AddressBean>>() {
|
||||
@Override
|
||||
public void subscribe(@NonNull ObservableEmitter<List<AddressBean>> emitter) throws Throwable {
|
||||
List<AddressBean> areaList = new ArrayList<>();
|
||||
String JsonData = new GetJsonDataUtil().getJson(mContext, "province.json");//获取assets目录下的json文件数据
|
||||
ArrayList<JsonBean> jsonBeanList = parseData(JsonData);//用Gson 转成实体
|
||||
for (JsonBean jsonBean : jsonBeanList) {//遍历省份
|
||||
String province = jsonBean.getName();
|
||||
for (JsonBean.CityBean cityBean : jsonBean.getCityList()) {//遍历该省份的所有城市
|
||||
String city = cityBean.getName();
|
||||
for (String district : cityBean.getArea()) {//遍历该省份的所有城市
|
||||
areaList.add(new AddressBean(province , city , district));
|
||||
}
|
||||
}
|
||||
}
|
||||
emitter.onNext(areaList);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<List<AddressBean>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("initJsonData", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(List<AddressBean> s) {
|
||||
Log.e("initJsonData", "onNext: ");
|
||||
Log.e("initJsonData", "initdatetime = " + (System.currentTimeMillis() - time) + "ms");
|
||||
mView.setJsonData(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("initJsonData", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("initJsonData", "onComplete: ");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<JsonBean> parseData(String result) {//Gson 解析
|
||||
ArrayList<JsonBean> detail = new ArrayList<>();
|
||||
try {
|
||||
JSONArray data = new JSONArray(result);
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
|
||||
detail.add(entity);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
@@ -81,11 +81,11 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
private ControlFragment mControlFragment;
|
||||
private HomeFragment mHomeFragment;
|
||||
// private CustomFragment mCustomFragment;
|
||||
// private SecondFragment mSecondFragment;
|
||||
private SecondFragment mSecondFragment;
|
||||
|
||||
private boolean is_twoscreen = false;
|
||||
private int appListIndex = 2;
|
||||
private int defaultCurrent = 1;
|
||||
private int appListIndex = 3;
|
||||
private int defaultCurrent = 2;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -111,18 +111,18 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
mBaseFragmentPagerAdapter = new BaseFragmentPagerAdapter(mFragmentManager, mFragments);
|
||||
// fragmentTransaction.add(R.id.viewPager, appListFragment);
|
||||
// fragmentTransaction.commit();
|
||||
|
||||
mControlFragment =new ControlFragment();
|
||||
mFragments.add(mControlFragment);
|
||||
// is_twoscreen = Settings.Global.getInt(getContentResolver(), "is_twoscreen", 1) == 1;
|
||||
// if (is_twoscreen) {
|
||||
// appListIndex = 2;
|
||||
// defaultCurrent = 1;
|
||||
// mSecondFragment = new SecondFragment();
|
||||
// mFragments.add(mSecondFragment);
|
||||
mSecondFragment = new SecondFragment();
|
||||
mFragments.add(mSecondFragment);
|
||||
// }
|
||||
// mCustomFragment = new CustomFragment();
|
||||
// mFragments.add(mCustomFragment);
|
||||
mControlFragment =new ControlFragment();
|
||||
mFragments.add(mControlFragment);
|
||||
|
||||
mHomeFragment =new HomeFragment();
|
||||
mFragments.add(mHomeFragment);
|
||||
|
||||
@@ -155,7 +155,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
});
|
||||
|
||||
mViewPager.setAdapter(mBaseFragmentPagerAdapter);
|
||||
mViewPager.setOffscreenPageLimit(2);
|
||||
mViewPager.setOffscreenPageLimit(3);
|
||||
mMagicIndicator.setNavigator(scaleCircleNavigator);
|
||||
ViewPagerHelper.bind(mMagicIndicator, mViewPager);
|
||||
if (mFragments.size() > 1) {
|
||||
@@ -380,6 +380,8 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
||||
Permission.WRITE_EXTERNAL_STORAGE,
|
||||
Permission.READ_PHONE_STATE,
|
||||
Permission.WRITE_SETTINGS,
|
||||
Permission.READ_CALL_LOG,
|
||||
Permission.WRITE_CALL_LOG,
|
||||
};
|
||||
|
||||
private void getPermission() {
|
||||
|
||||
@@ -1,33 +1,88 @@
|
||||
package com.uiuios.aios.activity.weather;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
||||
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
|
||||
import com.bigkoo.pickerview.view.OptionsPickerView;
|
||||
import com.google.gson.Gson;
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuios.aios.R;
|
||||
import com.uiuios.aios.activity.location.LocationAcivity;
|
||||
import com.uiuios.aios.adapter.WeatherDayApdapter;
|
||||
import com.uiuios.aios.base.BaseActivity;
|
||||
import com.uiuios.aios.bean.JsonBean;
|
||||
import com.uiuios.aios.bean.MapGeoResult;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.gson.GetJsonDataUtil;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.utils.ToastUtil;
|
||||
import com.uiuios.aios.view.HorizontalItemDecoration;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class WeatherActivity extends BaseActivity implements WeatherContact.WeatherView {
|
||||
private static final String TAG = WeatherActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.rv_weather)
|
||||
RecyclerView rv_weather;
|
||||
@BindView(R.id.tv_location)
|
||||
TextView tv_location;
|
||||
@BindView(R.id.iv_back)
|
||||
ImageView iv_back;
|
||||
@BindView(R.id.tv_refresh)
|
||||
TextView tv_refresh;
|
||||
|
||||
private WeatherPresenter mPresenter;
|
||||
private WeatherDayApdapter mWeatherDayApdapter;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private List<JsonBean> options1Items = new ArrayList<>();
|
||||
private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
|
||||
private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();
|
||||
private Thread thread;
|
||||
private static final int MSG_LOAD_DATA = 0x0001;
|
||||
private static final int MSG_LOAD_SUCCESS = 0x0002;
|
||||
private static final int MSG_LOAD_FAILED = 0x0003;
|
||||
private static boolean isLoaded = false;
|
||||
|
||||
|
||||
private String mProvince;
|
||||
private String mCity;
|
||||
private String mDistrict;
|
||||
|
||||
private ActivityResultLauncher<Intent> register;
|
||||
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -40,6 +95,7 @@ public class WeatherActivity extends BaseActivity implements WeatherContact.Weat
|
||||
mPresenter = new WeatherPresenter(this);
|
||||
mPresenter.attachView(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
RemoteManager.getInstance().getLocation();
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
|
||||
Resources resources = getResources();
|
||||
if (resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
@@ -59,16 +115,120 @@ public class WeatherActivity extends BaseActivity implements WeatherContact.Weat
|
||||
finish();
|
||||
}
|
||||
});
|
||||
tv_refresh.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String district = mMMKV.decodeString(CommonConfig.MANUALLY_SELECT_LOCATION_DISTRICT, "");
|
||||
String tude = mMMKV.decodeString(CommonConfig.MANUALLY_SELECT_LOCATION_TUDE, "");
|
||||
if (TextUtils.isEmpty(tude)) {
|
||||
mPresenter.getLocation();
|
||||
} else {
|
||||
tv_location.setText(district);
|
||||
mPresenter.getWeather(tude);
|
||||
}
|
||||
ToastUtil.show("刷新成功");
|
||||
}
|
||||
});
|
||||
tv_location.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
hideSoftKeyBoard(v);
|
||||
if (!isLoaded) {
|
||||
ToastUtil.show("位置数据没有加载完成");
|
||||
} else {
|
||||
// showPickerView();
|
||||
register.launch(new Intent(WeatherActivity.this, LocationAcivity.class));
|
||||
}
|
||||
}
|
||||
});
|
||||
register = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
|
||||
@Override
|
||||
public void onActivityResult(ActivityResult result) {
|
||||
Log.e(TAG, "onActivityResult: " + result);
|
||||
if (result != null) {
|
||||
Intent intent = result.getData();
|
||||
if (intent != null && result.getResultCode() == Activity.RESULT_OK) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
Log.e(TAG, "onActivityResult: " + bundle);
|
||||
String address = bundle.getString("address");
|
||||
mDistrict = bundle.getString("district");
|
||||
mMMKV.encode(CommonConfig.MANUALLY_SELECT_LOCATION_ADDRESS, address);
|
||||
mMMKV.encode(CommonConfig.MANUALLY_SELECT_LOCATION_DISTRICT, mDistrict);
|
||||
mPresenter.decodeGeo(address);
|
||||
tv_location.setText(mDistrict);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showPickerView() {// 弹出选择器
|
||||
OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
|
||||
@Override
|
||||
public void onOptionsSelect(int options1, int options2, int options3, View v) {
|
||||
//返回的分别是三个级别的选中位置
|
||||
mProvince = options1Items.size() > 0 ?
|
||||
options1Items.get(options1).getPickerViewText() : "";
|
||||
|
||||
mCity = options2Items.size() > 0
|
||||
&& options2Items.get(options1).size() > 0 ?
|
||||
options2Items.get(options1).get(options2) : "";
|
||||
|
||||
mDistrict = options2Items.size() > 0
|
||||
&& options3Items.get(options1).size() > 0
|
||||
&& options3Items.get(options1).get(options2).size() > 0 ?
|
||||
options3Items.get(options1).get(options2).get(options3) : "";
|
||||
|
||||
String address = mProvince + mCity + mDistrict;
|
||||
Log.e(TAG, "onOptionsSelect: " + address);
|
||||
tv_location.setText(mDistrict);
|
||||
mMMKV.encode(CommonConfig.MANUALLY_SELECT_LOCATION_ADDRESS, address);
|
||||
mMMKV.encode(CommonConfig.MANUALLY_SELECT_LOCATION_DISTRICT, mDistrict);
|
||||
mPresenter.decodeGeo(address);
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
.setTitleText("城市选择")
|
||||
.setDividerColor(Color.BLACK)
|
||||
.setTextColorCenter(Color.BLACK) //设置选中项文字颜色
|
||||
.setContentTextSize(20)
|
||||
.setLineSpacingMultiplier(2.5f)
|
||||
.build();
|
||||
|
||||
// pvOptions.setPicker(options1Items);//一级选择器
|
||||
// pvOptions.setPicker(options1Items, options2Items);//二级选择器
|
||||
pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
|
||||
pvOptions.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData() {
|
||||
mPresenter.getLocation();
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_DATA);
|
||||
String district = mMMKV.decodeString(CommonConfig.MANUALLY_SELECT_LOCATION_DISTRICT, "");
|
||||
String tude = mMMKV.decodeString(CommonConfig.MANUALLY_SELECT_LOCATION_TUDE, "");
|
||||
if (TextUtils.isEmpty(tude)) {
|
||||
mPresenter.getLocation();
|
||||
} else {
|
||||
tv_location.setText(district);
|
||||
mPresenter.getWeather(tude);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGeo(MapGeoResult mapGeoresult) {
|
||||
if (mapGeoresult != null) {
|
||||
mMMKV.encode(CommonConfig.MANUALLY_SELECT_LOCATION_TUDE, mapGeoresult.getLocation().toString());
|
||||
mPresenter.getWeather(mapGeoresult.getLocation().toString());
|
||||
} else {
|
||||
ToastUtil.show("获取位置信息失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocation(String location) {
|
||||
tv_location.setText(location);
|
||||
ToastUtil.show("刷新成功");
|
||||
mPresenter.getWeatherCache();
|
||||
}
|
||||
|
||||
@@ -77,8 +237,7 @@ public class WeatherActivity extends BaseActivity implements WeatherContact.Weat
|
||||
if (weatherCache != null) {
|
||||
mWeatherDayApdapter.setDailyBeans(weatherCache.getDaily());
|
||||
}
|
||||
mPresenter.getWeather();
|
||||
|
||||
mPresenter.getWeather(RemoteManager.getInstance().getLocationTude());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,4 +262,113 @@ public class WeatherActivity extends BaseActivity implements WeatherContact.Weat
|
||||
super.onDestroy();
|
||||
mPresenter.detachView();
|
||||
}
|
||||
|
||||
private void hideSoftKeyBoard(View view) {
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_LOAD_DATA:
|
||||
if (thread == null) {//如果已创建就不再重新创建子线程了
|
||||
Log.e(TAG, "handleMessage: Begin Parse Data");
|
||||
thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 子线程中解析省市区数据
|
||||
initJsonData();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
break;
|
||||
|
||||
case MSG_LOAD_SUCCESS:
|
||||
Log.e(TAG, "handleMessage: Parse Succeed");
|
||||
isLoaded = true;
|
||||
break;
|
||||
|
||||
case MSG_LOAD_FAILED:
|
||||
Log.e(TAG, "handleMessage: Parse Failed");
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private void initJsonData() {//解析数据
|
||||
|
||||
/**
|
||||
* 注意:assets 目录下的Json文件仅供参考,实际使用可自行替换文件
|
||||
* 关键逻辑在于循环体
|
||||
*
|
||||
* */
|
||||
String JsonData = new GetJsonDataUtil().getJson(this, "province.json");//获取assets目录下的json文件数据
|
||||
|
||||
ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 转成实体
|
||||
|
||||
/**
|
||||
* 添加省份数据
|
||||
*
|
||||
* 注意:如果是添加的JavaBean实体,则实体类需要实现 IPickerViewData 接口,
|
||||
* PickerView会通过getPickerViewText方法获取字符串显示出来。
|
||||
*/
|
||||
options1Items = jsonBean;
|
||||
|
||||
for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
|
||||
ArrayList<String> cityList = new ArrayList<>();//该省的城市列表(第二级)
|
||||
ArrayList<ArrayList<String>> province_AreaList = new ArrayList<>();//该省的所有地区列表(第三极)
|
||||
|
||||
for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
|
||||
String cityName = jsonBean.get(i).getCityList().get(c).getName();
|
||||
cityList.add(cityName);//添加城市
|
||||
ArrayList<String> city_AreaList = new ArrayList<>();//该城市的所有地区列表
|
||||
|
||||
//如果无地区数据,建议添加空字符串,防止数据为null 导致三个选项长度不匹配造成崩溃
|
||||
/*if (jsonBean.get(i).getCityList().get(c).getArea() == null
|
||||
|| jsonBean.get(i).getCityList().get(c).getArea().size() == 0) {
|
||||
city_AreaList.add("");
|
||||
} else {
|
||||
city_AreaList.addAll(jsonBean.get(i).getCityList().get(c).getArea());
|
||||
}*/
|
||||
city_AreaList.addAll(jsonBean.get(i).getCityList().get(c).getArea());
|
||||
province_AreaList.add(city_AreaList);//添加该省所有地区数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加城市数据
|
||||
*/
|
||||
options2Items.add(cityList);
|
||||
|
||||
/**
|
||||
* 添加地区数据
|
||||
*/
|
||||
options3Items.add(province_AreaList);
|
||||
}
|
||||
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);
|
||||
}
|
||||
|
||||
public ArrayList<JsonBean> parseData(String result) {//Gson 解析
|
||||
ArrayList<JsonBean> detail = new ArrayList<>();
|
||||
try {
|
||||
JSONArray data = new JSONArray(result);
|
||||
Gson gson = new Gson();
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
|
||||
detail.add(entity);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_FAILED);
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,24 +3,26 @@ package com.uiuios.aios.activity.weather;
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.uiuios.aios.base.BasePresenter;
|
||||
import com.uiuios.aios.base.BaseView;
|
||||
import com.uiuios.aios.bean.MapGeoResult;
|
||||
|
||||
public class WeatherContact {
|
||||
public interface Presenter extends BasePresenter<WeatherView> {
|
||||
void decodeGeo(String address);
|
||||
//获取定位缓存
|
||||
void getLocation();
|
||||
//获取天气缓存
|
||||
void getWeatherCache();
|
||||
//获取天气
|
||||
void getWeather();
|
||||
void getWeather(String locationTude);
|
||||
}
|
||||
|
||||
public interface WeatherView extends BaseView {
|
||||
void setGeo(MapGeoResult mapGeoresult);
|
||||
//设置定位缓存
|
||||
void setLocation(String location);
|
||||
//设置天气缓存
|
||||
void setWeatherCache(WeatherDailyBean weatherCache);
|
||||
//设置天气
|
||||
void setWeather(WeatherDailyBean weather);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,23 @@ package com.uiuios.aios.activity.weather;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.qweather.sdk.bean.weather.WeatherDailyBean;
|
||||
import com.qweather.sdk.view.QWeather;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiuios.aios.bean.MapGeoBean;
|
||||
import com.uiuios.aios.config.CommonConfig;
|
||||
import com.uiuios.aios.manager.RemoteManager;
|
||||
import com.uiuios.aios.network.NetInterfaceManager;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
/**
|
||||
@@ -40,7 +44,7 @@ public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
public WeatherPresenter(Context context) {
|
||||
WeatherPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
Log.e(TAG, "WeatherPresenter: " + context.getClass());
|
||||
}
|
||||
@@ -56,9 +60,45 @@ public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void decodeGeo(String address) {
|
||||
Log.e(TAG, "decodeGeo: " + address);
|
||||
NetInterfaceManager.getInstance().getGeoObservable(address)
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<MapGeoBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e("decodeGeo", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull MapGeoBean mapGeoBean) {
|
||||
Log.e("decodeGeo", "onNext: " + mapGeoBean);
|
||||
if (mapGeoBean.getStatus() == 0) {
|
||||
mView.setGeo(mapGeoBean.getResult());
|
||||
} else {
|
||||
mView.setGeo(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e("decodeGeo", "onError: " + e.getMessage());
|
||||
mView.setGeo(null);
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("decodeGeo", "onComplete: ");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getLocation() {
|
||||
String location = RemoteManager.getInstance().getCityDistrict();
|
||||
String location = RemoteManager.getInstance().getDistrict();
|
||||
mView.setLocation(location);
|
||||
}
|
||||
|
||||
@@ -73,8 +113,8 @@ public class WeatherPresenter implements WeatherContact.Presenter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getWeather() {
|
||||
QWeather.getWeather7D(mContext, RemoteManager.getInstance().getLocationTude(), new QWeather.OnResultWeatherDailyListener() {
|
||||
public void getWeather(String locationTude) {
|
||||
QWeather.getWeather7D(mContext, locationTude, new QWeather.OnResultWeatherDailyListener() {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
Log.e("getWeather", "onError: " + throwable.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user