Issue when sending images with file type in all caps fixed

This commit is contained in:
staccatomamba
2017-10-31 18:25:38 +01:00
parent d4300a025c
commit 2fecb449f8
9 changed files with 42 additions and 9 deletions

View File

@@ -33,7 +33,7 @@ android {
minSdkVersion 19
targetSdkVersion 26
versionCode 2
versionName "1.1"
versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
@@ -83,7 +83,7 @@ dependencies {
// Glide
// Circle ImageView
compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true;
transitive = true
}
// Secure Preferences
// Firebase

View File

@@ -22,4 +22,5 @@ public interface AppPrefsConstants {
String USER_PASSWORD = "user_password";
String USER_NAME = "user_name";
String VERIFY_CHAT_CODE_ERROR_MESSAGE = "verify_chat_code_error_message";
}

View File

@@ -55,6 +55,13 @@ public class AppPrefsModule {
return new BooleanPreference(sharedPreferences, AppPrefsConstants.SAVE_PASSWORD);
}
@Provides
@ApplicationScope
@Named(AppPrefsConstants.VERIFY_CHAT_CODE_ERROR_MESSAGE)
StringPreference provideVerifyChatCodeErrorMessage(@AppPrefs SecurePreferences sharedPreferences) {
return new StringPreference(sharedPreferences, AppPrefsConstants.VERIFY_CHAT_CODE_ERROR_MESSAGE);
}
@Provides
@ApplicationScope
@Named(AppPrefsConstants.USER_NAME)

View File

@@ -91,6 +91,9 @@ public interface ApplicationComponent {
@Named(AppPrefsConstants.USER_NAME)
StringPreference provideUserName();
@Named(AppPrefsConstants.VERIFY_CHAT_CODE_ERROR_MESSAGE)
StringPreference provideVerifyChatCodeErrorMessage();
@Named(AppPrefsConstants.USER_PASSWORD)
StringPreference providePassword();

View File

@@ -145,6 +145,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
}
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
setContentView(R.layout.activity_chat);
ButterKnife.bind(this);
@@ -154,8 +155,8 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
mEmptyLayout.setOnTryAgainClickListener(v -> mCallback.fetchMoreMessagesByGroupId());
setupRecyclerView();
EmojIconActions emojIcon = new EmojIconActions(this, mCoordinatorLayout, mChatMessageEmojiEditText, mEmojiButton);
emojIcon.ShowEmojIcon();
EmojIconActions emojiIcon = new EmojIconActions(this, mCoordinatorLayout, mChatMessageEmojiEditText, mEmojiButton);
emojiIcon.ShowEmojIcon();
showLoading();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
@@ -166,10 +167,13 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
linearLayoutManager.setReverseLayout(true);
mRecyclerView.setLayoutManager(linearLayoutManager);
mBaseChatAdapter.setMessageClickListener(this);
mRecyclerView.setAdapter(mBaseChatAdapter);
((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
mEndlessScrollListener = new EndlessScrollListener(VISIBLE_THRESHOLD, linearLayoutManager) {
@Override
public boolean onLoad() {
@@ -180,6 +184,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
return true;
}
};
mRecyclerView.addOnScrollListener(mEndlessScrollListener);
}

View File

@@ -98,6 +98,10 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
@Named(AppPrefsConstants.NAME)
StringPreference mProfileNamePreference;
@Inject
@Named(AppPrefsConstants.UPLOAD_MAX_SIZE)
LongPreference mUploadMaxSizePreference;
@Inject
RealmProvider mRealmProvider;
@@ -499,8 +503,17 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
File scaledImage = new File(tmpFileLocation);
boolean scaledImageExists = scaledImage.exists();
File fileToSend = scaledImageExists ? scaledImage : file;
Log.d("FILE_SIZE", "" + file.length() + " vs. " + mUploadMaxSizePreference.get());
if(mUploadMaxSizePreference.get() > 0L && fileToSend.length() > mUploadMaxSizePreference.get()){
getView().showError(R.string.error_file_is_too_large);
return;
}
// create RequestBody instance from file
RequestBody requestFile = RequestBody.create(getView().getMediaType(mimeType), scaledImageExists ? scaledImage : file);
RequestBody requestFile = RequestBody.create(getView().getMediaType(mimeType), fileToSend);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
@@ -543,9 +556,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
@Override
public void onNext(MessageResponse baseResponse) {
if (scaledImageExists) {
boolean delete = scaledImage.delete();
}
boolean delete = scaledImage.delete();
deleteLocalMessage(message);
baseResponse.response.message.status = Message.Status.DELIVERED;

View File

@@ -64,6 +64,10 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Inject
RegisterService mRegisterService;
@Inject
@Named(AppPrefsConstants.VERIFY_CHAT_CODE_ERROR_MESSAGE)
StringPreference mVerifyChatCodeErrorMessage;
@Inject
@Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
BooleanPreference mShowLoginAgainPreference;
@@ -529,6 +533,7 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Override
public void onNext(JsonObject response) {
if (!response.has("result") || response.get("result") == null) {
getView().showError("Test message after verifying the cat code");
logoutNavigation.logoutDirectly(false);
return;
}

View File

@@ -135,7 +135,7 @@ public class FileUtils {
* @return The MIME type for the given file.
*/
public static String getMimeType(File file) {
String extension = getExtension(file.getName());
String extension = getExtension(file.getName().toLowerCase());
if (extension.length() > 0) {
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1));

View File

@@ -85,5 +85,6 @@
<string name="attachments_title_text" formatted="false">Anhänge (%d/%d)</string>
<string name="select_photo_text">Eine Mediendatei anhängen</string>
<string name="select_doc_text">Ein Dokument anhängen</string>
<string name="error_file_is_too_large">Die Datei, die Sie versuchen hochzuladen, ist zu groß</string>
</resources>