Added a dialog to choose between categories to pick files from

This commit is contained in:
Lyndon
2017-10-27 17:16:09 +02:00
parent 7cd48da622
commit c9c3702c7a
33 changed files with 338 additions and 71 deletions

View File

@@ -57,6 +57,12 @@
android:screenOrientation="portrait"
android:theme="@style/ChatStyle" />
<activity
android:name=".filepicker.FilePickerActivity"
android:configChanges="orientation|screenSize"/>
<activity android:name=".filepicker.MediaDetailsActivity"
android:configChanges="orientation|screenSize"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="1dcc8d0ead50f1b328778876834fea3392c6fc22" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -1,5 +1,23 @@
package de.beyondsoft.ownchat.filepicker;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
import java.util.ArrayList;
import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.filepicker.fragments.DocFragment;
import de.beyondsoft.ownchat.filepicker.fragments.DocPickerFragment;
import de.beyondsoft.ownchat.filepicker.fragments.ImagePickerFragmentListener;
import de.beyondsoft.ownchat.filepicker.fragments.MediaPickerFragment;
import de.beyondsoft.ownchat.filepicker.utils.FragmentUtil;
/**
* Created by Lyndon on 26-Oct-2017.
*/
@@ -9,4 +27,144 @@ public class FilePickerActivity extends BaseFilePickerActivity implements
DocFragment.DocFragmentListener,
DocPickerFragment.DocPickerFragmentListener,
MediaPickerFragment.MediaPickerFragmentListener {
private static final String TAG = FilePickerActivity.class.getSimpleName();
private int type;
@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.activity_file_picker);
}
@Override
protected void initView() {
Intent intent = getIntent();
if (intent != null) {
if(getSupportActionBar()!=null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ArrayList<String> selectedPaths = intent.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA);
type = intent.getIntExtra(FilePickerConst.EXTRA_PICKER_TYPE, FilePickerConst.MEDIA_PICKER);
if(selectedPaths!=null) {
if (PickerManager.getInstance().getMaxCount() == 1) {
selectedPaths.clear();
}
if (type == FilePickerConst.MEDIA_PICKER) {
PickerManager.getInstance().add(selectedPaths, FilePickerConst.FILE_TYPE_MEDIA);
} else {
PickerManager.getInstance().add(selectedPaths, FilePickerConst.FILE_TYPE_DOCUMENT);
}
}
else
selectedPaths = new ArrayList<>();
setToolbarTitle(PickerManager.getInstance().getCurrentCount());
openSpecificFragment(type, selectedPaths);
}
}
private void openSpecificFragment(int type, @Nullable ArrayList<String> selectedPaths) {
if (type == FilePickerConst.MEDIA_PICKER) {
MediaPickerFragment photoFragment = MediaPickerFragment.newInstance();
FragmentUtil.addFragment(this, R.id.container, photoFragment);
} else {
if(PickerManager.getInstance().isDocSupport())
PickerManager.getInstance().addDocTypes();
DocPickerFragment photoFragment = DocPickerFragment.newInstance(selectedPaths);
FragmentUtil.addFragment(this, R.id.container, photoFragment);
}
}
private void setToolbarTitle(int count) {
ActionBar actionBar = getSupportActionBar();
if(actionBar!=null) {
if (PickerManager.getInstance().getMaxCount() > 1)
actionBar.setTitle(String.format(getString(R.string.attachments_title_text), count, PickerManager.getInstance().getMaxCount()));
else {
if (type == FilePickerConst.MEDIA_PICKER)
actionBar.setTitle(R.string.select_photo_text);
else
actionBar.setTitle(R.string.select_doc_text);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.picker_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int i = item.getItemId();
if (i == R.id.action_done) {
if (type == FilePickerConst.MEDIA_PICKER)
returnData(PickerManager.getInstance().getSelectedPhotos());
else
returnData(PickerManager.getInstance().getSelectedFiles());
return true;
} else if (i == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
super.onBackPressed();
setResult(RESULT_CANCELED);
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
case FilePickerConst.REQUEST_CODE_MEDIA_DETAIL:
if(resultCode== Activity.RESULT_OK)
{
if (type == FilePickerConst.MEDIA_PICKER)
returnData(PickerManager.getInstance().getSelectedPhotos());
else
returnData(PickerManager.getInstance().getSelectedFiles());
}
else
{
setToolbarTitle(PickerManager.getInstance().getCurrentCount());
}
break;
}
}
private void returnData(ArrayList<String> paths) {
Intent intent = new Intent();
if (type == FilePickerConst.MEDIA_PICKER) {
intent.putStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA, paths);
} else {
intent.putStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS, paths);
}
setResult(RESULT_OK, intent);
finish();
}
@Override
public void onItemSelected() {
setToolbarTitle(PickerManager.getInstance().getCurrentCount());
if(PickerManager.getInstance().getMaxCount()==1)
returnData(type == FilePickerConst.MEDIA_PICKER ? PickerManager.getInstance().getSelectedPhotos() : PickerManager.getInstance().getSelectedFiles());
}
}

View File

@@ -49,7 +49,7 @@ public class PickerManager {
fileTypes = new ArrayList<>();
}
public void setMaxCount(int count) {
void setMaxCount(int count) {
clearSelections();
this.mMaxCount = count;
}
@@ -58,18 +58,19 @@ public class PickerManager {
return mMaxCount;
}
public int getCurrentCount() {
int getCurrentCount() {
return mCurrentCount;
}
public void add(String path, int type) {
if (path != null && shouldAdd()) {
if (!mediaFiles.contains(path) && type == FilePickerConst.FILE_TYPE_MEDIA)
if (!mediaFiles.contains(path) && type == FilePickerConst.FILE_TYPE_MEDIA) {
mediaFiles.add(path);
else if (type == FilePickerConst.FILE_TYPE_DOCUMENT)
} else if (type == FilePickerConst.FILE_TYPE_DOCUMENT) {
docFiles.add(path);
else
} else {
return;
}
mCurrentCount++;
}
@@ -85,7 +86,6 @@ public class PickerManager {
if ((type == FilePickerConst.FILE_TYPE_MEDIA) && mediaFiles.contains(path)) {
mediaFiles.remove(path);
mCurrentCount--;
} else if (type == FilePickerConst.FILE_TYPE_DOCUMENT) {
docFiles.remove(path);
@@ -107,13 +107,15 @@ public class PickerManager {
public ArrayList<String> getSelectedFilePaths(ArrayList<BaseFile> files) {
ArrayList<String> paths = new ArrayList<>();
for (int index = 0; index < files.size(); index++) {
paths.add(files.get(index).getPath());
}
return paths;
}
public void clearSelections() {
private void clearSelections() {
docFiles.clear();
mediaFiles.clear();
fileTypes.clear();
@@ -125,7 +127,7 @@ public class PickerManager {
return theme;
}
public void setTheme(int theme) {
void setTheme(int theme) {
this.theme = theme;
}
@@ -133,7 +135,7 @@ public class PickerManager {
return showVideos;
}
public void setShowVideos(boolean showVideos) {
void setShowVideos(boolean showVideos) {
this.showVideos = showVideos;
}
@@ -141,7 +143,7 @@ public class PickerManager {
return mShowImages;
}
public void setShowImages(boolean showImages) {
void setShowImages(boolean showImages) {
this.mShowImages = showImages;
}
@@ -149,7 +151,7 @@ public class PickerManager {
return showGif;
}
public void setShowGif(boolean showGif) {
void setShowGif(boolean showGif) {
this.showGif = showGif;
}
@@ -157,16 +159,16 @@ public class PickerManager {
return showFolderView;
}
public void setShowFolderView(boolean showFolderView) {
void setShowFolderView(boolean showFolderView) {
this.showFolderView = showFolderView;
}
public void addFileType(FileType fileType)
void addFileType(FileType fileType)
{
fileTypes.add(fileType);
}
public void addDocTypes()
void addDocTypes()
{
String[] pdfs = {"pdf"};
fileTypes.add(new FileType(FilePickerConst.PDF,pdfs,R.drawable.document));
@@ -189,11 +191,11 @@ public class PickerManager {
return fileTypes;
}
public boolean isDocSupport() {
boolean isDocSupport() {
return docSupport;
}
public void setDocSupport(boolean docSupport) {
void setDocSupport(boolean docSupport) {
this.docSupport = docSupport;
}
@@ -201,7 +203,7 @@ public class PickerManager {
return enableCamera;
}
public void setEnableCamera(boolean enableCamera) {
void setEnableCamera(boolean enableCamera) {
this.enableCamera = enableCamera;
}
@@ -217,11 +219,11 @@ public class PickerManager {
return providerAuthorities;
}
public void setProviderAuthorities(String providerAuthorities) {
void setProviderAuthorities(String providerAuthorities) {
this.providerAuthorities = providerAuthorities;
}
public void setCameraDrawable(int drawable) {
void setCameraDrawable(int drawable) {
this.mCameraDrawble = drawable;
}

View File

@@ -15,7 +15,6 @@ import com.bumptech.glide.RequestManager;
import java.io.File;
import java.util.ArrayList;
import butterknife.BindView;
import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.filepicker.FilePickerConst;
import de.beyondsoft.ownchat.filepicker.PickerManager;
@@ -166,20 +165,20 @@ public class ImageGridAdapter extends SelectableAdapter<ImageGridAdapter.ImageVi
}
public static class ImageViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.checkbox)
CheckBox checkBox;
@BindView(R.id.iv_photo)
ImageView imageView;
@BindView(R.id.video_icon)
ImageView videoIcon;
@BindView(R.id.transparent_bg)
View selectBg;
public ImageViewHolder(View itemView) {
super(itemView);
checkBox = itemView.findViewById(R.id.checkbox);
imageView = itemView.findViewById(R.id.iv_photo);
videoIcon = itemView.findViewById(R.id.video_icon);
selectBg = itemView.findViewById(R.id.transparent_bg);
}
}
}

View File

@@ -9,14 +9,14 @@ import android.view.animation.AnimationUtils;
* Created by Lyndon on 26-Oct-2017.
*/
public class BaseFragment extends Fragment {
public static final String FILE_TYPE="FILE_TYPE";
public abstract class BaseFragment extends Fragment {
public static final String FILE_TYPE = "FILE_TYPE";
public BaseFragment() {
// Required empty public constructor
}
protected void fadeIn(View view)
{
protected void fadeIn(View view) {
Animation bottomUp = AnimationUtils.loadAnimation(getContext(),
android.R.anim.fade_in);
@@ -24,8 +24,7 @@ public class BaseFragment extends Fragment {
view.setVisibility(View.VISIBLE);
}
protected void fadeOut(View view)
{
protected void fadeOut(View view) {
Animation bottomUp = AnimationUtils.loadAnimation(getContext(),
android.R.anim.fade_out);

View File

@@ -29,10 +29,8 @@ public class MediaPickerFragment extends BaseFragment {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_media_picker, container, false);
}
@@ -55,8 +53,7 @@ public class MediaPickerFragment extends BaseFragment {
}
public static MediaPickerFragment newInstance() {
MediaPickerFragment photoPickerFragment = new MediaPickerFragment();
return photoPickerFragment;
return new MediaPickerFragment();
}
public interface MediaPickerFragmentListener {
@@ -65,7 +62,6 @@ public class MediaPickerFragment extends BaseFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
@@ -83,23 +79,26 @@ public class MediaPickerFragment extends BaseFragment {
SectionsPagerAdapter adapter = new SectionsPagerAdapter(getChildFragmentManager());
if(PickerManager.getInstance().showImages()) {
if (PickerManager.getInstance().isShowFolderView())
if (PickerManager.getInstance().isShowFolderView()) {
adapter.addFragment(MediaFolderPickerFragment.newInstance(FilePickerConst.MEDIA_TYPE_IMAGE), getString(R.string.images));
else
} else {
adapter.addFragment(MediaDetailPickerFragment.newInstance(FilePickerConst.MEDIA_TYPE_IMAGE), getString(R.string.images));
}
}
else
tabLayout.setVisibility(View.GONE);
if(PickerManager.getInstance().showVideo())
{
if(PickerManager.getInstance().isShowFolderView())
if(PickerManager.getInstance().isShowFolderView()) {
adapter.addFragment(MediaFolderPickerFragment.newInstance(FilePickerConst.MEDIA_TYPE_VIDEO), getString(R.string.videos));
else
} else {
adapter.addFragment(MediaDetailPickerFragment.newInstance(FilePickerConst.MEDIA_TYPE_VIDEO), getString(R.string.videos));
}
}
else
else {
tabLayout.setVisibility(View.GONE);
}
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);

View File

@@ -5,7 +5,7 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.page.common.BaseFragment;
import de.beyondsoft.ownchat.filepicker.fragments.BaseFragment;
/**
* Created by Lyndon on 26-Oct-2017.

View File

@@ -7,6 +7,9 @@ import de.beyondsoft.ownchat.data.events.LogoutDirectlyEvent;
import de.beyondsoft.ownchat.data.prefs.BooleanPreference;
import de.beyondsoft.ownchat.data.prefs.LongPreference;
import de.beyondsoft.ownchat.di.InjectionHelper;
import de.beyondsoft.ownchat.filepicker.FilePickerBuilder;
import de.beyondsoft.ownchat.filepicker.FilePickerConst;
import de.beyondsoft.ownchat.filepicker.utils.Orientation;
import de.beyondsoft.ownchat.model.Group;
import de.beyondsoft.ownchat.model.Message;
import de.beyondsoft.ownchat.page.common.RuntimePermissionActivity;
@@ -25,6 +28,7 @@ import org.greenrobot.eventbus.ThreadMode;
import android.Manifest;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
@@ -70,7 +74,7 @@ import okhttp3.MediaType;
abstract class BaseChatActivity extends RuntimePermissionActivity implements ChatView, BaseChatAdapter.MessageClickListener, LogoutNavigation {
private final static int STORAGE_REQUEST_CODE = 9999;
private final static int SELECT_FILE = 5055;
private final static int SELECT_FILE = 233;
private final static int CONFIRM_FILE = 666;
private final static int VISIBLE_THRESHOLD = 25;
protected final static String MESSAGE_ARG = "message_arg";
@@ -269,16 +273,57 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
}
private void selectFile(int requestCode) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
// Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
//
// intent.addCategory(Intent.CATEGORY_OPENABLE);
//
// intent.setType("*/*");
// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//
// startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.chat_select_file)), SELECT_FILE);
intent.addCategory(Intent.CATEGORY_OPENABLE);
// TODO: show attachment type dialog first
final String[] zipFileTypes = {".zip", ".rar", ".7zip"};
final String[] pdfFileTypes = {".pdf"};
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.file_chooser_dialog);
startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.chat_select_file)), SELECT_FILE);
ImageView attachFromGalleryImageView = dialog.findViewById(R.id.attachFromGalleryBtn);
ImageView attachDocumentImageView = dialog.findViewById(R.id.attachDocumentBtn);
ImageView attachAudioImageView = dialog.findViewById(R.id.attachAudioBtn);
attachAudioImageView.setOnClickListener(v -> {
dialog.dismiss();
});
attachDocumentImageView.setOnClickListener(v -> {
FilePickerBuilder.getInstance().setMaxCount(1)
.addFileSupport("ZIP", zipFileTypes)
.addFileSupport("PDF", pdfFileTypes)
.enableDocSupport(false)
.withOrientation(Orientation.PORTRAIT_ONLY)
.pickFile(this);
dialog.dismiss();
});
attachFromGalleryImageView.setOnClickListener(v -> {
FilePickerBuilder.getInstance().setMaxCount(1)
.enableVideoPicker(true)
.enableCameraSupport(false)
.showGifs(true)
.showFolderView(true)
.enableImagePicker(true)
.withOrientation(Orientation.PORTRAIT_ONLY)
.pickPhoto(this);
dialog.dismiss();
});
dialog.show();
}
@Override
@@ -299,11 +344,10 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
}
if (requestCode == SELECT_FILE) {
if (null == data.getData()) {
return;
}
final Uri uri = data.getData();
// TODO: support documents too (FilePickerConst.KEY_SELECTED_DOCS)
final Uri uri = Uri.fromFile(new File(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA) != null ?
data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA).get(0) :
data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS).get(0)));
if (Build.VERSION.SDK_INT >= 19) {
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
@@ -321,9 +365,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
}
Bundle bundle = new Bundle();
bundle.putString(Constants.FILENAME, uri.toString());
bundle.putString(Constants.FILENAME, data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA).get(0));
Intent intent = new Intent(this, FileConfirmationActivity.class);
intent.putExtras(bundle);
@@ -334,16 +376,14 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
}
if(requestCode == CONFIRM_FILE) {
String fileUriString = data.getStringExtra(Constants.FILE_URI);
String filePath = data.getStringExtra(Constants.FILE_PATH);
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)));
mCallback.sendFile(Uri.fromFile(new File(filePath)), fileMessageText);
}
}
@@ -400,6 +440,11 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
return MediaType.parse(getContentResolver().getType(fileUri));
}
@Override
public MediaType getMediaType(String mimeType) {
return MediaType.parse(mimeType);
}
@Override
public File getFile(Uri fileUri) {
return FileUtils.getFile(this, fileUri);

View File

@@ -71,11 +71,14 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
mCurrentDay = Calendar.getInstance();
mLastDay = Calendar.getInstance();
mIsRetrying = false;
if (!messages.isEmpty()) {
mPositionOffset.add(0);
mDateList.add(new Date(messages.get(0).createdAt));
}
int messageSize = messages.size();
for (int i = 1; i < messageSize; i++) {
mCurrentDay.setTimeInMillis(messages.get(i).createdAt);
mLastDay.setTimeInMillis(messages.get(i - 1).createdAt);
@@ -85,9 +88,11 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
mDateList.add(mLastDay.getTime());
mLastOffset++;
}
mPositionOffset.add(mLastOffset);
mDateList.add(new Date(messages.get(i).createdAt));
}
mMessages.addAll(messages);
notifyDataSetChanged();
}
@@ -96,11 +101,13 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
if (messages == null || messages.isEmpty() || mMessages.equals(messages)) {
return;
}
int currentMessagesCount = mMessages.size();
int lastOffsetBeforeParsing = mLastOffset;
int datesInserted = 0;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(messages.get(0).createdAt);
if (mCurrentDay.get(Calendar.DAY_OF_YEAR) != calendar.get(Calendar.DAY_OF_YEAR)) {
mDatePositions.add(currentMessagesCount + mLastOffset);
datesInserted++;
@@ -108,12 +115,15 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
mPositionOffset.add(0);
mLastOffset++;
}
mPositionOffset.add(mLastOffset);
mDateList.add(new Date(messages.get(0).createdAt));
int messageSize = messages.size();
for (int i = 1; i < messageSize; i++) {
mCurrentDay.setTimeInMillis(messages.get(i).createdAt);
mLastDay.setTimeInMillis(messages.get(i - 1).createdAt);
if (mCurrentDay.get(Calendar.DAY_OF_YEAR) != mLastDay.get(Calendar.DAY_OF_YEAR)) {
mDatePositions.add(currentMessagesCount + mLastOffset + i);
datesInserted++;
@@ -121,9 +131,11 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
mDateList.add(mLastDay.getTime());
mLastOffset++;
}
mPositionOffset.add(mLastOffset);
mDateList.add(new Date(messages.get(i).createdAt));
}
mMessages.addAll(messages);
notifyItemRangeInserted(currentMessagesCount + lastOffsetBeforeParsing, messages.size() + datesInserted);
}
@@ -221,10 +233,12 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
break;
}
}
if (index == -1) {
Log.e("BaseChatAdapter", "message not found!! " + newMessage.toString());
return;
}
mMessages.set(index, newMessage);
notifyItemChanged(index);
}
@@ -234,9 +248,11 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
if (mDatePositions.contains(position)) {
return DATE_TYPE;
}
if (position == mMessages.size() + mLastOffset) {
return LOADING_TYPE;
}
return mMessages.get(position - mPositionOffset.get(position)).senderId == mUserId ?
RIGHT_CHAT_TYPE : LEFT_CHAT_TYPE;
}
@@ -258,10 +274,12 @@ abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
break;
}
}
if (myMessage == null) {
Log.e("BaseChatAdapter", "message not found!! " + messageId);
return;
}
mMessages.set(index, myMessage);
notifyItemChanged(index);
}

View File

@@ -413,9 +413,11 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
* Send the file to the server.
*/
@Override
public void sendFile(Uri fileUri, String messageText, String mimeType) {
public void sendFile(Uri fileUri, String messageText) {
File file = getView().getFile(fileUri);
final String mimeType = FileUtils.getMimeType(file);
if (file == null || !file.exists()) {
getView().showToastMessage(R.string.error_file_not_found);
return;
@@ -457,8 +459,6 @@ 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))) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
@@ -500,7 +500,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
boolean scaledImageExists = scaledImage.exists();
// create RequestBody instance from file
RequestBody requestFile = RequestBody.create(getView().getMediaType(fileUri), scaledImageExists ? scaledImage : file);
RequestBody requestFile = RequestBody.create(getView().getMediaType(mimeType), scaledImageExists ? scaledImage : file);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);

View File

@@ -43,6 +43,8 @@ interface ChatView extends MVPView {
MediaType getMediaType(Uri fileUri);
MediaType getMediaType(String mimeType);
File getFile(Uri fileUri);
void enableMessageRetry(String messageId);
@@ -67,7 +69,7 @@ interface ChatView extends MVPView {
void resetMessages();
void sendFile(Uri fileUri, String messageText, String mimeType);
void sendFile(Uri fileUri, String messageText);
void sendMessage(String message);
@@ -81,5 +83,4 @@ interface ChatView extends MVPView {
void fetchNewMessages(long groupId);
}
}

View File

@@ -87,8 +87,9 @@ public class FileConfirmationActivity extends AppCompatActivity implements FileC
mSelectedUri = Uri.parse(fileUri);
// getFile(mSelectedUri).getPath()
Glide.with(this)
.load(getFile(mSelectedUri).getPath())
.load(fileUri)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new GlideDrawableImageViewTarget(mFileImageView));
@@ -133,7 +134,7 @@ public class FileConfirmationActivity extends AppCompatActivity implements FileC
void sendFile() {
Intent intent = new Intent();
intent.putExtra(Constants.FILE_URI, mSelectedUri.toString());
intent.putExtra(Constants.FILE_PATH, mSelectedUri.toString());
intent.putExtra(Constants.FILE_MESSAGE_TEXT, mMessageEmojiconEditText.getText().toString());
setResult(-1, intent);

View File

@@ -23,7 +23,7 @@ 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_PATH = "file_uri";
String FILE_MESSAGE_TEXT = "file_message_text";
String EXTRA_GROUP = "group";

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/attachFromGalleryBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:adjustViewBounds="false"
android:contentDescription="@null"
android:cropToPadding="false"
android:src="@mipmap/ic_file_dialog_gallery" />
<ImageView
android:id="@+id/attachDocumentBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:contentDescription="@null"
android:src="@mipmap/ic_file_picker_document" />
<ImageView
android:id="@+id/attachAudioBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:contentDescription="@null"
android:src="@mipmap/ic_file_dialog_audio" />
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -73,6 +73,7 @@
<!-- Impressum -->
<string name="impressum">Impressum</string>
<string name="done">Fertig</string>
<string name="no_files_found">Keine Dateien gefunden</string>
<string name="no_camera_exists">Keine Kamera vorhanden</string>
@@ -81,5 +82,8 @@
<string name="all_videos">Alle Videos</string>
<string name="all_photos">Alle Bilder</string>
<string name="all_files">Alle Dateien</string>
<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>
</resources>