Search in sources :

Example 1 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class MainActivity method onNavigationDrawerItemSelected.

@Override
public void onNavigationDrawerItemSelected(int position) {
    if (position == 1) {
        Intent intent = new Intent(this, ConversationActivity.class);
        if (ApplozicClient.getInstance(this).isContextBasedChat()) {
            intent.putExtra(ConversationUIService.CONTEXT_BASED_CHAT, true);
        }
        startActivity(intent);
        return;
    }
    /*
        if (position == 1) {
            ConversationFragment conversationFragment = new ConversationFragment();
            Contact contact = new Contact(this, "mobicomkit");
            mTitle = getString(R.string.user_id);
            addFragment(this, conversationFragment, "conversationFragment");
            conversationFragment.loadConversation(contact);
            return;

        }*/
    if (position == 0) {
        mTitle = getString(R.string.ecommerce);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.container, EcommerceFragment.newInstance("", "")).commit();
        return;
    }
    if (position == 2) {
        UserLogoutTask.TaskListener userLogoutTaskListener = new UserLogoutTask.TaskListener() {

            @Override
            public void onSuccess(Context context) {
                userLogoutTask = null;
                Toast.makeText(getBaseContext(), getBaseContext().getString(R.string.log_out_successful), Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
                finish();
            }

            @Override
            public void onFailure(Exception exception) {
                userLogoutTask = null;
                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                alertDialog.setTitle(getString(R.string.text_alert));
                alertDialog.setMessage(exception.toString());
                alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok_alert), new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                if (!isFinishing()) {
                    alertDialog.show();
                }
            }
        };
        userLogoutTask = new UserLogoutTask(userLogoutTaskListener, this);
        userLogoutTask.execute((Void) null);
    }
    if (position == 3) {
        Map<String, String> messageMetaData = new HashMap<>();
        messageMetaData.put(Message.MetaDataType.KEY.getValue(), Message.MetaDataType.HIDDEN.getValue());
        Message message = new Message();
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(MainActivity.this);
        message.setContactIds("android");
        message.setTo("android");
        message.setContentType(Message.ContentType.CUSTOM.getValue());
        message.setMessage("this is meta data hidden");
        message.setMetadata(messageMetaData);
        message.setStoreOnDevice(Boolean.TRUE);
        message.setRead(Boolean.TRUE);
        message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
        message.setSendToDevice(Boolean.FALSE);
        message.setType(Message.MessageType.MT_OUTBOX.getValue());
        message.setDeviceKeyString(userPreferences.getDeviceKeyString());
        message.setSource(Message.Source.MT_MOBILE_APP.getValue());
        new MobiComConversationService(MainActivity.this).sendMessage(message, MessageIntentService.class);
    }
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, PlaceholderFragment.newInstance(position + 1)).commit();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) Message(com.applozic.mobicomkit.api.conversation.Message) DialogInterface(android.content.DialogInterface) HashMap(java.util.HashMap) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Intent(android.content.Intent) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) FragmentManager(android.support.v4.app.FragmentManager) UserLogoutTask(com.applozic.mobicomkit.api.account.user.UserLogoutTask)

Example 2 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobiComUserPreference userPreference = MobiComUserPreference.getInstance(this);
    if (!userPreference.isRegistered()) {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);
        finish();
        return;
    }
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();
    // Set up the drawer.
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
    // Put Support Contact Data
    buildSupportContactData();
/*else {
            Intent intent = new Intent(this, ConversationActivity.class);
                startActivity(intent);
        }*/
/*ApplozicSetting.getInstance(this).setColor(ApplozicSetting.CUSTOM_MESSAGE_BACKGROUND_COLOR, Color.parseColor("#FFB3E5FC"));
        Message message = new Message("contact@applozic.com", "hey! here's a match <3");
        new MobiComMessageService(this, MessageIntentService.class).sendCustomMessage(message);*/
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Intent(android.content.Intent)

Example 3 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class ApplozicClient method isNotAllowed.

public boolean isNotAllowed() {
    MobiComUserPreference pref = MobiComUserPreference.getInstance(context);
    boolean isDebuggable = (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
    return !isDebuggable && (pref.getPricingPackage() == RegistrationResponse.PricingType.CLOSED.getValue() || pref.getPricingPackage() == RegistrationResponse.PricingType.BETA.getValue());
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference)

Example 4 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttService method typingStopped.

public void typingStopped(Contact contact, Channel channel) {
    String currentId;
    if (channel != null) {
        currentId = String.valueOf(channel.getKey());
    } else {
        currentId = contact.getUserId();
    }
    MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
    publishTopic(getApplicationKey(context), "0", mobiComUserPreference.getUserId(), currentId);
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference)

Example 5 with MobiComUserPreference

use of com.applozic.mobicomkit.api.account.user.MobiComUserPreference in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttService method subscribeToTypingTopic.

public synchronized void subscribeToTypingTopic(Channel channel) {
    try {
        String currentId = null;
        if (channel != null) {
            currentId = String.valueOf(channel.getKey());
        } else {
            MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
            currentId = mobiComUserPreference.getUserId();
        }
        final MqttClient client = connect();
        if (client == null || !client.isConnected()) {
            return;
        }
        client.subscribe("typing-" + getApplicationKey(context) + "-" + currentId, 0);
        Utils.printLog(context, TAG, "Subscribed to topic: " + "typing-" + getApplicationKey(context) + "-" + currentId);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) MqttException(org.eclipse.paho.client.mqttv3.MqttException)

Aggregations

MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)33 Message (com.applozic.mobicomkit.api.conversation.Message)8 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 Gson (com.google.gson.Gson)5 Contact (com.applozic.mobicommons.people.contact.Contact)4 PersonalizedMessage (com.applozic.mobicommons.personalization.PersonalizedMessage)4 User (com.applozic.mobicomkit.api.account.user.User)3 Channel (com.applozic.mobicommons.people.channel.Channel)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 NonNull (android.support.annotation.NonNull)2 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)2 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)2 InvalidApplicationException (com.applozic.mobicomkit.exception.InvalidApplicationException)2 UnAuthoriseException (com.applozic.mobicomkit.exception.UnAuthoriseException)2 MessageResponse (com.applozic.mobicomkit.feed.MessageResponse)2 SyncMessageFeed (com.applozic.mobicomkit.sync.SyncMessageFeed)2 JsonParser (com.google.gson.JsonParser)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2