Search in sources :

Example 6 with XMPPAccountSettings

use of com.xabber.android.data.xaccount.XMPPAccountSettings in project xabber-android by redsolution.

the class AccountSyncDialogFragment method onPositiveClick.

private void onPositiveClick(boolean needGoToMainActivity) {
    // set accounts to sync map
    if (!switchSyncAll.isChecked()) {
        Map<String, Boolean> syncState = new HashMap<>();
        for (XMPPAccountSettings account : xmppAccounts) {
            if (account.getStatus() != XMPPAccountSettings.SyncStatus.local) {
                syncState.put(account.getJid(), account.isSynchronization());
            } else if (account.isSynchronization() || XabberAccountManager.getInstance().getAccountSyncState(account.getJid()) != null) {
                syncState.put(account.getJid(), account.isSynchronization());
            }
        }
        XabberAccountManager.getInstance().setAccountSyncState(syncState);
    }
    // update timestamp in accounts if timestamp was changed in dialog
    for (XMPPAccountSettings account : xmppAccounts) {
        AccountJid accountJid = XabberAccountManager.getInstance().getExistingAccount(account.getJid());
        if (accountJid != null)
            AccountManager.getInstance().setTimestamp(accountJid, account.getTimestamp());
    }
    // set sync all
    SettingsManager.setSyncAllAccounts(switchSyncAll.isChecked());
    // callback to sync-request
    ((XabberAccountInfoActivity) getActivity()).onSyncClick(needGoToMainActivity);
}
Also used : HashMap(java.util.HashMap) XMPPAccountSettings(com.xabber.android.data.xaccount.XMPPAccountSettings) AccountJid(com.xabber.android.data.entity.AccountJid) XabberAccountInfoActivity(com.xabber.android.ui.activity.XabberAccountInfoActivity)

Example 7 with XMPPAccountSettings

use of com.xabber.android.data.xaccount.XMPPAccountSettings in project xabber-android by redsolution.

the class AccountSyncDialogFragment method setXmppAccounts.

public void setXmppAccounts(List<XMPPAccountSettings> items) {
    this.xmppAccounts = new ArrayList<>();
    for (XMPPAccountSettings account : items) {
        XMPPAccountSettings newAccount = new XMPPAccountSettings(account.getJid(), account.isSynchronization(), account.getTimestamp());
        newAccount.setUsername(account.getUsername());
        newAccount.setColor(account.getColor());
        newAccount.setOrder(account.getOrder());
        newAccount.setStatus(account.getStatus());
        newAccount.setDeleted(account.isDeleted());
        newAccount.setSyncNotAllowed(account.isSyncNotAllowed());
        this.xmppAccounts.add(newAccount);
    }
    Collections.sort(xmppAccounts);
}
Also used : XMPPAccountSettings(com.xabber.android.data.xaccount.XMPPAccountSettings)

Example 8 with XMPPAccountSettings

use of com.xabber.android.data.xaccount.XMPPAccountSettings in project xabber-android by redsolution.

