Search in sources :

Example 11 with FileClientService

use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.

the class MessageInfoFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    contactService = new AppContactService(getContext());
    fileClientService = new FileClientService(getContext());
    geoApiKey = Applozic.getInstance(getContext()).getGeoApiKey();
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService)

Example 12 with FileClientService

use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method getMessages.

public synchronized List<Message> getMessages(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId, boolean isSkipRead) {
    List<Message> messageList = new ArrayList<Message>();
    List<Message> cachedMessageList = messageDatabaseService.getMessages(startTime, endTime, contact, channel, conversationId);
    boolean isServerCallNotRequired = false;
    if (channel != null) {
        Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(channel.getKey());
        isServerCallNotRequired = (newChannel != null && !Channel.GroupType.OPEN.getValue().equals(newChannel.getType()));
    } else if (contact != null) {
        isServerCallNotRequired = true;
    }
    if (isServerCallNotRequired && (!cachedMessageList.isEmpty() && (cachedMessageList.size() > 1 || wasServerCallDoneBefore(contact, channel, conversationId)) || (contact == null && channel == null && cachedMessageList.isEmpty() && wasServerCallDoneBefore(contact, channel, conversationId)))) {
        Utils.printLog(context, TAG, "cachedMessageList size is : " + cachedMessageList.size());
        return cachedMessageList;
    }
    String data;
    try {
        data = messageClientService.getMessages(contact, channel, startTime, endTime, conversationId, isSkipRead);
        Utils.printLog(context, TAG, "Received response from server for Messages: " + data);
    } catch (Exception ex) {
        ex.printStackTrace();
        return cachedMessageList;
    }
    if (data == null || TextUtils.isEmpty(data) || data.equals("UnAuthorized Access") || !data.contains("{")) {
        // Note: currently not supporting syncing old channel messages from server
        if (channel != null && channel.getKey() != null) {
            return cachedMessageList;
        }
        return cachedMessageList;
    }
    updateServerCallDoneStatus(contact, channel, conversationId);
    try {
        Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).setExclusionStrategies(new AnnotationExclusionStrategy()).create();
        JsonParser parser = new JsonParser();
        JSONObject jsonObject = new JSONObject(data);
        String channelFeedResponse = "";
        String conversationPxyResponse = "";
        String element = parser.parse(data).getAsJsonObject().get("message").toString();
        String userDetailsElement = parser.parse(data).getAsJsonObject().get("userDetails").toString();
        if (!TextUtils.isEmpty(userDetailsElement)) {
            UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(userDetailsElement, UserDetail[].class);
            processUserDetails(userDetails);
        }
        if (jsonObject.has("groupFeeds")) {
            channelFeedResponse = parser.parse(data).getAsJsonObject().get("groupFeeds").toString();
            ChannelFeed[] channelFeeds = (ChannelFeed[]) GsonUtils.getObjectFromJson(channelFeedResponse, ChannelFeed[].class);
            ChannelService.getInstance(context).processChannelFeedList(channelFeeds, false);
            if (channel != null && !isServerCallNotRequired) {
                BroadcastService.sendUpdate(context, BroadcastService.INTENT_ACTIONS.UPDATE_TITLE_SUBTITLE.toString());
            }
        }
        if (jsonObject.has("conversationPxys")) {
            conversationPxyResponse = parser.parse(data).getAsJsonObject().get("conversationPxys").toString();
            Conversation[] conversationPxy = (Conversation[]) GsonUtils.getObjectFromJson(conversationPxyResponse, Conversation[].class);
            ConversationService.getInstance(context).processConversationArray(conversationPxy, channel, contact);
        }
        Message[] messages = gson.fromJson(element, Message[].class);
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
        if (messages != null && messages.length > 0 && cachedMessageList.size() > 0 && cachedMessageList.get(0).isLocalMessage()) {
            if (cachedMessageList.get(0).equals(messages[0])) {
                Utils.printLog(context, TAG, "Both messages are same.");
                deleteMessage(cachedMessageList.get(0));
            }
        }
        for (Message message : messages) {
            if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
                // we have to figure out if it is a parsing problem or response from server.
                if (message.getTo() == null) {
                    continue;
                }
                if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(message);
                }
                if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(message);
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
                    messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
                } else {
                    if (isServerCallNotRequired || contact == null && channel == null) {
                        messageDatabaseService.createMessage(message);
                    }
                }
                if (contact == null && channel == null) {
                    if (message.isHidden()) {
                        if (message.getGroupId() != null) {
                            Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                            if (newChannel != null) {
                                getMessages(null, null, null, newChannel, null, true);
                            }
                        } else {
                            getMessages(null, null, new Contact(message.getContactIds()), null, null, true);
                        }
                    }
                }
            }
            if (!isServerCallNotRequired) {
                messageList.add(message);
            }
        }
        if (contact == null && channel == null) {
            Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*   messageList.removeAll(cachedMessageList);
        messageList.addAll(cachedMessageList);

        Collections.sort(messageList, new Comparator<Message>() {
            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });*/
    List<Message> finalMessageList = messageDatabaseService.getMessages(startTime, endTime, contact, channel, conversationId);
    List<String> messageKeys = new ArrayList<>();
    for (Message msg : finalMessageList) {
        if (msg.getTo() == null) {
            continue;
        }
        if (Message.MetaDataType.HIDDEN.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
            continue;
        }
        if (msg.getMetadata() != null && msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
    }
    if (messageKeys != null && messageKeys.size() > 0) {
        Message[] replyMessageList = getMessageListByKeyList(messageKeys);
        if (replyMessageList != null) {
            for (Message replyMessage : replyMessageList) {
                if (replyMessage.getTo() == null) {
                    continue;
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(replyMessage);
                }
                if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(replyMessage);
                }
                replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                if (isServerCallNotRequired || contact == null && channel == null) {
                    messageDatabaseService.createMessage(replyMessage);
                }
            }
        }
    }
    if (messageList != null && !messageList.isEmpty()) {
        Collections.sort(messageList, new Comparator<Message>() {

            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });
    }
    return channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType()) ? messageList : finalMessageList;
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Conversation(com.applozic.mobicommons.people.channel.Conversation) UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) AnnotationExclusionStrategy(com.applozic.mobicommons.json.AnnotationExclusionStrategy) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) JsonParser(com.google.gson.JsonParser) GsonBuilder(com.google.gson.GsonBuilder) Channel(com.applozic.mobicommons.people.channel.Channel) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact) ArrayAdapterFactory(com.applozic.mobicommons.json.ArrayAdapterFactory) JSONObject(org.json.JSONObject)

