Image down sizing
This commit is contained in:
@@ -97,7 +97,13 @@
|
||||
android:name="com.google.firebase.messaging.default_notification_color"
|
||||
android:resource="@color/colorDefault" />
|
||||
|
||||
<activity android:name="de.beyondsoft.ownchat.page.fileconfirmation.FileConfirmationActivity"></activity>
|
||||
<activity
|
||||
android:name="de.beyondsoft.ownchat.page.fileconfirmation.FileConfirmationActivity"
|
||||
android:label=""
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/ChatStyle"
|
||||
/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -2,13 +2,11 @@ package de.beyondsoft.ownchat.data.firebase;
|
||||
|
||||
import com.google.firebase.messaging.FirebaseMessagingService;
|
||||
import com.google.firebase.messaging.RemoteMessage;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import de.beyondsoft.ownchat.R;
|
||||
import de.beyondsoft.ownchat.data.AppPrefsConstants;
|
||||
import de.beyondsoft.ownchat.data.api.common.ErrorHandlingResponseConverter;
|
||||
import de.beyondsoft.ownchat.data.api.responses.MessageResponse;
|
||||
import de.beyondsoft.ownchat.data.api.responses.MessagesResponse;
|
||||
import de.beyondsoft.ownchat.data.api.services.ChatService;
|
||||
import de.beyondsoft.ownchat.data.prefs.LongPreference;
|
||||
import de.beyondsoft.ownchat.data.repository.GroupRealmRepository;
|
||||
@@ -23,7 +21,6 @@ import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.LoggedOutUtils;
|
||||
import de.beyondsoft.ownchat.utils.rx.RxUtils;
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
import rx.functions.Func1;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
@@ -10,8 +10,10 @@ import de.beyondsoft.ownchat.di.InjectionHelper;
|
||||
import de.beyondsoft.ownchat.model.Group;
|
||||
import de.beyondsoft.ownchat.model.Message;
|
||||
import de.beyondsoft.ownchat.page.common.RuntimePermissionActivity;
|
||||
import de.beyondsoft.ownchat.page.fileconfirmation.FileConfirmationActivity;
|
||||
import de.beyondsoft.ownchat.page.login.LoginPresenter;
|
||||
import de.beyondsoft.ownchat.page.main.LogoutNavigation;
|
||||
import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.EndlessScrollListener;
|
||||
import de.beyondsoft.ownchat.utils.FileUtils;
|
||||
import de.beyondsoft.ownchat.utils.SystemUtils;
|
||||
@@ -69,6 +71,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
|
||||
private final static int STORAGE_REQUEST_CODE = 9999;
|
||||
private final static int SELECT_FILE = 5055;
|
||||
private final static int CONFIRM_FILE = 666;
|
||||
private final static int VISIBLE_THRESHOLD = 25;
|
||||
protected final static String MESSAGE_ARG = "message_arg";
|
||||
protected final static String GROUP_ARG = "group_arg";
|
||||
@@ -134,6 +137,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
if (!getIntent().hasExtra(GROUP_ARG) && !getIntent().hasExtra(MESSAGE_ARG)) {
|
||||
throw new RuntimeException("Arguments are missing. Please use createIntentMethodInstead;");
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
EventBus.getDefault().register(this);
|
||||
setContentView(R.layout.activity_chat);
|
||||
@@ -143,8 +147,10 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mBaseChatAdapter = getAdapter();
|
||||
mEmptyLayout.setOnTryAgainClickListener(v -> mCallback.fetchMoreMessagesByGroupId());
|
||||
setupRecyclerView();
|
||||
|
||||
EmojIconActions emojIcon = new EmojIconActions(this, mCoordinatorLayout, mChatMessageEmojiEditText, mEmojiButton);
|
||||
emojIcon.ShowEmojIcon();
|
||||
|
||||
showLoading();
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(mKeyboardListener);
|
||||
@@ -197,6 +203,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mRecyclerView.scrollToPosition(0);
|
||||
return;
|
||||
}
|
||||
|
||||
mBaseChatAdapter.addMessages(messages);
|
||||
}
|
||||
|
||||
@@ -206,6 +213,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mSnackbar = Snackbar.make(mCoordinatorLayout, errorRes, Snackbar.LENGTH_LONG);
|
||||
mSnackbar.setActionTextColor(ContextCompat.getColor(this, R.color.colorDefault));
|
||||
}
|
||||
|
||||
mSnackbar.setText(errorRes);
|
||||
mSnackbar.show();
|
||||
}
|
||||
@@ -251,7 +259,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
|
||||
@OnClick(R.id.chat_send_message)
|
||||
void messageSent() {
|
||||
// mLoginPresenter.checkIfVoucherStillAvailable(this);
|
||||
mCallback.sendMessage(mChatMessageEmojiEditText.getText().toString());
|
||||
mChatMessageEmojiEditText.setText("");
|
||||
}
|
||||
@@ -306,6 +313,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
// Check for the freshest data.
|
||||
try {
|
||||
//noinspection WrongConstant
|
||||
getContentResolver().takePersistableUriPermission(uri, takeFlags);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -316,17 +324,30 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mChatPresenter.attachView(this);
|
||||
}
|
||||
|
||||
// TODO: Show preview for images/gifs and maybe videos
|
||||
|
||||
/*Bundle bundle = new Bundle();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Constants.FILENAME, uri.toString());
|
||||
|
||||
|
||||
|
||||
Intent intent = new Intent(this, FileConfirmationActivity.class);
|
||||
intent.putExtras(bundle);
|
||||
|
||||
startActivityForResult(intent, 666);*/
|
||||
intent.putExtra(Constants.EXTRA_GROUP, mGroup);
|
||||
|
||||
mCallback.sendFile(uri);
|
||||
startActivityForResult(intent, 666);
|
||||
}
|
||||
|
||||
if(requestCode == CONFIRM_FILE) {
|
||||
String fileUriString = data.getStringExtra(Constants.FILE_URI);
|
||||
String fileMessageText = data.getStringExtra(Constants.FILE_MESSAGE_TEXT);
|
||||
|
||||
if (!mChatPresenter.isAttached()) {
|
||||
mChatPresenter.attachView(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
mCallback.sendFile(Uri.parse(fileUriString), fileMessageText, getContentResolver().getType(Uri.parse(fileUriString)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,16 +367,20 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
if (!mChatPresenter.isAttached()) {
|
||||
mChatPresenter.attachView(this);
|
||||
}
|
||||
|
||||
String[] split = message.filePath.split("/");
|
||||
String fileName = split[split.length - 1];
|
||||
File file = getExternalFilesDir(null);
|
||||
|
||||
if (file != null) {
|
||||
mCallback.downloadFile(message, file + "/" + fileName, itemPosition);
|
||||
return;
|
||||
}
|
||||
|
||||
file = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name) + "/" + fileName);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.mkdirs();
|
||||
|
||||
mCallback.downloadFile(message, file.getAbsolutePath(), itemPosition);
|
||||
}
|
||||
|
||||
@@ -371,7 +396,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mChatPresenter.attachView(this);
|
||||
}
|
||||
|
||||
mCallback.resendMessage(message);
|
||||
mCallback.resendMessage(message, !TextUtils.isEmpty(message.filePath) ? getContentResolver().getType(Uri.parse(message.filePath)) : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,7 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
private Calendar mLastDay;
|
||||
private MessageClickListener mMessageClickListener;
|
||||
private boolean mIsRetrying;
|
||||
protected HashMap<Integer, Integer> mDownloadProgressMap = new HashMap<>();
|
||||
private HashMap<Integer, Integer> mDownloadProgressMap = new HashMap<>();
|
||||
|
||||
BaseChatAdapter(long userId) {
|
||||
mUserId = userId;
|
||||
|
||||
@@ -20,18 +20,25 @@ import de.beyondsoft.ownchat.di.scopes.ActivityScope;
|
||||
import de.beyondsoft.ownchat.model.Group;
|
||||
import de.beyondsoft.ownchat.model.Message;
|
||||
import de.beyondsoft.ownchat.page.mvp.MVPAbstractPresenter;
|
||||
import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.SystemUtils;
|
||||
import de.beyondsoft.ownchat.utils.rx.RxUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -96,6 +103,9 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
@Inject
|
||||
RealmProvider mRealmProvider;
|
||||
|
||||
@Inject
|
||||
Context mContext;
|
||||
|
||||
@Inject
|
||||
ChatPresenter() {
|
||||
}
|
||||
@@ -405,7 +415,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
* Send the file to the server.
|
||||
*/
|
||||
@Override
|
||||
public void sendFile(Uri fileUri) {
|
||||
public void sendFile(Uri fileUri, String messageText, String mimeType) {
|
||||
File file = getView().getFile(fileUri);
|
||||
|
||||
if (file == null || !file.exists()) {
|
||||
@@ -413,12 +423,14 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
return;
|
||||
}
|
||||
|
||||
String tmpFileLocation = mContext.getExternalFilesDir(null) + "/tmp_" + file.getName();
|
||||
|
||||
String[] split = file.getAbsolutePath().split("/");
|
||||
|
||||
Message message = new Message(findUniqueRandomId(mRealmProvider, mUserIdPreference.get()),
|
||||
mGroupId,
|
||||
System.currentTimeMillis() / 1000,
|
||||
null,
|
||||
messageText,
|
||||
file.getPath(),
|
||||
file.getPath(),
|
||||
split[split.length - 1],
|
||||
@@ -447,8 +459,57 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
message.createdAt *= 1000;
|
||||
getView().addOneMessage(message);
|
||||
|
||||
// image/gif, image/jpeg, image/png
|
||||
|
||||
if((mimeType.equals(Constants.MIME_TYPE_JPEG) || mimeType.equals(Constants.MIME_TYPE_PNG)) && (file.length() > (1000L * 1024L))) {
|
||||
Log.i("IMAGE DOWN SCALING", "Trying to scale down the image");
|
||||
|
||||
try {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
|
||||
Bitmap bitmapToScale = BitmapFactory.decodeFile(file.getPath(), options);
|
||||
|
||||
int originalWidth = options.outWidth;
|
||||
int originalHeight = options.outHeight;
|
||||
|
||||
int newHeight, newWidth;
|
||||
double aspectRatio = ((double) originalWidth) / ((double) originalHeight);
|
||||
|
||||
if(originalHeight > originalWidth) {
|
||||
newWidth = 1080;
|
||||
newHeight = (int) (newWidth * aspectRatio);
|
||||
} else {
|
||||
newHeight = 1080;
|
||||
newWidth = (int) (newHeight * aspectRatio);
|
||||
}
|
||||
|
||||
Bitmap bitmap = Bitmap.createScaledBitmap(bitmapToScale, newWidth, newHeight, false);
|
||||
File tmpFile = new File(tmpFileLocation);
|
||||
tmpFile.createNewFile();
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
|
||||
fileOutputStream.write(outputStream.toByteArray());
|
||||
bitmap.recycle();
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
File scaledImage = new File(tmpFileLocation);
|
||||
boolean scaledImageExists = scaledImage.exists();
|
||||
|
||||
if(scaledImageExists) {
|
||||
Log.i("FILE SIZES", "" + ((int) (file.length() / 1024d)) + "Kb vs. " + (scaledImage.length() / 1024) + "Kb");
|
||||
}
|
||||
|
||||
// TODO: delete tempFile after it has been sent successfully
|
||||
|
||||
// create RequestBody instance from file
|
||||
RequestBody requestFile = RequestBody.create(getView().getMediaType(fileUri), file);
|
||||
RequestBody requestFile = RequestBody.create(getView().getMediaType(fileUri), scaledImageExists ? scaledImage : file);
|
||||
|
||||
// MultipartBody.Part is used to send also the actual file name
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
|
||||
@@ -457,8 +518,6 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
String groupIdString = String.valueOf(mGroupId);
|
||||
RequestBody groupIdBody = RequestBody.create(okhttp3.MultipartBody.FORM, groupIdString);
|
||||
|
||||
Log.d("SENDING FILE", "Sending file with text message...");
|
||||
|
||||
RequestBody textBody = RequestBody.create(okhttp3.MultipartBody.FORM, message.message == null ? "" : message.message);
|
||||
|
||||
mChatService.sendFile(groupIdBody, body, textBody)
|
||||
@@ -478,18 +537,25 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
newMessage.isRead = true;
|
||||
storeMessageLocally(newMessage, message.id, false);
|
||||
storeGroupLocally(mGroupId, message);
|
||||
|
||||
if (!isAttached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSystemUtils.isNetworkUnavailable()) {
|
||||
getView().showError(R.string.error_no_internet_connection);
|
||||
return;
|
||||
}
|
||||
|
||||
getView().showError(R.string.error_something_went_wrong);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(MessageResponse baseResponse) {
|
||||
if (scaledImageExists) {
|
||||
boolean delete = scaledImage.delete();
|
||||
Log.i("DELETED SCALED IMAGE", "Success: " + delete);
|
||||
}
|
||||
deleteLocalMessage(message);
|
||||
baseResponse.response.message.status = Message.Status.DELIVERED;
|
||||
baseResponse.response.message.isRead = true;
|
||||
@@ -562,12 +628,13 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resendMessage(Message message) {
|
||||
public void resendMessage(Message message, String mimeType) {
|
||||
if (mSystemUtils.isNetworkUnavailable()) {
|
||||
getView().enableMessageRetry(message.id);
|
||||
getView().showError(R.string.error_no_internet_connection);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(message.message)) {
|
||||
Uri fileUri = Uri.parse(message.uri);
|
||||
File file = getView().getFile(fileUri);
|
||||
@@ -577,6 +644,13 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: resize file
|
||||
// image/gif, image/jpeg, image/png
|
||||
|
||||
if(mimeType.equals("image/jpeg") || mimeType.equals("image/png")) {
|
||||
|
||||
}
|
||||
|
||||
// create RequestBody instance from file
|
||||
RequestBody requestFile = RequestBody.create(getView().getMediaType(fileUri), file);
|
||||
|
||||
@@ -620,6 +694,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
storeGroupLocally(mGroupId, baseResponse.response.message);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,11 @@ interface ChatView extends MVPView {
|
||||
|
||||
void resetMessages();
|
||||
|
||||
void sendFile(Uri fileUri);
|
||||
void sendFile(Uri fileUri, String messageText, String mimeType);
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
void resendMessage(Message message);
|
||||
void resendMessage(Message message, String mimeType);
|
||||
|
||||
void downloadFile(Message message, String filePath, int itemPosition);
|
||||
|
||||
|
||||
@@ -93,15 +93,21 @@ public class GroupChatActivity extends BaseChatActivity {
|
||||
@Override
|
||||
protected void setToolbar() {
|
||||
mSingleChatTitleTextView.setVisibility(View.GONE);
|
||||
|
||||
mGroupTitleTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
mGroupMembersTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
mExtraImageView.setVisibility(View.VISIBLE);
|
||||
|
||||
mGroupMembersTextView.setText(mGroup.getContactsNames());
|
||||
|
||||
mExtraImageView.setImageResource(R.drawable.vertical_dots);
|
||||
|
||||
mChatImageView.setImageResource(mGroup.isHelpGroup() ? R.drawable.avatar_help_group : R.drawable.avatar_team_group);
|
||||
|
||||
mGroupTitleTextView.setText(mGroup.name);
|
||||
mGroupTitleTextView.setTextColor(ContextCompat.getColor(this,
|
||||
mGroup.isHelpGroup() ? R.color.colorHelpGroup : R.color.colorTeamGroup));
|
||||
mGroupTitleTextView.setTextColor(ContextCompat.getColor(this, mGroup.isHelpGroup() ? R.color.colorHelpGroup : R.color.colorTeamGroup));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
package de.beyondsoft.ownchat.page.fileconfirmation;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
|
||||
|
||||
import butterknife.OnClick;
|
||||
import de.beyondsoft.ownchat.R;
|
||||
import de.beyondsoft.ownchat.di.InjectionHelper;
|
||||
import de.beyondsoft.ownchat.model.Group;
|
||||
import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.FileUtils;
|
||||
|
||||
@@ -21,6 +30,7 @@ import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import hani.momanii.supernova_emoji_library.Actions.EmojIconActions;
|
||||
import hani.momanii.supernova_emoji_library.Helper.EmojiconEditText;
|
||||
|
||||
public class FileConfirmationActivity extends AppCompatActivity implements FileConfirmationView {
|
||||
@@ -31,17 +41,35 @@ public class FileConfirmationActivity extends AppCompatActivity implements FileC
|
||||
@BindView(R.id.file_emoji_button)
|
||||
ImageView mEmojiButtonImageView;
|
||||
|
||||
@BindView(R.id.media_file_webview)
|
||||
WebView mFileWebView;
|
||||
@BindView(R.id.media_file)
|
||||
ImageView mFileImageView;
|
||||
|
||||
@BindView(R.id.file_relative_layout)
|
||||
RelativeLayout mRelativeLayout;
|
||||
|
||||
@BindView(R.id.file_send_message)
|
||||
ImageView mSendMessageButtonImageView;
|
||||
|
||||
@BindView(R.id.chat_toolbar_image_view)
|
||||
ImageView mChatImageView;
|
||||
|
||||
@BindView(R.id.chat_toolbar_single_title)
|
||||
TextView mSingleChatTitleTextView;
|
||||
|
||||
@BindView(R.id.chat_toolbar_group_title)
|
||||
TextView mGroupTitleTextView;
|
||||
|
||||
@BindView(R.id.chat_toolbar_group_members)
|
||||
TextView mGroupMembersTextView;
|
||||
|
||||
@BindView(R.id.chat_toolbar_extra_image)
|
||||
ImageView mExtraImageView;
|
||||
|
||||
@Inject
|
||||
FileConfirmationPresenter mFileConfirmationPresenter;
|
||||
|
||||
private Callback mCallback;
|
||||
private Uri mSelectedUri;
|
||||
private Group mGroup;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -52,43 +80,69 @@ public class FileConfirmationActivity extends AppCompatActivity implements FileC
|
||||
ButterKnife.bind(this);
|
||||
mFileConfirmationPresenter.attachView(this);
|
||||
|
||||
EmojIconActions emojiIcon = new EmojIconActions(this, mRelativeLayout, mMessageEmojiconEditText, mEmojiButtonImageView);
|
||||
emojiIcon.ShowEmojIcon();
|
||||
|
||||
String fileUri = getIntent().getStringExtra(Constants.FILENAME);
|
||||
|
||||
File file = getFile(Uri.parse(fileUri));
|
||||
String absolutePath = file.getAbsolutePath();
|
||||
mSelectedUri = Uri.parse(fileUri);
|
||||
|
||||
String html = "<html><head></head><body><img src=\""+ absolutePath + "\"></body></html>";
|
||||
try {
|
||||
mFileWebView.loadDataWithBaseURL("", html, "text/html", "utf-8", null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Glide.with(this)
|
||||
.load(getFile(mSelectedUri).getPath())
|
||||
.dontAnimate()
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.into(new GlideDrawableImageViewTarget(mFileImageView));
|
||||
|
||||
mGroup = getIntent().getParcelableExtra(Constants.EXTRA_GROUP);
|
||||
setToolBar();
|
||||
}
|
||||
|
||||
private void setToolBar() {
|
||||
if(mGroup.users.size() > 2) {
|
||||
mSingleChatTitleTextView.setVisibility(View.GONE);
|
||||
|
||||
mGroupTitleTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
mGroupMembersTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
mGroupMembersTextView.setText(mGroup.getContactsNames());
|
||||
|
||||
mExtraImageView.setImageResource(R.drawable.vertical_dots);
|
||||
|
||||
mChatImageView.setImageResource(mGroup.isHelpGroup() ? R.drawable.avatar_help_group : R.drawable.avatar_team_group);
|
||||
|
||||
mGroupTitleTextView.setText(mGroup.name);
|
||||
mGroupTitleTextView.setTextColor(ContextCompat.getColor(this, mGroup.isHelpGroup() ? R.color.colorHelpGroup : R.color.colorTeamGroup));
|
||||
} else {
|
||||
mSingleChatTitleTextView.setVisibility(View.VISIBLE);
|
||||
mSingleChatTitleTextView.setText(mGroup.name);
|
||||
mSingleChatTitleTextView.setTextColor(ContextCompat.getColor(this, mGroup.onlyEmployees ? de.beyondsoft.ownchat.R.color.colorBlack : de.beyondsoft.ownchat.R.color.colorHelpGroup));
|
||||
|
||||
if (TextUtils.isEmpty(mGroup.avatar)) {
|
||||
mChatImageView.setImageResource(mGroup.onlyEmployees ? de.beyondsoft.ownchat.R.drawable.avatar : R.drawable.avatar_help);
|
||||
} else {
|
||||
Glide.with(this).load(mGroup.avatar)
|
||||
.placeholder(de.beyondsoft.ownchat.R.drawable.avatar)
|
||||
.dontAnimate()
|
||||
.into(mChatImageView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getPath(Uri uri) {
|
||||
String[] projection = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
|
||||
@OnClick(R.id.file_send_message)
|
||||
void sendFile() {
|
||||
Intent intent = new Intent();
|
||||
|
||||
if(cursor == null) {
|
||||
return null;
|
||||
}
|
||||
intent.putExtra(Constants.FILE_URI, mSelectedUri.toString());
|
||||
intent.putExtra(Constants.FILE_MESSAGE_TEXT, mMessageEmojiconEditText.getText().toString());
|
||||
|
||||
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||
cursor.moveToFirst();
|
||||
String path = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
return path;
|
||||
setResult(-1, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFileSuccessful() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallback(Callback callback) {
|
||||
mCallback = callback;
|
||||
@OnClick(R.id.chat_toolbar_back_arrow)
|
||||
void backPressed() {
|
||||
onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package de.beyondsoft.ownchat.page.fileconfirmation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import de.beyondsoft.ownchat.data.api.services.ChatService;
|
||||
import de.beyondsoft.ownchat.page.mvp.MVPAbstractPresenter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -13,10 +11,7 @@ import javax.inject.Inject;
|
||||
* Created by Lyndon on 13-Oct-2017.
|
||||
*/
|
||||
|
||||
public class FileConfirmationPresenter extends MVPAbstractPresenter<FileConfirmationView> implements FileConfirmationView.Callback {
|
||||
|
||||
@Inject
|
||||
ChatService mChatService;
|
||||
public class FileConfirmationPresenter extends MVPAbstractPresenter<FileConfirmationView> {
|
||||
|
||||
@Inject
|
||||
Context mContext;
|
||||
@@ -27,17 +22,11 @@ public class FileConfirmationPresenter extends MVPAbstractPresenter<FileConfirma
|
||||
@Override
|
||||
protected void afterAttachView(@NonNull FileConfirmationView view) {
|
||||
super.afterAttachView(view);
|
||||
view.setCallback(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeDetachView(@NonNull FileConfirmationView view) {
|
||||
view.setCallback(null);
|
||||
super.beforeDetachView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFile(Uri fileUri) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.beyondsoft.ownchat.page.fileconfirmation;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import de.beyondsoft.ownchat.page.mvp.MVPLceView;
|
||||
|
||||
/**
|
||||
@@ -9,11 +7,5 @@ import de.beyondsoft.ownchat.page.mvp.MVPLceView;
|
||||
*/
|
||||
|
||||
public interface FileConfirmationView extends MVPLceView {
|
||||
void sendFileSuccessful();
|
||||
|
||||
void setCallback(Callback callback);
|
||||
|
||||
interface Callback {
|
||||
void sendFile(Uri fileUri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,11 @@ public interface Constants {
|
||||
String CHAT_IS_ALREADY_OPEN = "chat_is_already_open";
|
||||
String KEY_TEXT_REPLY = "key_text_reply";
|
||||
|
||||
String FILE_URI = "file_uri";
|
||||
String FILE_MESSAGE_TEXT = "file_message_text";
|
||||
String EXTRA_GROUP = "group";
|
||||
|
||||
String MIME_TYPE_JPEG = "image/jpeg";
|
||||
String MIME_TYPE_PNG = "image/png";
|
||||
String MIME_TYPE_GIF = "image/gif";
|
||||
}
|
||||
@@ -103,6 +103,7 @@ public class FileUtils {
|
||||
if (file != null) {
|
||||
return Uri.fromFile(file);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -134,7 +135,6 @@ public class FileUtils {
|
||||
* @return The MIME type for the given file.
|
||||
*/
|
||||
public static String getMimeType(File file) {
|
||||
|
||||
String extension = getExtension(file.getName());
|
||||
|
||||
if (extension.length() > 0) {
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:emojicon="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/file_relative_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="de.beyondsoft.ownchat.page.fileconfirmation.FileConfirmationActivity">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/media_file_webview"
|
||||
<include layout="@layout/chat_toolbar" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/media_file"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</WebView>
|
||||
</ImageView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<ImageView
|
||||
android:id="@+id/chat_item_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="90dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
@@ -84,7 +84,7 @@
|
||||
android:id="@+id/chat_item_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_below="@id/chat_item_file"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
emojicon:emojiconSize="20sp"
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
<ImageView
|
||||
android:id="@+id/chat_item_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="90dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<ImageView
|
||||
android:id="@+id/chat_item_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="90dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_marginTop="4dp"
|
||||
android:adjustViewBounds="true"
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
<ImageView
|
||||
android:id="@+id/chat_item_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="90dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
|
||||
Reference in New Issue
Block a user