|
@@ -1,15 +1,240 @@
|
|
|
package com.jixin.im.fragment;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.util.ArrayMap;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewStub;
|
|
|
import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.jixin.im.AppConstant;
|
|
|
+import com.jixin.im.R;
|
|
|
+import com.jixin.im.bean.ChatType;
|
|
|
+import com.jixin.im.bean.message.ChatMessage;
|
|
|
+import com.jixin.im.bean.message.XmppMessage;
|
|
|
+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.message.ChatActivity;
|
|
|
+import com.jixin.im.util.ToastUtil;
|
|
|
+import com.jixin.im.util.secure.Money;
|
|
|
+import com.klinker.android.link_builder.Link;
|
|
|
+import com.klinker.android.link_builder.LinkBuilder;
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.HttpUtils;
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.result.ObjectResult;
|
|
|
+import com.xuan.xuanhttplibrary.okhttp.result.Result;
|
|
|
|
|
|
+import okhttp3.Call;
|
|
|
|
|
|
|
|
|
public abstract class BaseRedPacketFragment extends EasyFragment {
|
|
|
- private int mRedPacketType;
|
|
|
- EditText mEdtPacketMoney;
|
|
|
- EditText mEdtRemark;
|
|
|
- TextView mSendRedPacket;
|
|
|
+
|
|
|
+
|
|
|
+ private String mChatType;
|
|
|
+ protected int mRedPacketType = 2;
|
|
|
+ protected EditText mEdtPacketMoney;
|
|
|
+ protected EditText mEdtRemark;
|
|
|
+ protected TextView tvSendRedPacket ;
|
|
|
+ protected TextView tvRedPacketType;
|
|
|
+ private ImageView ivIconPin;
|
|
|
+ private String mRoomId;
|
|
|
+
|
|
|
+ public BaseRedPacketFragment(String roomId){
|
|
|
+ this.mRoomId = roomId;
|
|
|
+ if (TextUtils.isEmpty(roomId)){
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityCreated(Bundle savedInstanceState, boolean createView) {
|
|
|
+ if (createView) {
|
|
|
+ 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 -> {
|
|
|
+
|
|
|
+ });
|
|
|
+ ViewStub mStubRedPacketCount = findViewById(R.id.view_stub_red_packet_count);
|
|
|
+ ViewStub mStubRedPacketType = findViewById(R.id.view_stub_red_packet_type);
|
|
|
+ boolean isShowSpellLuck= isShowSpellLuckViews()&& isGroupChatType();
|
|
|
+ showSpellLuckViews(isShowSpellLuck);
|
|
|
+ setSendRedPacketText();
|
|
|
+
|
|
|
+ int countLayoutId = inflateLayoutIdByRedPacketCount();
|
|
|
+ if (countLayoutId>0){
|
|
|
+ mStubRedPacketCount.setLayoutResource(countLayoutId);
|
|
|
+ View rootView = mStubRedPacketCount.inflate();
|
|
|
+ convertRedPacketCountViews(rootView);
|
|
|
+ }
|
|
|
+ int typeLayoutId = inflateLayoutIdByRedPacketType();
|
|
|
+ if (typeLayoutId>0){
|
|
|
+ mStubRedPacketType.setLayoutResource(typeLayoutId);
|
|
|
+ View rootView = mStubRedPacketType.inflate();
|
|
|
+ convertRedPacketTypeViews(rootView);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ mEdtPacketMoney.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ changeSendRedPacketButtonStyle();
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+// 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)){
|
|
|
+ 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(){
|
|
|
+ int textId = R.string.send_red_packet_1;
|
|
|
+ if (isGroupChatType()){
|
|
|
+ textId = R.string.send_group_red_packet;
|
|
|
+ }
|
|
|
+ tvSendRedPacket.setText(textId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected abstract Link.OnClickListener getLinkOnClickListener();
|
|
|
+
|
|
|
+ //是否显示拼手气按钮
|
|
|
+ protected boolean isShowSpellLuckViews(){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //是否显示切换手气红包和普通红包
|
|
|
+ private void showSpellLuckViews(boolean show){
|
|
|
+ if (show){
|
|
|
+ ivIconPin.setVisibility(View.VISIBLE);
|
|
|
+ tvRedPacketType.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ ivIconPin.setVisibility(View.GONE);
|
|
|
+ tvRedPacketType.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void showPinIcon(boolean show){
|
|
|
+ if (show){
|
|
|
+ ivIconPin.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ ivIconPin.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setSendRedPacketButtonStatus(boolean isNormal) {
|
|
|
+ tvSendRedPacket.setSelected(isNormal);
|
|
|
+ tvSendRedPacket.setClickable(isNormal);
|
|
|
+
|
|
|
+ }
|
|
|
+ protected abstract ArrayMap<String,String> getSendRedPacketParameters();
|
|
|
+
|
|
|
+
|
|
|
+ private void sendRedPacket(final String type, String pMoney, String count, final String words, String payPassword) {
|
|
|
+ if (!coreManager.isLogin()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DialogHelper.showDefaulteMessageProgressDialog(getActivity());
|
|
|
+ ArrayMap<String,String> params = getSendRedPacketParameters();
|
|
|
+ params.put("moneyStr",pMoney);
|
|
|
+ params.put("greetings", words);
|
|
|
+
|
|
|
+ String toUserId = "";
|
|
|
+ PaySecureHelper.generateParam(
|
|
|
+ getActivity(), payPassword, params,
|
|
|
+ "" + type + pMoney + count + words + toUserId,
|
|
|
+ t -> {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ ToastUtil.showToast(getContext(), getActivity().getString(R.string.tip_pay_secure_place_holder, t.getMessage()));
|
|
|
+ }, (p, code) -> {
|
|
|
+ HttpUtils.get().url(coreManager.getConfig().REDPACKET_SEND)
|
|
|
+ .params(p)
|
|
|
+ .build()
|
|
|
+ .execute(new BaseCallback<RedPacket>(RedPacket.class) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(ObjectResult<RedPacket> result) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ if (Result.checkSuccess(getContext(), result)) {
|
|
|
+ RedPacket redPacket = result.getData();
|
|
|
+ String objectId = redPacket.getId();
|
|
|
+ ChatMessage message = new ChatMessage();
|
|
|
+ message.setType(XmppMessage.TYPE_RED);
|
|
|
+ message.setFromUserId(coreManager.getSelf().getUserId());
|
|
|
+ message.setFromUserName(coreManager.getSelf().getNickName());
|
|
|
+ message.setContent(words); // 祝福语
|
|
|
+ message.setFilePath(type); // 用FilePath来储存红包类型
|
|
|
+ message.setFileSize(redPacket.getStatus()); //用filesize来储存红包状态
|
|
|
+ message.setObjectId(objectId); // 红包id
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
}
|