Example 13 with FileClientService

use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method getAlConversationList.

/**
 * @deprecated This method is no longer used and will be deprecated soon.
 */
@Deprecated
public synchronized List<Message> getAlConversationList(int status, int pageSize, Long lastFetchTime, boolean makeServerCall) throws Exception {
    List<Message> conversationList = new ArrayList<>();
    List<Message> cachedConversationList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
    if (!makeServerCall && !cachedConversationList.isEmpty()) {
        return cachedConversationList;
    }
    AlConversationResponse alConversationResponse = null;
    try {
        ApiResponse<AlConversationResponse> apiResponse = (ApiResponse<AlConversationResponse>) GsonUtils.getObjectFromJson(messageClientService.getAlConversationList(status, pageSize, lastFetchTime), new TypeToken<ApiResponse<AlConversationResponse>>() {
        }.getType());
        if (apiResponse != null) {
            alConversationResponse = apiResponse.getResponse();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    if (alConversationResponse == null) {
        return null;
    }
    try {
        if (alConversationResponse.getUserDetails() != null) {
            processUserDetails(alConversationResponse.getUserDetails());
        }
        if (alConversationResponse.getGroupFeeds() != null) {
            ChannelService.getInstance(context).processChannelFeedList(alConversationResponse.getGroupFeeds(), false);
        }
        Message[] messages = alConversationResponse.getMessage();
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
        if (messages != null && messages.length > 0 && cachedConversationList.size() > 0 && cachedConversationList.get(0).isLocalMessage()) {
            if (cachedConversationList.get(0).equals(messages[0])) {
                Utils.printLog(context, TAG, "Both messages are same.");
                deleteMessage(cachedConversationList.get(0));
            }
        }
        for (Message message : messages) {
            if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
                if (message.getTo() == null) {
                    continue;
                }
                if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(message);
                }
                if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(message);
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (isHideActionMessage && message.isActionMessage()) {
                    message.setHidden(true);
                }
                if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
                    messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
                } else {
                    messageDatabaseService.createMessage(message);
                }
                if (message.hasHideKey()) {
                    if (message.getGroupId() != null) {
                        Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                        if (newChannel != null) {
                            getMessagesWithNetworkMetaData(null, null, null, newChannel, null, true, false);
                        }
                    } else {
                        getMessagesWithNetworkMetaData(null, null, new Contact(message.getContactIds()), null, null, true, false);
                    }
                }
            }
            conversationList.add(message);
        }
        Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    List<Message> finalMessageList = messageDatabaseService.getAlConversationList(status, lastFetchTime);
    List<String> messageKeys = new ArrayList<>();
    for (Message msg : finalMessageList) {
        if (msg.getTo() == null) {
            continue;
        }
        if (Message.MetaDataType.HIDDEN.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
            continue;
        }
        if (msg.getMetadata() != null && msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
    }
    if (messageKeys != null && messageKeys.size() > 0) {
        Message[] replyMessageList = getMessageListByKeyList(messageKeys);
        if (replyMessageList != null) {
            for (Message replyMessage : replyMessageList) {
                if (replyMessage.getTo() == null) {
                    continue;
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(replyMessage);
                }
                if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(replyMessage);
                }
                replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                messageDatabaseService.createMessage(replyMessage);
            }
        }
    }
    if (!conversationList.isEmpty()) {
        Collections.sort(conversationList, new Comparator<Message>() {

            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });
    }
    return finalMessageList;
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) JsonSyntaxException(com.google.gson.JsonSyntaxException) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 14 with FileClientService

