|
@@ -22,7 +22,10 @@ import com.jixin.im.bean.redpacket.RedPacket;
|
|
|
import com.jixin.im.helper.DialogHelper;
|
|
|
import com.jixin.im.helper.PaySecureHelper;
|
|
|
import com.jixin.im.ui.base.EasyFragment;
|
|
|
+import com.jixin.im.ui.me.redpacket.ChangePayPasswordActivity;
|
|
|
import com.jixin.im.ui.message.ChatActivity;
|
|
|
+import com.jixin.im.util.Constants;
|
|
|
+import com.jixin.im.util.PreferenceUtils;
|
|
|
import com.jixin.im.util.ToastUtil;
|
|
|
import com.jixin.im.util.secure.Money;
|
|
|
import com.klinker.android.link_builder.Link;
|
|
@@ -35,32 +38,32 @@ import com.xuan.xuanhttplibrary.okhttp.result.Result;
|
|
|
import okhttp3.Call;
|
|
|
|
|
|
|
|
|
+/**
|
|
|
+ * Created by Harvey on 2020/09/17
|
|
|
+ * 发送红包基类
|
|
|
+ */
|
|
|
public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
|
|
|
-
|
|
|
private String mChatType;
|
|
|
protected int mRedPacketType = 2;
|
|
|
protected EditText mEdtPacketMoney;
|
|
|
protected EditText mEdtRemark;
|
|
|
- protected TextView tvSendRedPacket ;
|
|
|
+ protected TextView tvSendRedPacket;
|
|
|
protected TextView tvRedPacketType;
|
|
|
private ImageView ivIconPin;
|
|
|
- private String mRoomId;
|
|
|
+ protected String mRedPacketAcceptorId; //红包接收对象id 可以是roomId,也可以是userId
|
|
|
+
|
|
|
+ private int mRedPacketCount = 1; //默认红包个数
|
|
|
|
|
|
- public BaseRedPacketFragment(String roomId){
|
|
|
- this.mRoomId = roomId;
|
|
|
- if (TextUtils.isEmpty(roomId)){
|
|
|
+ public BaseRedPacketFragment(String chatType,String redPacketAcceptorId) {
|
|
|
+ this.mRedPacketAcceptorId = redPacketAcceptorId;
|
|
|
+ this.mChatType = chatType;
|
|
|
+ if (!isGroupChatType()) {
|
|
|
this.mChatType = ChatType.CHAT_PRIVATE;
|
|
|
- }else {
|
|
|
- this.mChatType= ChatType.CHAT_GROUP;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- public String getRoomId(){
|
|
|
- return mRoomId;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
protected int inflateLayoutId() {
|
|
|
return R.layout.fragment_password_red_packet;
|
|
@@ -74,30 +77,44 @@ public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void initView(){
|
|
|
+ private void initView() {
|
|
|
mEdtPacketMoney = findViewById(R.id.edt_input_money);
|
|
|
tvRedPacketType = findViewById(R.id.tv_red_packet_type);
|
|
|
ivIconPin = findViewById(R.id.iv_icon_pin);
|
|
|
|
|
|
mEdtRemark = findViewById(R.id.edt_input_remark);
|
|
|
tvSendRedPacket = findViewById(R.id.tv_send_red_packet);
|
|
|
+
|
|
|
+
|
|
|
tvSendRedPacket.setOnClickListener(v -> {
|
|
|
+ //发送红包点击事件
|
|
|
+ if (hasPayPassword()){
|
|
|
+ String money = mEdtPacketMoney.getText().toString();
|
|
|
+ String words = mEdtRemark.getText().toString();
|
|
|
+ PaySecureHelper.inputPayPassword(getActivity(), getString(R.string.chat_redpacket), money, password -> {
|
|
|
+ sendRedPacket(String.valueOf(tvRedPacketType), money, String.valueOf(mRedPacketCount), words, password);
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ setPayPassword();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
});
|
|
|
+
|
|
|
ViewStub mStubRedPacketCount = findViewById(R.id.view_stub_red_packet_count);
|
|
|
ViewStub mStubRedPacketType = findViewById(R.id.view_stub_red_packet_type);
|
|
|
- boolean isShowSpellLuck= isShowSpellLuckViews()&& isGroupChatType();
|
|
|
+ boolean isShowSpellLuck = isShowSpellLuckViews() && isGroupChatType();
|
|
|
showSpellLuckViews(isShowSpellLuck);
|
|
|
setSendRedPacketText();
|
|
|
|
|
|
int countLayoutId = inflateLayoutIdByRedPacketCount();
|
|
|
- if (countLayoutId>0){
|
|
|
+ if (countLayoutId > 0) {
|
|
|
mStubRedPacketCount.setLayoutResource(countLayoutId);
|
|
|
View rootView = mStubRedPacketCount.inflate();
|
|
|
convertRedPacketCountViews(rootView);
|
|
|
}
|
|
|
int typeLayoutId = inflateLayoutIdByRedPacketType();
|
|
|
- if (typeLayoutId>0){
|
|
|
+ if (typeLayoutId > 0) {
|
|
|
mStubRedPacketType.setLayoutResource(typeLayoutId);
|
|
|
View rootView = mStubRedPacketType.inflate();
|
|
|
convertRedPacketTypeViews(rootView);
|
|
@@ -121,57 +138,68 @@ public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
-// PaySecureHelper.inputPayPassword(this, getString(R.string.chat_redpacket), money, password -> {
|
|
|
-// sendRed(item == 0 ? "1" : "3", finalMoney, String.valueOf(1), finalWords, password);
|
|
|
-// });
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
- protected boolean isGroupChatType(){
|
|
|
- if (ChatType.CHAT_GROUP.equals(mChatType)){
|
|
|
+ protected boolean isGroupChatType() {
|
|
|
+ if (ChatType.CHAT_GROUP.equals(mChatType)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
protected abstract int inflateLayoutIdByRedPacketCount();
|
|
|
+
|
|
|
protected abstract int inflateLayoutIdByRedPacketType();
|
|
|
+
|
|
|
protected abstract void convertRedPacketTypeViews(View rootView);
|
|
|
+
|
|
|
protected abstract void convertRedPacketCountViews(View rootView);
|
|
|
+
|
|
|
protected abstract void changeSendRedPacketButtonStyle();
|
|
|
|
|
|
- private void setSendRedPacketText(){
|
|
|
+ private void setSendRedPacketText() {
|
|
|
int textId = R.string.send_red_packet_1;
|
|
|
- if (isGroupChatType()){
|
|
|
+ if (isGroupChatType()) {
|
|
|
textId = R.string.send_group_red_packet;
|
|
|
}
|
|
|
tvSendRedPacket.setText(textId);
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ protected int getRedPacketCount() {
|
|
|
+ return mRedPacketCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setRedPacketCount(int mRedPacketCount) {
|
|
|
+ this.mRedPacketCount = mRedPacketCount;
|
|
|
+ }
|
|
|
+
|
|
|
protected abstract Link.OnClickListener getLinkOnClickListener();
|
|
|
|
|
|
//是否显示拼手气按钮
|
|
|
- protected boolean isShowSpellLuckViews(){
|
|
|
+ protected boolean isShowSpellLuckViews() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//是否显示切换手气红包和普通红包
|
|
|
- private void showSpellLuckViews(boolean show){
|
|
|
- if (show){
|
|
|
+ private void showSpellLuckViews(boolean show) {
|
|
|
+ if (show) {
|
|
|
ivIconPin.setVisibility(View.VISIBLE);
|
|
|
tvRedPacketType.setVisibility(View.VISIBLE);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ivIconPin.setVisibility(View.GONE);
|
|
|
tvRedPacketType.setVisibility(View.GONE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected void showPinIcon(boolean show){
|
|
|
- if (show){
|
|
|
+ protected void showPinIcon(boolean show) {
|
|
|
+ if (show) {
|
|
|
ivIconPin.setVisibility(View.VISIBLE);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
ivIconPin.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
@@ -182,7 +210,20 @@ public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
tvSendRedPacket.setClickable(isNormal);
|
|
|
|
|
|
}
|
|
|
- protected abstract ArrayMap<String,String> getSendRedPacketParameters();
|
|
|
+
|
|
|
+ private boolean hasPayPassword() {
|
|
|
+ boolean hasPayPassword = PreferenceUtils.getBoolean(getContext(), Constants.IS_PAY_PASSWORD_SET + coreManager.getSelf().getUserId(), true);
|
|
|
+ return hasPayPassword;
|
|
|
+ }
|
|
|
+ private void setPayPassword(){
|
|
|
+ ToastUtil.showToast(getContext(), R.string.tip_no_pay_password);
|
|
|
+ Intent intent = new Intent(getContext(), ChangePayPasswordActivity.class);
|
|
|
+ startActivity(intent);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取发送红包不同的参数
|
|
|
+ protected abstract ArrayMap<String, String> getSendRedPacketParameters();
|
|
|
|
|
|
|
|
|
private void sendRedPacket(final String type, String pMoney, String count, final String words, String payPassword) {
|
|
@@ -190,14 +231,17 @@ public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
return;
|
|
|
}
|
|
|
DialogHelper.showDefaulteMessageProgressDialog(getActivity());
|
|
|
- ArrayMap<String,String> params = getSendRedPacketParameters();
|
|
|
- params.put("moneyStr",pMoney);
|
|
|
+ ArrayMap<String, String> params = getSendRedPacketParameters();
|
|
|
+ if (params==null){
|
|
|
+ params = new ArrayMap<>();
|
|
|
+ }
|
|
|
+ params.put("moneyStr", pMoney);
|
|
|
params.put("greetings", words);
|
|
|
|
|
|
- String toUserId = "";
|
|
|
+
|
|
|
PaySecureHelper.generateParam(
|
|
|
getActivity(), payPassword, params,
|
|
|
- "" + type + pMoney + count + words + toUserId,
|
|
|
+ "" + type + pMoney + count + words + mRedPacketAcceptorId,
|
|
|
t -> {
|
|
|
DialogHelper.dismissProgressDialog();
|
|
|
ToastUtil.showToast(getContext(), getActivity().getString(R.string.tip_pay_secure_place_holder, t.getMessage()));
|
|
@@ -224,7 +268,7 @@ public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
Intent intent = new Intent();
|
|
|
intent.putExtra(AppConstant.EXTRA_CHAT_MESSAGE, message.toJsonString());
|
|
|
// getActivity().setResult(viewPager.getCurrentItem() == 0 ? ChatActivity.REQUEST_CODE_SEND_RED_PT : ChatActivity.REQUEST_CODE_SEND_RED_KL, intent);
|
|
|
- getActivity(). finish();
|
|
|
+ getActivity().finish();
|
|
|
}
|
|
|
}
|
|
|
|