the class XMPPAccountAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    final XMPPAccountSettings account = items.get(position);
    XMPPAccountVH viewHolder = (XMPPAccountVH) holder;
    viewHolder.chkAccountSync.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            account.setSynchronization(isChecked);
        }
    });
    viewHolder.avatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (account.isSynchronization() || isAllChecked) {
                if (account.getStatus() == XMPPAccountSettings.SyncStatus.localNewer) {
                    account.setStatus(XMPPAccountSettings.SyncStatus.remoteNewer);
                    account.setTimestamp(0);
                    // change settings
                    XMPPAccountSettings set = XabberAccountManager.getInstance().getAccountSettingsForSync(account.getJid());
                    if (set != null) {
                        account.setColor(set.getColor());
                    }
                } else if (account.getStatus() == XMPPAccountSettings.SyncStatus.remoteNewer) {
                    account.setStatus(XMPPAccountSettings.SyncStatus.localNewer);
                    account.setTimestamp((int) (System.currentTimeMillis() / 1000L));
                    // change settings
                    AccountItem item = AccountManager.getInstance().getAccount(XabberAccountManager.getInstance().getExistingAccount(account.getJid()));
                    if (item != null) {
                        account.setColor(ColorManager.getInstance().convertIndexToColorName(item.getColorIndex()));
                    }
                }
                notifyDataSetChanged();
            }
        }
    });
    // set colors
    int colorId = ColorManager.getInstance().convertColorNameToId(account.getColor());
    viewHolder.color.setColorFilter(colorId);
    viewHolder.username.setTextColor(colorId);
    // set username
    if (account.getUsername() != null && !account.getUsername().isEmpty())
        viewHolder.username.setText(account.getUsername());
    else
        viewHolder.username.setText(account.getJid());
    if (account.isSynchronization() || isAllChecked) {
        if (account.getStatus() != null) {
            switch(account.getStatus()) {
                case local:
                    viewHolder.jid.setText(R.string.sync_status_local);
                    viewHolder.avatar.setImageResource(R.drawable.ic_sync_upload);
                    break;
                case remote:
                    viewHolder.jid.setText(R.string.sync_status_remote);
                    viewHolder.avatar.setImageResource(R.drawable.ic_sync_download);
                    break;
                case localNewer:
                    viewHolder.jid.setText(R.string.sync_status_local);
                    viewHolder.avatar.setImageResource(R.drawable.ic_sync_upload);
                    break;
                case remoteNewer:
                    if (account.isDeleted()) {
                        viewHolder.jid.setText(R.string.sync_status_deleted);
                        viewHolder.avatar.setImageResource(R.drawable.ic_delete_grey);
                    } else {
                        viewHolder.jid.setText(R.string.sync_status_remote);
                        viewHolder.avatar.setImageResource(R.drawable.ic_sync_download);
                    }
                    break;
                case localEqualsRemote:
                    viewHolder.jid.setText(R.string.sync_status_ok);
                    viewHolder.avatar.setImageResource(R.drawable.ic_sync_done);
                    break;
                default:
                    break;
            }
        }
    } else {
        viewHolder.jid.setText(R.string.sync_status_no);
        viewHolder.avatar.setImageResource(R.drawable.ic_sync_disable);
        viewHolder.username.setTextColor(context.getResources().getColor(R.color.grey_500));
    }
    // set sync checkbox
    if (account.isSyncNotAllowed()) {
        viewHolder.jid.setText(R.string.sync_status_not_allowed);
        viewHolder.chkAccountSync.setEnabled(false);
    } else if (isAllChecked) {
        viewHolder.chkAccountSync.setEnabled(false);
        viewHolder.chkAccountSync.setChecked(true);
    } else {
        viewHolder.chkAccountSync.setEnabled(true);
        viewHolder.chkAccountSync.setChecked(account.isSynchronization());
    }
}
Also used : XMPPAccountSettings(com.xabber.android.data.xaccount.XMPPAccountSettings) AccountItem(com.xabber.android.data.account.AccountItem) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Example 9 with XMPPAccountSettings

use of com.xabber.android.data.xaccount.XMPPAccountSettings in project xabber-android by redsolution.

the class XabberAccountInfoFragment method showSyncDialog.

public void showSyncDialog(final boolean noCancel) {
    Subscription getSettingsSubscription = AuthManager.getClientSettings().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<XMPPAccountSettings>>() {

        @Override
        public void call(List<XMPPAccountSettings> list) {
            List<XMPPAccountSettings> items = XabberAccountManager.getInstance().createSyncList(list);
            if (items != null && items.size() > 0) {
                // save full list to list for sync
                XabberAccountManager.getInstance().setXmppAccountsForSync(items);
                // show dialog
                AccountSyncDialogFragment.newInstance(noCancel).show(getFragmentManager(), AccountSyncDialogFragment.class.getSimpleName());
                dialogShowed = false;
            } else
                Toast.makeText(getActivity(), "Не удалось начать синхронизацию", Toast.LENGTH_SHORT).show();
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            handleErrorGetSettings(throwable);
        }
    });
    compositeSubscription.add(getSettingsSubscription);
}
Also used : XMPPAccountSettings(com.xabber.android.data.xaccount.XMPPAccountSettings) List(java.util.List) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 10 with XMPPAccountSettings

use of com.xabber.android.data.xaccount.XMPPAccountSettings in project xabber-android by redsolution.

the class AccountSyncActivity method getSyncStatus.

private void getSyncStatus() {
    if (!XabberAccountManager.getInstance().isAccountSynchronize(jid) || !NetworkManager.isNetworkAvailable()) {
        setSyncStatus(XMPPAccountSettings.SyncStatus.local);
        return;
    }
    ivStatus.setVisibility(View.INVISIBLE);
    progressBar.setVisibility(View.VISIBLE);
    Subscription getSettingsSubscription = AuthManager.getClientSettings().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<XMPPAccountSettings>>() {

        @Override
        public void call(List<XMPPAccountSettings> list) {
            handleSuccessGetSettings(list);
            ivStatus.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.INVISIBLE);
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            handleErrorGetSettings(throwable);
            ivStatus.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.INVISIBLE);
        }
    });
    compositeSubscription.add(getSettingsSubscription);
}
Also used : XMPPAccountSettings(com.xabber.android.data.xaccount.XMPPAccountSettings) List(java.util.List) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Aggregations

XMPPAccountSettings (com.xabber.android.data.xaccount.XMPPAccountSettings)14 List (java.util.List)8 Subscription (rx.Subscription)8 CompositeSubscription (rx.subscriptions.CompositeSubscription)5 AccountJid (com.xabber.android.data.entity.AccountJid)2 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NetworkException (com.xabber.android.data.NetworkException)1 AccountItem (com.xabber.android.data.account.AccountItem)1 XabberAccountInfoActivity (com.xabber.android.ui.activity.XabberAccountInfoActivity)1 HashMap (java.util.HashMap)1