use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.

the class NotificationService method notifyUserForNormalMessage.

// Cleanup: rename to a public api method eg: createApplozicMessageNotification()
public void notifyUserForNormalMessage(Contact contact, Channel channel, Message message, int index) {
    String notificationText;
    NotificationInfo notificationInfo = getNotificationInfo(contact, channel, message);
    if (notificationInfo == null) {
        return;
    }
    Bitmap notificationIconBitmap = notificationInfo.notificationIconBitmap;
    Contact displayNameContact = notificationInfo.displayNameContact;
    if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
        notificationText = getText(0);
    } else if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
        notificationText = getText(1);
    } else if (message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) {
        notificationText = getText(2);
    } else if (message.hasAttachment() && TextUtils.isEmpty(message.getMessage())) {
        notificationText = getText(3);
    } else {
        notificationText = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, null).toString();
    }
    Class activity = null;
    try {
        activity = Class.forName(activityToOpen);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    Intent intent = new Intent(context, activity);
    intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
    if (applozicClient.isChatListOnNotificationIsHidden()) {
        intent.putExtra("takeOrder", true);
    }
    if (applozicClient.isContextBasedChat()) {
        intent.putExtra("contextBasedChat", true);
    }
    intent.putExtra("sms_body", "text");
    intent.setType("vnd.android-dir/mms-sms");
    PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) (System.currentTimeMillis() & 0xfffffff), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, notificationChannels.getDefaultChannelId(muteNotifications(index)));
    mBuilder.setSmallIcon(notificationInfo.smallIconResourceId).setLargeIcon(ApplozicClient.getInstance(context).isShowAppIconInNotification() ? BitmapFactory.decodeResource(context.getResources(), iconResourceId) : notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(channel != null && !(Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) || Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName()))).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(muteNotifications(index) ? NotificationCompat.PRIORITY_LOW : NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis()).setContentTitle(notificationInfo.title).setContentText(channel != null && !(Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) || Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) ? (displayNameContact != null ? (displayNameContact.getDisplayName() + ": " + getSpannedText(notificationText)) : "" + getSpannedText(notificationText)) : getSpannedText(notificationText));
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setAutoCancel(true);
    if (notificationInfo.colorResourceId != null && notificationInfo.colorResourceId > 0) {
        mBuilder.setColor(context.getResources().getColor(notificationInfo.colorResourceId));
    }
    if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
        int totalCount = messageDatabaseService.getTotalUnreadCount();
        if (totalCount != 0) {
            mBuilder.setNumber(totalCount);
        }
    }
    if (!muteNotifications(index)) {
        mBuilder.setSound(TextUtils.isEmpty(notificationFilePath) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationFilePath));
    }
    if (message.hasAttachment()) {
        try {
            FileMeta fileMeta = message.getFileMetas();
            HttpURLConnection httpConn = null;
            if (fileMeta.getThumbnailBlobKey() != null) {
                Bitmap bitmap = new FileClientService(context).downloadAndSaveThumbnailImage(context, message, 200, 200);
                mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    WearableNotificationWithVoice notificationWithVoice = new WearableNotificationWithVoice(mBuilder, wearable_action_title, wearable_action_label, wearable_send_icon, message.getGroupId() != null ? String.valueOf(message.getGroupId()).hashCode() : message.getContactIds().hashCode());
    notificationWithVoice.setCurrentContext(context);
    notificationWithVoice.setPendingIntent(pendingIntent);
    try {
        notificationWithVoice.sendNotification();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Contact(com.applozic.mobicommons.people.contact.Contact) Bitmap(android.graphics.Bitmap) HttpURLConnection(java.net.HttpURLConnection) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 15 with FileClientService

use of com.applozic.mobicomkit.api.attachment.FileClientService in project Applozic-Android-SDK by AppLozic.

the class ChannelNameActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.update_channel_name_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(toolbar);
    mActionBar = getSupportActionBar();
    layout = (LinearLayout) findViewById(R.id.footerAd);
    applozicPermissions = new ApplozicPermissions(this, layout);
    mActionBar.setTitle(getString(R.string.update_channel_title_name));
    selectImageProfileIcon = (CircleImageView) findViewById(R.id.applozic_group_profile_camera);
    applozicGroupProfileIcon = (ImageView) findViewById(R.id.applozic_group_profile);
    String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
    fileClientService = new FileClientService(this);
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    if (!TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimary()) && !TextUtils.isEmpty(alCustomizationSettings.getThemeColorPrimaryDark())) {
        mActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(alCustomizationSettings.getThemeColorPrimary())));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.parseColor(alCustomizationSettings.getThemeColorPrimaryDark()));
        }
    }
    int drawableResourceId = getResources().getIdentifier(alCustomizationSettings.getAttachCameraIconName(), "drawable", getPackageName());
    selectImageProfileIcon.setImageResource(drawableResourceId);
    if (getIntent().getExtras() != null) {
        String groupInfoJson = getIntent().getExtras().getString(ChannelInfoActivity.GROUP_UPDTAE_INFO);
        groupInfoUpdate = (GroupInfoUpdate) GsonUtils.getObjectFromJson(groupInfoJson, GroupInfoUpdate.class);
    }
    if (groupInfoUpdate != null && !TextUtils.isEmpty(groupInfoUpdate.getLocalImagePath())) {
        File file = new File(groupInfoUpdate.getLocalImagePath());
        Uri uri = Uri.parse(file.getAbsolutePath());
        if (uri != null) {
            Utils.printLog(this, "ChannelNameActivity::", uri.toString());
            applozicGroupProfileIcon.setImageURI(uri);
        }
    } else {
        applozicGroupProfileIcon.setImageResource(R.drawable.applozic_group_icon);
    }
    channelName = (EditText) findViewById(R.id.newChannelName);
    channelName.setText(groupInfoUpdate.getNewName());
    ok = (Button) findViewById(R.id.channelNameOk);
    cancel = (Button) findViewById(R.id.channelNameCancel);
    selectImageProfileIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            processImagePicker();
        }
    });
    ok.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (channelName.getText().toString().equals(groupInfoUpdate.getNewName()) && imageChangeUri == null || groupInfoUpdate.getNewName() == null) {
                ChannelNameActivity.this.finish();
            }
            if (TextUtils.isEmpty(channelName.getText().toString()) || channelName.getText().toString().trim().length() == 0) {
                Toast.makeText(ChannelNameActivity.this, getString(R.string.channel_name_empty), Toast.LENGTH_SHORT).show();
                ChannelNameActivity.this.finish();
            } else {
                Intent intent = new Intent();
                groupInfoUpdate.setNewName(channelName.getText().toString());
                if (imageChangeUri != null && profilePhotoFile != null) {
                    groupInfoUpdate.setNewlocalPath(profilePhotoFile.getAbsolutePath());
                    groupInfoUpdate.setContentUri(imageChangeUri.toString());
                }
                intent.putExtra(ChannelInfoActivity.GROUP_UPDTAE_INFO, GsonUtils.getJsonFromObject(groupInfoUpdate, GroupInfoUpdate.class));
                setResult(RESULT_OK, intent);
                finish();
            }
        }
    });
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ChannelNameActivity.this.finish();
        }
    });
    connectivityReceiver = new ConnectivityReceiver();
    registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
Also used : IntentFilter(android.content.IntentFilter) AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) ApplozicPermissions(com.applozic.mobicomkit.uiwidgets.instruction.ApplozicPermissions) ConnectivityReceiver(com.applozic.mobicomkit.broadcast.ConnectivityReceiver) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) Uri(android.net.Uri) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) File(java.io.File) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)15 Intent (android.content.Intent)7 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)7 Contact (com.applozic.mobicommons.people.contact.Contact)7 Channel (com.applozic.mobicommons.people.channel.Channel)6 ArrayList (java.util.ArrayList)6 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)5 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)5 Gson (com.google.gson.Gson)5 JsonParser (com.google.gson.JsonParser)5 Message (com.applozic.mobicomkit.api.conversation.Message)4 AlCustomizationSettings (com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings)4 JSONException (org.json.JSONException)4 IntentFilter (android.content.IntentFilter)3 Bitmap (android.graphics.Bitmap)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 ConnectivityReceiver (com.applozic.mobicomkit.broadcast.ConnectivityReceiver)3 JsonObject (com.google.gson.JsonObject)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3