Search in sources :

Example 21 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class SecuritySettingsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View res = inflater.inflate(R.layout.fr_settings_encryption, container, false);
    res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    res.findViewById(R.id.big_divider).setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());
    ((TextView) res.findViewById(R.id.security_settings_title)).setTextColor(ActorSDK.sharedActor().style.getSettingsMainTitleColor());
    loading = (TextView) res.findViewById(R.id.loading);
    loading.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    loading.setVisibility(View.GONE);
    loading.setOnClickListener(v -> performLoad());
    authItems = (LinearLayout) res.findViewById(R.id.authItems);
    ((TextView) res.findViewById(R.id.settings_last_seen_title)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    ((TextView) res.findViewById(R.id.settings_last_seen_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    res.findViewById(R.id.lastSeen).setOnClickListener(v -> {
        String[] itemsValues = new String[] { "always", "contacts", "none" };
        String[] items = new String[] { getString(R.string.security_last_seen_everybody), getString(R.string.security_last_seen_contacts), getString(R.string.security_last_seen_nobody) };
        int currentLastSeen = Arrays.asList(itemsValues).indexOf(messenger().getPrivacy());
        new AlertDialog.Builder(getActivity()).setTitle(R.string.security_last_seen_title).setSingleChoiceItems(items, currentLastSeen, (dialog, which) -> {
            messenger().setPrivacy(itemsValues[which]);
            dialog.dismiss();
        }).setNegativeButton(R.string.dialog_cancel, null).setPositiveButton(R.string.dialog_ok, null).show();
    });
    res.findViewById(R.id.terminateSessions).setOnClickListener(v -> new AlertDialog.Builder(getActivity()).setMessage(R.string.security_terminate_message).setPositiveButton(R.string.dialog_yes, (dialog, which) -> execute(messenger().terminateAllSessions(), R.string.progress_common, new CommandCallback<Void>() {

        @Override
        public void onResult(Void res1) {
            performLoad();
        }

        @Override
        public void onError(Exception e) {
            performLoad();
            Toast.makeText(getActivity(), R.string.security_toast_unable_remove_auth, Toast.LENGTH_SHORT).show();
        }
    })).setNegativeButton(R.string.dialog_no, null).show().setCanceledOnTouchOutside(true));
    ((TextView) res.findViewById(R.id.settings_terminate_sessions_title)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
    ((TextView) res.findViewById(R.id.settings_terminate_sessions_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    performLoad();
    return res;
}
Also used : AlertDialog(android.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) LinearLayout(android.widget.LinearLayout) Arrays(java.util.Arrays) ActorSDK(im.actor.sdk.ActorSDK) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) Void(im.actor.runtime.actors.messages.Void) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) AlertDialog(android.app.AlertDialog) List(java.util.List) R(im.actor.sdk.R) TextView(android.widget.TextView) Toast(android.widget.Toast) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Collections(java.util.Collections) ApiAuthSession(im.actor.core.api.ApiAuthSession) ApiAuthHolder(im.actor.core.api.ApiAuthHolder) TextView(android.widget.TextView) CommandCallback(im.actor.core.viewmodel.CommandCallback) Void(im.actor.runtime.actors.messages.Void) TextView(android.widget.TextView) View(android.view.View)

Example 22 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class JsFacade method addContact.

@UsedByApp
public JsPromise addContact(final int uid) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            //noinspection ConstantConditions
            messenger.addContact(uid).start(new CommandCallback<Boolean>() {

                @Override
                public void onResult(Boolean res) {
                    Log.d(TAG, "addContact:result");
                    resolve();
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "addContact:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) CommandCallback(im.actor.core.viewmodel.CommandCallback) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Example 23 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class JsFacade method getIntegrationToken.

@UsedByApp
public JsPromise getIntegrationToken(final int gid) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            //noinspection ConstantConditions
            messenger.requestIntegrationToken(gid).start(new CommandCallback<String>() {

                @Override
                public void onResult(String res) {
                    Log.d(TAG, "getIntegrationToken:result");
                    resolve(res);
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "getIntegrationToken:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) CommandCallback(im.actor.core.viewmodel.CommandCallback) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Example 24 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class JsFacade method findAllDocs.

@UsedByApp
public JsPromise findAllDocs(final JsPeer peer) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            messenger.findAllDocs(peer.convert()).start(new CommandCallback<List<MessageSearchEntity>>() {

                @Override
                public void onResult(List<MessageSearchEntity> res) {
                    resolve(convertSearchRes(res));
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "findAllText:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) MessageSearchEntity(im.actor.core.entity.MessageSearchEntity) List(java.util.List) ArrayList(java.util.ArrayList) CommandCallback(im.actor.core.viewmodel.CommandCallback) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Example 25 with CommandCallback

use of im.actor.core.viewmodel.CommandCallback in project actor-platform by actorapp.

the class JsFacade method revokeIntegrationToken.

@UsedByApp
public JsPromise revokeIntegrationToken(final int gid) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            //noinspection ConstantConditions
            messenger.revokeIntegrationToken(gid).start(new CommandCallback<String>() {

                @Override
                public void onResult(String res) {
                    Log.d(TAG, "revokeIntegrationToken:result");
                    resolve(res);
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "revokeIntegrationToken:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) CommandCallback(im.actor.core.viewmodel.CommandCallback) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Aggregations

CommandCallback (im.actor.core.viewmodel.CommandCallback)37 UsedByApp (im.actor.core.js.annotations.UsedByApp)28 RpcException (im.actor.core.network.RpcException)28 JsPromiseExecutor (im.actor.runtime.js.utils.JsPromiseExecutor)28 Void (im.actor.runtime.actors.messages.Void)13 UserVM (im.actor.core.viewmodel.UserVM)8 ArrayList (java.util.ArrayList)8 View (android.view.View)7 TextView (android.widget.TextView)7 List (java.util.List)7 AlertDialog (android.app.AlertDialog)5 Intent (android.content.Intent)4 GroupVM (im.actor.core.viewmodel.GroupVM)4 DialogInterface (android.content.DialogInterface)3 ViewGroup (android.view.ViewGroup)3 Toast (android.widget.Toast)3 MessageSearchEntity (im.actor.core.entity.MessageSearchEntity)3 ActorSDK (im.actor.sdk.ActorSDK)3 R (im.actor.sdk.R)3 ActorSDKMessenger.messenger (im.actor.sdk.util.ActorSDKMessenger.messenger)3