-
This commit is contained in:
@@ -28,10 +28,10 @@ apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
buildToolsVersion "25.0.3"
|
||||
defaultConfig {
|
||||
applicationId "de.beyondsoft.ownchat"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 25
|
||||
versionCode 2
|
||||
versionName "1.1"
|
||||
@@ -86,8 +86,8 @@ dependencies {
|
||||
// emojis
|
||||
// circle progress
|
||||
// event bus
|
||||
compile 'com.android.support:appcompat-v7:25.3.0'
|
||||
compile 'com.android.support:design:25.3.0'
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
compile 'com.android.support:design:25.3.1'
|
||||
compile 'com.jakewharton:butterknife:8.4.0'
|
||||
compile 'com.google.dagger:dagger:2.7'
|
||||
compile 'io.reactivex:rxjava:1.1.6'
|
||||
|
||||
@@ -26,7 +26,6 @@ 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;
|
||||
@@ -38,7 +37,6 @@ 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;
|
||||
@@ -462,8 +460,6 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
// 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();
|
||||
|
||||
@@ -503,10 +499,6 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
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");
|
||||
}
|
||||
|
||||
// create RequestBody instance from file
|
||||
RequestBody requestFile = RequestBody.create(getView().getMediaType(fileUri), scaledImageExists ? scaledImage : file);
|
||||
|
||||
@@ -553,8 +545,8 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
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;
|
||||
@@ -643,15 +635,50 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: resize file
|
||||
// image/gif, image/jpeg, image/png
|
||||
String tmpFileLocation = mContext.getExternalFilesDir(null) + "/tmp_" + file.getName();
|
||||
|
||||
if(mimeType.equals("image/jpeg") || mimeType.equals("image/png")) {
|
||||
if((mimeType.equals(Constants.MIME_TYPE_JPEG) || mimeType.equals(Constants.MIME_TYPE_PNG)) && (file.length() > (1000L * 1024L))) {
|
||||
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) {
|
||||
aspectRatio = ((double) originalHeight) / ((double) 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();
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -527,6 +527,8 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
|
||||
if(result == 0) {
|
||||
deleteData(true);
|
||||
shouldClearAllPrefs = true;
|
||||
|
||||
// TODO: Der Chat-Code wurde deaktiviert
|
||||
}
|
||||
|
||||
if(result == 1) {
|
||||
|
||||
@@ -134,6 +134,7 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
|
||||
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
|
||||
getActivity().getContentResolver().takePersistableUriPermission(uri, takeFlags);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -210,8 +211,7 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
|
||||
|
||||
@OnTextChanged(value = R.id.profile_phone_number, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
||||
void phoneNumberChanged() {
|
||||
mUpdateProfileButton.setEnabled(!TextUtils.isEmpty(mPhoneNumberEditText.getText().toString())
|
||||
&& mPhoneNumberEditText.getText().toString().trim().length() > 0);
|
||||
mUpdateProfileButton.setEnabled(!TextUtils.isEmpty(mPhoneNumberEditText.getText().toString()) && mPhoneNumberEditText.getText().toString().trim().length() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,12 +227,14 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
|
||||
|
||||
private void selectFile() {
|
||||
Intent intent;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
|
||||
} else {
|
||||
intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
}
|
||||
|
||||
intent.setType("image/*");
|
||||
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
@@ -8,13 +8,21 @@ import de.beyondsoft.ownchat.data.prefs.StringPreference;
|
||||
import de.beyondsoft.ownchat.di.scopes.ActivityScope;
|
||||
import de.beyondsoft.ownchat.model.User;
|
||||
import de.beyondsoft.ownchat.page.mvp.MVPAbstractPresenter;
|
||||
import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.FileUtils;
|
||||
import de.beyondsoft.ownchat.utils.SystemUtils;
|
||||
import de.beyondsoft.ownchat.utils.rx.RxUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -41,6 +49,9 @@ class ProfilePresenter extends MVPAbstractPresenter<ProfileView> implements Prof
|
||||
@Named(AppPrefsConstants.LOGIN_TOKEN)
|
||||
StringPreference mToken;
|
||||
|
||||
@Inject
|
||||
Context mContext;
|
||||
|
||||
@Inject
|
||||
ProfilePresenter() {
|
||||
}
|
||||
@@ -97,12 +108,59 @@ class ProfilePresenter extends MVPAbstractPresenter<ProfileView> implements Prof
|
||||
}
|
||||
|
||||
File file = getView().getFile(uri);
|
||||
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
|
||||
|
||||
String tmpFileLocation = mContext.getExternalFilesDir(null) + "/tmp_" + file.getName();
|
||||
|
||||
String mimeType = FileUtils.getMimeType(mContext, uri);
|
||||
|
||||
if((mimeType.equals(Constants.MIME_TYPE_JPEG) || mimeType.equals(Constants.MIME_TYPE_PNG)) && (file.length() > (1000L * 1024L))) {
|
||||
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) {
|
||||
aspectRatio = ((double) originalHeight) / ((double) 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();
|
||||
|
||||
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), scaledImageExists ? scaledImage : file);
|
||||
MultipartBody.Part part = MultipartBody.Part.createFormData("picture", file.getName(), requestBody);
|
||||
|
||||
final Subscription subscription = mProfileService.uploadProfileImage(part)
|
||||
.compose(RxUtils.provideDefaultTransformer())
|
||||
.map(uploadImageResponse -> uploadImageResponse.response.picture)
|
||||
.subscribe(this::uploadImageSuccess, this::profileError);
|
||||
|
||||
addSubscription(subscription);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,31 +41,35 @@
|
||||
android:textColor="@color/colorManatee"
|
||||
android:textSize="10sp"
|
||||
tools:ignore="SmallSp"
|
||||
tools:text="Sasha Grey | 15:23" />
|
||||
tools:text="Sasha Grey | 15:23"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/chat_item_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="120dp"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_marginTop="4dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="fitStart"
|
||||
android:visibility="gone"/>
|
||||
android:scaleType="fitCenter"
|
||||
android:visibility="gone"
|
||||
tools:src="@drawable/document"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chat_item_file_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/chat_item_time"
|
||||
android:layout_marginTop="95dp"
|
||||
android:layout_below="@+id/chat_item_file"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:text="MyFile.txt"/>
|
||||
|
||||
<com.github.lzyzsd.circleprogress.DonutProgress
|
||||
android:id="@+id/chat_item_progress"
|
||||
@@ -78,13 +82,14 @@
|
||||
android:visibility="gone"
|
||||
custom:donut_finished_color="@color/colorDefault"
|
||||
custom:donut_text_color="@color/colorBlack"
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
|
||||
<hani.momanii.supernova_emoji_library.Helper.EmojiconTextView
|
||||
android:id="@+id/chat_item_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/chat_item_file"
|
||||
android:layout_below="@id/chat_item_file_name"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
emojicon:emojiconSize="20sp"
|
||||
|
||||
@@ -59,7 +59,8 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_toEndOf="@+id/chat_item_time"
|
||||
android:layout_toRightOf="@+id/chat_item_time"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/chat_item_message_status"
|
||||
@@ -97,10 +98,11 @@
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_marginTop="4dp"
|
||||
android:contentDescription="@null"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitEnd"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="fitCenter"
|
||||
android:visibility="gone"
|
||||
tools:src="@drawable/document"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
@@ -109,10 +111,11 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/chat_item_time"
|
||||
android:layout_marginTop="95dp"
|
||||
android:layout_below="@+id/chat_item_file"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:text="MyFile.txt"/>
|
||||
|
||||
<com.github.lzyzsd.circleprogress.DonutProgress
|
||||
android:id="@+id/chat_item_progress"
|
||||
@@ -132,13 +135,13 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/chat_item_file"
|
||||
android:layout_below="@id/chat_item_file_name"
|
||||
android:padding="0dp"
|
||||
android:textColor="@color/colorWhite"
|
||||
emojicon:emojiconSize="20sp"
|
||||
style="@style/BaseChatItemText"
|
||||
tools:text="Meine Freundin, die Maschine. Als sie mein Herz für sich gewann. Mit ihren ganzen kleinen Geschwistern, mit denen man alles machen kann. www.google.com"
|
||||
tools:visibility="gone"/>
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
@@ -33,17 +33,20 @@
|
||||
android:layout_marginTop="4dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="fitStart"
|
||||
android:visibility="gone" />
|
||||
android:scaleType="fitCenter"
|
||||
android:visibility="gone"
|
||||
tools:src="@drawable/document"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chat_item_file_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="95dp"
|
||||
android:visibility="gone"
|
||||
android:layout_below="@+id/chat_item_time"
|
||||
android:textColor="@color/colorBlack" />
|
||||
android:layout_below="@+id/chat_item_file"
|
||||
android:textColor="@color/colorBlack"
|
||||
tools:visibility="visible"
|
||||
tools:text="MyFile.txt"/>
|
||||
|
||||
<com.github.lzyzsd.circleprogress.DonutProgress
|
||||
android:id="@+id/chat_item_progress"
|
||||
@@ -62,7 +65,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
emojicon:emojiconSize="20sp"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:layout_below="@id/chat_item_file"
|
||||
android:layout_below="@id/chat_item_file_name"
|
||||
style="@style/BaseChatItemText"
|
||||
tools:text="Meine Freundin, die Maschine. Als sie mein Herz für sich gewann. Mit ihren ganzen kleinen Geschwistern, mit denen man alles machen kann." />
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
android:layout_toEndOf="@+id/chat_item_time"
|
||||
android:contentDescription="@null"
|
||||
android:visibility="gone"
|
||||
tools:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
@@ -82,15 +82,16 @@
|
||||
android:id="@+id/chat_item_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="120dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@id/chat_item_time"
|
||||
android:layout_marginTop="4dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="fitEnd"
|
||||
android:scaleType="fitCenter"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
tools:src="@drawable/document"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<com.github.lzyzsd.circleprogress.DonutProgress
|
||||
android:id="@+id/chat_item_progress"
|
||||
@@ -111,10 +112,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/chat_item_time"
|
||||
android:layout_marginTop="95dp"
|
||||
android:layout_below="@+id/chat_item_file"
|
||||
android:textColor="@color/colorBlack"
|
||||
android:visibility="gone"
|
||||
tools:text="MyFile.txt"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<hani.momanii.supernova_emoji_library.Helper.EmojiconTextView
|
||||
@@ -123,7 +124,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/chat_item_file"
|
||||
android:layout_below="@id/chat_item_file_name"
|
||||
android:visibility="gone"
|
||||
emojicon:emojiconSize="20sp"
|
||||
style="@style/BaseChatItemText"
|
||||
|
||||
Reference in New Issue
Block a user