use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelFragment method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inviteMessage = Utils.getMetaDataValue(getActivity().getApplicationContext(), SHARE_TEXT);
baseContactService = new AppContactService(getActivity());
mAdapter = new ChannelAdapter(getActivity().getApplicationContext());
if (savedInstanceState != null) {
mSearchTerm = savedInstanceState.getString(SearchManager.QUERY);
}
final Context context = getActivity().getApplicationContext();
mChannelImageLoader = new ImageLoader(context, getListPreferredItemHeight()) {
@Override
protected Bitmap processBitmap(Object data) {
return baseContactService.downloadGroupImage(context, (Channel) data);
}
};
// Set a placeholder loading image for the image loader
mChannelImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
// Add a cache to the image loader
mChannelImageLoader.addImageCache(getActivity().getSupportFragmentManager(), 0.1f);
mChannelImageLoader.setImageFadeIn(false);
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ConversationServiceTest method testDeleteSyncWithChannelReturnSuccess.
@Test
public void testDeleteSyncWithChannelReturnSuccess() {
try {
Channel channel = new Channel();
channel.setKey(000);
Mockito.when(messageClientService.syncDeleteConversationThreadFromServer(null, channel)).thenReturn("success");
Assert.assertEquals("success", mobiComConversationService.deleteSync(null, channel, null));
Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteChannelConversation(ArgumentMatchers.anyInt());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelInfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.channel_info_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String jsonString = FileUtils.loadSettingsJsonFile(getApplicationContext());
if (!TextUtils.isEmpty(jsonString)) {
alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
} else {
alCustomizationSettings = new AlCustomizationSettings();
}
refreshBroadcast = new RefreshBroadcast();
baseContactService = new AppContactService(getApplicationContext());
channelImage = (ImageView) findViewById(R.id.channelImage);
userPreference = MobiComUserPreference.getInstance(this);
createdBy = (TextView) findViewById(R.id.created_by);
groupParticipantsTexView = (TextView) findViewById(R.id.groupParticipantsTexView);
exitChannelButton = (Button) findViewById(R.id.exit_channel);
deleteChannelButton = (Button) findViewById(R.id.delete_channel_button);
channelDeleteRelativeLayout = (RelativeLayout) findViewById(R.id.channel_delete_relativeLayout);
channelExitRelativeLayout = (RelativeLayout) findViewById(R.id.channel_exit_relativeLayout);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
nestedScrollView = findViewById(R.id.nestedScrollView);
textViewGroupDescription = findViewById(R.id.groupDescriptionTexView);
cardViewGroupDescriptionContainer = findViewById(R.id.groupDescriptionCardView);
collapsingToolbarLayout.setContentScrimColor(Color.parseColor(alCustomizationSettings.getCollapsingToolbarLayoutColor()));
groupParticipantsTexView.setTextColor(Color.parseColor(alCustomizationSettings.getGroupParticipantsTextColor()));
deleteChannelButton.setBackgroundColor(Color.parseColor((alCustomizationSettings.getGroupDeleteButtonBackgroundColor())));
exitChannelButton.setBackgroundColor(Color.parseColor(alCustomizationSettings.getGroupExitButtonBackgroundColor()));
mActionBar = getSupportActionBar();
mActionBar.setDisplayHomeAsUpEnabled(true);
mActionBar.setHomeButtonEnabled(true);
mActionBar.setDisplayShowHomeEnabled(true);
mainListView = (ListView) findViewById(R.id.mainList);
mainListView.setLongClickable(true);
mainListView.setSmoothScrollbarEnabled(true);
if (Utils.hasLollipop()) {
mainListView.setNestedScrollingEnabled(true);
}
nestedScrollView.post(new Runnable() {
@Override
public void run() {
nestedScrollView.scrollTo(nestedScrollView.getLeft(), groupParticipantsTexView.getTop());
}
});
connectivityReceiver = new ConnectivityReceiver();
mobiComKitBroadcastReceiver = new MobiComKitBroadcastReceiver(this);
registerForContextMenu(mainListView);
if (alCustomizationSettings.isHideGroupExitButton()) {
channelExitRelativeLayout.setVisibility(View.GONE);
}
if (alCustomizationSettings.isHideGroupDeleteButton()) {
channelDeleteRelativeLayout.setVisibility(View.GONE);
}
if (getIntent().getExtras() != null) {
channelKey = getIntent().getIntExtra(CHANNEL_KEY, 0);
channelUpdateReceiver = getIntent().getParcelableExtra(CHANNEL_UPDATE_RECEIVER);
channel = ChannelService.getInstance(this).getChannelByChannelKey(channelKey);
isUserPresent = ChannelService.getInstance(this).processIsUserPresentInChannel(channelKey);
if (channel != null) {
String title = ChannelUtils.getChannelTitleName(channel, userPreference.getUserId());
if (!TextUtils.isEmpty(channel.getAdminKey())) {
contact = baseContactService.getContactById(channel.getAdminKey());
mActionBar.setTitle(title);
if (userPreference.getUserId().equals(contact.getUserId())) {
createdBy.setText(getString(R.string.channel_created_by) + " " + getString(R.string.you_string));
} else {
createdBy.setText(getString(R.string.channel_created_by) + " " + contact.getDisplayName());
}
}
updateChannelDescriptionUIFrom(channel.getMetadata());
if (!isUserPresent) {
channelExitRelativeLayout.setVisibility(View.GONE);
channelDeleteRelativeLayout.setVisibility(View.VISIBLE);
}
}
}
if (channel != null && channel.getType() != null) {
if (Channel.GroupType.BROADCAST.getValue().equals(channel.getType())) {
deleteChannelButton.setText(R.string.broadcast_delete_button);
exitChannelButton.setText(R.string.broadcast_exit_button);
channelExitRelativeLayout.setVisibility(View.GONE);
channelDeleteRelativeLayout.setVisibility(View.VISIBLE);
} else {
deleteChannelButton.setText(R.string.channel_delete_group_button);
exitChannelButton.setText(R.string.channel_exit_button);
}
}
contactImageLoader = new ImageLoader(getApplicationContext(), getListPreferredItemHeight()) {
@Override
protected Bitmap processBitmap(Object data) {
return baseContactService.downloadContactImage(getApplicationContext(), (Contact) data);
}
};
contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
contactImageLoader.addImageCache(this.getSupportFragmentManager(), 0.1f);
contactImageLoader.setImageFadeIn(false);
channelImageLoader = new ImageLoader(getApplicationContext(), getListPreferredItemHeight()) {
@Override
protected Bitmap processBitmap(Object data) {
return baseContactService.downloadGroupImage(getApplicationContext(), (Channel) data);
}
};
channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
channelImageLoader.addImageCache(this.getSupportFragmentManager(), 0.1f);
channelImageLoader.setImageFadeIn(false);
if (channelImage != null && !channel.isBroadcastMessage()) {
channelImageLoader.loadImage(channel, channelImage);
} else {
channelImage.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
}
channelUserMapperList = ChannelService.getInstance(this).getListOfUsersFromChannelUserMapper(channel.getKey());
contactsAdapter = new ContactsAdapter(this);
mainListView.setAdapter(contactsAdapter);
Helper.getListViewSize(mainListView);
mainListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
// Pause image loader to ensure smoother scrolling when flinging
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
contactImageLoader.setPauseWork(true);
} else {
contactImageLoader.setPauseWork(false);
}
}
@Override
public void onScroll(AbsListView absListView, int i, int i1, int i2) {
}
});
exitChannelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
leaveChannel(channel);
}
});
deleteChannelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteChannel(channel);
}
});
cardViewGroupDescriptionContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isUserPresent && alCustomizationSettings.isEditChannelDescriptionAllowed() && channel != null) {
Intent editChannelNameIntent = new Intent(ChannelInfoActivity.this, EditChannelDescriptionActivity.class);
GroupInfoUpdate groupInfoUpdate = new GroupInfoUpdate(channel.getMetadata(), channel.getKey());
String groupJson = GsonUtils.getJsonFromObject(groupInfoUpdate, GroupInfoUpdate.class);
editChannelNameIntent.putExtra(GROUP_UPDTAE_INFO, groupJson);
startActivityForResult(editChannelNameIntent, REQUEST_CODE_FOR_CHANNEL_NEW_DESCRIPTION);
} else {
Toast.makeText(ChannelInfoActivity.this, alCustomizationSettings.isEditChannelDescriptionAllowed() ? getString(R.string.channel_edit_description_alert) : getString(R.string.editing_channel_description_is_not_allowed), Toast.LENGTH_SHORT).show();
}
}
});
registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ConversationUIService method checkForStartNewConversation.
public void checkForStartNewConversation(Intent intent) {
Contact contact = null;
Channel channel = null;
Integer conversationId = null;
if (Intent.ACTION_SEND.equals(intent.getAction()) && intent.getType() != null) {
if ("text/plain".equals(intent.getType())) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
startContactActivityForResult(null, sharedText);
}
} else if (intent.getType().startsWith("image/")) {
// Todo: use this for image forwarding
}
}
Integer channelKey = intent.getIntExtra(GROUP_ID, -1);
String clientGroupId = intent.getStringExtra(CLIENT_GROUP_ID);
String channelName = intent.getStringExtra(GROUP_NAME);
if (!TextUtils.isEmpty(clientGroupId)) {
channel = ChannelService.getInstance(fragmentActivity).getChannelByClientGroupId(clientGroupId);
if (channel == null) {
return;
}
} else if (channelKey != -1 && channelKey != null && channelKey != 0) {
channel = ChannelService.getInstance(fragmentActivity).getChannel(channelKey);
}
if (channel != null && !TextUtils.isEmpty(channelName) && TextUtils.isEmpty(channel.getName())) {
channel.setName(channelName);
ChannelService.getInstance(fragmentActivity).updateChannel(channel);
}
String userId = intent.getStringExtra(USER_ID);
String fullName = intent.getStringExtra(DISPLAY_NAME);
if (!TextUtils.isEmpty(userId)) {
contact = baseContactService.getContactById(userId);
if (contact != null) {
if (!TextUtils.isEmpty(fullName)) {
Map<String, String> metadata = contact.getMetadata();
if (metadata == null) {
metadata = new HashMap<>();
metadata.put(Contact.AL_DISPLAY_NAME_UPDATED, "false");
contact.setMetadata(metadata);
} else if (!metadata.isEmpty() && !fullName.equals(contact.getDisplayName())) {
metadata.put(Contact.AL_DISPLAY_NAME_UPDATED, "false");
contact.setMetadata(metadata);
}
}
if (!TextUtils.isEmpty(fullName)) {
contact.setFullName(fullName);
}
}
String applicationId = intent.getStringExtra(APPLICATION_ID);
if (contact != null) {
contact.setApplicationId(applicationId);
}
baseContactService.upsert(contact);
}
String searchString = intent.getStringExtra(SEARCH_STRING);
String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
if (!TextUtils.isEmpty(messageJson)) {
Message message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
if (message.getGroupId() != null) {
channel = ChannelService.getInstance(fragmentActivity).getChannelByChannelKey(message.getGroupId());
if (channel.getParentKey() != null && channel.getParentKey() != 0) {
BroadcastService.parentGroupKey = channel.getParentKey();
MobiComUserPreference.getInstance(fragmentActivity).setParentGroupKey(channel.getParentKey());
}
} else {
contact = baseContactService.getContactById(message.getContactIds());
}
conversationId = message.getConversationId();
}
if (conversationId == null) {
conversationId = intent.getIntExtra(CONVERSATION_ID, 0);
}
if (conversationId != 0 && conversationId != null && getConversationFragment() != null) {
getConversationFragment().setConversationId(conversationId);
} else {
conversationId = null;
}
String defaultText = intent.getStringExtra(ConversationUIService.DEFAULT_TEXT);
if (!TextUtils.isEmpty(defaultText) && getConversationFragment() != null) {
getConversationFragment().setDefaultText(defaultText);
}
String forwardMessage = intent.getStringExtra(MobiComKitPeopleActivity.FORWARD_MESSAGE);
if (!TextUtils.isEmpty(forwardMessage)) {
Message messageToForward = (Message) GsonUtils.getObjectFromJson(forwardMessage, Message.class);
if (getConversationFragment() != null) {
getConversationFragment().forwardMessage(messageToForward, contact, channel);
}
}
if (contact != null) {
openConversationFragment(contact, conversationId, searchString, fullName);
}
if (channel != null) {
openConversationFragment(channel, conversationId, searchString, fullName);
}
String productTopicId = intent.getStringExtra(ConversationUIService.PRODUCT_TOPIC_ID);
String productImageUrl = intent.getStringExtra(ConversationUIService.PRODUCT_IMAGE_URL);
if (!TextUtils.isEmpty(productTopicId) && !TextUtils.isEmpty(productImageUrl)) {
try {
FileMeta fileMeta = new FileMeta();
fileMeta.setContentType("image");
fileMeta.setBlobKeyString(productImageUrl);
if (getConversationFragment() != null) {
getConversationFragment().sendProductMessage(productTopicId, fileMeta, contact, Message.ContentType.TEXT_URL.getValue());
}
} catch (Exception e) {
}
}
String sharedText = intent.getStringExtra(MobiComKitPeopleActivity.SHARED_TEXT);
if (!TextUtils.isEmpty(sharedText) && getConversationFragment() != null) {
getConversationFragment().sendMessage(sharedText);
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseService method getChannelByClientGroupId.
/**
* Will get a channel object from the database, corresponding to the passed client group id.
*
* @param clientGroupId the client group id. used to identify a channel (similar to with group id/channel key)
* @return the channel object, null if no such channel exists in database
*/
public Channel getChannelByClientGroupId(String clientGroupId) {
Channel channel = null;
try {
String structuredNameWhere = MobiComDatabaseHelper.CLIENT_GROUP_ID + " =?";
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.query(CHANNEL, null, structuredNameWhere, new String[] { String.valueOf(clientGroupId) }, null, null, null);
try {
if (cursor != null) {
if (cursor.getCount() > 0) {
cursor.moveToFirst();
channel = getChannel(cursor);
}
}
} finally {
if (cursor != null) {
cursor.close();
}
dbHelper.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return channel;
}
Aggregations