Example #1
0
 private void sendMessage() {
   String message = etMessage.getText().toString();
   if (message.trim().isEmpty()) {
     UIUtils.alert(this, R.string.message_is_empty);
     return;
   }
   if (isSendSMS) {
     sendMessageToServer(
         Prefs.getSendSmsJSON(
             userID,
             mItem.getChatGroupID() != null ? mItem.getChatGroupID() : "",
             mItem.getMemberID() != null ? mItem.getMemberID() : "",
             mItem.getID(),
             Message.Type.CHAT_TYPE_SEND_SMS,
             message,
             DateUtils.nowTime(),
             token));
   } else {
     sendMessageToServer(
         Prefs.getSendMessageJSON(
             userID,
             mItem.getChatGroupID(),
             mItem.getMemberID(),
             Message.Type.CHAT_TYPE_MESSAGE,
             message,
             DateUtils.nowTime(),
             token));
   }
   etMessage.setText("");
 }
Example #2
0
 private void sendMessageLocation(Location location) {
   sendMessageToServer(
       Prefs.getSendMessageJSON(
           userID,
           mItem.getChatGroupID(),
           mItem.getMemberID(),
           Message.Type.CHAT_TYPE_LOCATION,
           location.getLatitude() + "," + location.getLongitude(),
           DateUtils.nowTime(),
           token));
 }
Example #3
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("");
 }
Example #4
0
 private void sendMessageNullToServer() {
   sendMessageToServer(
       Prefs.getSendMessageJSON(
           userID, "", "", Type.VERIFY_AFTER_CONNECT_SOCKET, "", DateUtils.nowTime(), token));
 }
Example #5
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();
  }