Skip to content

Commit

Permalink
Merge pull request #2 from castaway2000/opensource
Browse files Browse the repository at this point in the history
Ux updates:
Photo from camera in chat
Profile from icon while in chat
Reorg on the ad space
  • Loading branch information
castaway2000 authored Dec 24, 2016
2 parents 00d7781 + 8e7e731 commit 837505a
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
targetSdkVersion 23
versionCode 25

versionName "2.0.25"
versionName "2.2.27"
// Enabling multidex support.
multiDexEnabled true

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.CAMERA"/>

<permission
android:name="saberapplications.pawpads.permission.C2D_MESSAGE"
Expand All @@ -29,6 +30,8 @@
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<uses-feature android:name="android.hardware.camera"/>

<uses-feature
android:name="android.hardware.location.gps"
android:required="true" />
Expand Down Expand Up @@ -81,6 +84,7 @@
android:name=".ui.chat.ChatActivity"
android:label="Chat"
android:parentActivityName=".ui.home.MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Expand Down
147 changes: 117 additions & 30 deletions app/src/main/java/saberapplications/pawpads/ui/chat/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
Expand All @@ -14,12 +15,17 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -53,9 +59,11 @@

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import saberapplications.pawpads.C;
import saberapplications.pawpads.R;
Expand All @@ -64,6 +72,7 @@
import saberapplications.pawpads.databinding.BindableBoolean;
import saberapplications.pawpads.databinding.BindableInteger;
import saberapplications.pawpads.ui.BaseActivity;
import saberapplications.pawpads.ui.profile.ProfileActivity;
import saberapplications.pawpads.util.AvatarLoaderHelper;
import saberapplications.pawpads.util.FileUtil;
import saberapplications.pawpads.views.BaseListAdapter;
Expand All @@ -76,29 +85,24 @@ public class ChatActivity extends BaseActivity {
public static final String RECIPIENT_ID = "user_id";
public static final String CURRENT_USER_ID = "current user id";
private static final int PICKFILE_REQUEST_CODE = 2;
private static final int PERMISSION_REQUEST = 200;
private static final int IMAGE_CAPTURE_REQUEST_CODE = 33;
private static final int READ_STORAGE_PERMISSION_REQUEST = 200;
private static final int WRITE_ST_CAMERA_PERMISSION_REQUEST = 205;
public final BindableBoolean isSendingMessage = new BindableBoolean();
public final BindableInteger uploadProgress = new BindableInteger(0);
public final BindableBoolean isBusy = new BindableBoolean(true);
//EditText editText_mail_id;
EditText editText_chat_message;

Button button_send_chat;

// BroadcastReceiver recieve_chat;
private QBDialog dialog;
private QBUser recipient;
private ChatMessagesAdapter chatAdapter;
private FrameLayout blockedContainer;
private LinearLayout messageContainer;

Bundle savedInstanceState;
ActivityChatBinding binding;
public final BindableBoolean isSendingMessage = new BindableBoolean();
public final BindableInteger uploadProgress = new BindableInteger(0);
public final BindableBoolean isBusy = new BindableBoolean(true);
int currentPage = 0;
int messagesPerPage = 15;
long paused;
boolean gotMessagesInOffline = false;

private Uri mPhotoUri;
// BroadcastReceiver recieve_chat;
private QBDialog dialog;
BroadcastReceiver updateChatReciever = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand All @@ -107,7 +111,10 @@ public void onReceive(Context context, Intent intent) {
}
}
};

