diff --git a/common/build.gradle b/common/build.gradle index b9ff40117..bcd252188 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -221,5 +221,8 @@ dependencies { //samsung插件包 api project(':IAP6Helper') + //時間選擇器 + api 'com.contrarywind:Android-PickerView:4.1.9' + } diff --git a/common/src/main/java/com/yunbao/common/bean/AvatarBean.java b/common/src/main/java/com/yunbao/common/bean/AvatarBean.java new file mode 100644 index 000000000..2fec7a998 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/AvatarBean.java @@ -0,0 +1,25 @@ +package com.yunbao.common.bean; + +public class AvatarBean extends BaseModel { + private String avatar; + private String avatarThumb; + + public AvatarBean() { + } + + public String getAvatar() { + return avatar; + } + + public void setAvatar(String avatar) { + this.avatar = avatar; + } + + public String getAvatarThumb() { + return avatarThumb; + } + + public void setAvatarThumb(String avatarThumb) { + this.avatarThumb = avatarThumb; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/MessageHiBean.java b/common/src/main/java/com/yunbao/common/bean/MessageHiBean.java new file mode 100644 index 000000000..88b158272 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/MessageHiBean.java @@ -0,0 +1,101 @@ +package com.yunbao.common.bean; + +import java.util.Date; + +public class MessageHiBean extends BaseModel { + public static final int TYPE_TEXT = 1; + public static final int TYPE_IMAGE = 2; + public static final int TYPE_AUDIO = 3; + private int id; + private int uid; + private String content; + private int duration; + private String base64; + private int type; + private long createTime; + private long updateTime; + private int status; + + // Getter方法 + public int getId() { + return id; + } + + public int getUid() { + return uid; + } + + public String getContent() { + return content; + } + + public int getDuration() { + return duration; + } + + public String getBase64() { + return base64; + } + + public int getType() { + return type; + } + + public long getCreateTime() { + return createTime; + } + + public long getUpdateTime() { + return updateTime; + } + + public int getStatus() { + return status; + } + + // Setter方法 + public void setId(int id) { + this.id = id; + } + + public void setUid(int uid) { + this.uid = uid; + } + + public void setContent(String content) { + this.content = content; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public void setBase64(String base64) { + this.base64 = base64; + } + + public void setType(int type) { + this.type = type; + } + + public void setCreateTime(long createTime) { + this.createTime = createTime; + } + + public void setUpdateTime(long updateTime) { + this.updateTime = updateTime; + } + + public void setStatus(int status) { + this.status = status; + } + + // 转换时间戳为Date(可选) + public Date getCreateTimeAsDate() { + return new Date(createTime * 1000); // 假设时间戳是秒单位 + } + + public Date getUpdateTimeAsDate() { + return new Date(updateTime * 1000); // 假设时间戳是秒单位 + } +} \ No newline at end of file diff --git a/common/src/main/java/com/yunbao/common/bean/MessageUserInfoBean.java b/common/src/main/java/com/yunbao/common/bean/MessageUserInfoBean.java index aded44ad0..b721ed934 100644 --- a/common/src/main/java/com/yunbao/common/bean/MessageUserInfoBean.java +++ b/common/src/main/java/com/yunbao/common/bean/MessageUserInfoBean.java @@ -86,6 +86,12 @@ public class MessageUserInfoBean extends BaseModel{ private String career; private String height; private String age; + @SerializedName("open_off") + private int openOff;//接单设置 1开启 2关闭 + + public int getOpenOff() { + return openOff; + } public String getAge() { if(StringUtil.isEmpty(age)){ diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index befe71ff6..843876693 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.yunbao.common.bean.ActiveModel; import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.AnchorRecommendModel; +import com.yunbao.common.bean.AvatarBean; import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.BattlePassPoints; import com.yunbao.common.bean.BattlePassTask; @@ -45,6 +46,7 @@ import com.yunbao.common.bean.LiveUserMailBoxModel; import com.yunbao.common.bean.MedalAchievementModel; import com.yunbao.common.bean.MessageChatIsAnchor; import com.yunbao.common.bean.MessageChatUserBean; +import com.yunbao.common.bean.MessageHiBean; import com.yunbao.common.bean.MessageUserInfoBean; import com.yunbao.common.bean.MsgSwitchDetailModel; import com.yunbao.common.bean.NewPeopleInfo; @@ -81,10 +83,14 @@ import java.util.List; import java.util.Map; import io.reactivex.Observable; +import okhttp3.MultipartBody; +import retrofit2.http.Body; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; +import retrofit2.http.Multipart; import retrofit2.http.POST; +import retrofit2.http.Part; import retrofit2.http.Query; import retrofit2.http.QueryMap; @@ -1169,17 +1175,68 @@ public interface PDLiveApi { @GET("/api/public/?service=Pdluser.friend") Observable>> getPdluserFriend(@Query("p") int p); + @GET("/api/public/?service=Pdluser.follow") Observable>> getPdluserFollow(@Query("p") int p); + @GET("/api/public/?service=Pdluser.fans") Observable>> getPdluserFans(@Query("p") int p); + @GET("/api/public/?service=Pdluser.search") Observable>> addressBookSearch(@Query("user_nicename") String key); + @GET("/api/public/?service=Pdlinfos.getOtherInfo") Observable> getOtherInfo(@Query("tuid") String tuid); + @GET("/api/public/?service=Userhome.getUserHomeBanner") Observable>> getUserHomeBanner(@Query("select_uid") String tuid); + @GET("/api/public/?service=Pdlinfos.getIsAnchor") Observable> getIsAnchor(); + @GET("/api/public/?service=Pdlinfos.getText") + Observable>> getHiConfig(); + + @POST("/api/public/?service=Pdlinfos.addText") + Observable>> setHiConfig( + @Body JSONObject content, + @Query("uid")String uid, + @Query("token")String token + ); + + @GET("/api/public/?service=Pdlinfos.editText") + Observable>> updateHiConfig( + @Query("id") int id, + @Query("content") String content, + @Query("type") int type, + @Query("duration") int duration, + @Query("status") int status + ); + + @GET("/api/public/?service=Pdlinfos.delText") + Observable>> delHiConfig( + @Query("id") int id + ); + @Multipart + @POST("/api/public/?service=Friendappinfos.updateAvatar") + Observable> updateFile(@Part MultipartBody.Part file, @Query("uid") String uid, @Query("token") String token); + @Multipart + @POST("/api/public/?service=Pdlinfos.updateMp3") + Observable> updateFileToMp3(@Part MultipartBody.Part file, @Query("uid") String uid, @Query("token") String token); + @GET("/api/public/?service=Pdlinfos.setInfo") + Observable>> initUserInfo( + @Query("sex") int sex, + @Query("user_nicename") String user_nicename, + @Query("avatar") String avatar, + @Query("birthday") String birthday + ); + + /** + * 接单设置 + * @param status 1开启 2关闭 + */ + @GET("/api/public/?service=Pdlinfos.setOpenOff") + Observable>> setOpenOff( + @Query("open_off") int status + ); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index f0f4a8bfb..06bcd4d1c 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -4,9 +4,12 @@ import android.content.Context; import android.text.TextUtils; import android.util.Log; +import com.alibaba.fastjson.JSONObject; +import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.R; import com.yunbao.common.bean.ActiveModel; +import com.yunbao.common.bean.AvatarBean; import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.BattlePassPoints; import com.yunbao.common.bean.BattlePassTask; @@ -28,6 +31,7 @@ import com.yunbao.common.bean.GiftNamingInfoModel; import com.yunbao.common.bean.GiftWallGiftDetail; import com.yunbao.common.bean.GiftWallModel; import com.yunbao.common.bean.HttpCallbackModel; +import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LinkMicUserBean; import com.yunbao.common.bean.LinkMicUserBeanV2; import com.yunbao.common.bean.ListInfoMessageModel; @@ -45,6 +49,7 @@ import com.yunbao.common.bean.LiveUserMailBoxModel; import com.yunbao.common.bean.MedalAchievementModel; import com.yunbao.common.bean.MessageChatIsAnchor; import com.yunbao.common.bean.MessageChatUserBean; +import com.yunbao.common.bean.MessageHiBean; import com.yunbao.common.bean.MessageUserInfoBean; import com.yunbao.common.bean.NobleRankHideUserListModel; import com.yunbao.common.bean.NobleTrumpetModel; @@ -76,8 +81,10 @@ import com.yunbao.common.http.API; import com.yunbao.common.http.ResponseModel; import com.yunbao.common.http.base.CheckLiveCallBack; import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.WordUtil; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -87,6 +94,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.RequestBody; +import retrofit2.http.Query; /** @@ -2774,7 +2785,7 @@ public class LiveNetManager { }).isDisposed(); } - public void addChatCount(String stream,HttpCallback callback) { + public void addChatCount(String stream, HttpCallback callback) { API.get().pdLiveApi(mContext) .addChatCount(stream) .subscribeOn(Schedulers.io()) @@ -2934,7 +2945,8 @@ public class LiveNetManager { }).isDisposed(); } - public void getPdluserFriend(int p,HttpCallback> callback) { + + public void getPdluserFriend(int p, HttpCallback> callback) { API.get().pdLiveApi(mContext) .getPdluserFriend(p) .subscribeOn(Schedulers.io()) @@ -2953,7 +2965,8 @@ public class LiveNetManager { } }).isDisposed(); } - public void getPdluserFollow(int p,HttpCallback> callback) { + + public void getPdluserFollow(int p, HttpCallback> callback) { API.get().pdLiveApi(mContext) .getPdluserFollow(p) .subscribeOn(Schedulers.io()) @@ -2972,7 +2985,8 @@ public class LiveNetManager { } }).isDisposed(); } - public void getPdluserFans(int p,HttpCallback> callback) { + + public void getPdluserFans(int p, HttpCallback> callback) { API.get().pdLiveApi(mContext) .getPdluserFans(p) .subscribeOn(Schedulers.io()) @@ -2991,7 +3005,8 @@ public class LiveNetManager { } }).isDisposed(); } - public void addressBookSearch(String search,HttpCallback> callback) { + + public void addressBookSearch(String search, HttpCallback> callback) { API.get().pdLiveApi(mContext) .addressBookSearch(search) .subscribeOn(Schedulers.io()) @@ -3010,7 +3025,8 @@ public class LiveNetManager { } }).isDisposed(); } - public void getOtherInfo(String touid,HttpCallback callback) { + + public void getOtherInfo(String touid, HttpCallback callback) { API.get().pdLiveApi(mContext) .getOtherInfo(touid) .subscribeOn(Schedulers.io()) @@ -3029,7 +3045,8 @@ public class LiveNetManager { } }).isDisposed(); } - public void getUserHomeBanner(String search,HttpCallback> callback) { + + public void getUserHomeBanner(String search, HttpCallback> callback) { API.get().pdLiveApi(mContext) .getUserHomeBanner(search) .subscribeOn(Schedulers.io()) @@ -3068,6 +3085,190 @@ public class LiveNetManager { } }).isDisposed(); } + + public void getHiConfig(HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .getHiConfig() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + + public void setHiConfig( + JSONObject content, + HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .setHiConfig(content, CommonAppConfig.getInstance().getUid(), CommonAppConfig.getInstance().getToken()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + + public void updateHiConfig( + int id, + String content, + int type, + int duration, + HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .updateHiConfig(id, content, type, duration, 1) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + + public void delHiConfig( + int id, + HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .delHiConfig(id) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + public void updateFile(File file, HttpCallback callback) { + MultipartBody.Part uploadFile = createUploadFile(file); + API.get().pdLiveApi(mContext) + .updateFile(uploadFile, CommonAppConfig.getInstance().getUid(), CommonAppConfig.getInstance().getToken()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel model) throws Exception { + if (callback != null) { + callback.onSuccess(model.getData().getInfo()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); + } + } + }).isDisposed(); + } + public void updateFileToMp3(File file, HttpCallback callback) { + MultipartBody.Part uploadFile = createUploadFile(file); + API.get().pdLiveApi(mContext) + .updateFileToMp3(uploadFile, CommonAppConfig.getInstance().getUid(), CommonAppConfig.getInstance().getToken()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Consumer>() { + @Override + public void accept(ResponseModel model) throws Exception { + if (callback != null) { + callback.onSuccess(model.getData().getInfo()); + } + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + if (callback != null) { + callback.onError(mContext.getString(com.yunbao.common.R.string.net_error)); + } + } + }).isDisposed(); + } + public void initUserInfo( + int sex, + String user_nicename, + String avatar, + String birthday, + HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .initUserInfo(sex, user_nicename, avatar, birthday) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + + public void setOpenOff( + int status, + HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .setOpenOff(status) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } + private MultipartBody.Part createUploadFile(File file) { + RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); + return MultipartBody.Part.createFormData("file", file.getName(), requestBody); + } + /** * 直播间取消网络请求 */ diff --git a/common/src/main/java/com/yunbao/common/interfaces/ImageResultCallback.java b/common/src/main/java/com/yunbao/common/interfaces/ImageResultCallback.java index ed482704e..4ebb50f2d 100644 --- a/common/src/main/java/com/yunbao/common/interfaces/ImageResultCallback.java +++ b/common/src/main/java/com/yunbao/common/interfaces/ImageResultCallback.java @@ -1,16 +1,38 @@ package com.yunbao.common.interfaces; +import com.yunbao.common.CommonAppContext; +import com.yunbao.common.bean.AvatarBean; +import com.yunbao.common.http.live.LiveNetManager; + import java.io.File; /** * Created by cxf on 2018/9/29. */ -public interface ImageResultCallback { +public abstract class ImageResultCallback { //跳转相机前执行 - void beforeCamera(); + public void beforeCamera() { + } - void onSuccess(File file); + public void onSuccess(File file) { + } - void onFailure(); + public void onFailure() { + } + + public void onSuccessToUrl(File file, OnItemClickListener listener) { + LiveNetManager.get(CommonAppContext.getTopActivity()) + .updateFile(file, new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(AvatarBean data) { + listener.onItemClick(data.getAvatar(), 0); + } + + @Override + public void onError(String error) { + listener.onItemClick(null, -1); + } + }); + } } diff --git a/common/src/main/java/com/yunbao/common/utils/ViewUtils.java b/common/src/main/java/com/yunbao/common/utils/ViewUtils.java index 7a6861ab2..a36d8d4e4 100644 --- a/common/src/main/java/com/yunbao/common/utils/ViewUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/ViewUtils.java @@ -6,4 +6,7 @@ public class ViewUtils { public static T findViewById(View view,int id,Class clazz){ return view.findViewById(id); } + public static T findViewById(View view,int id){ + return view.findViewById(id); + } } diff --git a/common/src/main/res/drawable/bg_msg_more.9.png b/common/src/main/res/drawable/bg_msg_more.9.png new file mode 100644 index 000000000..e0e7dcdbb Binary files /dev/null and b/common/src/main/res/drawable/bg_msg_more.9.png differ diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml index e83f7cea5..81f36666e 100644 --- a/main/src/main/AndroidManifest.xml +++ b/main/src/main/AndroidManifest.xml @@ -164,6 +164,12 @@ android:screenOrientation="portrait" /> + + + \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/CompleteUserInfoActivity.java b/main/src/main/java/com/yunbao/main/activity/CompleteUserInfoActivity.java new file mode 100644 index 000000000..243b7ccb8 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/activity/CompleteUserInfoActivity.java @@ -0,0 +1,240 @@ +package com.yunbao.main.activity; + +import android.app.Dialog; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bigkoo.pickerview.builder.TimePickerBuilder; +import com.bigkoo.pickerview.listener.OnTimeSelectListener; +import com.bigkoo.pickerview.view.TimePickerView; +import com.lxj.xpopup.XPopup; +import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.ImageResultCallback; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.L; +import com.yunbao.common.utils.ProcessImageUtil; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.ViewUtils; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.main.R; +import com.yunbao.main.dialog.UserAvatarPopup; + +import java.io.File; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class CompleteUserInfoActivity extends AbsActivity { + ImageView avatar; + View avatarChange; + EditText userName; + View man, woman, birthday; + Button submit; + ProcessImageUtil cameraUtil; + private File mAvatarFile; + + @Override + protected int getLayoutId() { + return R.layout.activity_user_info; + } + + @Override + protected void main(Bundle savedInstanceState) { + super.main(savedInstanceState); + Calendar calendar = Calendar.getInstance(); + year = calendar.get(Calendar.YEAR) - 18; + month = calendar.get(Calendar.MONTH); + day = calendar.get(Calendar.DAY_OF_MONTH); + cameraUtil = new ProcessImageUtil(this); + + initView(); + } + + int year; + int month; + int day; + + void initView() { + avatar = findViewById(R.id.avatar); + avatarChange = findViewById(R.id.btn_change); + userName = findViewById(R.id.edit_text); + man = findViewById(R.id.sex_man); + woman = findViewById(R.id.sex_woman); + birthday = findViewById(R.id.birthday); + submit = findViewById(R.id.submit); + + initSexView(); + initBirthdayView(); + initAvatarView(); + submit.setOnClickListener(view -> { + if (avatar.getTag() == null) { + ToastUtil.show("請選擇頭像"); + return; + } + if (StringUtil.isEmpty(userName.getText().toString())) { + ToastUtil.show("請輸入用戶名"); + return; + } + if (man.getTag() == null && woman.getTag() == null) { + ToastUtil.show("請選擇性別"); + return; + } + + LiveNetManager.get(mContext) + .initUserInfo( + man.getTag() != null ? 1 : 2, + userName.getText().toString(), + (String) avatar.getTag(), + year + "-" + (month + 1) + "-" + day, + new HttpCallback>() { + @Override + public void onSuccess(List data) { + ToastUtil.show("註冊成功"); + finish(); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + } + ); + }); + } + + private void initBirthdayView() { + ViewUtils.findViewById(birthday, R.id.audio_text, TextView.class).setText(String.format(Locale.getDefault(), "%d %s %d %s %d %s", + year, + WordUtil.getNewString(R.string.year), + month + 1, + WordUtil.getNewString(R.string.month), + day, + WordUtil.getNewString(R.string.day))); + birthday.setOnClickListener(view -> { + Calendar selectedDate = Calendar.getInstance(); + selectedDate.set(year, month, day); + Calendar startCalendar = Calendar.getInstance(); + Calendar endCalendar = Calendar.getInstance(); + startCalendar.set(1990, 1, 1); + endCalendar.setTime(new Date()); + TimePickerView pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() { + @Override + public void onTimeSelect(Date date, View v) { + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + year = calendar.get(Calendar.YEAR); + month = calendar.get(Calendar.MONTH); + day = calendar.get(Calendar.DAY_OF_MONTH); + + ViewUtils.findViewById(birthday, R.id.audio_text, TextView.class).setText(String.format(Locale.getDefault(), "%d %s %d %s %d %s", + year, + WordUtil.getNewString(R.string.year), + month + 1, + WordUtil.getNewString(R.string.month), + day, + WordUtil.getNewString(R.string.day) + )); + } + }).setRangDate(startCalendar, endCalendar).setCancelText(WordUtil.getNewString(R.string.activity_reg_user_info_birthday_title)) + .setSubmitColor(Color.parseColor("#A279E4")) + .setSubmitText(WordUtil.getNewString(R.string.complete)) + .setContentTextSize(20) + .setDate(selectedDate) + .build(); + pvTime.show(); + + }); + } + + Dialog loading; + + private void initAvatarView() { + ImgLoader.display(this, "https://downs.yaoulive.com/defaultblue.jpg", avatar); + avatar.setTag("https://downs.yaoulive.com/defaultblue.jpg"); + avatarChange.setOnClickListener(view -> { + UserAvatarPopup userAvatarPopup = new UserAvatarPopup(this, userAvatar1 -> { + avatar.setTag(userAvatar1); + ImgLoader.display(this, userAvatar1, avatar); + //txtChoose.setVisibility(View.GONE); + }, isCamera -> { + if (isCamera) { + cameraUtil.getImageByCamera(); + } else { + cameraUtil.getImageByAlumb(); + } + }); + new XPopup.Builder(mContext).asCustom(userAvatarPopup).show(); + + }); + cameraUtil.setImageResultCallback(new ImageResultCallback() { + + @Override + public void onSuccess(File file) { + loading = DialogUitl.loadingDialog(mContext); + loading.show(); + L.e("cameraUtil.setImageResultCallback:"); + onSuccessToUrl(file, new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + avatar.setTag(bean); + loading.dismiss(); + } + }); + } + }); + + } + + void initSexView() { + ViewUtils.findViewById(man, R.id.sex_bg).setBackgroundResource(R.drawable.dialog_bg_chat_status_config_select); + ViewUtils.findViewById(man, R.id.sex_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#00A3FF"))); + ViewUtils.findViewById(man, R.id.sex_top_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#00A3FF"))); + ViewUtils.findViewById(woman, R.id.sex_bg).setBackgroundResource(R.drawable.dialog_bg_chat_status_config_unselect); + ViewUtils.findViewById(woman, R.id.sex_icon, ImageView.class).setImageResource(R.mipmap.ic_woman); + ViewUtils.findViewById(woman, R.id.sex_top_icon, ImageView.class).setImageResource(R.mipmap.ic_woman_avatar); + ViewUtils.findViewById(woman, R.id.sex_text, TextView.class).setText(R.string.activity_reg_user_info_sex_woman); + ViewUtils.findViewById(woman, R.id.sex_text, TextView.class).setTextColor(Color.parseColor("#333333")); + ViewUtils.findViewById(man, R.id.sex_text, TextView.class).setTextColor(Color.parseColor("#00A3FF")); + man.setTag("man"); + woman.setTag(null); + man.setOnClickListener(view -> { + ViewUtils.findViewById(man, R.id.sex_bg).setBackgroundResource(R.drawable.dialog_bg_chat_status_config_select); + ViewUtils.findViewById(woman, R.id.sex_bg).setBackgroundResource(R.drawable.dialog_bg_chat_status_config_unselect); + ViewUtils.findViewById(man, R.id.sex_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#00A3FF"))); + ViewUtils.findViewById(man, R.id.sex_top_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#00A3FF"))); + ViewUtils.findViewById(woman, R.id.sex_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#333333"))); + ViewUtils.findViewById(woman, R.id.sex_top_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#333333"))); + ViewUtils.findViewById(woman, R.id.sex_text, TextView.class).setTextColor(Color.parseColor("#333333")); + ViewUtils.findViewById(man, R.id.sex_text, TextView.class).setTextColor(Color.parseColor("#00A3FF")); + man.setTag("man"); + woman.setTag(null); + }); + woman.setOnClickListener(view -> { + ViewUtils.findViewById(woman, R.id.sex_bg).setBackgroundResource(R.drawable.dialog_bg_chat_status_config_select); + ViewUtils.findViewById(man, R.id.sex_bg).setBackgroundResource(R.drawable.dialog_bg_chat_status_config_unselect); + ViewUtils.findViewById(woman, R.id.sex_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#FF4874"))); + ViewUtils.findViewById(woman, R.id.sex_top_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#FF4874"))); + ViewUtils.findViewById(man, R.id.sex_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#333333"))); + ViewUtils.findViewById(man, R.id.sex_top_icon, ImageView.class).setImageTintList(ColorStateList.valueOf(Color.parseColor("#333333"))); + ViewUtils.findViewById(man, R.id.sex_text, TextView.class).setTextColor(Color.parseColor("#333333")); + ViewUtils.findViewById(woman, R.id.sex_text, TextView.class).setTextColor(Color.parseColor("#FF4874")); + man.setTag(null); + woman.setTag("man"); + }); + } +} diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 2b280ad62..a3f5f6b9c 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -119,6 +119,7 @@ import com.yunbao.main.http.MainHttpUtil; import com.yunbao.main.interfaces.MainAppBarLayoutListener; import com.yunbao.main.manager.imrongcloud.ConversationIMListManager; import com.yunbao.main.utils.GenerateTestUserSig; +import com.yunbao.main.utils.UserInfoManager; import com.yunbao.main.views.FloatBannerView; import com.yunbao.main.views.MainHomeCommunityViewHolder; import com.yunbao.main.views.MainHomeLiveViewHolder; @@ -220,6 +221,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene ActivityCompat.postponeEnterTransition(this); ConversationIMListManager.get(this); OpenAdManager.getInstance(); + UserInfoManager.updateMyInfo(this, null); //在请求一下这个接口给我后台版本号 CommonHttpUtil.getConfig(mContext, new CommonCallback() { @Override @@ -638,9 +640,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene floatBanner.setVisibility(View.VISIBLE); findViewById(R.id.banner_click).setVisibility(View.VISIBLE); } else { - if (mainHomeViewHolder!=null&&mainHomeViewHolder.isFloatWarOrder()){ + if (mainHomeViewHolder != null && mainHomeViewHolder.isFloatWarOrder()) { floatWarOrder.setVisibility(View.GONE); - }else { + } else { floatWarOrder.setVisibility(View.VISIBLE); } diff --git a/main/src/main/java/com/yunbao/main/activity/MessageHiConfigActivity.java b/main/src/main/java/com/yunbao/main/activity/MessageHiConfigActivity.java new file mode 100644 index 000000000..8baf0ea28 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/activity/MessageHiConfigActivity.java @@ -0,0 +1,424 @@ +package com.yunbao.main.activity; + +import android.app.Dialog; +import android.content.Intent; +import android.media.AudioAttributes; +import android.media.MediaPlayer; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.View; +import android.view.ViewParent; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.CacheMemoryUtils; +import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.bean.MessageHiBean; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.ImageResultCallback; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.ProcessImageUtil; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.ViewUtils; +import com.yunbao.main.R; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class MessageHiConfigActivity extends AbsActivity { + View text1, text2, text3; + View audio1, audio2, audio3; + View image1, image2, image3; + ProcessImageUtil imageUtil; + + MessageHiBean[] audios = new MessageHiBean[3]; + MessageHiBean[] texts = new MessageHiBean[3]; + MessageHiBean[] images = new MessageHiBean[3]; + + + @Override + protected int getLayoutId() { + return R.layout.activity_message_hi_config; + } + + @Override + protected void main(Bundle savedInstanceState) { + super.main(savedInstanceState); + imageUtil = new ProcessImageUtil(this); + initView(); + initData(); + } + + @Override + protected void onResume() { + super.onResume(); + String cache = CacheMemoryUtils.getInstance().get(MessageHiConfigRecordActivity.RECORD_CACHE_URL); + if (StringUtil.isEmpty(cache)) { + return; + } + if (audio1.getTag() == null) { + toAudio(audio1); + } else if (audio2.getTag() == null) { + toAudio(audio2); + } else if (audio3.getTag() == null) { + toAudio(audio3); + } + } + + private void toAudio(View audio) { + MessageHiBean bean = new MessageHiBean(); + bean.setContent(CacheMemoryUtils.getInstance().get(MessageHiConfigRecordActivity.RECORD_CACHE_URL)); + bean.setDuration(CacheMemoryUtils.getInstance().get(MessageHiConfigRecordActivity.RECORD_CACHE_TIME)); + bean.setType(MessageHiBean.TYPE_AUDIO); + CacheMemoryUtils.getInstance().remove(MessageHiConfigRecordActivity.RECORD_CACHE_URL); + CacheMemoryUtils.getInstance().remove(MessageHiConfigRecordActivity.RECORD_CACHE_TIME); + audio.setTag(bean); + setAudio(audio); + } + + private void initView() { + text1 = findViewById(R.id.text_1); + text2 = findViewById(R.id.text_2); + text3 = findViewById(R.id.text_3); + audio1 = findViewById(R.id.audio_1); + audio2 = findViewById(R.id.audio_2); + audio3 = findViewById(R.id.audio_3); + image1 = findViewById(R.id.image_1); + image2 = findViewById(R.id.image_2); + image3 = findViewById(R.id.image_3); + + findViewById(R.id.rootView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + text1.clearFocus(); + text2.clearFocus(); + text3.clearFocus(); + } + }); + + findViewById(R.id.btn_save).setOnClickListener(view -> { + List list = new ArrayList<>(); + + text1.clearFocus(); + text2.clearFocus(); + text3.clearFocus(); + + boolean audioReady = false; + boolean textReady = false; + boolean imageReady = false; + + if (audio1.getTag() != null) { + list.add((MessageHiBean) audio1.getTag()); + audioReady = true; + } + if (audio2.getTag() != null) { + list.add((MessageHiBean) audio2.getTag()); + audioReady = true; + } + if (audio3.getTag() != null) { + list.add((MessageHiBean) audio3.getTag()); + audioReady = true; + } + if (text1.getTag() != null) { + list.add((MessageHiBean) text1.getTag()); + textReady = true; + } + if (text2.getTag() != null) { + list.add((MessageHiBean) text2.getTag()); + textReady = true; + } + if (text3.getTag() != null) { + list.add((MessageHiBean) text3.getTag()); + textReady = true; + } + if (image1.getTag() != null) { + list.add((MessageHiBean) image1.getTag()); + imageReady = true; + } + if (image2.getTag() != null) { + list.add((MessageHiBean) image2.getTag()); + imageReady = true; + } + if (image3.getTag() != null) { + list.add((MessageHiBean) image3.getTag()); + imageReady = true; + } + if (!audioReady) { + ToastUtil.show(R.string.dialog_msg_hi_config_audio_refuse_save_audio); + return; + } + if (!textReady) { + ToastUtil.show(R.string.dialog_msg_hi_config_audio_refuse_save_text); + return; + } + if (!imageReady) { + ToastUtil.show(R.string.dialog_msg_hi_config_audio_refuse_save_image); + return; + } + JSONObject json = new JSONObject(); + json.put("content", list); + System.out.println(">>>>> " + json); + LiveNetManager.get(mContext) + .setHiConfig(json, new HttpCallback>() { + @Override + public void onSuccess(List data) { + MessageHiConfigActivity.this.finish(); + } + + @Override + public void onError(String error) { + + } + }); + + }); + } + + private void updateUi() { +//bg_msg_list_item + if (audios[0] != null) { + audio1.setTag(audios[0]); + } + if (audios[1] != null) { + audio2.setTag(audios[1]); + } + if (audios[2] != null) { + audio3.setTag(audios[2]); + } + if (texts[0] != null) { + text1.setTag(texts[0]); + } + if (texts[1] != null) { + text2.setTag(texts[1]); + } + if (texts[2] != null) { + text3.setTag(texts[2]); + } + if (images[0] != null) { + image1.setTag(images[0]); + } + if (images[1] != null) { + image2.setTag(images[1]); + } + if (images[2] != null) { + image3.setTag(images[2]); + } + setAudio(audio1); + setAudio(audio2); + setAudio(audio3); + setText(text1); + setText(text2); + setText(text3); + setImage(image1); + setImage(image2); + setImage(image3); + + } + + private void setAudio(View view) { + MessageHiBean bean = (MessageHiBean) view.getTag(); + if (bean == null) { + ViewUtils.findViewById(view, R.id.audio_text, TextView.class).setText(R.string.dialog_msg_hi_config_record); + ViewUtils.findViewById(view, R.id.audio_play).setVisibility(View.GONE); + ViewUtils.findViewById(view, R.id.audio_del).setVisibility(View.GONE); + ViewUtils.findViewById(view, R.id.audio_image, ImageView.class).setImageResource(R.mipmap.ic_message_hi_config_record); + view.setBackgroundResource(R.drawable.dialog_bg_msg_hi_config_unselect); + view.setOnClickListener(v -> { + mContext.startActivity(new Intent(mContext, MessageHiConfigRecordActivity.class)); + }); + return; + } + ViewUtils.findViewById(view, R.id.audio_text, TextView.class).setText(bean.getDuration() + "s"); + ViewUtils.findViewById(view, R.id.audio_image, ImageView.class).setImageResource(R.mipmap.ic_message_hi_config_audio); + ViewUtils.findViewById(view, R.id.audio_play).setVisibility(View.VISIBLE); + ViewUtils.findViewById(view, R.id.audio_del).setVisibility(View.VISIBLE); + view.setBackgroundResource(R.drawable.dialog_bg_chat_status_config); + ViewUtils.findViewById(view, R.id.audio_play).setOnClickListener(v -> { + play(bean.getContent()); + }); + ViewUtils.findViewById(view, R.id.audio_del).setOnClickListener(v -> { + view.setTag(null); + setAudio(view); + }); + view.setOnClickListener(v -> { + play(bean.getContent()); + }); + } + + private void setText(View view) { + setText(view, null, false); + } + + private void setText(View view, String defText, boolean isFocusable) { + MessageHiBean bean = (MessageHiBean) view.getTag(); + if (bean == null) { + ViewUtils.findViewById(view, R.id.edit_text, EditText.class).setEnabled(true); + ViewUtils.findViewById(view, R.id.edit_edit).setVisibility(View.GONE); + ViewUtils.findViewById(view, R.id.edit_del).setVisibility(View.GONE); + view.setBackgroundResource(R.drawable.dialog_bg_msg_hi_config_unselect); + ViewUtils.findViewById(view, R.id.edit_text, EditText.class).setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean b) { + View parent = (View) view.getParent(); + if (b) { + parent.setBackgroundResource(R.drawable.dialog_bg_chat_status_config_select); + } else { + parent.setBackgroundResource(R.drawable.dialog_bg_msg_hi_config_unselect); + String string = ((EditText) view).getText().toString(); + if (!StringUtil.isEmpty(string)) { + MessageHiBean hi = new MessageHiBean(); + hi.setType(MessageHiBean.TYPE_TEXT); + hi.setContent(string); + ((View) view.getParent()).setTag(hi); + setText((View) view.getParent()); + } + } + } + }); + if (isFocusable) { + ViewUtils.findViewById(view, R.id.edit_text, EditText.class).requestFocus(); + } + if (StringUtil.isEmpty(defText)) { + ViewUtils.findViewById(view, R.id.edit_text, EditText.class).setText(defText); + } + return; + } + ViewUtils.findViewById(view, R.id.edit_text, EditText.class).setText(bean.getContent()); + ViewUtils.findViewById(view, R.id.edit_text, EditText.class).setEnabled(false); + view.setBackgroundResource(R.drawable.bg_msg_list_item); + ViewUtils.findViewById(view, R.id.edit_edit).setVisibility(View.VISIBLE); + ViewUtils.findViewById(view, R.id.edit_del).setVisibility(View.VISIBLE); + ViewUtils.findViewById(view, R.id.edit_edit).setOnClickListener(v -> { + View parent = (View) v.getParent(); + ViewUtils.findViewById(parent, R.id.edit_text, EditText.class).setText(""); + parent.setTag(null); + setText(parent, ((EditText) v).getText().toString(), true); + }); + ViewUtils.findViewById(view, R.id.edit_del).setOnClickListener(v -> { + View parent = (View) v.getParent(); + ViewUtils.findViewById(parent, R.id.edit_text, EditText.class).setText(""); + parent.setTag(null); + setText(parent); + }); + + } + + private void setImage(View view) { + MessageHiBean bean = (MessageHiBean) view.getTag(); + if (bean == null) { + ViewUtils.findViewById(view, R.id.img_img, ImageView.class).setImageResource(R.mipmap.ic_message_hi_config_image_add); + view.setOnClickListener(v -> { + uploadImage(view); + }); + return; + } + ImgLoader.display(mContext, bean.getContent(), ViewUtils.findViewById(view, R.id.img_img, ImageView.class)); + ViewUtils.findViewById(view, R.id.img_close).setVisibility(View.VISIBLE); + + ViewUtils.findViewById(view, R.id.img_close).setOnClickListener(v -> { + view.setTag(null); + setImage(view); + }); + view.setOnClickListener(v -> { + }); + } + + Dialog loading; + + private void uploadImage(View view) { + imageUtil.setImageResultCallback(new ImageResultCallback() { + + @Override + public void onSuccess(File file) { + onSuccessToUrl(file, new OnItemClickListener() { + @Override + public void onItemClick(String url, int position) { + if (position == -1) { + loading.dismiss(); + ToastUtil.show("连接超时"); + return; + } + loading.dismiss(); + MessageHiBean item = new MessageHiBean(); + item.setContent(url); + item.setType(MessageHiBean.TYPE_IMAGE); + item.setStatus(1); + view.setTag(item); + setImage(view); + } + }); + } + + @Override + public void onFailure() { + super.onFailure(); + if(loading!=null){ + loading.dismiss(); + } + } + }); + imageUtil.getImageByAlumb(); + loading = DialogUitl.loadingDialog(mContext); + loading.show(); + } + + private void play(String url) { + try { + MediaPlayer mediaPlayer = new MediaPlayer(); + mediaPlayer.setAudioAttributes( + new AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .setUsage(AudioAttributes.USAGE_MEDIA) + .build() + ); + mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mediaPlayer) { + mediaPlayer.release(); + } + }); + mediaPlayer.setDataSource(url); + mediaPlayer.prepare(); // might take long! (for buffering, etc) + mediaPlayer.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void initData() { + LiveNetManager.get(mContext) + .getHiConfig(new HttpCallback>() { + @Override + public void onSuccess(List data) { + int textLength = 0; + int audioLength = 0; + int imageLength = 0; + for (MessageHiBean bean : data) { + if (bean.getType() == MessageHiBean.TYPE_TEXT) { + texts[textLength++] = bean; + } else if (bean.getType() == MessageHiBean.TYPE_IMAGE) { + images[imageLength++] = bean; + } else if (bean.getType() == MessageHiBean.TYPE_AUDIO) { + audios[audioLength++] = bean; + } + } + updateUi(); + } + + @Override + public void onError(String error) { + + } + }); + } + +} diff --git a/main/src/main/java/com/yunbao/main/activity/MessageHiConfigRecordActivity.java b/main/src/main/java/com/yunbao/main/activity/MessageHiConfigRecordActivity.java new file mode 100644 index 000000000..372330a76 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/activity/MessageHiConfigRecordActivity.java @@ -0,0 +1,224 @@ +package com.yunbao.main.activity; + +import android.Manifest; +import android.annotation.SuppressLint; +import android.app.Dialog; +import android.media.AudioAttributes; +import android.media.MediaPlayer; +import android.net.Uri; +import android.os.Bundle; +import android.os.SystemClock; +import android.view.MotionEvent; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.blankj.utilcode.util.CacheMemoryUtils; +import com.blankj.utilcode.util.PermissionUtils; +import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.AvatarBean; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.main.R; +import com.yunbao.main.utils.AudioRecordManager; + +import java.io.File; + +import io.rong.imkit.manager.AudioPlayManager; +import io.rong.imkit.utils.PermissionCheckUtil; + +public class MessageHiConfigRecordActivity extends AbsActivity { + public static final String RECORD_CACHE_URL = "cache_hi_config_record_url"; + public static final String RECORD_CACHE_TIME = "cache_hi_config_record_time"; + View imgRecording; + Button resetBtn, saveBtn, recordBtn; + TextView timerText, tipsText; + private float mLastTouchY; + private long smStartRecTime; + + private boolean mUpDirection; + private boolean isAudio; + private boolean isDownload = false; + private File recordFile; + private int recordTime; + + @Override + protected int getLayoutId() { + return R.layout.activity_hi_config_record; + } + + @SuppressLint("ClickableViewAccessibility") + @Override + protected void main(Bundle savedInstanceState) { + super.main(savedInstanceState); + imgRecording = findViewById(R.id.img_recording); + resetBtn = findViewById(R.id.btn_reset); + saveBtn = findViewById(R.id.btn_save); + recordBtn = findViewById(R.id.btn_record); + timerText = findViewById(R.id.timer); + tipsText = findViewById(R.id.text_tips_long); + + recordBtn.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + System.out.println("点击事件:" + event.getAction() + " isAudio = " + isAudio); + float mOffsetLimit = 70.0F * v.getContext().getResources().getDisplayMetrics().density; + String[] permissions = new String[]{Manifest.permission.RECORD_AUDIO}; + if (!PermissionCheckUtil.checkPermissions(v.getContext(), permissions) && event.getAction() == 0) { + PermissionCheckUtil.requestPermissions(mContext, permissions, 100); + PermissionUtils.permission(Manifest.permission.RECORD_AUDIO).request(); + System.out.println("点击事件 没权限掉了"); + return true; + } else { + isDownload = true; + if (event.getAction() == MotionEvent.ACTION_DOWN) { + isAudio = true; + System.out.println("点击事件:点下 isAudio = " + isAudio); + if (isAudio) { + if (onDown(v, event.getY())) { + System.out.println("点击事件:内部点击,返回掉了"); + return true; + } + } else { + System.out.println("点击事件,准备进token"); + } + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (isAudio) { + onMove(v, event, mOffsetLimit); + } + + } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { + isDownload = false; + if (isAudio) { + onUp(v, event); + } + } + if (isAudio) { + + } + } + return true; + } + }); + + resetBtn.setOnClickListener(view -> { + recordFile = null; + recordTime = 0; + resetBtn.setVisibility(View.GONE); + saveBtn.setVisibility(View.GONE); + tipsText.setText(R.string.dialog_msg_hi_config_audio_btn); + timerText.setText(""); + timerText.setVisibility(View.GONE); + }); + saveBtn.setOnClickListener(view -> { + Dialog loading = DialogUitl.loadingDialog(mContext); + loading.show(); + LiveNetManager.get(mContext) + .updateFileToMp3(recordFile, new HttpCallback() { + @Override + public void onSuccess(AvatarBean data) { + CacheMemoryUtils.getInstance().put(RECORD_CACHE_URL, data.getAvatar()); + CacheMemoryUtils.getInstance().put(RECORD_CACHE_TIME, recordTime); + loading.dismiss(); + finish(); + } + + @Override + public void onError(String error) { + loading.dismiss(); + ToastUtil.show(error); + } + }); + }); + } + + private boolean onDown(View v, float mLastTouchY) { + System.out.println("点击事件 mLastTouchY = " + mLastTouchY); + + if (saveBtn.getVisibility() == View.VISIBLE) { + play(recordFile); + return true; + } + + if (AudioPlayManager.getInstance().isPlaying()) { + AudioPlayManager.getInstance().stopPlay(); + } + + + MessageHiConfigRecordActivity.this.mLastTouchY = mLastTouchY; + MessageHiConfigRecordActivity.this.mUpDirection = false; + smStartRecTime = SystemClock.elapsedRealtime(); + resetBtn.setVisibility(View.GONE); + saveBtn.setVisibility(View.GONE); + AudioRecordManager.getInstance().startRecord(v.getRootView(), new AudioRecordManager.IAudioRecordStateChangeListener() { + @Override + public void onTimer(int timer) { + System.out.println("------------》时间 " + timer); + timerText.setText(timer + "s"); + timerText.setVisibility(View.VISIBLE); + if (timer >= 5) { + AudioRecordManager.getInstance().stopRecord(); + } + } + + @Override + public void onDone(File file, int timer) { + recordFile = file; + recordTime = timer; + resetBtn.setVisibility(View.VISIBLE); + saveBtn.setVisibility(View.VISIBLE); + tipsText.setVisibility(View.VISIBLE); + tipsText.setText(R.string.dialog_msg_hi_config_audio_btn_play); + + } + }); + return false; + } + + private boolean onMove(View v, MotionEvent event, float mOffsetLimit) { + if (MessageHiConfigRecordActivity.this.mLastTouchY - event.getY() > mOffsetLimit && !MessageHiConfigRecordActivity.this.mUpDirection) { + AudioRecordManager.getInstance().willCancelRecord(); + MessageHiConfigRecordActivity.this.mUpDirection = true; + } else if (event.getY() - MessageHiConfigRecordActivity.this.mLastTouchY > -mOffsetLimit && MessageHiConfigRecordActivity.this.mUpDirection) { + AudioRecordManager.getInstance().continueRecord(); + MessageHiConfigRecordActivity.this.mUpDirection = false; + } + return false; + } + + private boolean onUp(View v, MotionEvent event) { + AudioRecordManager.getInstance().stopRecord(); + isAudio = false; + if (mUpDirection) { + return false; + } + + return false; + } + + private void play(File file) { + try { + MediaPlayer mediaPlayer = new MediaPlayer(); + mediaPlayer.setAudioAttributes( + new AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .setUsage(AudioAttributes.USAGE_MEDIA) + .build() + ); + mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mediaPlayer) { + mediaPlayer.release(); + } + }); + mediaPlayer.setDataSource(getApplicationContext(), Uri.fromFile(file)); + mediaPlayer.prepare(); + mediaPlayer.start(); + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter2.java b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter2.java new file mode 100644 index 000000000..4d532f5bf --- /dev/null +++ b/main/src/main/java/com/yunbao/main/adapter/UserAvatarSelectAdapter2.java @@ -0,0 +1,109 @@ +package com.yunbao.main.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.bean.UserAvatarSelectBean; +import com.yunbao.common.custom.RatioRoundImageView; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.main.R; + +import java.util.ArrayList; +import java.util.List; + +public class UserAvatarSelectAdapter2 extends RecyclerView.Adapter { + private Context mContext; + private List list = new ArrayList<>(); + private OnItemClickListener onClickListener; + private int selectId = -1; + private int defId = -1; + private UserAvatarSelectBean selectInfo; + + public void setList(List list) { + this.list = list; + notifyDataSetChanged(); + } + + public int getSelect() { + if (selectId == -1 && getItemCount() > 0) { + return list.get(0).getId(); + } + return selectId; + } + + public void setOnClickListener(OnItemClickListener onClickListener) { + this.onClickListener = onClickListener; + } + + public int getDefId() { + return defId; + } + + public UserAvatarSelectAdapter2(Context mContext) { + this.mContext = mContext; + } + + @NonNull + @Override + public AvatarSelectViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new AvatarSelectViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_user_avatar_select, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull AvatarSelectViewHolder holder, int position) { + holder.setData(list.get(position), position); + } + + @Override + public int getItemCount() { + return list.size(); + } + + public void setDef(int id) { + this.defId = id; + } + + public class AvatarSelectViewHolder extends RecyclerView.ViewHolder { + private View hide; + private View show; + private RatioRoundImageView avatar; + + public AvatarSelectViewHolder(@NonNull View itemView) { + super(itemView); + hide = itemView.findViewById(R.id.hideCover); + show = itemView.findViewById(R.id.showCover); + avatar = itemView.findViewById(R.id.avatar); + itemView.setOnClickListener(v -> { + selectInfo = (UserAvatarSelectBean) v.getTag(); + selectId = selectInfo.getId(); + notifyDataSetChanged(); + onClickListener.onItemClick(selectInfo, defId); + }); + } + + public void setData(UserAvatarSelectBean bean, int position) { + ImgLoader.display(itemView.getContext(), bean.getPath(), avatar); + if (selectId == -1 && bean.getChecked() == 1) { + selectId = bean.getId(); + defId = bean.getId(); + selectInfo = bean; + } + hide.setVisibility(View.GONE); + /*if (select == bean.getId()) { + show.setVisibility(View.VISIBLE); + hide.setVisibility(View.GONE); + } else { + show.setVisibility(View.INVISIBLE); + hide.setVisibility(View.VISIBLE); + }*/ + itemView.setTag(bean); + } + } + +} diff --git a/main/src/main/java/com/yunbao/main/dialog/MessageStatusConfigDialog.java b/main/src/main/java/com/yunbao/main/dialog/MessageStatusConfigDialog.java new file mode 100644 index 000000000..f1529dbea --- /dev/null +++ b/main/src/main/java/com/yunbao/main/dialog/MessageStatusConfigDialog.java @@ -0,0 +1,71 @@ +package com.yunbao.main.dialog; + +import android.content.Context; +import android.widget.RadioButton; +import android.widget.RadioGroup; + +import androidx.annotation.NonNull; + +import com.lxj.xpopup.XPopup; +import com.yunbao.common.bean.BaseModel; +import com.yunbao.common.dialog.AbsDialogCenterPopupWindow; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.main.R; +import com.yunbao.main.utils.UserInfoManager; + +import java.util.List; + +public class MessageStatusConfigDialog extends AbsDialogCenterPopupWindow { + RadioGroup radioGroup; + + public MessageStatusConfigDialog(@NonNull Context context) { + super(context); + } + + @Override + public void buildDialog(XPopup.Builder builder) { + + } + + @Override + public int bindLayoutId() { + return R.layout.dialog_message_status_config; + } + + @Override + protected void onCreate() { + super.onCreate(); + radioGroup = findViewById(R.id.radioGroup); + if (UserInfoManager.getMyInfo() != null) { + if (UserInfoManager.getMyInfo().getInfo().getOpenOff() == 1) { + ((RadioButton) radioGroup.getChildAt(0)).setChecked(true); + } else { + ((RadioButton) radioGroup.getChildAt(1)).setChecked(true); + } + } + findViewById(R.id.save).setOnClickListener(view -> { + String tag = findViewById(radioGroup.getCheckedRadioButtonId()).getTag().toString(); + int status = 2; + if (tag.equals(WordUtil.getString(R.string.dialog_msg_status_online_config))) { + status = 1; + } + LiveNetManager.get(mContext) + .setOpenOff(status, new HttpCallback>() { + @Override + public void onSuccess(List data) { + ToastUtil.show("成功"); + dismiss(); + UserInfoManager.updateMyInfo(mContext, null); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + }); + } +} diff --git a/main/src/main/java/com/yunbao/main/dialog/MsgMoreDialog.java b/main/src/main/java/com/yunbao/main/dialog/MsgMoreDialog.java new file mode 100644 index 000000000..c00591a8e --- /dev/null +++ b/main/src/main/java/com/yunbao/main/dialog/MsgMoreDialog.java @@ -0,0 +1,54 @@ +package com.yunbao.main.dialog; + +import android.content.Context; +import android.content.Intent; +import android.view.View; + +import androidx.annotation.NonNull; + +import com.lxj.xpopup.core.AttachPopupView; + +import com.yunbao.common.utils.Bus; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.main.R; +import com.yunbao.main.activity.MessageHiConfigActivity; + +/** + * 消息右上角更多菜单 + */ +public class MsgMoreDialog extends AttachPopupView{ + View config, read; + + public MsgMoreDialog(@NonNull Context context) { + super(context); + } + + @Override + protected int getImplLayoutId() { + return R.layout.dialog_msg_more; + } + + @Override + protected void onCreate() { + super.onCreate(); + config = findViewById(R.id.ll_config); + read = findViewById(R.id.ll_read); + ViewClicksAntiShake.clicksAntiShake(config, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + getContext().startActivity(new Intent(getContext(), MessageHiConfigActivity.class)); + dismiss(); + } + }); + ViewClicksAntiShake.clicksAntiShake(read, new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + new MessageStatusConfigDialog(getContext()) + .showDialog(); + dismiss(); + } + }); + + } + +} diff --git a/main/src/main/java/com/yunbao/main/dialog/UserAvatarPopup.java b/main/src/main/java/com/yunbao/main/dialog/UserAvatarPopup.java new file mode 100644 index 000000000..d09471a6c --- /dev/null +++ b/main/src/main/java/com/yunbao/main/dialog/UserAvatarPopup.java @@ -0,0 +1,126 @@ +package com.yunbao.main.dialog; + +import android.content.Context; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.lxj.xpopup.core.BottomPopupView; +import com.yunbao.common.bean.UserAvatarSelectBean; +import com.yunbao.common.custom.ItemDecoration; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.main.R; +import com.yunbao.main.adapter.UserAvatarSelectAdapter; +import com.yunbao.main.adapter.UserAvatarSelectAdapter2; + +import java.util.ArrayList; +import java.util.List; + +public class UserAvatarPopup extends BottomPopupView implements View.OnClickListener { + + RecyclerView recyclerView; + private Button camera; + private Button album; + private Context mContext; + + UserAvatarSelectAdapter2 adapter; + private OnItemClickListener onItemClickListener; + + public UserAvatarPopup(@NonNull Context context) { + super(context); + } + + public interface OnItemClickListener { + void onItemClick(String userAvatar); + } + + private onIsCameraClickListener onIsCameraClickListener; + + public interface onIsCameraClickListener { + void onIsCamera(boolean isCamera); + } + + public UserAvatarPopup(@NonNull Context context, OnItemClickListener onItemClickListener, onIsCameraClickListener onIsCameraClickListener) { + super(context); + this.mContext = context; + this.onIsCameraClickListener = onIsCameraClickListener; + this.onItemClickListener = onItemClickListener; + } + + @Override + public void onClick(View v) { + + } + + // 返回自定义弹窗的布局 + @Override + protected int getImplLayoutId() { + return R.layout.dialog_user_avatar; + } + + // 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑 + @Override + protected void onCreate() { + super.onCreate(); + initView(); + initDate(); + } + + /** + * 加载系统头像 + */ + private void initDate() { + adapter = new UserAvatarSelectAdapter2(mContext); + recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4)); + + ItemDecoration decoration1 = new ItemDecoration(mContext, 0x00000000, 0, 0); + decoration1.setOnlySetItemOffsetsButNoDraw(true); + recyclerView.addItemDecoration(decoration1); + + recyclerView.setAdapter(adapter); + adapter.setOnClickListener(new com.yunbao.common.interfaces.OnItemClickListener() { + @Override + public void onItemClick(UserAvatarSelectBean bean, int position) { + onItemClickListener.onItemClick(bean.getPath()); + dismiss(); + } + }); + + LiveNetManager.get(mContext).getSystemUserAvatar(new HttpCallback>() { + @Override + public void onSuccess(List data) { + adapter.setList(data); + } + + @Override + public void onError(String error) { + adapter.setList(new ArrayList<>()); + } + }); + } + + private void initView() { + recyclerView = findViewById(R.id.recyclerView); + camera = findViewById(R.id.camera); + album = findViewById(R.id.album); + camera.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + onIsCameraClickListener.onIsCamera(true); + dialog.dismiss(); + } + }); + album.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + onIsCameraClickListener.onIsCamera(false); + dialog.dismiss(); + } + }); + } +} diff --git a/main/src/main/java/com/yunbao/main/utils/AudioRecordManager.java b/main/src/main/java/com/yunbao/main/utils/AudioRecordManager.java new file mode 100644 index 000000000..f26c43f7a --- /dev/null +++ b/main/src/main/java/com/yunbao/main/utils/AudioRecordManager.java @@ -0,0 +1,840 @@ +package com.yunbao.main.utils; + + +import android.annotation.TargetApi; +import android.content.Context; +import android.media.AudioManager; +import android.media.MediaRecorder; +import android.net.Uri; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.SystemClock; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.PopupWindow; +import android.widget.TextView; + +import com.yunbao.common.utils.ToastUtil; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + +import io.rong.common.RLog; +import io.rong.imkit.IMCenter; +import io.rong.imkit.config.RongConfigCenter; +import io.rong.imkit.feature.destruct.DestructManager; +import io.rong.imlib.IRongCallback; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.common.SavePathUtils; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.ConversationIdentifier; +import io.rong.imlib.typingmessage.TypingMessageManager; +import io.rong.message.HQVoiceMessage; +import io.rong.message.VoiceMessage; + +public class AudioRecordManager implements Handler.Callback { + private static final String TAG = "AudioRecordManager"; + private static final int RC_SAMPLE_RATE_8000 = 8000; + private static final int RC_SAMPLE_RATE_16000 = 16000; + private static final String VOICE_PATH = "/voice/"; + private final int AUDIO_RECORD_EVENT_TRIGGER; + private final int AUDIO_RECORD_EVENT_SAMPLING; + private final int AUDIO_RECORD_EVENT_WILL_CANCEL; + private final int AUDIO_RECORD_EVENT_CONTINUE; + private final int AUDIO_RECORD_EVENT_RELEASE; + private final int AUDIO_RECORD_EVENT_ABORT; + private final int AUDIO_RECORD_EVENT_TIME_OUT; + private final int AUDIO_RECORD_EVENT_TICKER; + private final int AUDIO_RECORD_EVENT_SEND_FILE; + private final int AUDIO_AA_ENCODING_BIT_RATE; + AudioRecordManager.IAudioState idleState; + AudioRecordManager.IAudioState recordState; + AudioRecordManager.IAudioState sendingState; + AudioRecordManager.IAudioState cancelState; + AudioRecordManager.IAudioState timerState; + private int RECORD_INTERVAL; + private AudioRecordManager.SamplingRate mSampleRate; + private AudioRecordManager.IAudioState mCurAudioState; + private View mRootView; + private Context mContext; + private Handler mHandler; + private AudioManager mAudioManager; + private MediaRecorder mMediaRecorder; + private Uri mAudioPath; + private long smStartRecTime; + private AudioManager.OnAudioFocusChangeListener mAfChangeListener; + private PopupWindow mRecordWindow; + private ImageView mStateIV; + private TextView mStateTV; + private TextView mTimerTV; + private int recordTime = 0; + private IAudioRecordStateChangeListener recordStateChangeListener; + + @TargetApi(21) + private AudioRecordManager() { + this.AUDIO_RECORD_EVENT_TRIGGER = 1; + this.AUDIO_RECORD_EVENT_SAMPLING = 2; + this.AUDIO_RECORD_EVENT_WILL_CANCEL = 3; + this.AUDIO_RECORD_EVENT_CONTINUE = 4; + this.AUDIO_RECORD_EVENT_RELEASE = 5; + this.AUDIO_RECORD_EVENT_ABORT = 6; + this.AUDIO_RECORD_EVENT_TIME_OUT = 7; + this.AUDIO_RECORD_EVENT_TICKER = 8; + this.AUDIO_RECORD_EVENT_SEND_FILE = 9; + this.AUDIO_AA_ENCODING_BIT_RATE = 32000; + this.idleState = new AudioRecordManager.IdleState(); + this.recordState = new AudioRecordManager.RecordState(); + this.sendingState = new AudioRecordManager.SendingState(); + this.cancelState = new AudioRecordManager.CancelState(); + this.timerState = new AudioRecordManager.TimerState(); + this.RECORD_INTERVAL = 60; + this.mSampleRate = AudioRecordManager.SamplingRate.RC_SAMPLE_RATE_8000; + RLog.d("AudioRecordManager", "AudioRecordManager"); + this.mHandler = new Handler(Looper.getMainLooper(), this); + this.mCurAudioState = this.idleState; + this.idleState.enter(); + } + + public static AudioRecordManager getInstance() { + return AudioRecordManager.SingletonHolder.sInstance; + } + + public final boolean handleMessage(Message msg) { + RLog.i("AudioRecordManager", "handleMessage " + msg.what); + AudioRecordManager.AudioStateMessage m; + switch (msg.what) { + case 2: + this.sendEmptyMessage(2); + break; + case 7: + m = new AudioRecordManager.AudioStateMessage(); + m.what = msg.what; + m.obj = msg.obj; + this.sendMessage(m); + break; + case 8: + m = new AudioRecordManager.AudioStateMessage(); + m.what = 7; + m.obj = msg.obj; + this.sendMessage(m); + } + + return false; + } + + private void initView(View root) { + LayoutInflater inflater = LayoutInflater.from(root.getContext()); + View view = inflater.inflate(io.rong.imkit.R.layout.rc_voice_record_popup, (ViewGroup) null); + this.mStateIV = (ImageView) view.findViewById(io.rong.imkit.R.id.rc_audio_state_image); + this.mStateTV = (TextView) view.findViewById(io.rong.imkit.R.id.rc_audio_state_text); + this.mTimerTV = (TextView) view.findViewById(io.rong.imkit.R.id.rc_audio_timer); + this.mRecordWindow = new PopupWindow(view, -1, -1); + this.mRecordWindow.showAtLocation(root, 17, 0, 0); + this.mRecordWindow.setFocusable(true); + this.mRecordWindow.setOutsideTouchable(false); + this.mRecordWindow.setTouchable(false); + } + + private void setTimeoutView(int counter) { + if (counter > 0) { + if (this.mRecordWindow != null) { + this.mStateIV.setVisibility(View.GONE); + this.mStateTV.setVisibility(View.VISIBLE); + this.mStateTV.setText(io.rong.imkit.R.string.rc_voice_rec); + // this.mStateTV.setBackgroundResource(17170445); + this.mTimerTV.setText(String.format("%s", counter)); + this.mTimerTV.setVisibility(View.VISIBLE); + } + } else if (this.mRecordWindow != null) { + this.mStateIV.setVisibility(View.VISIBLE); + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_warning); + this.mStateTV.setText(io.rong.imkit.R.string.rc_voice_too_long); + // this.mStateTV.setBackgroundResource(17170445); + this.mTimerTV.setVisibility(View.GONE); + } + + } + + private void setRecordingView() { + RLog.d("AudioRecordManager", "setRecordingView"); + if (this.mRecordWindow != null) { + this.mStateIV.setVisibility(View.VISIBLE); + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_1); + this.mStateTV.setVisibility(View.VISIBLE); + this.mStateTV.setText(io.rong.imkit.R.string.rc_voice_rec); + // this.mStateTV.setBackgroundResource(17170445); + this.mTimerTV.setVisibility(View.GONE); + } + + } + + private void setCancelView() { + RLog.d("AudioRecordManager", "setCancelView"); + if (this.mRecordWindow != null) { + this.mTimerTV.setVisibility(View.GONE); + this.mStateIV.setVisibility(View.VISIBLE); + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_cancel); + this.mStateTV.setVisibility(View.VISIBLE); + this.mStateTV.setText(io.rong.imkit.R.string.rc_voice_cancel); + this.mStateTV.setBackgroundResource(io.rong.imkit.R.drawable.rc_voice_cancel_background); + } + + } + + private void setCallStateChangeListener() { + if (Build.VERSION.SDK_INT < 21) { + try { + if (this.mContext == null) { + return; + } + + TelephonyManager manager = (TelephonyManager) this.mContext.getSystemService(Context.TELEPHONY_SERVICE); + manager.listen(new PhoneStateListener() { + public void onCallStateChanged(int state, String incomingNumber) { + switch (state) { + case 1: + AudioRecordManager.this.sendEmptyMessage(6); + case 0: + case 2: + default: + super.onCallStateChanged(state, incomingNumber); + } + } + }, 32); + } catch (SecurityException var2) { + RLog.e("AudioRecordManager", "AudioRecordManager", var2); + } + } + + } + + private void destroyView() { + RLog.d("AudioRecordManager", "destroyView"); + if (this.mRecordWindow != null) { + this.mHandler.removeMessages(7); + this.mHandler.removeMessages(8); + this.mHandler.removeMessages(2); + this.mRecordWindow.dismiss(); + this.mRecordWindow = null; + this.mStateIV = null; + this.mStateTV = null; + this.mTimerTV = null; + this.mContext = null; + this.mRootView = null; + } + + } + + public int getMaxVoiceDuration() { + return this.RECORD_INTERVAL; + } + + /** + * @deprecated + */ + public void setMaxVoiceDuration(int maxVoiceDuration) { + this.RECORD_INTERVAL = maxVoiceDuration; + } + + public void startRecord(View rootView, IAudioRecordStateChangeListener recordStateChangeListener) { + this.recordStateChangeListener = recordStateChangeListener; + if (rootView != null) { + this.mRootView = rootView; + this.mContext = rootView.getContext().getApplicationContext(); + this.mAudioManager = (AudioManager) this.mContext.getSystemService(Context.AUDIO_SERVICE); + if (this.mAfChangeListener != null) { + this.mAudioManager.abandonAudioFocus(this.mAfChangeListener); + this.mAfChangeListener = null; + } + + this.mAfChangeListener = new AudioManager.OnAudioFocusChangeListener() { + public void onAudioFocusChange(int focusChange) { + RLog.d("AudioRecordManager", "OnAudioFocusChangeListener " + focusChange); + if (focusChange == -1) { + AudioRecordManager.this.mAudioManager.abandonAudioFocus(AudioRecordManager.this.mAfChangeListener); + AudioRecordManager.this.mAfChangeListener = null; + AudioRecordManager.this.mHandler.post(new Runnable() { + public void run() { + AudioRecordManager.this.sendEmptyMessage(6); + } + }); + } + + } + }; + this.sendEmptyMessage(1); + recordTime = 0; + new Timer().schedule(getTask(), 0, 1000); + /* if (TypingMessageManager.getInstance().isShowMessageTyping() && conversationIdentifier.getType().equals(Conversation.ConversationType.PRIVATE)) { + RongIMClient.getInstance().sendTypingStatus(conversationIdentifier.getType(), this.mConversationIdentifier.getTargetId(), "RC:VcMsg"); + }*/ + + } + } + + private TimerTask task; + + private TimerTask getTask() { + task = new TimerTask() { + @Override + public void run() { + mHandler.post(() -> { + recordStateChangeListener.onTimer(recordTime++); + }); + } + }; + return task; + } + + public void willCancelRecord() { + this.sendEmptyMessage(3); + } + + public void continueRecord() { + this.sendEmptyMessage(4); + } + + public void stopRecord() { + this.sendEmptyMessage(5); + } + + public void destroyRecord() { + AudioRecordManager.AudioStateMessage msg = new AudioRecordManager.AudioStateMessage(); + msg.obj = true; + msg.what = 5; + this.sendMessage(msg); + } + + void sendMessage(AudioRecordManager.AudioStateMessage message) { + this.mCurAudioState.handleMessage(message); + } + + void sendEmptyMessage(int event) { + AudioRecordManager.AudioStateMessage message = new AudioRecordManager.AudioStateMessage(); + message.what = event; + this.mCurAudioState.handleMessage(message); + } + + private void startRec() { + RLog.d("AudioRecordManager", "startRec"); + + try { + this.muteAudioFocus(this.mAudioManager, true); + this.mAudioManager.setMode(AudioManager.MODE_NORMAL); + this.mMediaRecorder = new MediaRecorder(); + this.mMediaRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() { + public void onError(MediaRecorder mr, int what, int extra) { + RLog.e("AudioRecordManager", "MediaRecorder:onError: what = " + what + ", extra = " + extra); + } + }); + int bpsNb = RongConfigCenter.featureConfig().getAudioNBEncodingBitRate(); + int bpsWb = RongConfigCenter.featureConfig().getAudioWBEncodingBitRate(); + if (RongConfigCenter.featureConfig().getVoiceMessageType() == IMCenter.VoiceMessageType.HighQuality) { + this.mMediaRecorder.setAudioEncodingBitRate(32000); + } else { + this.mMediaRecorder.setAudioSamplingRate(this.mSampleRate.value); + if (this.mSampleRate.equals(AudioRecordManager.SamplingRate.RC_SAMPLE_RATE_8000)) { + this.mMediaRecorder.setAudioEncodingBitRate(bpsNb); + } else { + this.mMediaRecorder.setAudioEncodingBitRate(bpsWb); + } + } + + this.mMediaRecorder.setAudioChannels(1); + this.mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + if (RongConfigCenter.featureConfig().getVoiceMessageType().equals(IMCenter.VoiceMessageType.HighQuality)) { + this.mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS); + this.mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); + } else if (this.mSampleRate.equals(AudioRecordManager.SamplingRate.RC_SAMPLE_RATE_8000)) { + this.mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); + this.mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + } else { + this.mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB); + this.mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB); + } + + File savePath = SavePathUtils.getSavePath(this.mContext.getCacheDir()); + if (!savePath.exists()) { + throw new FileNotFoundException(savePath.getPath()); + } + + if (!savePath.canWrite()) { + boolean result = savePath.setWritable(true, true); + if (!result) { + String msg = savePath.getPath() + " could not be writable."; + throw new IOException(msg); + } + } + + this.mAudioPath = Uri.fromFile(new File(savePath, System.currentTimeMillis() + "temp.voice")); + this.mMediaRecorder.setOutputFile(this.mAudioPath.getPath()); + this.mMediaRecorder.prepare(); + this.mMediaRecorder.start(); + Message message = Message.obtain(); + message.what = 7; + message.obj = 10; + this.mHandler.removeMessages(7); + this.mHandler.sendMessageDelayed(message, (long) (this.RECORD_INTERVAL * 1000 - 10000)); + } catch (RuntimeException | IOException var6) { + RLog.e("AudioRecordManager", "startRec", var6); + this.mMediaRecorder.release(); + this.mMediaRecorder = null; + this.mHandler.sendEmptyMessage(6); + } + + } + + private boolean checkAudioTimeLength() { + long delta = SystemClock.elapsedRealtime() - this.smStartRecTime; + return delta < 1000L; + } + + private void stopRec() { + RLog.d("AudioRecordManager", "stopRec"); + if (task != null) { + task.cancel(); + task = null; + } + try { + this.muteAudioFocus(this.mAudioManager, false); + if (this.mMediaRecorder != null) { + this.mMediaRecorder.stop(); + this.mMediaRecorder.release(); + this.mMediaRecorder = null; + } + } catch (Exception var2) { + RLog.e("AudioRecordManager", "stopRec", var2); + } + + } + + private void deleteAudioFile() { + RLog.d("AudioRecordManager", "deleteAudioFile"); + if (this.mAudioPath != null) { + File file = new File(this.mAudioPath.getPath()); + if (file.exists()) { + boolean deleteResult = file.delete(); + if (!deleteResult) { + RLog.e("AudioRecordManager", "deleteAudioFile delete file failed. path :" + this.mAudioPath.getPath()); + } + } + } + + } + + private void sendAudioFile() { + RLog.d("AudioRecordManager", "sendAudioFile path = " + this.mAudioPath); + if (this.mAudioPath != null) { + File file = new File(this.mAudioPath.getPath()); + if (!file.exists() || file.length() == 0L) { + RLog.e("AudioRecordManager", "sendAudioFile fail cause of file length 0 or audio permission denied"); + return; + } + + int duration = (int) (SystemClock.elapsedRealtime() - this.smStartRecTime) / 1000; + Log.i(TAG, "sendAudioFile: 语音文件:" + file.getAbsoluteFile() + "|时间:" + duration); + recordStateChangeListener.onDone(file, duration); + /*if (RongConfigCenter.featureConfig().getVoiceMessageType() == IMCenter.VoiceMessageType.HighQuality) { + HQVoiceMessage hqVoiceMessage = HQVoiceMessage.obtain(this.mAudioPath, Math.min(duration, this.RECORD_INTERVAL)); + if (DestructManager.isActive()) { + hqVoiceMessage.setDestructTime((long)DestructManager.VOICE_DESTRUCT_TIME); + } + + io.rong.imlib.model.Message message = io.rong.imlib.model.Message.obtain(this.mConversationIdentifier, hqVoiceMessage); + IMCenter.getInstance().sendMediaMessage(message, DestructManager.isActive() ? this.mContext.getResources().getString(io.rong.imkit.R.string.rc_conversation_summary_content_burn) : null, (String)null, new IRongCallback.ISendMediaMessageCallback() { + public void onProgress(io.rong.imlib.model.Message message, int progress) { + } + + public void onCanceled(io.rong.imlib.model.Message message) { + } + + public void onAttached(io.rong.imlib.model.Message message) { + } + + public void onSuccess(io.rong.imlib.model.Message message) { + } + + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + RLog.d("AudioRecordManager", "onError = " + errorCode.toString()); + } + }); + } else { + VoiceMessage voiceMessage = VoiceMessage.obtain(this.mAudioPath, Math.min(duration, this.RECORD_INTERVAL)); + if (DestructManager.isActive()) { + voiceMessage.setDestructTime((long)DestructManager.VOICE_DESTRUCT_TIME); + } + + IMCenter.getInstance().sendMessage(io.rong.imlib.model.Message.obtain(this.mConversationIdentifier, voiceMessage), DestructManager.isActive() ? this.mContext.getResources().getString(io.rong.imkit.R.string.rc_conversation_summary_content_burn) : null, (String)null, new IRongCallback.ISendMessageCallback() { + public void onAttached(io.rong.imlib.model.Message message) { + } + + public void onSuccess(io.rong.imlib.model.Message message) { + } + + public void onError(io.rong.imlib.model.Message message, RongIMClient.ErrorCode errorCode) { + } + }); + }*/ + } + + } + + private void audioDBChanged() { + if (this.mMediaRecorder != null) { + int db = 0; + + try { + db = this.mMediaRecorder.getMaxAmplitude() / 600; + } catch (IllegalStateException var3) { + RLog.e("AudioRecordManager", "audioDBChanged IllegalStateException"); + } + + switch (db / 5) { + case 0: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_1); + break; + case 1: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_2); + break; + case 2: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_3); + break; + case 3: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_4); + break; + case 4: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_5); + break; + case 5: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_6); + break; + default: + this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_6); + } + } + + } + + private void muteAudioFocus(AudioManager audioManager, boolean bMute) { + if (Build.VERSION.SDK_INT < 8) { + RLog.d("AudioRecordManager", "muteAudioFocus Android 2.1 and below can not stop music"); + } else if (audioManager == null) { + RLog.e("AudioRecordManager", "audioManager is null"); + } else { + if (bMute) { + audioManager.requestAudioFocus(this.mAfChangeListener, 3, 2); + } else { + audioManager.abandonAudioFocus(this.mAfChangeListener); + this.mAfChangeListener = null; + } + + } + } + + public int getSamplingRate() { + return this.mSampleRate.getValue(); + } + + public void setSamplingRate(AudioRecordManager.SamplingRate sampleRate) { + this.mSampleRate = sampleRate; + } + + class AudioStateMessage { + public int what; + public Object obj; + + AudioStateMessage() { + } + + public AudioRecordManager.AudioStateMessage obtain() { + return AudioRecordManager.this.new AudioStateMessage(); + } + } + + abstract class IAudioState { + IAudioState() { + } + + void enter() { + } + + abstract void handleMessage(AudioRecordManager.AudioStateMessage message); + } + + class TimerState extends AudioRecordManager.IAudioState { + TimerState() { + super(); + } + + void handleMessage(AudioRecordManager.AudioStateMessage msg) { + RLog.d("AudioRecordManager", this.getClass().getSimpleName() + " handleMessage : " + msg.what); + switch (msg.what) { + case 3: + AudioRecordManager.this.setCancelView(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.cancelState; + case 4: + default: + break; + case 5: + AudioRecordManager.this.mHandler.postDelayed(new Runnable() { + public void run() { + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.sendAudioFile(); + AudioRecordManager.this.destroyView(); + } + }, 500L); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + AudioRecordManager.this.idleState.enter(); + break; + case 6: + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.destroyView(); + AudioRecordManager.this.deleteAudioFile(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + AudioRecordManager.this.idleState.enter(); + break; + case 7: + int counter = (Integer) msg.obj; + if (counter >= 0) { + Message message = Message.obtain(); + message.what = 8; + message.obj = counter - 1; + AudioRecordManager.this.mHandler.sendMessageDelayed(message, 1000L); + AudioRecordManager.this.setTimeoutView(counter); + } else { + AudioRecordManager.this.mHandler.postDelayed(new Runnable() { + public void run() { + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.sendAudioFile(); + AudioRecordManager.this.destroyView(); + } + }, 500L); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + } + } + + } + } + + class CancelState extends AudioRecordManager.IAudioState { + CancelState() { + super(); + } + + void handleMessage(AudioRecordManager.AudioStateMessage msg) { + RLog.d("AudioRecordManager", this.getClass().getSimpleName() + " handleMessage : " + msg.what); + switch (msg.what) { + case 1: + case 2: + case 3: + default: + break; + case 4: + AudioRecordManager.this.setRecordingView(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.recordState; + AudioRecordManager.this.sendEmptyMessage(2); + break; + case 5: + case 6: + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.destroyView(); + AudioRecordManager.this.deleteAudioFile(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + AudioRecordManager.this.idleState.enter(); + break; + case 7: + int counter = (Integer) msg.obj; + if (counter > 0) { + Message message = Message.obtain(); + message.what = 8; + message.obj = counter - 1; + AudioRecordManager.this.mHandler.sendMessageDelayed(message, 1000L); + } else { + AudioRecordManager.this.mHandler.postDelayed(new Runnable() { + public void run() { + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.sendAudioFile(); + AudioRecordManager.this.destroyView(); + } + }, 500L); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + AudioRecordManager.this.idleState.enter(); + } + } + + } + } + + class SendingState extends AudioRecordManager.IAudioState { + SendingState() { + super(); + } + + void handleMessage(AudioRecordManager.AudioStateMessage message) { + RLog.d("AudioRecordManager", "SendingState handleMessage " + message.what); + switch (message.what) { + case 9: + AudioRecordManager.this.stopRec(); + if ((Boolean) message.obj) { + AudioRecordManager.this.sendAudioFile(); + } + + AudioRecordManager.this.destroyView(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + default: + } + } + } + + class RecordState extends AudioRecordManager.IAudioState { + RecordState() { + super(); + } + + void handleMessage(AudioRecordManager.AudioStateMessage msg) { + RLog.d("AudioRecordManager", this.getClass().getSimpleName() + " handleMessage : " + msg.what); + switch (msg.what) { + case 2: + AudioRecordManager.this.audioDBChanged(); + AudioRecordManager.this.mHandler.sendEmptyMessageDelayed(2, 150L); + break; + case 3: + AudioRecordManager.this.setCancelView(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.cancelState; + case 4: + default: + break; + case 5: + final boolean checked = AudioRecordManager.this.checkAudioTimeLength(); + boolean activityFinished = false; + if (msg.obj != null) { + activityFinished = (Boolean) msg.obj; + } + + if (checked && !activityFinished) { + AudioRecordManager.this.mStateIV.setImageResource(io.rong.imkit.R.drawable.rc_voice_volume_warning); + AudioRecordManager.this.mStateTV.setText(io.rong.imkit.R.string.rc_voice_short); + AudioRecordManager.this.mHandler.removeMessages(2); + } + + if (!activityFinished && AudioRecordManager.this.mHandler != null) { + AudioRecordManager.this.mHandler.postDelayed(new Runnable() { + public void run() { + AudioRecordManager.AudioStateMessage message = AudioRecordManager.this.new AudioStateMessage(); + message.what = 9; + message.obj = !checked; + AudioRecordManager.this.sendMessage(message); + } + }, 500L); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.sendingState; + } else { + AudioRecordManager.this.stopRec(); + if (!checked && activityFinished) { + AudioRecordManager.this.sendAudioFile(); + } + + AudioRecordManager.this.destroyView(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + } + break; + case 6: + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.destroyView(); + AudioRecordManager.this.deleteAudioFile(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + AudioRecordManager.this.idleState.enter(); + break; + case 7: + int counter = (Integer) msg.obj; + AudioRecordManager.this.setTimeoutView(counter); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.timerState; + if (counter >= 0) { + Message message = Message.obtain(); + message.what = 8; + message.obj = counter - 1; + AudioRecordManager.this.mHandler.sendMessageDelayed(message, 1000L); + } else { + AudioRecordManager.this.mHandler.postDelayed(new Runnable() { + public void run() { + AudioRecordManager.this.stopRec(); + AudioRecordManager.this.sendAudioFile(); + AudioRecordManager.this.destroyView(); + } + }, 500L); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.idleState; + } + } + + } + } + + class IdleState extends AudioRecordManager.IAudioState { + public IdleState() { + super(); + RLog.d("AudioRecordManager", "IdleState"); + } + + void enter() { + super.enter(); + if (AudioRecordManager.this.mHandler != null) { + AudioRecordManager.this.mHandler.removeMessages(7); + AudioRecordManager.this.mHandler.removeMessages(8); + AudioRecordManager.this.mHandler.removeMessages(2); + } + + } + + void handleMessage(AudioRecordManager.AudioStateMessage msg) { + RLog.d("AudioRecordManager", "IdleState handleMessage : " + msg.what); + switch (msg.what) { + case 1: + AudioRecordManager.this.initView(AudioRecordManager.this.mRootView); + AudioRecordManager.this.setRecordingView(); + AudioRecordManager.this.startRec(); + AudioRecordManager.this.setCallStateChangeListener(); + AudioRecordManager.this.smStartRecTime = SystemClock.elapsedRealtime(); + AudioRecordManager.this.mCurAudioState = AudioRecordManager.this.recordState; + AudioRecordManager.this.sendEmptyMessage(2); + default: + } + } + } + + static class SingletonHolder { + static AudioRecordManager sInstance = new AudioRecordManager(); + + SingletonHolder() { + } + } + + public static enum SamplingRate { + RC_SAMPLE_RATE_8000(8000), + RC_SAMPLE_RATE_16000(16000); + + private int value; + + private SamplingRate(int sampleRate) { + this.value = sampleRate; + } + + public int getValue() { + return this.value; + } + } + + public interface IAudioRecordStateChangeListener { + void onTimer(int timer); + + void onDone(File file, int timer); + } +} \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/utils/UserInfoManager.java b/main/src/main/java/com/yunbao/main/utils/UserInfoManager.java new file mode 100644 index 000000000..ed28fc1ef --- /dev/null +++ b/main/src/main/java/com/yunbao/main/utils/UserInfoManager.java @@ -0,0 +1,36 @@ +package com.yunbao.main.utils; + +import android.content.Context; + +import com.yunbao.common.CommonAppConfig; +import com.yunbao.common.bean.MessageUserInfoBean; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.main.dialog.UserAvatarPopup; + +public class UserInfoManager { + private static MessageUserInfoBean myInfo; + + public static MessageUserInfoBean getMyInfo() { + return myInfo; + } + + public static void updateMyInfo(Context context, OnItemClickListener listener) { + LiveNetManager.get(context) + .getOtherInfo(CommonAppConfig.getInstance().getUid(), new HttpCallback() { + @Override + public void onSuccess(MessageUserInfoBean data) { + if (listener != null) { + listener.onItemClick(data, 0); + } + myInfo = data; + } + + @Override + public void onError(String error) { + + } + }); + } +} diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java index c0ab43cf1..00906f5c2 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON; import com.binioter.guideview.Guide; import com.binioter.guideview.GuideBuilder; import com.facebook.appevents.AppEventsLogger; +import com.lxj.xpopup.XPopup; import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAParser; @@ -31,12 +32,15 @@ import com.opensource.svgaplayer.SVGAVideoEntity; import com.umeng.analytics.MobclickAgent; import com.yunbao.common.bean.ImUserInfoModel; import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.bean.MessageChatIsAnchor; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.LiveHttpUtil; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.NoviceInstructorManager; import com.yunbao.common.manager.imrongcloud.MessageIMManager; +import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.LiveRoomCheckLivePresenter; import com.yunbao.common.utils.RouteUtil; @@ -50,8 +54,11 @@ import com.yunbao.live.bean.ImUserBean; import com.yunbao.live.event.RecommendLiveRoomEvent; import com.yunbao.live.http.ImHttpUtil; import com.yunbao.main.R; +import com.yunbao.main.activity.CompleteUserInfoActivity; import com.yunbao.main.activity.MainActivity; +import com.yunbao.main.activity.MessageHiConfigRecordActivity; import com.yunbao.main.adapter.SystemMessageAdapter; +import com.yunbao.main.dialog.MsgMoreDialog; import com.yunbao.main.fragment.MainMessageChatFragment; import com.yunbao.main.manager.imrongcloud.ConversationIMListManager; @@ -80,8 +87,9 @@ public class MainMessageViewHolder extends AbsMainViewHolder { private Handler netHandler; private MainActivity mContext; private View contacts; + private View more; private EditText search; - + XPopup.Builder moreXPopup; private String homeZdyPop; public MainMessageViewHolder setHomeZdyPop(String homeZdyPop) { @@ -126,10 +134,13 @@ public class MainMessageViewHolder extends AbsMainViewHolder { imgSystemMessages = (ImageView) findViewById(R.id.img_system_messages); imgNewsOnline = (ImageView) findViewById(R.id.img_news_online); contacts = findViewById(R.id.news_icon_contacts); + more = findViewById(R.id.news_icon_more); search = findViewById(R.id.search); contacts.setOnClickListener(view -> { //通讯录 - RouteUtil.forwardActivity(RouteUtil.PATH_ADDRESSBOOK); + // RouteUtil.forwardActivity(RouteUtil.PATH_ADDRESSBOOK); + // mContext.startActivity(new Intent(mContext, CompleteUserInfoActivity.class)); + mContext.startActivity(new Intent(mContext, MessageHiConfigRecordActivity.class)); }); search.addTextChangedListener(new TextWatcher() { @Override @@ -152,7 +163,10 @@ public class MainMessageViewHolder extends AbsMainViewHolder { } }); netHandler = new Handler(); - + moreXPopup = new XPopup.Builder(mContext).atView(more); + more.setOnClickListener(view -> { + moreXPopup.asCustom(new MsgMoreDialog(mContext)).show(); + }); } @Override @@ -240,7 +254,23 @@ public class MainMessageViewHolder extends AbsMainViewHolder { MessageIMManager.get(mContext).getSystemMessages(); } }); + LiveNetManager.get(mContext) + .getIsAnchor(new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(MessageChatIsAnchor data) { + AppManager.runDebugCode(() -> { + more.setVisibility(View.VISIBLE); + }); + if (data.getIsAnchor() == 1) { + more.setVisibility(View.VISIBLE); + } + } + @Override + public void onError(String error) { + + } + }); } @@ -302,7 +332,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder { textNewsInteraction.setText(String.valueOf(numberInt)); } } - // ImgLoader.display(mContext, userBean.getNewImage(), imgNewsInteraction); + // ImgLoader.display(mContext, userBean.getNewImage(), imgNewsInteraction); ViewClicksAntiShake.clicksAntiShake(imgNewsInteraction, () -> { MobclickAgent.onEvent(mContext, "information_system_interactive", "互動消息"); type = userBean.getType(); diff --git a/main/src/main/res/drawable/bg_btn_activity_user_info_avatar_change.xml b/main/src/main/res/drawable/bg_btn_activity_user_info_avatar_change.xml new file mode 100644 index 000000000..a2d51fbba --- /dev/null +++ b/main/src/main/res/drawable/bg_btn_activity_user_info_avatar_change.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/bg_btn_hi_config_record_reset.xml b/main/src/main/res/drawable/bg_btn_hi_config_record_reset.xml new file mode 100644 index 000000000..015d2f96e --- /dev/null +++ b/main/src/main/res/drawable/bg_btn_hi_config_record_reset.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/bg_btn_hi_config_record_save.xml b/main/src/main/res/drawable/bg_btn_hi_config_record_save.xml new file mode 100644 index 000000000..4be1ae65e --- /dev/null +++ b/main/src/main/res/drawable/bg_btn_hi_config_record_save.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/bg_user_avatar.xml b/main/src/main/res/drawable/bg_user_avatar.xml new file mode 100644 index 000000000..9ff74fedd --- /dev/null +++ b/main/src/main/res/drawable/bg_user_avatar.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/main/src/main/res/drawable/dialog_bg_chat_status_config.xml b/main/src/main/res/drawable/dialog_bg_chat_status_config.xml new file mode 100644 index 000000000..785032a56 --- /dev/null +++ b/main/src/main/res/drawable/dialog_bg_chat_status_config.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/dialog_bg_chat_status_config_select.xml b/main/src/main/res/drawable/dialog_bg_chat_status_config_select.xml new file mode 100644 index 000000000..6d36051d1 --- /dev/null +++ b/main/src/main/res/drawable/dialog_bg_chat_status_config_select.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/dialog_bg_chat_status_config_unselect.xml b/main/src/main/res/drawable/dialog_bg_chat_status_config_unselect.xml new file mode 100644 index 000000000..2d081c6f6 --- /dev/null +++ b/main/src/main/res/drawable/dialog_bg_chat_status_config_unselect.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/dialog_bg_msg_hi_config_unselect.xml b/main/src/main/res/drawable/dialog_bg_msg_hi_config_unselect.xml new file mode 100644 index 000000000..05c349fc9 --- /dev/null +++ b/main/src/main/res/drawable/dialog_bg_msg_hi_config_unselect.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/view_btn_chat_status_config.xml b/main/src/main/res/drawable/view_btn_chat_status_config.xml new file mode 100644 index 000000000..af66622b6 --- /dev/null +++ b/main/src/main/res/drawable/view_btn_chat_status_config.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/view_btn_chat_status_config_off_color.xml b/main/src/main/res/drawable/view_btn_chat_status_config_off_color.xml new file mode 100644 index 000000000..7da21f67c --- /dev/null +++ b/main/src/main/res/drawable/view_btn_chat_status_config_off_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/view_btn_chat_status_config_online_color.xml b/main/src/main/res/drawable/view_btn_chat_status_config_online_color.xml new file mode 100644 index 000000000..a4ac57418 --- /dev/null +++ b/main/src/main/res/drawable/view_btn_chat_status_config_online_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/view_btn_chat_status_config_textcolor.xml b/main/src/main/res/drawable/view_btn_chat_status_config_textcolor.xml new file mode 100644 index 000000000..f562ea784 --- /dev/null +++ b/main/src/main/res/drawable/view_btn_chat_status_config_textcolor.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/view_btn_hi_config_record.xml b/main/src/main/res/drawable/view_btn_hi_config_record.xml new file mode 100644 index 000000000..af513813b --- /dev/null +++ b/main/src/main/res/drawable/view_btn_hi_config_record.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/activity_hi_config_record.xml b/main/src/main/res/layout/activity_hi_config_record.xml new file mode 100644 index 000000000..f05394e9b --- /dev/null +++ b/main/src/main/res/layout/activity_hi_config_record.xml @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +