Search in sources :

Example 1 with LoadHistorySettings

use of com.xabber.android.data.extension.mam.LoadHistorySettings in project xabber-android by redsolution.

the class ChatFragment method loadHistoryIfNeeded.

private void loadHistoryIfNeeded() {
    AccountItem accountItem = AccountManager.getInstance().getAccount(this.account);
    if (accountItem == null) {
        return;
    }
    LoadHistorySettings loadHistorySettings = accountItem.getLoadHistorySettings();
    if (loadHistorySettings != LoadHistorySettings.current && loadHistorySettings != LoadHistorySettings.all) {
        return;
    }
    if (isRemoteHistoryRequested) {
        return;
    }
    int visibleItemCount = layoutManager.getChildCount();
    if (visibleItemCount == 0) {
        return;
    }
    int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
    if (firstVisibleItemPosition / visibleItemCount <= 2) {
        requestRemoteHistoryLoad();
        return;
    }
    if (firstVisibleItemPosition < firstRemoteSyncedItemPosition) {
        requestRemoteHistoryLoad();
        return;
    }
    if (firstVisibleItemPosition - firstRemoteSyncedItemPosition < visibleItemCount * 2) {
        requestRemoteHistoryLoad();
        return;
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) LoadHistorySettings(com.xabber.android.data.extension.mam.LoadHistorySettings)

Example 2 with LoadHistorySettings

use of com.xabber.android.data.extension.mam.LoadHistorySettings in project xabber-android by redsolution.

the class ChatFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    EventBus.getDefault().register(this);
    AccountItem accountItem = AccountManager.getInstance().getAccount(this.account);
    if (accountItem != null) {
        LoadHistorySettings loadHistorySettings = accountItem.getLoadHistorySettings();
        if (loadHistorySettings == LoadHistorySettings.all || loadHistorySettings == LoadHistorySettings.current) {
            if (!isRemoteHistoryRequested) {
                MamManager.getInstance().requestLastHistoryByUser(getChat());
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) LoadHistorySettings(com.xabber.android.data.extension.mam.LoadHistorySettings)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)2 LoadHistorySettings (com.xabber.android.data.extension.mam.LoadHistorySettings)2