private QBUser recipient;
private ChatMessagesAdapter chatAdapter;
private FrameLayout blockedContainer;
private LinearLayout messageContainer;
private QBMessageListener messageListener = new QBMessageListener() {
@Override
public void processMessage(QBChat qbChat, final QBChatMessage qbChatMessage) {
Expand Down Expand Up @@ -140,6 +147,11 @@ public void processError(QBChat qbChat, QBChatException e, QBChatMessage qbChatM
private boolean isBlocked;
private boolean userDeleted;

public static boolean isImage(File file) {
String fileName = file.getName();
String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
return ext.equals("jpeg") || ext.equals("jpg") || ext.equals("png") || ext.equals("bmp");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -188,7 +200,6 @@ public void onItemClick(QBChatMessage item) {

}


private void init() {
runOnUiThread(new Runnable() {
@Override
Expand All @@ -214,7 +225,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICKFILE_REQUEST_CODE) {
sendAttachment(data.getData());
}

if (requestCode == IMAGE_CAPTURE_REQUEST_CODE) {
sendAttachment(mPhotoUri);
}

}
}
Expand Down Expand Up @@ -390,7 +403,6 @@ protected void onStop() {
isBusy.set(true);
}


private void onBlocked() {
Toast.makeText(this, getString(R.string.text_you_blocked), Toast.LENGTH_LONG).show();
messageContainer.setVisibility(View.GONE);
Expand Down Expand Up @@ -524,21 +536,73 @@ protected void onPostExecute(QBChatMessage qbChatMessage) {
}

public void selectFile() {
final CharSequence[] items = {
getString(R.string.dialog_take_from_camera),
getString(R.string.dialog_get_from_gallery),
getString(R.string.cancel)};
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppAlertDialogTheme);
builder.setTitle(getString(R.string.dialog_send_file_title));
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals(getString(R.string.dialog_take_from_camera))) {
getImgFromCamera();
} else if (items[item].equals(getString(R.string.dialog_get_from_gallery))) {
getImgFromGallery();
} else if (items[item].equals(getString(R.string.cancel))) {
dialog.dismiss();
}
}
});
builder.setCancelable(false);
builder.show();
}

private void getImgFromCamera() {
int permCameraCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA);
int permWriteCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permCameraCheck != PackageManager.PERMISSION_GRANTED || permWriteCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{ Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE },
WRITE_ST_CAMERA_PERMISSION_REQUEST);
return;
}
isExternalDialogOpened = true;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mPhotoUri = Uri.fromFile(getOutputMediaFile());
intent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoUri);
startActivityForResult(intent, IMAGE_CAPTURE_REQUEST_CODE);
}

private static File getOutputMediaFile() {
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "PawPads");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
return new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
}

private void getImgFromGallery() {
int permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSION_REQUEST);
READ_STORAGE_PERMISSION_REQUEST);
return;
}
isExternalDialogOpened = true;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);


}

public void loadData() {
Expand Down Expand Up @@ -582,7 +646,6 @@ protected void onPostExecute(List<QBChatMessage> chatMessages) {

}


public void unblockUser() {
binding.unblock.setEnabled(false);
binding.unblock.setText(R.string.unblocking);
Expand Down Expand Up @@ -641,20 +704,21 @@ protected void onPostExecute(Boolean result) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PERMISSION_REQUEST: {
case READ_STORAGE_PERMISSION_REQUEST: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
getImgFromGallery();
}
break;
}
case WRITE_ST_CAMERA_PERMISSION_REQUEST: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
selectFile();
getImgFromCamera();
}
break;
}
}
}

public static boolean isImage(File file) {
String fileName = file.getName();
String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
return ext.equals("jpeg") || ext.equals("jpg") || ext.equals("png") || ext.equals("bmp");
}

@Override
public void onChatMessage(QBPrivateChat qbPrivateChat, final QBChatMessage qbChatMessage) {
if (dialog == null) return;
Expand All @@ -675,4 +739,27 @@ public void run() {
}
});
}

public void openProfile() {
hideSoftKeyboard();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if(recipient != null) {
Intent intent = new Intent(ChatActivity.this, ProfileActivity.class);
intent.putExtra(C.QB_USERID, recipient.getId());
intent.putExtra(C.QB_USER, recipient);
startActivity(intent);
}
}
}, 50);
}

public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ else if ("content".equalsIgnoreCase(uri.getScheme())) {
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
if((uri.toString()).contains("file:///")) return uri.getPath();
return uri.getPath();
}
return null;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
android:layout_marginRight="16dp"
android:scaleType="centerCrop"
android:src="@drawable/user_placeholder"
android:onClick="@{() -> activity.openProfile() }"
app:riv_oval="true" />

<saberapplications.pawpads.views.FontTextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/margin_for_ad_bottom"
android:background="#ffffff">

<android.support.v4.view.ViewPager
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen tools:override="true" name="design_fab_image_size">56dp</dimen>
<dimen name="margin_for_ad_bottom">50dp</dimen>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
<string name="unable_to_get_file">Unable to get specified file</string>
<string name="verify_internet_connection">Please verify your internet connection</string>
<string name="reconnect_message">Server connection is lost. Trying to reconnect</string>
<string name="dialog_take_from_camera">Take from camera</string>
<string name="dialog_get_from_gallery">Choose from gallery</string>
<string name="dialog_send_file_title">Send file</string>
<array name="genders">
<item>Male</item>
<item>Female</item>
Expand Down

0 comments on commit 837505a

Please sign in to comment.