Exemplo n.º 1
0
 private void sendMessageImage(String urlImage) {
   if (TextUtil.isEmpty(urlImage)) {
     UIUtils.alert(this, R.string.url_image_is_null);
     return;
   }
   sendMessageToServer(
       Prefs.getSendMessageJSON(
           userID,
           mItem.getChatGroupID(),
           mItem.getMemberID(),
           Message.Type.CHAT_TYPE_IMAGE,
           urlImage,
           DateUtils.nowTime(),
           token));
   etMessage.setText("");
 }
Exemplo n.º 2
0
  private void requestGetListChat() {
    CallServicePOST cs =
        new CallServicePOST(
            "getListChat",
            new CallServicePOST.JsonCallback() {
              @Override
              public void handleData(String mCmd, JSONObject json) throws JSONException {
                if (json != null) {
                  int status = json.getInt("status");
                  if (status == 1) {
                    JSONArray jArray = json.getJSONArray("data");

                    for (int i = 0; i < jArray.length(); i++) {
                      JSONObject info = jArray.getJSONObject(i);
                      Message message = Message.parseMassge(info);
                      message.setSendout(message.getSenderId().equals(userID));
                      Log.d(TAG + ":check", "message send out: " + message.isSendout());
                      appendMessageToTop(message);
                      lastMessageTime = message.getUnix_timestamp();
                    }
                    if (mAdapter != null) {
                      mAdapter.notifyDataSetChanged();
                      lvMessages.setSelection(mAdapter.getCount() - 1);
                    }
                    if (mItem.isNewChat()) {
                      sendBroadcastReadChat();
                      mItem.setNewChat(false);
                    }

                    //						if (isSendSMS && mAdapter.getCount() > 0) {
                    //							findViewById(R.id.layoutCall).setVisibility(View.VISIBLE);
                    //						}

                    //						if (jArray != null) {
                    //							enableGetMore = (jArray.length() < Values.LIMIT_GET_LIST_TRAVELERS) ?
                    // false : true;
                    //						}
                    hideLayoutNote();
                  } else {
                    try {
                      String errorCode = json.get("errorCode").toString();
                      if (errorCode.equals(CallServicePOST.ErrorCode.CONNECT_SERVER_FAIL)) {
                        UIUtils.alert(
                            ChatScreen.this,
                            R.string.connect_to_server_failed_plz_wait_a_moment_and_try_again);
                      } else {
                        if (listMessages != null && listMessages.size() > 0) {
                          Log.d(TAG + ":handleData", "ERROR " + errorCode + " !!");
                        } else {
                          UIUtils.alert(ChatScreen.this, "ERROR " + errorCode + " !!");
                        }
                      }
                    } catch (Exception e) {
                      Log.d(TAG + ":handleData", e.getMessage());
                    }
                  }
                }
                hideLoading();
                stopSwipeRefresh();
              }
            });

    try {
      String url =
          RemoteMethods.get(
              RemoteMethods.getChatConversation,
              URLEncoder.encode(userID, "UTF-8"),
              URLEncoder.encode(
                  TextUtil.isEmpty(mItem.getChatGroupID()) ? mItem.getID() : mItem.getChatGroupID(),
                  "UTF-8"),
              Values.LIMIT_GET_LIST_CHAT);
      if (lastMessageTime != null) {
        url += "&currentTime=" + lastMessageTime;
      }
      cs.execute(url);
    } catch (Exception e) {
      hideLoading();
    }
  }
Exemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chatscreen_layout);
    startWebSocketClient();
    picasso = Picasso.with(this);
    mPrefs = Prefs.get(this);

    try {
      Bundle bundle = getIntent().getExtras();
      mItem = bundle.getParcelable(Extras.ITEM);
    } catch (Exception e) {
      finish();
    }

    userID = mPrefs.getString(Prefs.ID, null);
    token = mPrefs.getString(Prefs.LoginToken, null);
    deviceId = mPrefs.getString(Prefs.DeviceId, null);
    version = mPrefs.getString(Prefs.Version, null);
    locale = mPrefs.getString(Prefs.LanguageLocale, null);

    String fileName = mPrefs.getString(Prefs.FileName, null);
    String domainName = mPrefs.getString(Prefs.DomainName, null);
    userAvatar = domainName + fileName;

    if (mItem.getIsAccepted() != null && mItem.getIsAccepted().equals("1")) {
      isSendSMS = false;
    } else {
      isSendSMS = true;
    }

    isMsLief = mItem.getIsMsLief() != null && mItem.getIsMsLief().equals("1");

    TextView tvTitlebar = (TextView) findViewById(R.id.tvTitleBar);
    lvMessages = (ListView) findViewById(R.id.lvMessages);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.lySwipeRefresh);
    etMessage = (EditText) findViewById(R.id.etMessage);
    tvSend = (TextView) findViewById(R.id.tvSend);
    ImageView ivAvatarNote = (ImageView) findViewById(R.id.ivAvatarNote);
    layoutNote = findViewById(R.id.layoutNote);
    tvNote = (TextView) findViewById(R.id.tvNote);
    tvSmsLimit = (TextView) findViewById(R.id.tvSmsLimit);
    ivBackgroundAlert = (ImageView) findViewById(R.id.ivBackgroundAlert);
    tvContentAlert = (TextView) findViewById(R.id.tvContentAlert);
    tvContentAlert.setText(
        String.format(
            getString(R.string.cannot_send_message_cause_out_of_sms_free),
            mItem.getNameResidence(),
            mItem.getNameResidence()));
    ivBgQuickAction = (ImageView) findViewById(R.id.ivBgQuickAction);

    showAlertSmsLimit(false);

    tvSmsLimit.setVisibility(isSendSMS ? View.VISIBLE : View.GONE);
    findViewById(R.id.ivAction).setVisibility(isSendSMS ? View.INVISIBLE : View.VISIBLE);

    tvTitlebar.setText(TextUtil.isEmpty(mItem.getNameResidence()) ? "" : mItem.getNameResidence());
    picasso
        .load(mItem.getUrlAvatar() != null ? mItem.getUrlAvatar() : "null")
        .resize(100, 100)
        .placeholder(mItem.getResIconRelationship())
        .into(ivAvatarNote);

    if (isMsLief) {
      tvNote.setText(R.string.fell_free_to_ask_lief);
    } else {
      tvNote.setText(
          isSendSMS
              ? String.format(
                  getString(R.string._stil_hasnt_replied_to_your_invitation),
                  mItem.getNameResidence())
              : getString(R.string.break_the_ice_by_chatting_first));
    }
    if (isSendSMS) {
      etMessage.setFilters(new InputFilter[] {new InputFilter.LengthFilter(120)});
      etMessage.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void afterTextChanged(Editable s) {
              tvSmsLimit.setText("" + (120 - s.length()));
            }
          });

      if (!isMsLief) {
        setupPopup();
        findViewById(R.id.ivMore).setVisibility(View.VISIBLE);
      }
    }

    listMessages = new ArrayList<Message>();
    mAdapter =
        new MessagesListAdapter(
            this, listMessages, userAvatar, mItem.getUrlAvatar(), mItem.getResIconRelationship());
    lvMessages.setAdapter(mAdapter);

    Log.d(TAG, "now time: " + DateUtils.nowTime());
    if (UIUtils.isConnectingToInternet(this)) {
      //        	showLoading();
      startSwipeRefresh();
      requestCheckSocket();
      requestGetListChat();
    }

    swipeRefreshLayout.setColorSchemeResources(
        android.R.color.holo_blue_light,
        android.R.color.holo_green_light,
        android.R.color.holo_orange_light,
        android.R.color.holo_red_light);

    swipeRefreshLayout.setOnRefreshListener(this);
    findViewById(R.id.ivBack).setOnClickListener(this);
    findViewById(R.id.tvCall).setOnClickListener(this);
    findViewById(R.id.tvCallNow).setOnClickListener(this);
    findViewById(R.id.ivAction).setOnClickListener(this);
    findViewById(R.id.ivMore).setOnClickListener(this);
    tvSend.setOnClickListener(this);
    ivBackgroundAlert.setOnClickListener(this);
    tvContentAlert.setOnClickListener(this);

    prepareLocationRequest();

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    registerReceiver();
  }