예제 #1
0
 private void actionPopup(int actionId) {
   if (isMsLief) {
     return;
   }
   switch (actionId) {
     case ACTION_ID_CALL:
       startCall();
       break;
     case ACTION_ID_REMOVE:
       String title =
           String.format(getString(R.string.remove_from_your_lovedones), mItem.getFullName());
       if (UIUtils.ensureNetworkInternet(this, false)) {
         UIUtils.alert(
             this,
             title,
             true,
             R.string.cancel,
             null,
             R.string.yes,
             new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialog, int which) {
                 removeUser();
               }
             });
       }
       break;
   }
 }
예제 #2
0
 private void onPhoto(Uri imgUri) {
   filePath = AndroidUtils.getPath(this, imgUri);
   if (UIUtils.ensureNetworkInternet(this, false)) {
     if (filePath != null) {
       requestUpdateAvatar(filePath);
     } else {
       hideLoading();
       UIUtils.alert(this, R.string.file_not_found);
     }
   }
 }
예제 #3
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("");
 }
예제 #4
0
 private void shareLocation() {
   if (haveGoogleService) {
     if (mLastLocation != null) {
       sendMessageLocation(mLastLocation);
     } else {
       if (isProviderGPSEnabled()) {
         Toast.makeText(this, R.string.please_wait_to_get_location_from_gps, Toast.LENGTH_LONG)
             .show();
         startLocationUpdates();
       } else {
         UIUtils.alert(this, R.string.please_turn_on_gps_to_get_your_location);
       }
     }
   } else {
     UIUtils.alert(this, R.string.cannot_get_your_location);
   }
 }
예제 #5
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.ivMore:
       UIUtils.hideSoftInput(this);
       showMoreAction(true, v);
       break;
     case R.id.tvContentAlert:
       break;
     case R.id.ivBackgroundAlert:
       showAlertSmsLimit(false);
       break;
     case R.id.ivBack:
       UIUtils.hideSoftInput(this);
       finish();
       break;
     case R.id.tvCall:
     case R.id.tvCallNow:
       startCall();
       break;
     case R.id.tvSend:
       //			UIUtils.hideSoftInput(this);
       if (UIUtils.ensureNetworkInternet(this, false)) {
         sendMessage();
       }
       break;
     case R.id.ivAction:
       if (UIUtils.ensureNetworkInternet(this, false)) {
         if (isSendSMS) {
           return;
         }
         askWhatForShare();
       }
       break;
     default:
       UIUtils.alert(this, "still building");
       break;
   }
 }
예제 #6
0
 @Override
 public void onRefresh() {
   //		if (!enableGetMore) {
   //			stopSwipeRefresh();
   //			return;
   //		}
   if (UIUtils.ensureNetworkInternet(this, false)) {
     requestCheckSocket();
     requestGetListChat();
   } else {
     stopSwipeRefresh();
   }
 }
예제 #7
0
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   switch (action) {
     case Actions.SHOW_ALERT_SEND_SMS_FAILED_OUT_OF_FREE_SMS:
       showAlertSmsLimit(true);
       break;
     case Actions.SHOW_ALERT_SEND_SMS_FAILED_WRONG_NUMBER:
       UIUtils.alert(
           ChatScreen.this, R.string.cannot_send_message_cause_wrong_number, R.string.oop);
       break;
   }
 }
예제 #8
0
  private void onPickCamera() {
    boolean takePhoto = Utils.isIntentAvailable(this, MediaStore.ACTION_IMAGE_CAPTURE);
    if (!takePhoto) {
      UIUtils.alert(this, R.string.not_found_camera);
      return;
    }

    mPhotoPath = Utils.nextPath(this) + ".jpg";
    Uri imageUri = Uri.fromFile(new File(mPhotoPath));

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    Intent openInChooser = Intent.createChooser(intent, getString(R.string.complete_action_using));
    startActivityForResult(openInChooser, PICK_CAMERA);
  }
예제 #9
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("");
 }
예제 #10
0
  private void requestUpdateAvatar(final String filePath) {
    if (filePath == null) {
      UIUtils.alert(this, R.string.file_not_found);
      hideLoading();
      return;
    }
    if (UIUtils.ensureNetworkInternet(this, false)) {
      showLoading();
      final File file = new File(filePath);
      if (file.exists() && file.canRead() && file.isFile()) {
        if (file.length() > Values.FILE_SIZE_LIMIT) {
          UIUtils.alert(this, getString(R.string.file_size_must_be_less_than_size_limit, "30MB"));
          hideLoading();
          return;
        }
      } else {
        UIUtils.alert(this, R.string.file_not_found);
        hideLoading();
        return;
      }

      try {
        uploadTask =
            new AsyncTask<Object, Object, String>() {
              @Override
              protected String doInBackground(Object... params) {
                String response =
                    HttpUtils.uploadFileImageByPost(RemoteMethods.uploadImage, filePath);
                return response;
              }

              @Override
              protected void onPostExecute(String response) {
                if (response != null) {
                  try {
                    JSONObject json = new JSONObject(response);
                    Log.d(TAG, json.toString());
                    int status = json.getInt("status");
                    if (status == 1) {
                      urlImage = json.getString("data");
                      sendMessageImage(urlImage);
                    } 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 (errorCode.equals(CallServiceCustomPOST.ErrorCode.FULL_STORAGE)) {
                          UIUtils.alert(
                              ChatScreen.this, R.string.full_storage_please_upgrade, R.string.oop);
                        } else {
                          UIUtils.alert(ChatScreen.this, "errorCode: " + errorCode);
                        }
                      } catch (Exception e) {
                        Log.d(TAG, json.toString());
                      }
                    }
                    hideLoading();
                  } catch (Exception e) {
                    hideLoading();
                    e.printStackTrace();
                  }
                } else {
                  hideLoading();
                  UIUtils.alert(ChatScreen.this, R.string.upload_failed);
                }
              }
            };

        boolean isPending = (uploadTask.getStatus().equals(AsyncTask.Status.PENDING));
        if (isPending) {
          Log.i(TAG, "upFile + " + isPending);
          uploadTask.execute();
          if (uploadTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
            uploadTask = null;
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
예제 #11
0
 private void startCall() {
   UIUtils.startCall(this, mItem.getFullPhoneNumber());
 }
예제 #12
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();
  }
예제 #13
0
 @Override
 protected void onPause() {
   UIUtils.hideSoftInput(this);
   super.onPause();
   //		stopLocationUpdates();
 }