use of com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseServiceTest method createDb.
@Before
public void createDb() {
Context context = ApplicationProvider.getApplicationContext();
dbHelper = new MobiComDatabaseHelper(ApplicationProvider.getApplicationContext(), null, null, MobiComDatabaseHelper.DB_VERSION);
channelDatabaseService = ChannelDatabaseService.getTestInstance(context, dbHelper);
messageDatabaseService = new MessageDatabaseService(context, dbHelper);
channel = new Channel();
Map<String, String> metadata = new HashMap<>();
metadata.put("met1", "1");
metadata.put("met2", "2");
channel.setMetadata(metadata);
channel.setKey(12345);
channel.setParentKey(123);
channel.setParentClientGroupId("parentId");
channel.setClientGroupId("clientId");
channel.setName("dname");
channel.setAdminKey("adminKey");
channel.setType((short) 1);
channel.setUnreadCount(10);
channel.setImageUrl("imageUrl");
channel.setLocalImageUri("localImageUri");
channel.setNotificationAfterTime(123456L);
channel.setDeletedAtTime(123456L);
channel.setKmStatus(1);
channel1 = new Channel();
Map<String, String> metadata1 = new HashMap<>();
metadata.put("met11", "1");
metadata.put("met21", "2");
channel1.setMetadata(metadata1);
channel1.setKey(123451);
channel1.setParentKey(1231);
channel1.setParentClientGroupId("parentId1");
channel1.setClientGroupId("clientId");
channel1.setName("bname1");
channel1.setAdminKey("adminKey1");
channel1.setType((short) 11);
channel1.setUnreadCount(101);
channel1.setImageUrl("imageUrl1");
channel1.setLocalImageUri("localImageUri1");
channel1.setNotificationAfterTime(12345L);
channel1.setDeletedAtTime(12345L);
channel1.setKmStatus(11);
channel2 = new Channel();
Map<String, String> metadata2 = new HashMap<>();
metadata.put("met12", "1");
metadata.put("met22", "2");
channel2.setMetadata(metadata2);
channel2.setKey(123452);
channel2.setParentKey(1232);
channel2.setParentClientGroupId("parentId2");
channel2.setClientGroupId("clientId2");
channel2.setName("aname2");
channel2.setAdminKey("adminKey2");
channel2.setType((short) 12);
channel2.setUnreadCount(102);
channel2.setImageUrl("imageUrl2");
channel2.setLocalImageUri("localImageUri2");
channel2.setNotificationAfterTime(1234L);
channel2.setDeletedAtTime(1234L);
channel2.setKmStatus(12);
channel3 = new Channel();
Map<String, String> metadata3 = new HashMap<>();
metadata.put("met13", "1");
metadata.put("met23", "2");
channel3.setMetadata(metadata3);
channel3.setKey(123453);
channel3.setParentKey(1233);
channel3.setParentClientGroupId("parentId3");
channel3.setClientGroupId("clientId3");
channel3.setName("cname3");
channel3.setAdminKey("adminKey3");
channel3.setType((short) 13);
channel3.setUnreadCount(103);
channel3.setImageUrl("imageUrl3");
channel3.setLocalImageUri("localImageUri3");
channel3.setNotificationAfterTime(123L);
channel3.setDeletedAtTime(123L);
channel3.setKmStatus(13);
// ChannelUserMapper objects
channelUserMapper = new ChannelUserMapper();
// for channel1
channelUserMapper.setKey(123451);
channelUserMapper.setUserKey("clientId");
channelUserMapper.setUnreadCount(20);
channelUserMapper.setStatus((short) 2);
channelUserMapper.setParentKey(123);
channelUserMapper.setRole(4);
channelUserMapper1 = new ChannelUserMapper();
// for channel1
channelUserMapper1.setKey(123451);
channelUserMapper1.setUserKey("clientId1");
channelUserMapper1.setUnreadCount(201);
channelUserMapper1.setStatus((short) 2);
channelUserMapper1.setParentKey(1231);
channelUserMapper1.setRole(41);
channelUserMapper2 = new ChannelUserMapper();
// for channel2
channelUserMapper2.setKey(123452);
channelUserMapper2.setUserKey("clientId2");
channelUserMapper2.setUnreadCount(202);
channelUserMapper2.setStatus((short) 3);
channelUserMapper2.setParentKey(1232);
channelUserMapper2.setRole(42);
}
use of com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService in project Applozic-Android-SDK by AppLozic.
the class ScheduleMessageService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
Calendar c = Calendar.getInstance();
long time = c.getTimeInMillis();
MessageDatabaseService messageDatabaseService = new MessageDatabaseService(getApplicationContext());
MobiComConversationService conversationService = new MobiComConversationService(getApplicationContext());
List<Message> messages = messageDatabaseService.getScheduledMessages(time);
for (Message message : messages) {
message.setScheduledAt(null);
conversationService.sendMessage(message);
// Todo: broadcast for scheduled message fragment.
}
messageDatabaseService.deleteScheduledMessages(time);
}
use of com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService in project Applozic-Android-SDK by AppLozic.
the class MobiComQuickConversationFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String jsonString = FileUtils.loadSettingsJsonFile(ApplozicService.getContext(getContext()));
if (!TextUtils.isEmpty(jsonString)) {
alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
} else {
alCustomizationSettings = new AlCustomizationSettings();
}
syncCallService = SyncCallService.getInstance(getActivity());
conversationUIService = new ConversationUIService(getActivity());
baseContactService = new AppContactService(getActivity());
messageDatabaseService = new MessageDatabaseService(getActivity());
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
MobiComUserPreference.getInstance(getActivity()).setDeviceTimeOffset(DateUtils.getTimeDiffFromUtc());
}
});
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
setHasOptionsMenu(true);
BroadcastService.lastIndexForChats = 0;
}
use of com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService in project Applozic-Android-SDK by AppLozic.
the class AttachmentDownloader method loadAttachmentImage.
public void loadAttachmentImage(Message message, Context context) {
File file = null;
HttpURLConnection connection = null;
InputStream inputStream = null;
OutputStream output = null;
try {
FileMeta fileMeta = message.getFileMetas();
String contentType = fileMeta.getContentType();
String fileName = null;
if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
fileName = fileMeta.getName();
} else {
fileName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
}
file = FileClientService.getFilePath(fileName, context.getApplicationContext(), contentType);
try {
if (!file.exists()) {
connection = new URLServiceProvider(context).getDownloadConnection(message);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK || connection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
inputStream = connection.getInputStream();
} else {
// TODO: Error Handling...
Utils.printLog(context, TAG, "Got Error response while uploading file : " + connection.getResponseCode());
return;
}
output = new FileOutputStream(file);
byte[] data = new byte[1024];
long totalSize = fileMeta.getSize();
long progressCount = 0;
int count = 0;
int prevPrecentage = 0;
while ((count = inputStream.read(data)) != -1) {
output.write(data, 0, count);
progressCount = progressCount + count;
long percentage = progressCount * 100 / totalSize;
android.os.Message msg = new android.os.Message();
// Message code 2 represents image is successfully downloaded....
if (percentage + 1 != prevPrecentage) {
mPhotoTask.handleDownloadState(5);
mPhotoTask.downloadProgress((int) percentage + 1);
msg.what = 5;
msg.arg1 = (int) percentage + 1;
msg.obj = this;
// msg.sendToTarget();
prevPrecentage = (int) percentage + 1;
}
if ((percentage % 10 == 0)) {
msg.what = 1;
msg.obj = this;
}
if (Thread.interrupted()) {
if (file != null && file.exists()) {
file.delete();
Utils.printLog(context, TAG, "Downloading cancelled : " + file.getAbsolutePath());
}
throw new InterruptedException();
}
}
output.flush();
}
} finally {
if (output != null) {
output.close();
}
if (inputStream != null) {
inputStream.close();
}
}
// Todo: Fix this, so that attach package can be moved to mobicom mobicom.
new MessageDatabaseService(context).updateInternalFilePath(message.getKeyString(), file.getAbsolutePath());
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add(file.getAbsolutePath());
message.setFilePaths(arrayList);
MediaScannerConnection.scanFile(mPhotoTask.getContext(), new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch (FileNotFoundException ex) {
ex.printStackTrace();
Utils.printLog(context, TAG, "File not found on server");
} catch (Exception ex) {
// If partial file got created delete it, we try to download it again
if (file != null && file.exists()) {
Utils.printLog(context, TAG, " Exception occured while downloading :" + file.getAbsolutePath());
file.delete();
}
ex.printStackTrace();
Utils.printLog(context, TAG, "Exception fetching file from server");
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
use of com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService in project Applozic-Android-SDK by AppLozic.
the class ApplozicDocumentView method registerEvents.
public void registerEvents() {
previewLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (alStoragePermissionListener.isPermissionGranted()) {
if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
// Starts downloading this View, using the current cache setting
mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
// After successfully downloading the image, this marks that it's available.
showDownloadInProgress();
}
if (mDownloadThread == null) {
mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
if (mDownloadThread != null)
mDownloadThread.setAttachementViewNew(attachmentViewProperties);
}
} else {
alStoragePermissionListener.checkPermission(new ALStoragePermission() {
@Override
public void onAction(boolean didGrant) {
if (didGrant) {
if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
// Starts downloading this View, using the current cache setting
mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
// After successfully downloading the image, this marks that it's available.
showDownloadInProgress();
}
if (mDownloadThread == null) {
mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
if (mDownloadThread != null)
mDownloadThread.setAttachementViewNew(attachmentViewProperties);
}
}
}
});
}
}
});
downloadedLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (alStoragePermissionListener.isPermissionGranted()) {
playAudio();
} else {
alStoragePermissionListener.checkPermission(new ALStoragePermission() {
@Override
public void onAction(boolean didGrant) {
if (didGrant) {
playAudio();
}
}
});
}
}
});
downloadInProgressLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cancelDownload();
}
});
retryLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
message.setCanceled(false);
MessageDatabaseService messageDatabaseService = new MessageDatabaseService(context);
messageDatabaseService.updateCanceledFlag(message.getMessageId(), 0);
new MobiComConversationService(context).sendMessage(message, null);
showDownloadInProgress();
}
});
}
Aggregations