diff --git a/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java b/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java index 03ba23e9f..5736848df 100644 --- a/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java +++ b/common/src/main/java/com/yunbao/common/manager/IMLoginManager.java @@ -1,26 +1,35 @@ package com.yunbao.common.manager; import android.content.Context; +import android.os.Handler; +import android.util.Log; import androidx.annotation.NonNull; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.google.gson.Gson; import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.base.BaseCacheManager; +import java.util.Map; + /** * 登录者信息管理 */ public class IMLoginManager extends BaseCacheManager { - - private final static String KEY_USER_INFO = "keyUserInfo"; - private static IMLoginManager manager; private IMLoginModel userInfo; + //根据用户信息 + private Handler netHandler = new Handler(); + private Context context; private IMLoginManager(Context context) { super(context); + this.context = context; } /** @@ -54,19 +63,46 @@ public class IMLoginManager extends BaseCacheManager { * @param model */ public void setupLoginUser(@NonNull IMLoginModel model) { - put(KEY_USER_INFO, new Gson().toJson(model)); this.userInfo = model; - + netHandler.post(isInstructorRunnable); } + /** + * 获取是不是新手指导员的身份 + */ + private Runnable isInstructorRunnable = new Runnable() { + @Override + public void run() { + HttpClient.getInstance().get("User.isInstructor", "isInstructor") + .params("uid", userInfo.getId()) + .params("token", userInfo.getToken()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (info.length > 0) { + if ("1".equals(info[0])) { + userInfo.setIsAdmin("1"); + InstructorRemarkManager.get(context).getNetInstructorRemark(); + } else { + userInfo.setIsAdmin("0"); + } + } + put(KEY_USER_INFO, new Gson().toJson(userInfo)); + } + }); + + } + }; + + /** * 退出登录 */ public void logout() { //删除用户登录信息 - deleteByKey(KEY_USER_INFO); - //用户对象置空 - userInfo=null; + deleteByKey(KEY_USER_INFO); + //用户对象置空 + userInfo = null; manager = null; } diff --git a/common/src/main/java/com/yunbao/common/manager/InstructorRemarkManager.java b/common/src/main/java/com/yunbao/common/manager/InstructorRemarkManager.java new file mode 100644 index 000000000..68ba76ab4 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/InstructorRemarkManager.java @@ -0,0 +1,111 @@ +package com.yunbao.common.manager; + +import android.content.Context; +import android.os.Handler; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.google.gson.Gson; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.http.HttpClient; +import com.yunbao.common.manager.base.BaseCacheManager; + +import java.util.Map; + +/** + * 新手指导员备注列表 + */ +public class InstructorRemarkManager extends BaseCacheManager { + private final static String KEY_INSTRUCTOR_REMARK = "InstructorRemark"; + private static InstructorRemarkManager manager; + private Context context; + private Map instructorRemarkMap; + private Handler netHandler = new Handler(); + + private InstructorRemarkManager(Context context) { + super(context); + this.context = context; + } + + /** + * 获取指导员备注信息 + * + * @return + */ + public Map getInstructorRemark() { + if (null == instructorRemarkMap) { + instructorRemarkMap = JSON.parseObject(getString(KEY_INSTRUCTOR_REMARK), new TypeReference>() { + }); + } + return instructorRemarkMap; + } + + /** + * 设置指导员备注信息 + */ + public void setInstructorRemark(String map) { + this.instructorRemarkMap = JSON.parseObject(map, new TypeReference>() { + }); + put(KEY_INSTRUCTOR_REMARK, map); + } + + /** + * 新增备注 + * + * @param key 用户id + * @param value 备注信息 + */ + public void addInstructorRemark(String key, String value) { + this.instructorRemarkMap.put(key, value); + String json = new Gson().toJson(instructorRemarkMap).toString(); + put(KEY_INSTRUCTOR_REMARK, json); + } + + /** + * 从服务器获取信息 + */ + public void getNetInstructorRemark() { + netHandler.post(getInstructorRemarkRunnable); + } + + /** + * 获取单利 + * + * @return + */ + public static InstructorRemarkManager get(Context context) { + if (null == manager) { + manager = new InstructorRemarkManager(context); + } + return manager; + } + + + /** + * 获取备注信息 + */ + private Runnable getInstructorRemarkRunnable = new Runnable() { + @Override + public void run() { + IMLoginModel userInfo = IMLoginManager.get(context).getUserInfo(); + HttpClient.getInstance().get("User.getInstructorRemark", "getInstructorRemark") + .params("uid", userInfo.getId()) + .params("token", userInfo.getToken()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + instructorRemarkMap = JSON.parseObject(info[0], new TypeReference>() { + + }); + setInstructorRemark(info[0]); + } + + } + }); + + + } + }; +} diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index eb00d57dd..41f237ebe 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -91,6 +91,9 @@ android:windowSoftInputMode="stateHidden|adjustResize"> + \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/activity/EditNameRemarksActivity.java b/live/src/main/java/com/yunbao/live/activity/EditNameRemarksActivity.java index f9f516a29..a103f46cb 100644 --- a/live/src/main/java/com/yunbao/live/activity/EditNameRemarksActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/EditNameRemarksActivity.java @@ -1,22 +1,28 @@ package com.yunbao.live.activity; +import android.net.Uri; import android.text.InputFilter; import android.text.TextUtils; import android.view.View; import android.widget.EditText; -import com.google.gson.Gson; -import com.yunbao.common.Constants; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.GsonUtils; import com.yunbao.common.activity.AbsActivity; -import com.yunbao.common.bean.ChatRemarksBean; +import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; -import com.yunbao.common.utils.SpUtil; +import com.yunbao.common.manager.InstructorRemarkManager; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; +import com.yunbao.live.bean.SearchUserBean; import com.yunbao.live.http.LiveHttpUtil; -import static com.yunbao.live.views.SystemMessageViewHolder.updataNkname; +import org.greenrobot.eventbus.EventBus; + +import io.rong.imkit.userinfo.RongUserInfoManager; +import io.rong.imlib.model.UserInfo; /** @@ -27,6 +33,9 @@ import static com.yunbao.live.views.SystemMessageViewHolder.updataNkname; public class EditNameRemarksActivity extends AbsActivity implements View.OnClickListener { private EditText mEditText; + private String userId; + public final static String NAMEREMARK = "NameRemark"; + @Override protected int getLayoutId() { @@ -36,21 +45,18 @@ public class EditNameRemarksActivity extends AbsActivity implements View.OnClick @Override protected void main() { setTitle(WordUtil.getString(R.string.edit_profile_update_remarks)); + userId = getIntent().getStringExtra(NAMEREMARK); mEditText = (EditText) findViewById(R.id.edit); mEditText.setFilters(new InputFilter[]{ new InputFilter.LengthFilter(10) }); + String content = InstructorRemarkManager.get(mContext).getInstructorRemark().get(userId); findViewById(R.id.btn_save).setOnClickListener(this); - String content = getIntent().getStringExtra(Constants.REMARKS); - if (!TextUtils.isEmpty(content)) { - if (content.length() > 10) { - content = content.substring(0, 10); - } - mEditText.setText(content); - mEditText.setSelection(content.length()); - } + mEditText.setText(content); + mEditText.setSelection(content.length()); } + @Override public void onClick(View v) { if (!canClick()) { @@ -62,25 +68,44 @@ public class EditNameRemarksActivity extends AbsActivity implements View.OnClick return; } - LiveHttpUtil.setInstructorRemark(SystemMessageActivity.nowUid, content, new HttpCallback() { + LiveHttpUtil.setInstructorRemark(userId, content, new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { ToastUtil.show(msg); if (code == 0) { - Constants.isSetRemark = SystemMessageActivity.nowUid; - Constants.isSetRemarkText = content; - updataNkname(); - //增加备注本地存储 - Constants.remarksListNow.add(new ChatRemarksBean(SystemMessageActivity.nowUid,content)); - String remarksList = new Gson().toJson(Constants.remarksListNow); - SpUtil.setStringValue("remarksList", remarksList); - finish(); + InstructorRemarkManager.get(mContext).addInstructorRemark(userId, content); + //刷新列表内用户信息 + addUserInfoProvider(content); + } } }); } + /** + * 刷新用户信息 + */ + public void addUserInfoProvider(String remark) { + CommonHttpUtil.getUserBaseinfo(userId, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0 && info.length > 0) { + JSONObject obj = JSON.parseObject(info[0]); + SearchUserBean userBean = JSON.toJavaObject(obj, SearchUserBean.class); + String userNiceName = userBean.getUserNiceName() + "(" + remark + ")"; + UserInfo userInfo = new UserInfo(userId, userNiceName, Uri.parse(userBean.getAvatar())); + //使用空白字段存储自己服务器用户的所有的信息 + userInfo.setExtra(GsonUtils.toJson(userBean)); + RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo); + EventBus.getDefault().post(userNiceName); + finish(); + } + + } + }); + } + @Override protected void onDestroy() { super.onDestroy(); diff --git a/live/src/main/java/com/yunbao/live/activity/PDLiveConversationActivity.java b/live/src/main/java/com/yunbao/live/activity/PDLiveConversationActivity.java index 1ef9e226f..56785e3e4 100644 --- a/live/src/main/java/com/yunbao/live/activity/PDLiveConversationActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/PDLiveConversationActivity.java @@ -6,7 +6,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.text.TextUtils; import android.util.Log; -import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; @@ -29,6 +28,10 @@ import com.yunbao.live.bean.SearchUserBean; import com.yunbao.live.dialog.MenuPopuwWindow; import com.yunbao.live.views.InputPanelViewHolder; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + import java.util.ArrayList; import io.rong.imkit.conversation.ConversationFragment; @@ -60,6 +63,7 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl @Override protected void main() { super.main(); + EventBus.getDefault().register(this); mContext = this; getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); initView(); @@ -105,17 +109,17 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl titleView = findViewById(R.id.titleView); imgMore = findViewById(R.id.img_more); imBack = findViewById(R.id.btn_back); - imgMore.setOnClickListener(this); - imBack.setOnClickListener(this); - findViewById(R.id.container).setOnTouchListener(new View.OnTouchListener() { + findViewById(R.id.root_layout).setOnClickListener(new View.OnClickListener() { @Override - public boolean onTouch(View v, MotionEvent event) { + public void onClick(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); - return false; } }); + imgMore.setOnClickListener(this); + imBack.setOnClickListener(this); + inputPanel.addMediaMessageCallback(new InputPanelViewHolder.MediaMessageCallback() { @Override public void choosePic(int intoIndex) { @@ -182,4 +186,18 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl } } } + + @Override + protected void onDestroy() { + super.onDestroy(); + EventBus.getDefault().unregister(this); + } + + //消息中心 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageIMEvent(String event) { + if (!TextUtils.isEmpty(event)) { + titleView.setText(event); + } + } } diff --git a/live/src/main/java/com/yunbao/live/dialog/MenuPopuwWindow.java b/live/src/main/java/com/yunbao/live/dialog/MenuPopuwWindow.java index 5d85b921a..13f9da443 100644 --- a/live/src/main/java/com/yunbao/live/dialog/MenuPopuwWindow.java +++ b/live/src/main/java/com/yunbao/live/dialog/MenuPopuwWindow.java @@ -1,6 +1,7 @@ package com.yunbao.live.dialog; import android.app.Activity; +import android.content.Intent; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -10,8 +11,10 @@ import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; +import com.yunbao.common.Constants; import com.yunbao.common.utils.ToastUtil; import com.yunbao.live.R; +import com.yunbao.live.activity.EditNameRemarksActivity; import io.rong.imlib.RongIMClient; @@ -24,7 +27,7 @@ public class MenuPopuwWindow implements View.OnClickListener { private View popupView; private TextView tvBlack, tvBlackMove; private LinearLayout ltRemarks; - private PopupWindow popupWindow; + private PopupWindow popupWindow; public MenuPopuwWindow(Activity context) { this.mContext = context; @@ -81,7 +84,7 @@ public class MenuPopuwWindow implements View.OnClickListener { * @return */ public void show(View view) { - popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); + popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); popupWindow.showAsDropDown(view); WindowManager.LayoutParams lp = mContext.getWindow().getAttributes(); lp.alpha = 0.8f; @@ -132,7 +135,10 @@ public class MenuPopuwWindow implements View.OnClickListener { } }); } else if (id == R.id.lt_remarks) {//添加备注 - + Intent intent = new Intent(mContext, EditNameRemarksActivity.class); + intent.putExtra(EditNameRemarksActivity.NAMEREMARK, userId); + mContext.startActivity(intent); + popupWindow.dismiss(); } } } diff --git a/live/src/main/java/com/yunbao/live/views/InputPanel.java b/live/src/main/java/com/yunbao/live/views/InputPanel.java deleted file mode 100644 index 8a93ea240..000000000 --- a/live/src/main/java/com/yunbao/live/views/InputPanel.java +++ /dev/null @@ -1,408 +0,0 @@ -package com.yunbao.live.views; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProvider; - -import com.yunbao.live.R; - -import io.rong.imkit.IMCenter; -import io.rong.imkit.conversation.extension.InputMode; -import io.rong.imkit.conversation.extension.RongExtensionCacheHelper; -import io.rong.imkit.conversation.extension.RongExtensionViewModel; -import io.rong.imkit.manager.AudioPlayManager; -import io.rong.imkit.manager.AudioRecordManager; -import io.rong.imkit.utils.PermissionCheckUtil; -import io.rong.imkit.utils.RongUtils; -import io.rong.imlib.IMLibExtensionModuleManager; -import io.rong.imlib.RongIMClient; -import io.rong.imlib.model.Conversation; -import io.rong.imlib.model.HardwareResource; - -import static android.view.View.VISIBLE; - -public class InputPanel { - private final String TAG = this.getClass().getSimpleName(); - private Conversation.ConversationType mConversationType; - private Context mContext; - private String mTargetId; - private InputPanel.InputStyle mInputStyle; - private Fragment mFragment; - private View mInputPanel; - private boolean mIsVoiceInputMode; - private ImageView mVoiceToggleBtn; - private EditText mEditText; - private TextView mVoiceInputBtn; - private ImageView mEmojiToggleBtn; - private Button mSendBtn; - private ImageView mAddBtn; - private ViewGroup mAddOrSendBtn; - private RongExtensionViewModel mExtensionViewModel; - private String mInitialDraft = ""; - private float mLastTouchY; - private boolean mUpDirection; - private View.OnTouchListener mOnVoiceBtnTouchListener = new View.OnTouchListener() { - public boolean onTouch(View v, MotionEvent event) { - float mOffsetLimit = 70.0F * v.getContext().getResources().getDisplayMetrics().density; - String[] permissions = new String[]{"android.permission.RECORD_AUDIO"}; - if (!PermissionCheckUtil.checkPermissions(v.getContext(), permissions) && event.getAction() == 0) { - PermissionCheckUtil.requestPermissions(InputPanel.this.mFragment, permissions, 100); - return true; - } else { - if (event.getAction() == 0) { - if (AudioPlayManager.getInstance().isPlaying()) { - AudioPlayManager.getInstance().stopPlay(); - } - - if (RongUtils.phoneIsInUse(v.getContext()) || IMLibExtensionModuleManager.getInstance().onRequestHardwareResource(HardwareResource.ResourceType.VIDEO) || IMLibExtensionModuleManager.getInstance().onRequestHardwareResource(HardwareResource.ResourceType.AUDIO)) { - Toast.makeText(v.getContext(), v.getContext().getResources().getString(R.string.rc_voip_occupying), Toast.LENGTH_SHORT).show(); - return true; - } - - AudioRecordManager.getInstance().startRecord(v.getRootView(), InputPanel.this.mConversationType, InputPanel.this.mTargetId); - InputPanel.this.mLastTouchY = event.getY(); - InputPanel.this.mUpDirection = false; - ((TextView) v).setText(R.string.rc_voice_release_to_send); - ((TextView) v).setBackground(v.getContext().getResources().getDrawable(R.drawable.rc_ext_voice_touched_button)); - } else if (event.getAction() == 2) { - if (InputPanel.this.mLastTouchY - event.getY() > mOffsetLimit && !InputPanel.this.mUpDirection) { - AudioRecordManager.getInstance().willCancelRecord(); - InputPanel.this.mUpDirection = true; - ((TextView) v).setText(R.string.rc_voice_press_to_input); - ((TextView) v).setBackground(v.getContext().getResources().getDrawable(R.drawable.rc_ext_voice_idle_button)); - } else if (event.getY() - InputPanel.this.mLastTouchY > -mOffsetLimit && InputPanel.this.mUpDirection) { - AudioRecordManager.getInstance().continueRecord(); - InputPanel.this.mUpDirection = false; - ((TextView) v).setBackground(v.getContext().getResources().getDrawable(R.drawable.rc_ext_voice_touched_button)); - ((TextView) v).setText(R.string.rc_voice_release_to_send); - } - } else if (event.getAction() == 1 || event.getAction() == 3) { - AudioRecordManager.getInstance().stopRecord(); - ((TextView) v).setText(R.string.rc_voice_press_to_input); - ((TextView) v).setBackground(v.getContext().getResources().getDrawable(R.drawable.rc_ext_voice_idle_button)); - } - - if (InputPanel.this.mConversationType.equals(Conversation.ConversationType.PRIVATE)) { - RongIMClient.getInstance().sendTypingStatus(InputPanel.this.mConversationType, InputPanel.this.mTargetId, "RC:VcMsg"); - } - - return true; - } - } - }; - private View.OnClickListener mOnSendBtnClick = new View.OnClickListener() { - public void onClick(View v) { - InputPanel.this.mExtensionViewModel.onSendClick(); - } - }; - private View.OnFocusChangeListener mOnEditTextFocusChangeListener = new View.OnFocusChangeListener() { - public void onFocusChange(View v, boolean hasFocus) { - if (hasFocus) { - if (InputPanel.this.mExtensionViewModel != null && InputPanel.this.mExtensionViewModel.getInputModeLiveData() != null) { - InputPanel.this.mExtensionViewModel.getInputModeLiveData().postValue(InputMode.TextInput); - } - - if (!TextUtils.isEmpty(InputPanel.this.mEditText.getText())) { - InputPanel.this.mSendBtn.setVisibility(VISIBLE); - InputPanel.this.mAddBtn.setVisibility(View.GONE); - } - } else { - EditText editText = InputPanel.this.mExtensionViewModel.getEditTextWidget(); - if (editText.getText() != null && editText.getText().length() == 0) { - InputPanel.this.mSendBtn.setVisibility(View.GONE); - InputPanel.this.mAddBtn.setVisibility(VISIBLE); - } - } - - } - }; - private TextWatcher mEditTextWatcher = new TextWatcher() { - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - public void onTextChanged(CharSequence s, int start, int before, int count) { - if (s != null && s.length() != 0) { - InputPanel.this.mAddOrSendBtn.setVisibility(VISIBLE); - InputPanel.this.mSendBtn.setVisibility(VISIBLE); - InputPanel.this.mAddBtn.setVisibility(View.GONE); - } else { - IMCenter.getInstance().saveTextMessageDraft(InputPanel.this.mConversationType, InputPanel.this.mTargetId, InputPanel.this.mEditText.getText().toString(), (RongIMClient.ResultCallback) null); - if (!InputPanel.this.mInputStyle.equals(InputPanel.InputStyle.STYLE_CONTAINER_EXTENSION) && !InputPanel.this.mInputStyle.equals(InputPanel.InputStyle.STYLE_SWITCH_CONTAINER_EXTENSION)) { - InputPanel.this.mAddOrSendBtn.setVisibility(View.GONE); - } else { - InputPanel.this.mAddOrSendBtn.setVisibility(VISIBLE); - InputPanel.this.mAddBtn.setVisibility(VISIBLE); - InputPanel.this.mSendBtn.setVisibility(View.GONE); - } - } - - int offset; - if (count == 0) { - int var10000 = start + before; - offset = -before; - } else { - offset = count; - } - - if (Conversation.ConversationType.PRIVATE.equals(InputPanel.this.mConversationType) && offset != 0) { - RongIMClient.getInstance().sendTypingStatus(InputPanel.this.mConversationType, InputPanel.this.mTargetId, "RC:TxtMsg"); - } - - } - - public void afterTextChanged(Editable s) { - } - }; - - public InputPanel(Fragment fragment, ViewGroup parent, InputPanel.InputStyle inputStyle, Conversation.ConversationType type, String targetId) { - this.mFragment = fragment; - this.mInputStyle = inputStyle; - this.mConversationType = type; - this.mTargetId = targetId; - this.initView(fragment.getContext(), parent); - this.mExtensionViewModel = (RongExtensionViewModel) (new ViewModelProvider(fragment)).get(RongExtensionViewModel.class); - this.mExtensionViewModel.getInputModeLiveData().observe(fragment.getViewLifecycleOwner(), new Observer() { - public void onChanged(InputMode inputMode) { - InputPanel.this.updateViewByInputMode(inputMode); - } - }); - if (fragment.getContext() != null) { - this.mIsVoiceInputMode = RongExtensionCacheHelper.isVoiceInputMode(fragment.getContext(), this.mConversationType, this.mTargetId); - } - - if (this.mIsVoiceInputMode) { - this.mExtensionViewModel.getInputModeLiveData().setValue(InputMode.VoiceInput); - } else { - this.getDraft(); - this.mExtensionViewModel.getInputModeLiveData().setValue(InputMode.TextInput); - } - - } - - @SuppressLint({"ClickableViewAccessibility"}) - private void initView(final Context context, ViewGroup parent) { - this.mContext = context; - this.mInputPanel = LayoutInflater.from(context).inflate(R.layout.rc_extension_input_panel, parent, false); - this.mVoiceToggleBtn = (ImageView) this.mInputPanel.findViewById(R.id.input_panel_voice_toggle); - this.mEditText = (EditText) this.mInputPanel.findViewById(R.id.edit_btn); - this.mVoiceInputBtn = (TextView) this.mInputPanel.findViewById((R.id.press_to_speech_btn)); - this.mEmojiToggleBtn = (ImageView) this.mInputPanel.findViewById((R.id.input_panel_emoji_btn)); - this.mAddOrSendBtn = (ViewGroup) this.mInputPanel.findViewById((R.id.input_panel_add_or_send)); - this.mSendBtn = (Button) this.mInputPanel.findViewById((R.id.input_panel_send_btn)); - this.mAddBtn = (ImageView) this.mInputPanel.findViewById((R.id.input_panel_add_btn)); - this.mSendBtn.setOnClickListener(this.mOnSendBtnClick); - this.mEditText.setOnFocusChangeListener(this.mOnEditTextFocusChangeListener); - this.mEditText.addTextChangedListener(this.mEditTextWatcher); - this.mVoiceToggleBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - if (InputPanel.this.mIsVoiceInputMode) { - InputPanel.this.mIsVoiceInputMode = false; - InputPanel.this.mExtensionViewModel.getInputModeLiveData().setValue(InputMode.TextInput); - InputPanel.this.mEditText.requestFocus(); - if (TextUtils.isEmpty(InputPanel.this.mInitialDraft)) { - InputPanel.this.getDraft(); - } - } else { - InputPanel.this.mExtensionViewModel.getInputModeLiveData().postValue(InputMode.VoiceInput); - InputPanel.this.mIsVoiceInputMode = true; - } - - RongExtensionCacheHelper.saveVoiceInputMode(context, InputPanel.this.mConversationType, InputPanel.this.mTargetId, InputPanel.this.mIsVoiceInputMode); - } - }); - this.mEmojiToggleBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - if (InputPanel.this.mExtensionViewModel != null) { - if (InputPanel.this.mExtensionViewModel.getInputModeLiveData().getValue() != null && ((InputMode) InputPanel.this.mExtensionViewModel.getInputModeLiveData().getValue()).equals(InputMode.EmoticonMode)) { - InputPanel.this.mEditText.requestFocus(); - InputPanel.this.mExtensionViewModel.getInputModeLiveData().postValue(InputMode.TextInput); - } else { - InputPanel.this.mExtensionViewModel.getInputModeLiveData().postValue(InputMode.EmoticonMode); - } - - } - } - }); - this.mAddBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - if (InputPanel.this.mExtensionViewModel.getInputModeLiveData().getValue() != null && ((InputMode) InputPanel.this.mExtensionViewModel.getInputModeLiveData().getValue()).equals(InputMode.PluginMode)) { - InputPanel.this.mEditText.requestFocus(); - InputPanel.this.mExtensionViewModel.getInputModeLiveData().setValue(InputMode.TextInput); - } - - InputPanel.this.mExtensionViewModel.getInputModeLiveData().setValue(InputMode.PluginMode); - } - }); - this.mVoiceInputBtn.setOnTouchListener(this.mOnVoiceBtnTouchListener); - this.setInputPanelStyle(this.mInputStyle); - } - - private void updateViewByInputMode(InputMode inputMode) { - if (!inputMode.equals(InputMode.TextInput) && !inputMode.equals(InputMode.PluginMode)) { - if (inputMode.equals(InputMode.VoiceInput)) { - this.mVoiceToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_toggle_keyboard_btn))); - this.mVoiceInputBtn.setVisibility(VISIBLE); - this.mEditText.setVisibility(View.GONE); - this.mEmojiToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_input_panel_emoji))); - } else if (inputMode.equals(InputMode.EmoticonMode)) { - this.mVoiceToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_toggle_voice_btn))); - this.mEmojiToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_toggle_keyboard_btn))); - this.mEditText.setVisibility(View.GONE); - this.mVoiceInputBtn.setVisibility(View.GONE); - } - } else { - if (inputMode.equals(InputMode.TextInput)) { - this.mIsVoiceInputMode = false; - } - - this.mVoiceToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_toggle_voice_btn))); - this.mEmojiToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_input_panel_emoji))); - this.mEditText.setVisibility(VISIBLE); - this.mVoiceInputBtn.setVisibility(View.GONE); - this.mEmojiToggleBtn.setImageDrawable(this.mContext.getResources().getDrawable((R.drawable.rc_ext_input_panel_emoji))); - } - - } - - public EditText getEditText() { - return this.mEditText; - } - - public View getRootView() { - return this.mInputPanel; - } - - public void setVisible(int viewId, boolean visible) { - this.mInputPanel.findViewById(viewId).setVisibility(visible ? VISIBLE : View.GONE); - } - - public void setInputPanelStyle(InputPanel.InputStyle style) { - switch (style) { - case STYLE_SWITCH_CONTAINER_EXTENSION: - this.setSCE(); - break; - case STYLE_CONTAINER: - this.setC(); - break; - case STYLE_CONTAINER_EXTENSION: - this.setCE(); - break; - case STYLE_SWITCH_CONTAINER: - this.setSC(); - break; - default: - this.setSCE(); - } - - this.mInputStyle = style; - } - - private void setSCE() { - if (this.mInputPanel != null) { - this.mVoiceToggleBtn.setVisibility(VISIBLE); - this.mEmojiToggleBtn.setVisibility(VISIBLE); - this.mAddBtn.setVisibility(VISIBLE); - } - - } - - private void setC() { - if (this.mInputPanel != null) { - this.mVoiceToggleBtn.setVisibility(View.GONE); - this.mAddOrSendBtn.setVisibility(View.GONE); - this.mEmojiToggleBtn.setVisibility(View.GONE); - this.mAddBtn.setVisibility(View.GONE); - this.mSendBtn.setVisibility(View.GONE); - } - - } - - private void setCE() { - if (this.mInputPanel != null) { - this.mVoiceToggleBtn.setVisibility(View.GONE); - this.mAddOrSendBtn.setVisibility(VISIBLE); - this.mEmojiToggleBtn.setVisibility(VISIBLE); - this.mAddBtn.setVisibility(VISIBLE); - } - - } - - private void setSC() { - if (this.mInputPanel != null) { - this.mVoiceToggleBtn.setVisibility(VISIBLE); - this.mAddOrSendBtn.setVisibility(View.GONE); - this.mAddBtn.setVisibility(View.GONE); - } - - } - - private void getDraft() { - RongIMClient.getInstance().getTextMessageDraft(this.mConversationType, this.mTargetId, new RongIMClient.ResultCallback() { - public void onSuccess(String s) { - if (!TextUtils.isEmpty(s)) { - InputPanel.this.mInitialDraft = s; - InputPanel.this.mEditText.setText(s); - InputPanel.this.mEditText.setSelection(s.length()); - InputPanel.this.mEditText.requestFocus(); - } - - } - - public void onError(RongIMClient.ErrorCode errorCode) { - } - }); - } - - public void onDestroy() { - this.mFragment = null; - this.mExtensionViewModel = null; - if (this.mEditText != null && this.mEditText.getText() != null && !this.mInitialDraft.equals(this.mEditText.getText().toString())) { - IMCenter.getInstance().saveTextMessageDraft(this.mConversationType, this.mTargetId, this.mEditText.getText().toString(), (RongIMClient.ResultCallback) null); - } - - } - - public static enum InputStyle { - STYLE_SWITCH_CONTAINER_EXTENSION(291), - STYLE_SWITCH_CONTAINER(288), - STYLE_CONTAINER_EXTENSION(35), - STYLE_CONTAINER(32); - - int v; - - private InputStyle(int v) { - this.v = v; - } - - public static InputPanel.InputStyle getStyle(int v) { - InputPanel.InputStyle result = null; - InputPanel.InputStyle[] var2 = values(); - int var3 = var2.length; - - for (int var4 = 0; var4 < var3; ++var4) { - InputPanel.InputStyle style = var2[var4]; - if (style.v == v) { - result = style; - break; - } - } - - return result; - } - } -} diff --git a/live/src/main/java/com/yunbao/live/views/InputPanelViewHolder.java b/live/src/main/java/com/yunbao/live/views/InputPanelViewHolder.java index 16668a925..447fcb90c 100644 --- a/live/src/main/java/com/yunbao/live/views/InputPanelViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/InputPanelViewHolder.java @@ -188,6 +188,7 @@ public class InputPanelViewHolder extends LinearLayout implements View.OnClickLi } public void afterTextChanged(Editable s) { + editBtn.clearFocus(); } }; diff --git a/live/src/main/java/com/yunbao/live/views/SystemMessageViewHolder.java b/live/src/main/java/com/yunbao/live/views/SystemMessageViewHolder.java index b9b1cc135..915c7a8e6 100644 --- a/live/src/main/java/com/yunbao/live/views/SystemMessageViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/SystemMessageViewHolder.java @@ -11,12 +11,6 @@ import android.media.MediaMetadataRetriever; import android.net.Uri; import android.os.Handler; import android.os.Parcelable; -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; -import androidx.cardview.widget.CardView; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -36,6 +30,13 @@ import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.cardview.widget.CardView; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.alibaba.fastjson.JSON; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; @@ -1522,9 +1523,9 @@ public class SystemMessageViewHolder extends AbsViewHolder implements View.OnCli } - public static void updataNkname() { - if (!TextUtils.isEmpty(Constants.isSetRemarkText)) { - titleView.setText(SystemMessageActivity.nowTitle + "(" + Constants.isSetRemarkText + ")"); + public static void updataNkname(String remarkText) { + if (!TextUtils.isEmpty(remarkText)) { + titleView.setText(SystemMessageActivity.nowTitle + "(" + remarkText + ")"); } } diff --git a/live/src/main/res/layout/activity_conversation.xml b/live/src/main/res/layout/activity_conversation.xml index 9a246fbc1..6b8cbda9f 100644 --- a/live/src/main/res/layout/activity_conversation.xml +++ b/live/src/main/res/layout/activity_conversation.xml @@ -1,7 +1,10 @@ diff --git a/live/src/main/res/layout/rc_extension_input_panel.xml b/live/src/main/res/layout/rc_extension_input_panel.xml new file mode 100644 index 000000000..f884747f1 --- /dev/null +++ b/live/src/main/res/layout/rc_extension_input_panel.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + +