Die Suche funktioniert nun
This commit is contained in:
@@ -27,14 +27,14 @@ apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion '27.0.3'
|
||||
buildToolsVersion '28.0.2'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "de.beyondsoft.ownchat"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 27
|
||||
versionCode 21
|
||||
versionName "1.21"
|
||||
versionCode 23
|
||||
versionName "1.23"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
<application
|
||||
android:name="de.beyondsoft.ownchat.BewoplanerApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
@@ -91,6 +90,11 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="@string/default_notification_channel_id"
|
||||
/>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
|
||||
@@ -18,6 +18,7 @@ import de.beyondsoft.ownchat.model.Group;
|
||||
import de.beyondsoft.ownchat.model.Message;
|
||||
import de.beyondsoft.ownchat.page.main.MainActivity;
|
||||
import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.Utils;
|
||||
import de.beyondsoft.ownchat.utils.rx.RxUtils;
|
||||
import rx.Observable;
|
||||
|
||||
@@ -75,18 +76,33 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
@Named(AppPrefsConstants.USER_ID)
|
||||
LongPreference mUserIdReference;
|
||||
|
||||
@Override
|
||||
public void onDeletedMessages() {
|
||||
Utils.makeFirebaseLogEntry("onDeletedMessages. Possible reasons:\n" +
|
||||
" Too many messages stored on the FCM server. This can occur when an app's servers send a bunch of non-collapsible messages to FCM servers while the device is offline.\n" +
|
||||
" The device hasn't connected in a long time and the app server has recently (within the last 4 weeks) sent a message to the app on that device.");
|
||||
|
||||
super.onDeletedMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||
Log.i("FIREBASE_RECEIVER", "onMessageReceived called");
|
||||
|
||||
Map<String, String> dataMap = remoteMessage.getData();
|
||||
|
||||
Utils.makeFirebaseLogEntry("onMessageReceived: " + dataMap.get(Constants.MESSAGE_ID));
|
||||
|
||||
InjectionHelper.getMessagingComponent(this).inject(HandleMessagesService.this);
|
||||
|
||||
customizeNotification(remoteMessage.getData());
|
||||
customizeNotification(dataMap);
|
||||
}
|
||||
|
||||
private void customizeNotification(Map<String, String> dataMap) {
|
||||
String messageId = dataMap.get(Constants.MESSAGE_ID);
|
||||
|
||||
Utils.makeFirebaseLogEntry("customizeNotification for message " + messageId);
|
||||
|
||||
mChatService.getMessage(messageId)
|
||||
.compose(RxUtils.provideDefaultTransformer())
|
||||
.flatMap(new ErrorHandlingResponseConverter<>())
|
||||
@@ -97,6 +113,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void getMessageSuccess(Message message) {
|
||||
Log.i("FIREBASE_RECEIVER", "Message received");
|
||||
Utils.makeFirebaseLogEntry("getMessageSuccess called for message " + message.id);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
@@ -212,11 +229,13 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
}
|
||||
}.execute(new URL(message.senderAvatar));
|
||||
} catch(MalformedURLException e) {
|
||||
Utils.makeFirebaseLogEntry("Exception in getMessageSuccess (" + message.id + ")" + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void getMessageError(Throwable throwable) {
|
||||
Utils.makeFirebaseLogEntry("getMessageError " + throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -324,7 +343,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
public static CharSequence getReplyMessage(Intent intent) {
|
||||
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
||||
|
||||
if (remoteInput != null) {
|
||||
if(remoteInput != null) {
|
||||
return remoteInput.getCharSequence(Constants.KEY_TEXT_REPLY);
|
||||
}
|
||||
|
||||
@@ -332,7 +351,6 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
}
|
||||
|
||||
private static class DownloadAvatarTask extends AsyncTask<URL, Void, Bitmap> {
|
||||
|
||||
@Override
|
||||
protected Bitmap doInBackground(URL... urls) {
|
||||
if(urls == null || urls.length == 0) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.util.Log;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import de.beyondsoft.ownchat.utils.Utils;
|
||||
import rx.Subscriber;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
@@ -33,6 +34,7 @@ public class MessagingInstanceIdService extends FirebaseInstanceIdService {
|
||||
InjectionHelper.getMessagingComponent(sAndroidContext).inject(this);
|
||||
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
|
||||
Log.d(TAG, "Refreshed token: " + refreshedToken);
|
||||
Utils.makeFirebaseLogEntry("MessagingInstanceIdService: onTokenRefresh");
|
||||
sendRegistrationToServer(refreshedToken);
|
||||
}
|
||||
|
||||
@@ -42,16 +44,19 @@ public class MessagingInstanceIdService extends FirebaseInstanceIdService {
|
||||
.subscribe(new Subscriber<RegisterResponse>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
Utils.makeFirebaseLogEntry("MessagingInstanceIdService: sendRegistrationToServer onCompleted");
|
||||
Log.d(TAG, "onCompleted: " + token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Utils.makeFirebaseLogEntry("MessagingInstanceIdService: sendRegistrationToServer onError: " + (e != null ? e.toString() : "throwable is null!"));
|
||||
Log.d(TAG, "onError: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(RegisterResponse registerResponse) {
|
||||
Utils.makeFirebaseLogEntry("MessagingInstanceIdService: sendRegistrationToServer onNext");
|
||||
Log.d(TAG, "onNext: ");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
|
||||
import de.beyondsoft.ownchat.R;
|
||||
import de.beyondsoft.ownchat.utils.Utils;
|
||||
|
||||
public class NotificationUtils extends ContextWrapper {
|
||||
private NotificationManager mManager;
|
||||
@@ -19,6 +20,8 @@ public class NotificationUtils extends ContextWrapper {
|
||||
|
||||
public void createNotificationChannel() {
|
||||
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
Utils.makeFirebaseLogEntry("createNotificationChannel because Android version is higher than 8.0 (Oreo)");
|
||||
|
||||
NotificationChannel androidChannel = new NotificationChannel(getString(R.string.default_notification_channel_id), getString(R.string.default_notification_channel_name), NotificationManager.IMPORTANCE_HIGH);
|
||||
androidChannel.enableLights(true);
|
||||
androidChannel.enableVibration(true);
|
||||
@@ -29,6 +32,8 @@ public class NotificationUtils extends ContextWrapper {
|
||||
}
|
||||
|
||||
public NotificationManager getManager() {
|
||||
Utils.makeFirebaseLogEntry("NotificationUtils: getManager");
|
||||
|
||||
if(mManager == null) {
|
||||
mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ReplyNotificationReceiver extends BroadcastReceiver {
|
||||
Bundle bundle = intent.getBundleExtra(BUNDLE);
|
||||
long groupId = bundle.getLong(Constants.GROUP_ID);
|
||||
|
||||
if(replyMessage != null && replyMessage instanceof String) {
|
||||
if(replyMessage instanceof String) {
|
||||
sendMessage(context, (String) replyMessage, (int) groupId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ 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.utils.BeyondSoftLog;
|
||||
import de.beyondsoft.ownchat.utils.ui.TouchableImageView;
|
||||
import de.beyondsoft.ownchat.model.Group;
|
||||
import de.beyondsoft.ownchat.model.Message;
|
||||
@@ -72,9 +71,7 @@ import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -234,8 +231,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
return false;
|
||||
}
|
||||
|
||||
mIsJumpingToMessage = false;
|
||||
|
||||
mCallback.fetchMoreMessagesByGroupId();
|
||||
return true;
|
||||
}
|
||||
@@ -245,8 +240,8 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
if(mCallback != null) {
|
||||
mCallback.setIsScrollingDown(dy > 0);
|
||||
|
||||
if(mGroup != null && mBaseChatAdapter != null && mBaseChatAdapter.mMessages.size() > 0) {
|
||||
mHasNewerMessages = mCallback.hasNewerMessages(mGroup.id, mBaseChatAdapter.mMessages.get(0).id);
|
||||
if(mGroup != null && mBaseChatAdapter != null && mBaseChatAdapter.mItemList.size() > 0) {
|
||||
mHasNewerMessages = mCallback.hasNewerMessages(mGroup.id, ((Message) mBaseChatAdapter.mItemList.get(0)).id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,6 +416,8 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
|
||||
@OnClick(R.id.chat_send_message)
|
||||
void messageSent() {
|
||||
closeSearchView();
|
||||
|
||||
mCallback.sendMessage(mChatMessageEmojiEditText.getText().toString());
|
||||
mChatMessageEmojiEditText.setText("");
|
||||
}
|
||||
@@ -750,8 +747,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mCallback.resendMessage(message, !TextUtils.isEmpty(message.filePath) ? getContentResolver().getType(Uri.parse(message.filePath)) : "");
|
||||
}
|
||||
|
||||
private Message focusedMessage;
|
||||
|
||||
private boolean mIsJumpingToMessage;
|
||||
@Override
|
||||
public void jumpToMessage(Message message) {
|
||||
@@ -763,8 +758,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mChatPresenter.attachView(this);
|
||||
}
|
||||
|
||||
focusedMessage = message;
|
||||
|
||||
mCallback.loadMessagesInContext(mGroup.id, message.createdAt, message);
|
||||
}
|
||||
|
||||
@@ -775,7 +768,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
|
||||
mIsJumpingToMessage = true;
|
||||
|
||||
mRecyclerView.postDelayed(() -> mRecyclerView.smoothScrollToPosition(position), 350);
|
||||
mRecyclerView.postDelayed(() -> mRecyclerView.smoothScrollToPosition(position), 50);
|
||||
} catch(Exception e) {
|
||||
Log.e("SCROLL_TO_MESSAGE", e.getMessage(), e);
|
||||
}
|
||||
@@ -869,7 +862,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
mBaseChatAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
mRecyclerView.scrollToPosition(0);
|
||||
scrollToPositionZero();
|
||||
}
|
||||
|
||||
protected void setGroupFromArguments() {
|
||||
@@ -1011,7 +1004,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
|
||||
@Override
|
||||
public void scrollToPositionZero() {
|
||||
if(mRecyclerView != null) {
|
||||
mRecyclerView.scrollToPosition(0);
|
||||
mRecyclerView.postDelayed(() -> mRecyclerView.scrollToPosition(0), 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,27 +15,25 @@ import android.widget.TextView;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.github.lzyzsd.circleprogress.DonutProgress;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.Optional;
|
||||
|
||||
import de.beyondsoft.ownchat.R;
|
||||
import de.beyondsoft.ownchat.model.DateItem;
|
||||
import de.beyondsoft.ownchat.model.Message;
|
||||
import de.beyondsoft.ownchat.model.RecyclerViewItem;
|
||||
import de.beyondsoft.ownchat.utils.BeyondSoftLog;
|
||||
import de.beyondsoft.ownchat.utils.DateUtils;
|
||||
import de.beyondsoft.ownchat.utils.Utils;
|
||||
import de.beyondsoft.ownchat.utils.ui.GlideApp;
|
||||
import de.beyondsoft.ownchat.utils.ui.ViewUtils;
|
||||
|
||||
import hani.momanii.supernova_emoji_library.Helper.EmojiconTextView;
|
||||
|
||||
public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
@@ -47,21 +45,11 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
|
||||
private long mUserId;
|
||||
|
||||
|
||||
private final ArrayList<RecyclerViewItem> mItemList = new ArrayList<>();
|
||||
final ArrayList<RecyclerViewItem> mItemList = new ArrayList<>();
|
||||
private final ArrayList<RecyclerViewItem> mTempItemList = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
public final ArrayList<Message> mMessages = new ArrayList<>();
|
||||
private final List<Integer> mDatePositions = new ArrayList<>();
|
||||
final List<Date> mDateList = new ArrayList<>();
|
||||
final List<Integer> mPositionOffset = new ArrayList<>();
|
||||
|
||||
private boolean mIsLoading;
|
||||
private int mLastOffset = 0;
|
||||
private Calendar mCurrentDay;
|
||||
private Calendar mLastDay;
|
||||
private Calendar mNextDay;
|
||||
private MessageClickListener mMessageClickListener;
|
||||
private boolean mIsRetrying;
|
||||
@@ -70,55 +58,23 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
BaseChatAdapter(long userId) {
|
||||
mUserId = userId;
|
||||
mCurrentDay = Calendar.getInstance();
|
||||
mLastDay = Calendar.getInstance();
|
||||
mNextDay = Calendar.getInstance();
|
||||
}
|
||||
|
||||
// TODO: finish switching from mMessages to mItemList
|
||||
void setMessages(ArrayList<Message> messages) {
|
||||
mItemList.clear();
|
||||
mMessages.clear();
|
||||
mDatePositions.clear();
|
||||
mDateList.clear();
|
||||
mPositionOffset.clear();
|
||||
|
||||
mIsLoading = false;
|
||||
mLastOffset = 0;
|
||||
mCurrentDay = Calendar.getInstance();
|
||||
mLastDay = Calendar.getInstance();
|
||||
mNextDay = 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);
|
||||
|
||||
if(mCurrentDay.get(Calendar.DAY_OF_YEAR) != mLastDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
mDatePositions.add(i + mLastOffset);
|
||||
mPositionOffset.add(0);
|
||||
mDateList.add(mLastDay.getTime());
|
||||
mLastOffset++;
|
||||
}
|
||||
|
||||
mPositionOffset.add(mLastOffset);
|
||||
mDateList.add(new Date(messages.get(i).createdAt));
|
||||
}
|
||||
|
||||
mMessages.addAll(messages);
|
||||
|
||||
for(int i = 0; i < messages.size(); i++) {
|
||||
mCurrentDay.setTimeInMillis(messages.get(i).createdAt);
|
||||
mNextDay.setTimeInMillis((i == messages.size() - 1) ? mCurrentDay.getTimeInMillis() : messages.get(i + 1).getCreatedAt());
|
||||
mNextDay.setTimeInMillis((i == messages.size() - 1) ? mCurrentDay.getTimeInMillis() : messages.get(i + 1).createdAt);
|
||||
|
||||
mItemList.add(messages.get(i));
|
||||
|
||||
if(mNextDay.get(Calendar.DAY_OF_YEAR) < mCurrentDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
if(Utils.isBefore(mNextDay, mCurrentDay)) {
|
||||
mItemList.add(new DateItem(mCurrentDay.getTime()));
|
||||
}
|
||||
}
|
||||
@@ -126,128 +82,63 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// TODO: finish switching from mMessages to mItemList
|
||||
void addMessagesWhenScrollingDown(ArrayList<Message> messages) {
|
||||
mDatePositions.clear();
|
||||
mDateList.clear();
|
||||
mPositionOffset.clear();
|
||||
|
||||
mIsLoading = false;
|
||||
mLastOffset = 0;
|
||||
mCurrentDay = Calendar.getInstance();
|
||||
mLastDay = Calendar.getInstance();
|
||||
mIsRetrying = false;
|
||||
|
||||
if(!mMessages.isEmpty()) {
|
||||
mPositionOffset.add(0);
|
||||
mDateList.add(new Date(mMessages.get(0).createdAt));
|
||||
}
|
||||
|
||||
for(Message message : messages) {
|
||||
if(!mMessages.contains(message)) {
|
||||
mMessages.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(mMessages, (m1, m2) -> Long.compare(m1.createdAt, m2.createdAt) * -1);
|
||||
|
||||
int messageSize = mMessages.size();
|
||||
|
||||
for(int i = 1; i < messageSize; i++) {
|
||||
mCurrentDay.setTimeInMillis(mMessages.get(i).createdAt);
|
||||
mLastDay.setTimeInMillis(mMessages.get(i - 1).createdAt);
|
||||
|
||||
if(mCurrentDay.get(Calendar.DAY_OF_YEAR) != mLastDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
mDatePositions.add(i + mLastOffset);
|
||||
mPositionOffset.add(0);
|
||||
mDateList.add(mLastDay.getTime());
|
||||
mLastOffset++;
|
||||
}
|
||||
|
||||
mPositionOffset.add(mLastOffset);
|
||||
mDateList.add(new Date(mMessages.get(i).createdAt));
|
||||
}
|
||||
|
||||
mTempItemList.clear();
|
||||
|
||||
for(int i = 0; i < messages.size(); i++) {
|
||||
if(mItemList.contains(messages.get(i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mCurrentDay.setTimeInMillis(messages.get(i).createdAt);
|
||||
mNextDay.setTimeInMillis((i == messages.size() - 1) ? mCurrentDay.getTimeInMillis() : messages.get(i + 1).getCreatedAt());
|
||||
mNextDay.setTimeInMillis((i == messages.size() - 1) ? mCurrentDay.getTimeInMillis() : messages.get(i + 1).createdAt);
|
||||
|
||||
mTempItemList.add(messages.get(i));
|
||||
|
||||
if(mNextDay.get(Calendar.DAY_OF_YEAR) < mCurrentDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
if(Utils.isBefore(mNextDay, mCurrentDay)) {
|
||||
mTempItemList.add(new DateItem(mCurrentDay.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
mItemList.addAll(0, mTempItemList);
|
||||
|
||||
notifyDataSetChanged();
|
||||
notifyItemRangeInserted(0, mTempItemList.size());
|
||||
}
|
||||
|
||||
// TODO: finish switching from mMessages to mItemList
|
||||
void addMessages(ArrayList<Message> messages) {
|
||||
if(messages == null || messages.isEmpty() || mMessages.equals(messages)) {
|
||||
if(messages == null || messages.isEmpty() || mItemList.equals(messages)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Message> filteredList = new ArrayList<>();
|
||||
|
||||
for(Message message : messages) {
|
||||
if(!mMessages.contains(message)) {
|
||||
if(!mItemList.contains(message)) {
|
||||
filteredList.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
int currentMessagesCount = mMessages.size();
|
||||
int lastOffsetBeforeParsing = mLastOffset;
|
||||
int datesInserted = 0;
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(filteredList.get(0).createdAt);
|
||||
|
||||
if(mCurrentDay.get(Calendar.DAY_OF_YEAR) != calendar.get(Calendar.DAY_OF_YEAR)) {
|
||||
mDatePositions.add(currentMessagesCount + mLastOffset);
|
||||
datesInserted++;
|
||||
mDateList.add(new Date(filteredList.get(0).createdAt));
|
||||
mPositionOffset.add(0);
|
||||
mLastOffset++;
|
||||
}
|
||||
|
||||
mPositionOffset.add(mLastOffset);
|
||||
mDateList.add(new Date(filteredList.get(0).createdAt));
|
||||
int messageSize = filteredList.size();
|
||||
|
||||
for(int i = 1; i < messageSize; i++) {
|
||||
for(int i = 0; i < filteredList.size(); i++) {
|
||||
mCurrentDay.setTimeInMillis(filteredList.get(i).createdAt);
|
||||
mLastDay.setTimeInMillis(filteredList.get(i - 1).createdAt);
|
||||
mNextDay.setTimeInMillis((i == filteredList.size() - 1) ? mCurrentDay.getTimeInMillis() : filteredList.get(i + 1).getCreatedAt());
|
||||
|
||||
if(mCurrentDay.get(Calendar.DAY_OF_YEAR) != mLastDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
mDatePositions.add(currentMessagesCount + mLastOffset + i);
|
||||
datesInserted++;
|
||||
mPositionOffset.add(0);
|
||||
mDateList.add(mLastDay.getTime());
|
||||
mLastOffset++;
|
||||
}
|
||||
mItemList.add(filteredList.get(i));
|
||||
|
||||
mPositionOffset.add(mLastOffset);
|
||||
mDateList.add(new Date(filteredList.get(i).createdAt));
|
||||
}
|
||||
|
||||
for(int i = 0; i < messages.size(); i++) {
|
||||
mCurrentDay.setTimeInMillis(messages.get(i).createdAt);
|
||||
mNextDay.setTimeInMillis((i == messages.size() - 1) ? mCurrentDay.getTimeInMillis() : messages.get(i + 1).getCreatedAt());
|
||||
|
||||
mItemList.add(messages.get(i));
|
||||
|
||||
if(mNextDay.get(Calendar.DAY_OF_YEAR) < mCurrentDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
if(Utils.isBefore(mNextDay, mCurrentDay)) {
|
||||
mItemList.add(new DateItem(mCurrentDay.getTime()));
|
||||
datesInserted++;
|
||||
}
|
||||
}
|
||||
|
||||
mMessages.addAll(filteredList);
|
||||
notifyItemRangeInserted(currentMessagesCount + lastOffsetBeforeParsing, filteredList.size() + datesInserted);
|
||||
notifyItemRangeInserted(mItemList.size() - 1, filteredList.size() + datesInserted);
|
||||
}
|
||||
|
||||
void setItemProgress(int itemPosition, int progress) {
|
||||
@@ -265,59 +156,25 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// TODO: change from mMessages to mItemList
|
||||
void addMessage(Message message) {
|
||||
if(mMessages.contains(message)) {
|
||||
if(mItemList.contains(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Message> currentMessages = new ArrayList<>();
|
||||
currentMessages.add(message);
|
||||
currentMessages.addAll(mMessages);
|
||||
mMessages.clear();
|
||||
mMessages.addAll(currentMessages);
|
||||
Calendar oldNewestMessageDay = Calendar.getInstance();
|
||||
|
||||
Calendar lastDay = Calendar.getInstance();
|
||||
if(mItemList.size() > 0) {
|
||||
oldNewestMessageDay.setTimeInMillis(mItemList.get(0).getCreatedAt());
|
||||
|
||||
if(mMessages.size() > 1) {
|
||||
lastDay.setTimeInMillis(mMessages.get(1).createdAt);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(message.createdAt);
|
||||
|
||||
if(Utils.isBefore(oldNewestMessageDay, calendar)) {
|
||||
mItemList.add(0, new DateItem(calendar.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(message.createdAt);
|
||||
|
||||
if(calendar.get(Calendar.DAY_OF_YEAR) != lastDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
// New date inserted
|
||||
setMessages(new ArrayList<>(mMessages));
|
||||
return;
|
||||
}
|
||||
|
||||
List<Integer> positionOffset = new ArrayList<>();
|
||||
positionOffset.add(0);
|
||||
positionOffset.addAll(mPositionOffset);
|
||||
mPositionOffset.clear();
|
||||
mPositionOffset.addAll(positionOffset);
|
||||
|
||||
List<Date> currentDateList = new ArrayList<>();
|
||||
currentDateList.add(new Date(message.createdAt));
|
||||
currentDateList.addAll(mDateList);
|
||||
mDateList.clear();
|
||||
mDateList.addAll(currentDateList);
|
||||
|
||||
List<Integer> currentDatePositions = new ArrayList<>();
|
||||
boolean newDateAdded = false;
|
||||
|
||||
if(calendar.get(Calendar.DAY_OF_YEAR) != lastDay.get(Calendar.DAY_OF_YEAR)) {
|
||||
currentDatePositions.add(1);
|
||||
newDateAdded = true;
|
||||
}
|
||||
|
||||
for(int i = 0, size = mDatePositions.size(); i < size; i++) {
|
||||
currentDatePositions.add(mDatePositions.get(i) + (newDateAdded ? 2 : 1));
|
||||
}
|
||||
|
||||
mDatePositions.clear();
|
||||
mDatePositions.addAll(currentDatePositions);
|
||||
mItemList.add(0, message);
|
||||
|
||||
notifyItemInserted(0);
|
||||
}
|
||||
@@ -349,90 +206,41 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int count1 = mMessages.size() + mLastOffset + (mIsLoading ? 1 : 0);
|
||||
int count2 = mItemList.size() + (mIsLoading ? 1 : 0);
|
||||
|
||||
int countMessages = 0;
|
||||
int countDates = 0;
|
||||
for(RecyclerViewItem item : mItemList) {
|
||||
if(item.getClass().equals(Message.class)) {
|
||||
countMessages++;
|
||||
} else {
|
||||
countDates++;
|
||||
}
|
||||
}
|
||||
|
||||
if(count1 - count2 > 2) {
|
||||
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.GERMANY);
|
||||
// StringBuilder blubb = new StringBuilder("DateItems:\n");
|
||||
// for(RecyclerViewItem item : mItemList) {
|
||||
// if(item.getClass().equals(DateItem.class)) {
|
||||
// blubb.append(simpleDateFormat.format(((DateItem) item).date)).append("\n");
|
||||
// }
|
||||
// }
|
||||
// BeyondSoftLog.logScrollingEvent_W(blubb.toString());
|
||||
//
|
||||
// StringBuilder blubb2 = new StringBuilder("Dates:\n");
|
||||
// ArrayList<Date> dateList = new ArrayList<>();
|
||||
// for(Date date : mDateList) {
|
||||
// Date d2 = new Date(date.getYear(), date.getMonth(), date.getDate());
|
||||
//
|
||||
// if(!dateList.contains(d2)) {
|
||||
// dateList.add(d2);
|
||||
// blubb2.append(simpleDateFormat.format(d2)).append("\n");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// BeyondSoftLog.logScrollingEvent_D(blubb2.toString());
|
||||
|
||||
BeyondSoftLog.logScrollingEvent_V("getItemCount() was called");
|
||||
|
||||
logNewMessages();
|
||||
logOldMessages();
|
||||
|
||||
BeyondSoftLog.logScrollingEvent_I("" + count1 + " vs. " + count2 + "\n" +
|
||||
"Number of messages: " + String.format("%1$4s", countMessages) + "\n" +
|
||||
"Number of dates: " + String.format("%1$4s", countDates) + "\n\n" +
|
||||
|
||||
"Size of mMessages: " + String.format("%1$4s", mMessages.size()) + "\n" +
|
||||
"Size of mDateList: " + String.format("%1$4s", mDateList.size()) + "\n" +
|
||||
"Last offset: " + String.format("%1$4s", mLastOffset) + "\n" +
|
||||
"------------------------\n" +
|
||||
" " + String.format("%1$4s", count2));
|
||||
}
|
||||
|
||||
return mMessages.size() + mLastOffset + (mIsLoading ? 1 : 0);
|
||||
return mItemList.size() + (mIsLoading ? 1 : 0);
|
||||
}
|
||||
|
||||
void updateMessage(Message newMessage, String oldMessageId) {
|
||||
int index = -1;
|
||||
for(int i = 0; i < mMessages.size(); i++) {
|
||||
if(oldMessageId.equals(mMessages.get(i).id)) {
|
||||
for(int i = 0; i < mItemList.size(); i++) {
|
||||
if(oldMessageId.equals(((Message) mItemList.get(i)).id)) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(index == -1) {
|
||||
Log.e("BaseChatAdapter", "message not found!! " + newMessage.toString());
|
||||
Log.e("BaseChatAdapter", "message not found! " + newMessage.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
mMessages.set(index, newMessage);
|
||||
mItemList.set(index, newMessage);
|
||||
notifyItemChanged(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if(mDatePositions.contains(position)) {
|
||||
return DATE_TYPE;
|
||||
}
|
||||
|
||||
if(position == mMessages.size() + mLastOffset) {
|
||||
if(position == mItemList.size()) {
|
||||
return LOADING_TYPE;
|
||||
}
|
||||
|
||||
return mMessages.get(position - mPositionOffset.get(position)).senderId == mUserId ? RIGHT_CHAT_TYPE : LEFT_CHAT_TYPE;
|
||||
RecyclerViewItem item = mItemList.get(position);
|
||||
|
||||
if(item.getClass().equals(DateItem.class)) {
|
||||
return DATE_TYPE;
|
||||
}
|
||||
|
||||
Message message = (Message) item;
|
||||
return message.senderId == mUserId ? RIGHT_CHAT_TYPE : LEFT_CHAT_TYPE;
|
||||
}
|
||||
|
||||
void setMessageClickListener(MessageClickListener messageClickListener) {
|
||||
@@ -443,8 +251,13 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
mIsRetrying = false;
|
||||
Message myMessage = null;
|
||||
int index = -1;
|
||||
for(int i = 0; i < mMessages.size(); i++) {
|
||||
Message message = mMessages.get(i);
|
||||
|
||||
for(int i = 0; i < mItemList.size(); i++) {
|
||||
if(!mItemList.get(i).getClass().equals(Message.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Message message = (Message) mItemList.get(i);
|
||||
if(messageId.equals(message.id)) {
|
||||
index = i;
|
||||
myMessage = message;
|
||||
@@ -458,7 +271,7 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
return;
|
||||
}
|
||||
|
||||
mMessages.set(index, myMessage);
|
||||
mItemList.set(index, myMessage);
|
||||
notifyItemChanged(index);
|
||||
}
|
||||
|
||||
@@ -597,12 +410,22 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
void jumpToMessage() {
|
||||
int currentPosition = getAdapterPosition();
|
||||
|
||||
int position = currentPosition - mPositionOffset.get(currentPosition);
|
||||
if(position >= mMessages.size()) {
|
||||
position = 0;
|
||||
int position = currentPosition;
|
||||
|
||||
// TODO: Needs to be improved!
|
||||
if(!mItemList.get(currentPosition).getClass().equals(Message.class)) {
|
||||
for(int i = currentPosition; i > 0; i--) {
|
||||
if(mItemList.get(i).getClass().equals(Message.class)) {
|
||||
position = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Message messageToJumpTo = mMessages.get(position);
|
||||
if(!mItemList.get(position).getClass().equals(Message.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Message messageToJumpTo = (Message) mItemList.get(position);
|
||||
|
||||
mMessageClickListener.jumpToMessage(messageToJumpTo);
|
||||
}
|
||||
@@ -616,8 +439,22 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
|
||||
mIsRetrying = true;
|
||||
int currentPosition = getAdapterPosition();
|
||||
int position = currentPosition;
|
||||
|
||||
Message messageToResend = mMessages.get(currentPosition - mPositionOffset.get(currentPosition));
|
||||
// TODO: Needs to be improved!
|
||||
if(!mItemList.get(currentPosition).getClass().equals(Message.class)) {
|
||||
for(int i = currentPosition; i > 0; i--) {
|
||||
if(mItemList.get(i).getClass().equals(Message.class)) {
|
||||
position = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!mItemList.get(position).getClass().equals(Message.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Message messageToResend = (Message) mItemList.get(position);
|
||||
|
||||
if(statusProgressBar != null) {
|
||||
statusProgressBar.setVisibility(View.VISIBLE);
|
||||
@@ -639,8 +476,24 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
@Optional
|
||||
@OnClick(R.id.chat_item_file)
|
||||
void fileClicked() {
|
||||
// TODO: Needs to be improved!
|
||||
int currentPosition = getAdapterPosition();
|
||||
Message message = mMessages.get(currentPosition - mPositionOffset.get(currentPosition));
|
||||
int position = currentPosition;
|
||||
|
||||
if(!mItemList.get(currentPosition).getClass().equals(Message.class)) {
|
||||
for(int i = currentPosition; i > 0; i--) {
|
||||
if(mItemList.get(i).getClass().equals(Message.class)) {
|
||||
position = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!mItemList.get(position).getClass().equals(Message.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Message message = (Message) mItemList.get(position);
|
||||
|
||||
|
||||
if(message.status != Message.Status.DELIVERED) {
|
||||
mMessageClickListener.localFileClicked(Uri.parse(message.uri));
|
||||
@@ -671,50 +524,4 @@ public abstract class BaseChatAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
|
||||
void jumpToMessage(Message message);
|
||||
}
|
||||
|
||||
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.GERMANY);
|
||||
private void logOldMessages() {
|
||||
StringBuilder stringBuilder = new StringBuilder("Content of mMessages and the dates:\n");
|
||||
|
||||
int limit = mMessages.size() + mLastOffset + (mIsLoading ? 1 : 0);
|
||||
|
||||
for(int i = 0; i < limit; i++) {
|
||||
if(i == 150) {
|
||||
int b = i * 9;
|
||||
}
|
||||
int kek = getItemViewType(i);
|
||||
|
||||
if(kek == DATE_TYPE) {
|
||||
stringBuilder.append(String.format("%1$4s", i)).append(" ").append(simpleDateFormat.format(mDateList.get(i))).append("\n");
|
||||
} else if(kek == LOADING_TYPE) {
|
||||
stringBuilder.append("<LOADING>\n");
|
||||
} else {
|
||||
Message m = mMessages.get(i - mPositionOffset.get(i));
|
||||
stringBuilder.append(String.format("%1$4s", i)).append(" ").append(simpleDateFormat.format(m.createdAt)).append(": ").append((m.message == null ? m.originalFilename : m.message)).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
stringBuilder.append("\n");
|
||||
|
||||
BeyondSoftLog.logScrollingEvent_D(stringBuilder.toString());
|
||||
}
|
||||
|
||||
private void logNewMessages() {
|
||||
StringBuilder stringBuilder = new StringBuilder("Content of mItemList:\n");
|
||||
|
||||
int i = 0;
|
||||
for(RecyclerViewItem item : mItemList) {
|
||||
if(item.getClass().equals(Message.class)) {
|
||||
Message message = (Message) item;
|
||||
stringBuilder.append(String.format("%1$4s", i)).append(" ").append(simpleDateFormat.format(message.createdAt)).append(": ").append((message.message == null ? message.originalFilename : message.message)).append("\n");
|
||||
} else {
|
||||
DateItem dateItem = (DateItem) item;
|
||||
stringBuilder.append(String.format("%1$4s", i)).append(" ").append(simpleDateFormat.format(dateItem.date)).append("\n");
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
BeyondSoftLog.logScrollingEvent_W(stringBuilder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,13 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
private boolean mFetchMore;
|
||||
private ArrayList<Message> mMessages = new ArrayList<>();
|
||||
private ArrayList<Pair<Message, String>> mMessageToUpdate = new ArrayList<>();
|
||||
|
||||
private String mText;
|
||||
private Message mMessageToScrollTo;
|
||||
|
||||
private int mDownwardsOffset = -1;
|
||||
private int mIndexLow = -1;
|
||||
private int mIndexHigh = -1;
|
||||
|
||||
public int getPage() {
|
||||
return mPage;
|
||||
@@ -142,8 +148,9 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
*/
|
||||
@Override
|
||||
public void loadMessagesFromServerByGroupId(long groupId) {
|
||||
if(!mFetchMore) {
|
||||
if(!mFetchMore && !mIsScrollingDown) {
|
||||
getView().hideMessagesLoading();
|
||||
mLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -271,6 +278,8 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
mOffset = 0;
|
||||
mFetchMore = true;
|
||||
mDownwardsOffset = -1;
|
||||
mIndexLow = -1;
|
||||
mIndexHigh = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +339,6 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
.subscribe(this::loadMessagesFromDBSuccessful, this::loadMessagesError);
|
||||
}
|
||||
|
||||
private String mText;
|
||||
public void searchMessagesFromDBByGroupIdAndText(long groupId, String text) {
|
||||
MessagesByGroupAndSearchTextSpecification messagesByGroupAndSearchTextSpecification = new MessagesByGroupAndSearchTextSpecification(mUserIdPreference.get());
|
||||
messagesByGroupAndSearchTextSpecification.setGroupId(groupId);
|
||||
@@ -396,7 +404,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
getView().showEmptySearchResultMessage(mText);
|
||||
}
|
||||
|
||||
private Message mMessageToScrollTo;
|
||||
|
||||
public void loadMessagesInContext(long groupId, long createdAt, Message messageToScrollTo) {
|
||||
MessageByGroupIdSpecification messageByGroupIdSpecification = new MessageByGroupIdSpecification(mUserIdPreference.get());
|
||||
messageByGroupIdSpecification.setGroupId(groupId);
|
||||
@@ -410,6 +418,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
.subscribe(this::loadMessagesInContextSuccessful, this::loadMessagesError);
|
||||
}
|
||||
|
||||
|
||||
private void loadMessagesInContextSuccessful(ArrayList<Message> messages) {
|
||||
if(!isAttached()) {
|
||||
return;
|
||||
@@ -447,6 +456,9 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
mPage = (int) Math.ceil(pos / lim);
|
||||
boolean isFirstPage = mPage == FIRST_PAGE;
|
||||
|
||||
mIndexLow = mOffset;
|
||||
mIndexHigh = endOffset;
|
||||
|
||||
getView().messagesLoaded(new ArrayList<>(mMessages.subList(mOffset, endOffset)));
|
||||
|
||||
if(isFirstPage && mSystemUtils.isNetworkUnavailable()) {
|
||||
@@ -479,9 +491,6 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
getView().showEmptyMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send messages to view.
|
||||
*/
|
||||
private void loadMessagesFromDBSuccessful(ArrayList<Message> messages) {
|
||||
if(!isAttached()) {
|
||||
return;
|
||||
@@ -495,18 +504,26 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
getView().hideMessagesLoading();
|
||||
|
||||
if(!mMessages.isEmpty()) {
|
||||
int offsetTmp, endOffsetTmp;
|
||||
int offsetTmp, endOffsetTmp, downwardsEndOffset;
|
||||
|
||||
int endOffset = mOffset + LIMIT > mMessages.size() ? mMessages.size() : mOffset + LIMIT;
|
||||
|
||||
if(mIsScrollingDown) {
|
||||
if(mDownwardsOffset < 0) {
|
||||
mDownwardsOffset = mOffset >= (LIMIT * 2) ? mOffset - (LIMIT * 2) : 0;
|
||||
} else {
|
||||
mDownwardsOffset = mDownwardsOffset >= (LIMIT * 2) ? mDownwardsOffset - (LIMIT * 2) : 0;
|
||||
}
|
||||
if(mIndexLow > -1 && mIndexHigh > -1) {
|
||||
downwardsEndOffset = mIndexLow;
|
||||
mDownwardsOffset = downwardsEndOffset > LIMIT ? downwardsEndOffset - LIMIT : 0;
|
||||
|
||||
int downwardsEndOffset = mDownwardsOffset + (LIMIT * 2) > mMessages.size() ? mMessages.size() : mDownwardsOffset + (LIMIT * 2);
|
||||
mIndexHigh = -1;
|
||||
mIndexLow = -1;
|
||||
} else {
|
||||
if(mDownwardsOffset < 0) {
|
||||
mDownwardsOffset = mOffset > LIMIT ? mOffset - LIMIT : 0;
|
||||
} else {
|
||||
mDownwardsOffset = mDownwardsOffset > LIMIT ? mDownwardsOffset - LIMIT : 0;
|
||||
}
|
||||
|
||||
downwardsEndOffset = mDownwardsOffset + LIMIT > mMessages.size() ? mMessages.size() : mDownwardsOffset + LIMIT;
|
||||
}
|
||||
|
||||
offsetTmp = mDownwardsOffset;
|
||||
endOffsetTmp = downwardsEndOffset;
|
||||
@@ -515,8 +532,8 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
endOffsetTmp = endOffset;
|
||||
}
|
||||
|
||||
if(mOffset > endOffset) {
|
||||
Utils.makeScrollLog("Offset is greater than endOffset: " + mOffset + " > " + endOffset);
|
||||
if(offsetTmp > endOffsetTmp) {
|
||||
Utils.makeScrollLog("Offset is greater than endOffset: " + offsetTmp + " > " + endOffsetTmp + (mIsScrollingDown ? "; scrolling down" : "; scrolling up"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -567,7 +584,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
}
|
||||
|
||||
/**
|
||||
* If mMessages size is bigger then 25 and network is available, get more messages from the server.
|
||||
* If mMessages size is bigger than 25 and network is available, get more messages from the server.
|
||||
*/
|
||||
@Override
|
||||
public void fetchMoreMessagesByGroupId() {
|
||||
@@ -1143,21 +1160,25 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
|
||||
private Observable<Group> getGroupById(ArrayList<Group> groups) {
|
||||
Group group = null;
|
||||
|
||||
for(Group group1 : groups) {
|
||||
if(group1.id == mGroupId) {
|
||||
group = group1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Observable.just(group);
|
||||
}
|
||||
|
||||
private void groupsError(Throwable throwable) {
|
||||
Log.e(ChatPresenter.class.getSimpleName(), throwable.getMessage(), throwable);
|
||||
|
||||
if(mSystemUtils.isNetworkUnavailable()) {
|
||||
getView().showError(R.string.error_no_internet_connection);
|
||||
return;
|
||||
}
|
||||
|
||||
getView().showError(R.string.error_something_went_wrong);
|
||||
}
|
||||
|
||||
@@ -1187,12 +1208,8 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
private Observable<String> downloadFileFromUrl(@NonNull String fileUrl, @NonNull String filePath, int itemPosition) {
|
||||
return Observable.create(subscriber -> {
|
||||
try {
|
||||
//set the download URL, a url that points to a file on the internet
|
||||
//this is the file to be downloaded
|
||||
URL url = new URL(fileUrl);
|
||||
//create the new connection
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
//set up some things on the connection
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoOutput(true);
|
||||
|
||||
@@ -1202,17 +1219,13 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
|
||||
if(file.length() > 0) {
|
||||
urlConnection.setRequestProperty("Range", "bytes=" + file.length() + "-");
|
||||
//this will be used to append the downloaded data into the file already existing
|
||||
fileOutput = new FileOutputStream(file, true);
|
||||
} else {
|
||||
//this will be used to write the downloaded data into the file we created
|
||||
fileOutput = new FileOutputStream(file);
|
||||
}
|
||||
|
||||
//and connect!
|
||||
urlConnection.connect();
|
||||
|
||||
//this is the total size of the file
|
||||
int totalSize = urlConnection.getContentLength();
|
||||
|
||||
if(file.length() == totalSize || totalSize == -1) {
|
||||
@@ -1221,34 +1234,30 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
return;
|
||||
}
|
||||
|
||||
//this will be used in reading the data from the internet
|
||||
inputStream = urlConnection.getInputStream();
|
||||
|
||||
//variable to store total downloaded bytes
|
||||
long downloadedSize = file.length();
|
||||
totalSize += downloadedSize;
|
||||
|
||||
//create a buffer...
|
||||
byte[] buffer = new byte[1024];
|
||||
int bufferLength = 0;
|
||||
int bufferLength;
|
||||
int lastPercentage = 0;
|
||||
int percentage = 0;
|
||||
int percentage;
|
||||
|
||||
//now, read through the input buffer and write the contents to the file
|
||||
while((bufferLength = inputStream.read(buffer, 0, 1024)) >= 0) {
|
||||
//add the data in the buffer to the file in the file output stream (the file on the sd card
|
||||
fileOutput.write(buffer, 0, bufferLength);
|
||||
//add up the size so we know how much is downloaded
|
||||
downloadedSize += bufferLength;
|
||||
percentage = (int) (downloadedSize * 100 / totalSize);
|
||||
|
||||
if(percentage - lastPercentage > 1) {
|
||||
lastPercentage = percentage;
|
||||
|
||||
if(isAttached()) {
|
||||
getView().showItemProgress(itemPosition, percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
//close the output stream when done
|
||||
|
||||
fileOutput.close();
|
||||
|
||||
subscriber.onNext(FileUtils.getFileTypeFromFilePath(filePath));
|
||||
@@ -1272,6 +1281,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
boolean goOn = true;
|
||||
while(goOn) {
|
||||
MessageRealm messageRealm = messageByIdSpecification.toRealmQuery(realm).findFirst();
|
||||
|
||||
if(messageRealm == null) {
|
||||
goOn = false;
|
||||
} else {
|
||||
@@ -1279,6 +1289,7 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView> implements Cha
|
||||
messageByIdSpecification.setMessageId(randomId);
|
||||
}
|
||||
}
|
||||
|
||||
realm.commitTransaction();
|
||||
realm.close();
|
||||
return randomId;
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
@@ -216,6 +215,8 @@ public class GroupChatActivity extends BaseChatActivity {
|
||||
mGroupMembersTextView.setVisibility(View.VISIBLE);
|
||||
mGroupTitleTextView.setVisibility(View.VISIBLE);
|
||||
mChatImageView.setVisibility(View.VISIBLE);
|
||||
mChatSearchView.setQuery("", false);
|
||||
mChatSearchView.setIconified(true);
|
||||
mChatSearchView.clearFocus();
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
class GroupChatAdapter extends BaseChatAdapter {
|
||||
|
||||
GroupChatAdapter(long userId) {
|
||||
@@ -59,17 +61,18 @@ class GroupChatAdapter extends BaseChatAdapter {
|
||||
case LOADING_TYPE:
|
||||
break;
|
||||
case DATE_TYPE:
|
||||
((DateViewHolder) holder).dateTextView.setText(DateUtils.toDayOfYearString(mDateList.get(position)));
|
||||
((DateViewHolder) holder).dateTextView.setText(DateUtils.toDayOfYearString(new Date(mItemList.get(position).getCreatedAt())));
|
||||
|
||||
break;
|
||||
case LEFT_CHAT_TYPE:
|
||||
final Message leftMessage = mMessages.get(position - mPositionOffset.get(position));
|
||||
final Message leftMessage = (Message) mItemList.get(position);
|
||||
MessageViewHolder leftMessageViewHolder = (MessageViewHolder) holder;
|
||||
setGroupMessage(leftMessageViewHolder, leftMessage, position, true);
|
||||
|
||||
break;
|
||||
case RIGHT_CHAT_TYPE:
|
||||
final Message rightMessage = mMessages.get(position - mPositionOffset.get(position));
|
||||
final Message rightMessage = (Message) mItemList.get(position);
|
||||
|
||||
MessageViewHolder rightMessageViewHolder = (MessageViewHolder) holder;
|
||||
setGroupMessage(rightMessageViewHolder, rightMessage, position, false);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -204,6 +203,8 @@ public class SingleChatActivity extends BaseChatActivity {
|
||||
public void closeSearchView() {
|
||||
mSingleChatTitleTextView.setVisibility(View.VISIBLE);
|
||||
mChatImageView.setVisibility(View.VISIBLE);
|
||||
mChatSearchView.setQuery("", false);
|
||||
mChatSearchView.setIconified(true);
|
||||
mChatSearchView.clearFocus();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package de.beyondsoft.ownchat.page.chat;
|
||||
|
||||
import de.beyondsoft.ownchat.R;
|
||||
import de.beyondsoft.ownchat.model.Message;
|
||||
import de.beyondsoft.ownchat.utils.BeyondSoftLog;
|
||||
import de.beyondsoft.ownchat.utils.DateUtils;
|
||||
import de.beyondsoft.ownchat.utils.ui.ViewUtils;
|
||||
|
||||
@@ -14,6 +15,8 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
class SingleChatAdapter extends BaseChatAdapter {
|
||||
|
||||
SingleChatAdapter(long userId) {
|
||||
@@ -57,19 +60,19 @@ class SingleChatAdapter extends BaseChatAdapter {
|
||||
case LOADING_TYPE:
|
||||
break;
|
||||
case DATE_TYPE:
|
||||
((DateViewHolder) holder).dateTextView.setText(DateUtils.toDayOfYearString(mDateList.get(position)));
|
||||
((DateViewHolder) holder).dateTextView.setText(DateUtils.toDayOfYearString(new Date(mItemList.get(position).getCreatedAt())));
|
||||
|
||||
break;
|
||||
case LEFT_CHAT_TYPE:
|
||||
MessageViewHolder leftChatHolder = (MessageViewHolder) holder;
|
||||
final Message leftMessage = mMessages.get(position - mPositionOffset.get(position));
|
||||
final Message leftMessage = (Message) mItemList.get(position);
|
||||
setSingleMessage(leftChatHolder, leftMessage, position, true);
|
||||
|
||||
break;
|
||||
case RIGHT_CHAT_TYPE:
|
||||
MessageViewHolder rightChatHolder = (MessageViewHolder) holder;
|
||||
|
||||
final Message rightMessage = mMessages.get(position - mPositionOffset.get(position));
|
||||
final Message rightMessage = (Message) mItemList.get(position);
|
||||
|
||||
setSingleMessage(rightChatHolder, rightMessage, position, false);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import de.beyondsoft.ownchat.page.main.MainActivity;
|
||||
import de.beyondsoft.ownchat.utils.AppStoppedService;
|
||||
import de.beyondsoft.ownchat.utils.DialogHandler;
|
||||
import de.beyondsoft.ownchat.utils.ui.ViewUtils;
|
||||
|
||||
import com.securepreferences.SecurePreferences;
|
||||
|
||||
import android.content.Intent;
|
||||
@@ -19,7 +20,6 @@ import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
@@ -28,9 +28,7 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -42,9 +40,6 @@ import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnEditorAction;
|
||||
|
||||
/**
|
||||
* Created by imarneanu on 2/10/17.
|
||||
*/
|
||||
public class LoginActivity extends AppCompatActivity implements LoginView {
|
||||
|
||||
@BindView(R.id.login_chat_code)
|
||||
@@ -96,7 +91,7 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
|
||||
|
||||
@OnEditorAction(R.id.login_password)
|
||||
public boolean passwordDoneClicked(int actionId) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
if(actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
ViewUtils.hideKeyboard(this);
|
||||
}
|
||||
|
||||
@@ -118,7 +113,7 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
|
||||
public void customerIdIsNotValid(int status) {
|
||||
int dialogMessage;
|
||||
|
||||
switch (status) {
|
||||
switch(status) {
|
||||
case 1:
|
||||
dialogMessage = R.string.login_customer_id_is_invalid;
|
||||
break;
|
||||
@@ -151,7 +146,7 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
|
||||
public void retrievedUploadMaxSize() {
|
||||
mCallback.tryToRegisterDevice(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID), FirebaseInstanceId.getInstance().getToken());
|
||||
|
||||
if (!mSavePasswordCheckbox.isChecked()) {
|
||||
if(!mSavePasswordCheckbox.isChecked()) {
|
||||
startService(new Intent(getBaseContext(), AppStoppedService.class));
|
||||
}
|
||||
|
||||
@@ -162,14 +157,14 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
|
||||
|
||||
//TODO: change defaultValue: null to defaultValue: ""
|
||||
private void decryptPreference() {
|
||||
for (Map.Entry<String, ?> entry : mSecuredPrefs.getAll().entrySet()) {
|
||||
for(Map.Entry<String, ?> entry : mSecuredPrefs.getAll().entrySet()) {
|
||||
final String key = entry.getKey();
|
||||
|
||||
if (key == null) {
|
||||
if(key == null) {
|
||||
continue;
|
||||
} else if (key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.CHAT_CODE))) {
|
||||
} else if(key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.CHAT_CODE))) {
|
||||
mChatCodeEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.CHAT_CODE, null)));
|
||||
} else if (key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.ACCOUNT_NO))) {
|
||||
} else if(key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.ACCOUNT_NO))) {
|
||||
mAccountEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.ACCOUNT_NO, null)));
|
||||
} else if(key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.USER_NAME))) {
|
||||
mUsernameEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.USER_NAME, null)));
|
||||
@@ -215,7 +210,7 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
if (mSnackbar == null) {
|
||||
if(mSnackbar == null) {
|
||||
mSnackbar = Snackbar.make(findViewById(R.id.login_coordinator_layout), message, Snackbar.LENGTH_LONG).setAction("Retry", view -> verifyIfIsChecked());
|
||||
mSnackbar.setActionTextColor(ContextCompat.getColor(this, R.color.colorDefault));
|
||||
}
|
||||
|
||||
@@ -48,4 +48,10 @@ public interface Constants {
|
||||
"hq+w3Brvaw2VFn3EK6BlspkENnWAa6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiV" +
|
||||
"FrqoM7hD8bEfwzB/onkxEz0tNvjj/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3D" +
|
||||
"kwIDAQAB";
|
||||
|
||||
String LOG_FILES_DIR_NAME = "ownChatLogFiles";
|
||||
String MESSAGES_LOG_FILE_NAME = "messages_log";
|
||||
String NOTIFICATION_LOG_FILE_NAME = "notification_log";
|
||||
String TEXT_FILE_FORMAT = ".txt";
|
||||
String FIREBASE_LOG = "firebase_log";
|
||||
}
|
||||
@@ -13,9 +13,6 @@ public abstract class EndlessScrollListener extends RecyclerView.OnScrollListene
|
||||
private int mVisibleItem;
|
||||
protected boolean mHasNewerMessages = false;
|
||||
|
||||
public int mPreviousVisibleItem;
|
||||
public boolean mIsScrollingDownLock;
|
||||
|
||||
public void reset() {
|
||||
mPreviousTotal = 0;
|
||||
}
|
||||
@@ -32,7 +29,7 @@ public abstract class EndlessScrollListener extends RecyclerView.OnScrollListene
|
||||
mVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
|
||||
if(mLoading) {
|
||||
if(totalItemCount > mPreviousTotal) {
|
||||
if(totalItemCount >= mPreviousTotal - 1) {
|
||||
mLoading = false;
|
||||
mPreviousTotal = totalItemCount;
|
||||
}
|
||||
@@ -44,19 +41,9 @@ public abstract class EndlessScrollListener extends RecyclerView.OnScrollListene
|
||||
|
||||
recyclerView.post(() -> {
|
||||
try {
|
||||
//BaseChatAdapter adapter = (BaseChatAdapter) recyclerView.getAdapter();
|
||||
|
||||
//mVisibleItem -= adapter.getPositionOffsetForIndex(mVisibleItem);
|
||||
|
||||
|
||||
if(!mLoading && dy <= 0 && ((totalItemCount - visibleItemCount) <= (mVisibleItem + mVisibleThreshold))) {
|
||||
mLoading = onLoad();
|
||||
} else if(!mIsScrollingDownLock && !mLoading && dy > 0 && mHasNewerMessages && (mVisibleItem <= (mVisibleThreshold / 5))) {
|
||||
// TODO: maybe remove after structural changes to the messages list
|
||||
// mPreviousVisibleItem = mVisibleItem + adapter.getPositionOffsetForIndex(mVisibleItem);
|
||||
// mIsScrollingDownLock = true;
|
||||
// TODO -----------------------------------------------------------
|
||||
|
||||
} else if(!mLoading && dy > 0 && mHasNewerMessages && (mVisibleItem <= mVisibleThreshold)) {
|
||||
mLoading = onLoad();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
||||
@@ -25,27 +25,22 @@ import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Peli
|
||||
@@ -1239,7 +1234,7 @@ public class FileUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Utils.copyExifData(image, tmpFile, null);
|
||||
Utils.copyExifData(image, tmpFile);
|
||||
|
||||
Log.i("COMPRESSING IMAGE", "file size after compression: " + tmpFile.length() + " bytes. Before compression: " + image.length());
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.beyondsoft.ownchat.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
@@ -14,7 +15,6 @@ import org.apache.sanselan.common.IImageMetadata;
|
||||
import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
|
||||
import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter;
|
||||
import org.apache.sanselan.formats.tiff.TiffImageMetadata;
|
||||
import org.apache.sanselan.formats.tiff.constants.TagInfo;
|
||||
import org.apache.sanselan.formats.tiff.constants.TiffConstants;
|
||||
import org.apache.sanselan.formats.tiff.write.TiffOutputDirectory;
|
||||
import org.apache.sanselan.formats.tiff.write.TiffOutputField;
|
||||
@@ -23,24 +23,25 @@ import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import de.beyondsoft.ownchat.BewoplanerApplication;
|
||||
|
||||
import static de.beyondsoft.ownchat.utils.Constants.LOG_FILES_DIR_NAME;
|
||||
import static de.beyondsoft.ownchat.utils.Constants.TEXT_FILE_FORMAT;
|
||||
|
||||
/**
|
||||
* Created by imarneanu on 2/13/17.
|
||||
*/
|
||||
public class Utils {
|
||||
/**
|
||||
* Clears activity's back stack
|
||||
*
|
||||
* @param appCompatActivity The activity which will have no fragments in back stack
|
||||
*/
|
||||
public static void clearFullBackStack(AppCompatActivity appCompatActivity) {
|
||||
FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager();
|
||||
|
||||
if(fragmentManager.getBackStackEntryCount() > 0) {
|
||||
// clear the fragment back stack
|
||||
FragmentManager.BackStackEntry first = fragmentManager.getBackStackEntryAt(0);
|
||||
fragmentManager.popBackStackImmediate(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
}
|
||||
@@ -50,88 +51,73 @@ public class Utils {
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
View view = activity.getCurrentFocus();
|
||||
|
||||
if (view == null) {
|
||||
if(view == null) {
|
||||
view = new View(activity);
|
||||
}
|
||||
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
public static boolean copyExifData(File sourceFile, File destFile, List<TagInfo> excludedFields) {
|
||||
static boolean copyExifData(File sourceFile, File destFile) {
|
||||
String tempFileName = destFile.getAbsolutePath() + ".tmp";
|
||||
File tempFile = null;
|
||||
OutputStream tempStream = null;
|
||||
|
||||
try {
|
||||
tempFile = new File (tempFileName);
|
||||
tempFile = new File(tempFileName);
|
||||
|
||||
TiffOutputSet sourceSet = getSanselanOutputSet(sourceFile, TiffConstants.DEFAULT_TIFF_BYTE_ORDER);
|
||||
TiffOutputSet destSet = getSanselanOutputSet(destFile, sourceSet.byteOrder);
|
||||
|
||||
// If the EXIF data endianess of the source and destination files
|
||||
// differ then fail. This only happens if the source and
|
||||
// destination images were created on different devices. It's
|
||||
// technically possible to copy this data by changing the byte
|
||||
// order of the data, but handling this case is outside the scope
|
||||
// of this implementation
|
||||
if (sourceSet.byteOrder != destSet.byteOrder) return false;
|
||||
if(sourceSet.byteOrder != destSet.byteOrder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
destSet.getOrCreateExifDirectory();
|
||||
|
||||
// Go through the source directories
|
||||
List<?> sourceDirectories = sourceSet.getDirectories();
|
||||
for (int i=0; i<sourceDirectories.size(); i++) {
|
||||
for(int i=0; i<sourceDirectories.size(); i++) {
|
||||
TiffOutputDirectory sourceDirectory = (TiffOutputDirectory)sourceDirectories.get(i);
|
||||
TiffOutputDirectory destinationDirectory = getOrCreateExifDirectory(destSet, sourceDirectory);
|
||||
|
||||
if (destinationDirectory == null) continue; // failed to create
|
||||
if(destinationDirectory == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Loop the fields
|
||||
List<?> sourceFields = sourceDirectory.getFields();
|
||||
for (int j=0; j<sourceFields.size(); j++) {
|
||||
// Get the source field
|
||||
for(int j=0; j<sourceFields.size(); j++) {
|
||||
TiffOutputField sourceField = (TiffOutputField) sourceFields.get(j);
|
||||
|
||||
// Check exclusion list
|
||||
if (excludedFields != null && excludedFields.contains(sourceField.tagInfo)) {
|
||||
destinationDirectory.removeField(sourceField.tagInfo);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove any existing field
|
||||
destinationDirectory.removeField(sourceField.tagInfo);
|
||||
|
||||
// Add field
|
||||
destinationDirectory.add(sourceField);
|
||||
}
|
||||
}
|
||||
|
||||
// Save data to destination
|
||||
tempStream = new BufferedOutputStream(new FileOutputStream(tempFile));
|
||||
new ExifRewriter().updateExifMetadataLossless(destFile, tempStream, destSet);
|
||||
tempStream.close();
|
||||
|
||||
// Replace file
|
||||
if (destFile.delete()) {
|
||||
if(destFile.delete()) {
|
||||
tempFile.renameTo(destFile);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (ImageReadException | ImageWriteException | IOException exception) {
|
||||
catch(ImageReadException | ImageWriteException | IOException exception) {
|
||||
exception.printStackTrace();
|
||||
} finally {
|
||||
if (tempStream != null) {
|
||||
if(tempStream != null) {
|
||||
try {
|
||||
tempStream.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (tempFile != null) {
|
||||
if (tempFile.exists()) {
|
||||
if(tempFile != null) {
|
||||
if(tempFile.exists()) {
|
||||
tempFile.delete();
|
||||
}
|
||||
}
|
||||
@@ -187,4 +173,62 @@ public class Utils {
|
||||
public static void makeScrollLog(String message) {
|
||||
Log.i("SCROLLING_LOG", message);
|
||||
}
|
||||
|
||||
private static void makeLogEntry(String entry, String fileName) {
|
||||
try {
|
||||
entry += "\n\n";
|
||||
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy_MM_dd", Locale.GERMAN);
|
||||
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy_MM_dd_HH:mm:ss", Locale.GERMAN);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
Date today = calendar.getTime();
|
||||
|
||||
String logDirPath = BewoplanerApplication.getAppContext().getExternalFilesDir(null) + File.separator + LOG_FILES_DIR_NAME;
|
||||
|
||||
File logDir = new File(logDirPath);
|
||||
if(!logDir.exists()) {
|
||||
logDir.mkdir();
|
||||
}
|
||||
|
||||
String logFileName = logDirPath + File.separator + fileName + "_" + simpleDateFormat.format(today) + TEXT_FILE_FORMAT;
|
||||
|
||||
File logFile = new File(logFileName);
|
||||
|
||||
if(!logFile.exists()) {
|
||||
logFile.createNewFile();
|
||||
}
|
||||
|
||||
FileWriter fileWriter = new FileWriter(logFile, true);
|
||||
|
||||
entry = simpleDateFormat2.format(today) + ": " + entry;
|
||||
|
||||
fileWriter.append(entry);
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
|
||||
} catch(IOException e) {
|
||||
BeyondSoftLog.logScrollingEvent_E("An error occurred while attempting to write the log file", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void makeFirebaseLogEntry(String entry) {
|
||||
makeLogEntry(entry, Constants.FIREBASE_LOG);
|
||||
}
|
||||
|
||||
public static boolean isBefore(Calendar calendar1, Calendar calendar2) {
|
||||
calendar1.set(Calendar.HOUR, 0);
|
||||
calendar1.set(Calendar.MINUTE, 0);
|
||||
calendar1.set(Calendar.SECOND, 0);
|
||||
calendar1.set(Calendar.MILLISECOND, 0);
|
||||
calendar1.set(Calendar.HOUR_OF_DAY, 0);
|
||||
|
||||
calendar2.set(Calendar.HOUR, 0);
|
||||
calendar2.set(Calendar.MINUTE, 0);
|
||||
calendar2.set(Calendar.SECOND, 0);
|
||||
calendar2.set(Calendar.MILLISECOND, 0);
|
||||
calendar2.set(Calendar.HOUR_OF_DAY, 0);
|
||||
|
||||
return calendar1.before(calendar2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
android:textSize="11sp"
|
||||
android:visibility="gone"
|
||||
tools:ignore="SmallSp"
|
||||
tools:text="Lyndon Jetten, Sonja Estevao, Jörg Behr, Christian Bäurle, Markus Bäurle, Mike Gahn"
|
||||
tools:text="Lyndon Jetten, Sonja Estevao, Jörg Behr, Christian Bäurle, Markus Bäurle, Mike Gahn, Özlem Göktepe"
|
||||
tools:visibility="visible"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ buildscript {
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
classpath 'com.android.tools.build:gradle:3.2.0'
|
||||
classpath 'io.realm:realm-gradle-plugin:5.3.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#Tue Apr 10 11:16:46 CEST 2018
|
||||
#Tue Sep 25 13:06:52 CEST 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||
|
||||
Reference in New Issue
Block a user