From cfae78eba36d4a6af668118445753558c8e4e53c Mon Sep 17 00:00:00 2001 From: Rafael da Veiga Cabral Date: Thu, 21 May 2020 18:00:22 -0300 Subject: [PATCH 01/21] NY9868: [AN]: Use try and finally to protect the cursorFeatures at DbHelper --- .../mobile/communicator/data/db/DbHelper.java | 1338 +++++++++++------ 1 file changed, 837 insertions(+), 501 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java b/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java index e04dc92f74..a98c8f51af 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java @@ -182,34 +182,45 @@ public class DbHelper { } public PushNotificationCounter getPush(@NonNull String uniqueId) { - Cursor cursor = mDb.query("SELECT * FROM " + PushTable.TABLE_NAME + " WHERE " + PushTable.Column.UNIQUE_ID + " = '" + uniqueId + "'"); - if (cursor != null) { - PushNotificationCounter p = null; - if (cursor.getCount() != 0) { - cursor.moveToFirst(); - p = PushTable.parseCursor(cursor); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + PushTable.TABLE_NAME + " WHERE " + PushTable.Column.UNIQUE_ID + " = '" + uniqueId + "'"); + if (cursor != null) { + PushNotificationCounter p = null; + if (cursor.getCount() != 0) { + cursor.moveToFirst(); + p = PushTable.parseCursor(cursor); + } + return p; + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); - return p; } return null; } public PushNotificationCounter getPush(@NonNull String uniqueId, @NonNull String type) { - Cursor cursor = mDb.query("SELECT * FROM " + PushTable.TABLE_NAME + " WHERE " + PushTable.Column.UNIQUE_ID + " = '" + uniqueId + "'"); - if (cursor == null || cursor.getCount() == 0) { - if (cursor != null) cursor.close(); - PushNotificationCounter p = new PushNotificationCounter(); - p.count = 1; - p.uniqueId = uniqueId; - p.type = type; - p.id = mDb.insert(PushTable.TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, PushTable.toContentValues(p)); - return p; - } else { - cursor.moveToFirst(); - PushNotificationCounter p = PushTable.parseCursor(cursor); - cursor.close(); - return p; + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + PushTable.TABLE_NAME + " WHERE " + PushTable.Column.UNIQUE_ID + " = '" + uniqueId + "'"); + if (cursor == null || cursor.getCount() == 0) { + PushNotificationCounter p = new PushNotificationCounter(); + p.count = 1; + p.uniqueId = uniqueId; + p.type = type; + p.id = mDb.insert(PushTable.TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, PushTable.toContentValues(p)); + return p; + } else { + cursor.moveToFirst(); + PushNotificationCounter p = PushTable.parseCursor(cursor); + return p; + } + } finally { + if (cursor != null) { + cursor.close(); + } } } @@ -304,16 +315,22 @@ public class DbHelper { @VisibleForTesting public List getLocalContacts() { List localContacts = new ArrayList<>(); - Cursor cursor = mDb.query("SELECT * FROM " - + LocalContactsTable.TABLE_NAME + " WHERE " - + LocalContactsTable.Column.PHONE_ID + " !='' ORDER BY " - + LocalContactsTable.Column.DISPLAY_NAME + " ASC"); - if (cursor != null) { - while (cursor.moveToNext()) { - LocalContact localContact = LocalContactsTable.parseCursor(cursor); - localContacts.add(localContact); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + + LocalContactsTable.TABLE_NAME + " WHERE " + + LocalContactsTable.Column.PHONE_ID + " !='' ORDER BY " + + LocalContactsTable.Column.DISPLAY_NAME + " ASC"); + if (cursor != null) { + while (cursor.moveToNext()) { + LocalContact localContact = LocalContactsTable.parseCursor(cursor); + localContacts.add(localContact); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return localContacts; } @@ -329,46 +346,64 @@ public class DbHelper { public Completable clearTables() { return Completable.fromAction(() -> { - Cursor cursor = mDb.query("SELECT name FROM sqlite_master WHERE type IS 'table'" + - " AND name NOT IN ('sqlite_master', 'sqlite_sequence', 'android_metadata')"); - if (cursor == null) return; - String[] tables = new String[cursor.getCount()]; - int i = 0; - while (cursor.moveToNext()) { - tables[i++] = cursor.getString(0); - } - cursor.close(); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT name FROM sqlite_master WHERE type IS 'table'" + + " AND name NOT IN ('sqlite_master', 'sqlite_sequence', 'android_metadata')"); + if (cursor == null) return; + String[] tables = new String[cursor.getCount()]; + int i = 0; + while (cursor.moveToNext()) { + tables[i++] = cursor.getString(0); + } - for (String table : tables) { - String dropQuery = "DELETE FROM " + table; - mDb.execute(dropQuery); + for (String table : tables) { + String dropQuery = "DELETE FROM " + table; + mDb.execute(dropQuery); + } + } finally { + if (cursor != null) { + cursor.close(); + } } }); } public AuthModel getAuth() { - Cursor cursor = mDb.query("SELECT * FROM " + AuthTable.TABLE_NAME); + Cursor cursor = null; AuthModel auth = null; - if (cursor != null) { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - auth = AuthTable.parseCursor(cursor); - auth.settings = getAuthFeatures(auth); + try { + cursor = mDb.query("SELECT * FROM " + AuthTable.TABLE_NAME); + if (cursor != null) { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + auth = AuthTable.parseCursor(cursor); + auth.settings = getAuthFeatures(auth); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return auth; } public ProfileModel getProfile() { ProfileModel profile = null; - Cursor cursor = mDb.query("SELECT * FROM " + ProfileTable.TABLE_NAME); - if (cursor != null) { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - profile = ProfileTable.parseCursor(cursor); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ProfileTable.TABLE_NAME); + if (cursor != null) { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + profile = ProfileTable.parseCursor(cursor); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return profile; } @@ -1173,15 +1208,21 @@ public class DbHelper { public List getAuthFeatures(AuthModel auth) { ArrayList services = new ArrayList<>(); - final Cursor cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_AUTH + "' AND " + - FeatureTable.Column.TARGET_ID + " = '" + auth.devKey + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - final FeatureModel feature = FeatureTable.parseCursor(cursor); - services.add(feature); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_AUTH + "' AND " + + FeatureTable.Column.TARGET_ID + " = '" + auth.devKey + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + final FeatureModel feature = FeatureTable.parseCursor(cursor); + services.add(feature); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return services; } @@ -1189,15 +1230,21 @@ public class DbHelper { private List getContactFeatures(String ids) { ArrayList services = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_CONTACT + "' AND " + - FeatureTable.Column.TARGET_ID + " IN (" + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final FeatureModel feature = FeatureTable.parseCursor(cursor); - services.add(feature); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_CONTACT + "' AND " + + FeatureTable.Column.TARGET_ID + " IN (" + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final FeatureModel feature = FeatureTable.parseCursor(cursor); + services.add(feature); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return services; @@ -1206,15 +1253,21 @@ public class DbHelper { private List getJobFeatures(String ids) { List services = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_JOB + "' AND " + - FeatureTable.Column.TARGET_ID + " IN (" + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final FeatureModel feature = FeatureTable.parseCursor(cursor); - services.add(feature); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_JOB + "' AND " + + FeatureTable.Column.TARGET_ID + " IN (" + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final FeatureModel feature = FeatureTable.parseCursor(cursor); + services.add(feature); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return services; @@ -1223,14 +1276,20 @@ public class DbHelper { private List getContactsByIDs(String ids) { List contacts = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.PHONE_ID + " IN (" + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final ContactModel feature = ContactsTable.parseCursor(cursor); - contacts.add(feature); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.PHONE_ID + " IN (" + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final ContactModel feature = ContactsTable.parseCursor(cursor); + contacts.add(feature); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return contacts; @@ -1259,32 +1318,44 @@ public class DbHelper { } private void getMemberFeatures(MemberModel member) { - final Cursor cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE (" + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_MEMBER + "' OR " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_CONTACT + "')" + - " AND " + - "(" + FeatureTable.Column.TARGET_ID + " = '" + member.id + "' OR " + - FeatureTable.Column.TARGET_ID + " = '" + member.phone_id + "')" ); - if (cursor != null) { - while (cursor.moveToNext()) { - member.settings.add(FeatureTable.parseCursor(cursor)); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE (" + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_MEMBER + "' OR " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_CONTACT + "')" + + " AND " + + "(" + FeatureTable.Column.TARGET_ID + " = '" + member.id + "' OR " + + FeatureTable.Column.TARGET_ID + " = '" + member.phone_id + "')" ); + if (cursor != null) { + while (cursor.moveToNext()) { + member.settings.add(FeatureTable.parseCursor(cursor)); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } private void setMemberServices(MemberModel member) { ArrayList services = new ArrayList<>(); if (member != null) { - final Cursor cursor = mDb.query("SELECT * FROM " + ServiceTable.TABLE_NAME + " WHERE " + - ServiceTable.Column.TARGET_TYPE + " = '" + ServiceTable.TYPE_MEMBER + "' AND " + - ServiceTable.Column.TARGET_ID + " = '" + member.id + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - final ServiceModel service = ServiceTable.parseCursor(cursor); - member.services.add(ServiceTable.parseCursor(cursor)); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ServiceTable.TABLE_NAME + " WHERE " + + ServiceTable.Column.TARGET_TYPE + " = '" + ServiceTable.TYPE_MEMBER + "' AND " + + ServiceTable.Column.TARGET_ID + " = '" + member.id + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + final ServiceModel service = ServiceTable.parseCursor(cursor); + member.services.add(ServiceTable.parseCursor(cursor)); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } } @@ -1292,17 +1363,23 @@ public class DbHelper { private List getMemberFeatures(String ids) { ArrayList services = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE (" + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_MEMBER + "' OR " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_CONTACT + "')" + - " AND " + - FeatureTable.Column.TARGET_ID + " IN ( " + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final FeatureModel feature = FeatureTable.parseCursor(cursor); - services.add(feature); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE (" + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_MEMBER + "' OR " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_CONTACT + "')" + + " AND " + + FeatureTable.Column.TARGET_ID + " IN ( " + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final FeatureModel feature = FeatureTable.parseCursor(cursor); + services.add(feature); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return services; @@ -1328,15 +1405,21 @@ public class DbHelper { private List getServices(String ids, int type) { ArrayList services = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query("SELECT * FROM " + ServiceTable.TABLE_NAME + " WHERE " + - ServiceTable.Column.TARGET_TYPE + " = '" + type + "' AND " + - ServiceTable.Column.TARGET_ID + " IN ( " + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final ServiceModel service = ServiceTable.parseCursor(cursor); - services.add(service); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ServiceTable.TABLE_NAME + " WHERE " + + ServiceTable.Column.TARGET_TYPE + " = '" + type + "' AND " + + ServiceTable.Column.TARGET_ID + " IN ( " + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final ServiceModel service = ServiceTable.parseCursor(cursor); + services.add(service); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return services; @@ -1345,16 +1428,22 @@ public class DbHelper { public ContactModel getContactsByNickname(String nickname) { ContactModel contact = null; if (StringUtils.isNotEmpty(nickname)) { - final Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE LOWER(" + - ContactsTable.Column.NICK + ") = '" + nickname.toLowerCase() + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - contact = ContactsTable.parseCursor(cursor); - break; + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE LOWER(" + + ContactsTable.Column.NICK + ") = '" + nickname.toLowerCase() + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + contact = ContactsTable.parseCursor(cursor); + break; + } + if (contact != null) { + setContactData(contact); + } } - cursor.close(); - if (contact != null) { - setContactData(contact); + } finally { + if (cursor != null) { + cursor.close(); } } } @@ -1365,16 +1454,22 @@ public class DbHelper { ContactModel contact = null; if (StringUtils.isNotEmpty(phoneNumber)) { String phone = phoneNumber + "_%"; - final Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.PHONE_ID + " LIKE '" + phone + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - contact = ContactsTable.parseCursor(cursor); - break; + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.PHONE_ID + " LIKE '" + phone + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + contact = ContactsTable.parseCursor(cursor); + break; + } + if (contact != null) { + setContactData(contact); + } } - cursor.close(); - if (contact != null) { - setContactData(contact); + } finally { + if (cursor != null) { + cursor.close(); } } } @@ -1389,21 +1484,27 @@ public class DbHelper { public ContactModel getContactByPhoneId(String phoneId, String activeRosterId) { ContactModel contact = null; if (StringUtils.isNotEmpty(phoneId)) { - final Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.PHONE_ID + " = '" + phoneId + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - contact = ContactsTable.parseCursor(cursor); - break; - } - cursor.close(); - if (contact != null) { - setContactData(contact); - if (activeRosterId != null) { - ArrayList cs = new ArrayList<>(Arrays.asList(contact)); - loadContactsMessagesByRosterId(cs, activeRosterId); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.PHONE_ID + " = '" + phoneId + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + contact = ContactsTable.parseCursor(cursor); + break; + } + if (contact != null) { + setContactData(contact); + if (activeRosterId != null) { + ArrayList cs = new ArrayList<>(Arrays.asList(contact)); + loadContactsMessagesByRosterId(cs, activeRosterId); + } } } + } finally { + if (cursor != null) { + cursor.close(); + } } } return contact; @@ -1412,16 +1513,22 @@ public class DbHelper { public ContactModel getContactsByEmail(String email) { ContactModel contact = null; if (StringUtils.isNotEmpty(email)) { - final Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.EMAIL + " = '" + email + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - contact = ContactsTable.parseCursor(cursor); - break; + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.EMAIL + " = '" + email + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + contact = ContactsTable.parseCursor(cursor); + break; + } + if (contact != null) { + setContactData(contact); + } } - cursor.close(); - if (contact != null) { - setContactData(contact); + } finally { + if (cursor != null) { + cursor.close(); } } } @@ -1438,15 +1545,21 @@ public class DbHelper { private List getRoomFeatures(String roomIds) { ArrayList services = new ArrayList<>(); if (StringUtils.isNotEmpty(roomIds)) { - final Cursor cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_ROOM + "' AND " + - FeatureTable.Column.TARGET_ID + " IN ( " + roomIds + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final FeatureModel feature = FeatureTable.parseCursor(cursor); - services.add(feature); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_ROOM + "' AND " + + FeatureTable.Column.TARGET_ID + " IN ( " + roomIds + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final FeatureModel feature = FeatureTable.parseCursor(cursor); + services.add(feature); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return services; @@ -1489,14 +1602,20 @@ public class DbHelper { private ArrayList getSimpleRosterByProfile(ProfileModel profile) { ArrayList rosters = new ArrayList<>(); if (profile != null) { - final Cursor cursor = mDb.query("SELECT * FROM " + RosterTable.TABLE_NAME + " WHERE " + - RosterTable.Column.PROFILE_ID + " = '" + profile.phone + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - final RosterModel roster = RosterTable.parseCursor(cursor); - rosters.add(roster); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + RosterTable.TABLE_NAME + " WHERE " + + RosterTable.Column.PROFILE_ID + " = '" + profile.phone + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + final RosterModel roster = RosterTable.parseCursor(cursor); + rosters.add(roster); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return rosters; @@ -1527,15 +1646,21 @@ public class DbHelper { public ContactModel getContactsByRosterIdAndPhoneId(@NonNull String rosterId, String phoneId ) { ContactModel contactModel = null; String rosterIds = "'" + rosterId + "'"; - Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.ROSTER_ID + " IN (" + rosterIds + ") AND " + - ContactsTable.Column.PHONE_ID + " == '" + phoneId + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - contactModel = ContactsTable.parseCursor(cursor); - break; + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.ROSTER_ID + " IN (" + rosterIds + ") AND " + + ContactsTable.Column.PHONE_ID + " == '" + phoneId + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + contactModel = ContactsTable.parseCursor(cursor); + break; + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return contactModel; } @@ -1543,14 +1668,20 @@ public class DbHelper { public int getContactsCountByRosterIdAndStatus(@NonNull String rosterId, String status ) { int count = 0; String rosterIds = "'" + rosterId + "'"; - Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.ROSTER_ID + " IN (" + rosterIds + ") AND " + - ContactsTable.Column.STATUS + " == '" + status + "'"); - if (cursor != null) { - if (cursor.getCount() > 0) { - count = cursor.getCount(); - }; - cursor.close(); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.ROSTER_ID + " IN (" + rosterIds + ") AND " + + ContactsTable.Column.STATUS + " == '" + status + "'"); + if (cursor != null) { + if (cursor.getCount() > 0) { + count = cursor.getCount(); + }; + } + } finally { + if (cursor != null) { + cursor.close(); + } } return count; } @@ -1559,16 +1690,22 @@ public class DbHelper { @NonNull String activeRosterId) { String rosterIds = "'" + rosterId + "'"; List contacts = new ArrayList<>(); - Cursor cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + - ContactsTable.Column.ROSTER_ID + " IN (" + rosterIds + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - ContactModel contact = ContactsTable.parseCursor(cursor); - contacts.add(contact); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactsTable.TABLE_NAME + " WHERE " + + ContactsTable.Column.ROSTER_ID + " IN (" + rosterIds + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + ContactModel contact = ContactsTable.parseCursor(cursor); + contacts.add(contact); + } + setContactsData(contacts, false); + loadContactsMessagesByRosterId(contacts, activeRosterId); + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); - setContactsData(contacts, false); - loadContactsMessagesByRosterId(contacts, activeRosterId); } return contacts; } @@ -1667,18 +1804,24 @@ public class DbHelper { long limit) { List contacts = new ArrayList<>(); String roster_Id = StringUtils.getIdFromRosterId(rosterId); - Cursor cursor = mDb.query(getMyContactsWithFiltersQuery(roster_Id, showRequested, - onlyTimeline, isForCotacts, newerThan, limit)); - if (cursor != null) { - while (cursor.moveToNext()) { - contacts.add(ContactsTable.parseCursor(cursor)); - } - cursor.close(); - if (!isForCotacts) { - contacts = getMyContactsMessagesWithFilters(rosterId, contacts, true, newerThan); + Cursor cursor = null; + try { + cursor = mDb.query(getMyContactsWithFiltersQuery(roster_Id, showRequested, + onlyTimeline, isForCotacts, newerThan, limit)); + if (cursor != null) { + while (cursor.moveToNext()) { + contacts.add(ContactsTable.parseCursor(cursor)); + } + if (!isForCotacts) { + contacts = getMyContactsMessagesWithFilters(rosterId, contacts, true, newerThan); + } + if (!onlyTimeline) { + setContactsData(contacts, !isForCotacts); + } } - if (!onlyTimeline) { - setContactsData(contacts, !isForCotacts); + } finally { + if (cursor != null) { + cursor.close(); } } return contacts; @@ -1757,14 +1900,20 @@ public class DbHelper { @Nullable public RoomModel getChatRoomByRoomIdWithData(String roomId, boolean withData) { - Cursor cursor = mDb.query("SELECT * FROM " + RoomTable.TABLE_NAME + - " WHERE " + RoomTable.Column._ID + " = '" + roomId + "'"); + Cursor cursor = null; RoomModel room = null; - if (cursor != null) { - if (cursor.moveToFirst()) { - room = RoomTable.parseCursor(cursor); + try { + cursor = mDb.query("SELECT * FROM " + RoomTable.TABLE_NAME + + " WHERE " + RoomTable.Column._ID + " = '" + roomId + "'"); + if (cursor != null) { + if (cursor.moveToFirst()) { + room = RoomTable.parseCursor(cursor); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } if (withData && room != null) { List rooms = new ArrayList<>(Arrays.asList(room)); @@ -1779,16 +1928,22 @@ public class DbHelper { boolean onlyTimeline, boolean onlyActive) { List rooms = new ArrayList<>(); - Cursor cursor = mDb.query(sql); - if (cursor != null) { - while (cursor.moveToNext()) { - RoomModel room = RoomTable.parseCursor(cursor); - if ((!onlyActive || (onlyActive && room.isActiveRoom()))) { - rooms.add(room); + Cursor cursor = null; + try { + cursor = mDb.query(sql); + if (cursor != null) { + while (cursor.moveToNext()) { + RoomModel room = RoomTable.parseCursor(cursor); + if ((!onlyActive || (onlyActive && room.isActiveRoom()))) { + rooms.add(room); + } } + setRoomData(rooms, onlyTimeline); + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); - setRoomData(rooms, onlyTimeline); } return rooms; } @@ -1890,20 +2045,26 @@ public class DbHelper { boolean isAddReplied, boolean minimalData) { List list = new ArrayList<>(); - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - MessageModel message = MessagesTable.parseCursor(cursor); - list.add(message); - } - cursor.close(); - setMessagesDesc(list); - if (!minimalData) { - checkStarMessage(list); - if (isAddReplied) { - addRepliedToMessage(list); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + MessageModel message = MessagesTable.parseCursor(cursor); + list.add(message); + } + setMessagesDesc(list); + if (!minimalData) { + checkStarMessage(list); + if (isAddReplied) { + addRepliedToMessage(list); + } } } + } finally { + if (cursor != null) { + cursor.close(); + } } return list; } @@ -1911,18 +2072,24 @@ public class DbHelper { @Nullable private MessageModel getMessage(String query, boolean isAddReplied) { MessageModel message = null; - Cursor cursor = mDb.query(query); - if (cursor != null) { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - message = MessagesTable.parseCursor(cursor); - setMessageDesc(message); - checkStarMessage(message); - if (isAddReplied && message.isReply()) { - addRepliedToMessage(message); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + message = MessagesTable.parseCursor(cursor); + setMessageDesc(message); + checkStarMessage(message); + if (isAddReplied && message.isReply()) { + addRepliedToMessage(message); + } } } - cursor.close(); + } finally { + if (cursor != null) { + cursor.close(); + } } return message; } @@ -1942,17 +2109,23 @@ public class DbHelper { String query = "SELECT * FROM " + StarTable.TABLE_NAME + " WHERE " + StarTable.Column.MESSAGE_ID + " IN (" + ids + ") AND " + StarTable.Column.STATUS + " != '" + StarModel.Statuses.REMOVE.atom + "'"; - Cursor cursor = mDb.query(query); - if (cursor != null) { - if (cursor.getCount() > 0) { - while (cursor.moveToNext()) { - StarModel star = StarTable.parseCursor(cursor); - starMessageId.add(star.messageId); - starId.put(star.messageId, star.serverId); - starClientId.put(star.messageId, star.clientId); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + StarModel star = StarTable.parseCursor(cursor); + starMessageId.add(star.messageId); + starId.put(star.messageId, star.serverId); + starClientId.put(star.messageId, star.clientId); + } } } - cursor.close(); + } finally { + if (cursor != null) { + cursor.close(); + } } String messagesId = TextUtils.join(", ", starMessageId); for (MessageModel message : list) { @@ -1968,14 +2141,19 @@ public class DbHelper { String query = "SELECT * FROM " + StarTable.TABLE_NAME + " WHERE " + StarTable.Column.MESSAGE_ID + " = " + message.serverId + " AND " + StarTable.Column.STATUS + " != '" + StarModel.Statuses.REMOVE.atom + "'"; - Cursor cursor = mDb.query(query); - message.isStarred = cursor != null && cursor.getCount() > 0; - if (message.isStarred) { - cursor.moveToNext(); - message.starServerId = StarTable.getServerId(cursor); - message.starClientId = StarTable.getClientId(cursor); + Cursor cursor = null; + try { + cursor = mDb.query(query); + message.isStarred = cursor != null && cursor.getCount() > 0; + if (message.isStarred) { + cursor.moveToNext(); + message.starServerId = StarTable.getServerId(cursor); + message.starClientId = StarTable.getClientId(cursor); + } + } finally { + if (cursor != null) + cursor.close(); } - if (cursor != null) cursor.close(); } private void addRepliedToMessage(List list) { @@ -2071,25 +2249,31 @@ public class DbHelper { StarTable.Column.STATUS + " = '" + StarModel.Statuses.REMOVE.atom + "'"; List list = new ArrayList<>(); List ids = new ArrayList<>(); - Cursor cursor = mDb.query(queryInto); - if (cursor != null) { - while (cursor.moveToNext()) { - StarModel star = StarTable.parseCursor(cursor); - ids.add(String.valueOf(star.messageId)); - list.add(star); - } - cursor.close(); - if (!list.isEmpty()) { - List messages = getStaticMessageByIds(TextUtils.join(", ", ids), MessageModel.StaticTypes.STAR); - for (StarModel star : list) { - for (MessageModel message : messages) { - if (message.serverId != null && message.serverId.equals(star.messageId)) { - star.message = message; - break; + Cursor cursor = null; + try { + cursor = mDb.query(queryInto); + if (cursor != null) { + while (cursor.moveToNext()) { + StarModel star = StarTable.parseCursor(cursor); + ids.add(String.valueOf(star.messageId)); + list.add(star); + } + if (!list.isEmpty()) { + List messages = getStaticMessageByIds(TextUtils.join(", ", ids), MessageModel.StaticTypes.STAR); + for (StarModel star : list) { + for (MessageModel message : messages) { + if (message.serverId != null && message.serverId.equals(star.messageId)) { + star.message = message; + break; + } } } } } + } finally { + if (cursor != null) { + cursor.close(); + } } return list; } @@ -2153,37 +2337,49 @@ public class DbHelper { ArrayList descFeatures = new ArrayList<>(); String query = "SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + FeatureTable.Column.TARGET_ID + " = '" + descId + "'"; - Cursor cursorFeature = mDb.query(query); - if (cursorFeature != null) { - while (cursorFeature.moveToNext()) { - desc.data.add(FeatureTable.parseCursor(cursorFeature)); + Cursor cursorFeature = null; + try { + cursorFeature = mDb.query(query); + if (cursorFeature != null) { + while (cursorFeature.moveToNext()) { + desc.data.add(FeatureTable.parseCursor(cursorFeature)); + } + } + } finally { + if (cursorFeature != null) { + cursorFeature.close(); } - cursorFeature.close(); } } } private void setMessagesDescByIds(List messageList, String ids) { if (!StringUtils.isNotEmpty(ids)) return; - Cursor cursorDesc = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + - DescTable.Column.TARGET_ID + " IN (" + ids + ") AND " + - DescTable.Column.TARGET_TYPE + " = " + DescTable.TYPE_MESSAGE); - List descList = new ArrayList<>(); - if (cursorDesc != null) { - while (cursorDesc.moveToNext()) { - DescModel desc = DescTable.parseCursor(cursorDesc); - descList.add(desc); - } - cursorDesc.close(); - } - if (!messageList.isEmpty() && !descList.isEmpty()) { - for (MessageModel msg : messageList) { - for (DescModel desc : descList) { - if (desc.targetId.equals(String.valueOf(msg.localId))) { - msg.files.add(desc); + Cursor cursorDesc = null; + try { + cursorDesc = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + + DescTable.Column.TARGET_ID + " IN (" + ids + ") AND " + + DescTable.Column.TARGET_TYPE + " = " + DescTable.TYPE_MESSAGE); + List descList = new ArrayList<>(); + if (cursorDesc != null) { + while (cursorDesc.moveToNext()) { + DescModel desc = DescTable.parseCursor(cursorDesc); + descList.add(desc); + } + } + if (!messageList.isEmpty() && !descList.isEmpty()) { + for (MessageModel msg : messageList) { + for (DescModel desc : descList) { + if (desc.targetId.equals(String.valueOf(msg.localId))) { + msg.files.add(desc); + } } + setDescFeatures(msg.files); } - setDescFeatures(msg.files); + } + } finally { + if (cursorDesc != null) { + cursorDesc.close(); } } } @@ -2220,13 +2416,19 @@ public class DbHelper { private List getDesc(String query) { List descs = new ArrayList<>(); - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - DescModel desc = DescTable.parseCursor(cursor); - descs.add(desc); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + DescModel desc = DescTable.parseCursor(cursor); + descs.add(desc); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } setDescFeatures(descs); return descs; @@ -2382,15 +2584,21 @@ public class DbHelper { private List getTagsByRosters(String ids) { ArrayList stars = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query( + Cursor cursor = null; + try { + cursor = mDb.query( "SELECT * FROM " + TagTable.TABLE_NAME + " WHERE " + - TagTable.Column.ROSTER_ID + " IN (" + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final TagModel tag = TagTable.parseCursor(cursor); - stars.add(tag); + TagTable.Column.ROSTER_ID + " IN (" + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final TagModel tag = TagTable.parseCursor(cursor); + stars.add(tag); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return stars; @@ -2481,15 +2689,21 @@ public class DbHelper { public TimelineSettingsModel getTimelineSettingsByRoster(String rosterId) { TimelineSettingsModel timelines = null; if (rosterId == null) return timelines; - final Cursor cursor = mDb.query( + Cursor cursor = null; + try { + cursor = mDb.query( "SELECT * FROM " + TimelineSettingsTable.TABLE_NAME + " WHERE " + - TimelineSettingsTable.Column.ROSTER_ID + "= '" + rosterId + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - timelines = TimelineSettingsTable.parseCursor(cursor); - break; + TimelineSettingsTable.Column.ROSTER_ID + "= '" + rosterId + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + timelines = TimelineSettingsTable.parseCursor(cursor); + break; + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return timelines; } @@ -2551,13 +2765,19 @@ public class DbHelper { MessagesTable.Column.LOCAL_ID + " = '" + message.localId + "' limit 1"; } else return false; MessageModel resMessage = null; - Cursor cursor = mDb.query(queryInto); - if (cursor != null) { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - resMessage = MessagesTable.parseCursor(cursor); + Cursor cursor = null; + try { + cursor = mDb.query(queryInto); + if (cursor != null) { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + resMessage = MessagesTable.parseCursor(cursor); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return resMessage != null; } @@ -2601,21 +2821,27 @@ public class DbHelper { private List getMembersByRoom(String ids, boolean minimalData, boolean loadMemberFeatures) { ArrayList members = new ArrayList<>(); if (StringUtils.isNotEmpty(ids)) { - final Cursor cursor = mDb.query( + Cursor cursor = null; + try { + cursor = mDb.query( "SELECT * FROM " + MemberTable.TABLE_NAME + " WHERE " + - MemberTable.Column.ROOM_ID + " IN (" + ids + ")" + - " ORDER BY " + MemberTable.Column.UPDATE + " DESC"); - if (cursor != null) { - while (cursor.moveToNext()) { - MemberModel member = getMember(cursor); - members.add(member); + MemberTable.Column.ROOM_ID + " IN (" + ids + ")" + + " ORDER BY " + MemberTable.Column.UPDATE + " DESC"); + if (cursor != null) { + while (cursor.moveToNext()) { + MemberModel member = getMember(cursor); + members.add(member); + } + if (!minimalData) { + getMemberFeatures(members); + setMemberServices(members); + } else if (loadMemberFeatures) { + getMemberFeatures(members); + } } - cursor.close(); - if (!minimalData) { - getMemberFeatures(members); - setMemberServices(members); - } else if (loadMemberFeatures) { - getMemberFeatures(members); + } finally { + if (cursor != null) { + cursor.close(); } } } @@ -2626,40 +2852,46 @@ public class DbHelper { if (room != null) { long time = System.currentTimeMillis(); - final Cursor cursor = mDb.query( + Cursor cursor = null; + try { + cursor = mDb.query( "SELECT * FROM " + MemberTable.TABLE_NAME + " WHERE " + - MemberTable.Column.ROOM_ID + " = '" + room.id + "'" + - " ORDER BY " + MemberTable.Column.UPDATE + " DESC" ); - //////////////////////////////////////////////////////////////////////////////////////////// - // TEST TEST TEST - if (BuildConfig.DEBUG) { - //Timber.i("######## TEST_POINT_"+(minimalData? 7 : 6) +": getObsChatRoomsFiltered - setRoomData ->getMembersByRoom 1: " + (System.currentTimeMillis() - time) + ", forList= " + minimalData); - time = System.currentTimeMillis(); - } - //////////////////////////////////////////////////////////////////////////////////////////// - if (cursor != null) { - while (cursor.moveToNext()) { - MemberModel member = MemberTable.parseCursor(cursor); - getMemberFeatures(member); - //////////////////////////////////////////////////////////////////////////////////////////// - // TEST TEST TEST - if (BuildConfig.DEBUG) { - //Timber.i("######## TEST_POINT_"+(minimalData? 7 : 6) +": getObsChatRoomsFiltered - setRoomData ->getMembersByRoom 2: " + (System.currentTimeMillis() - time) + ", forList= " + minimalData); - time = System.currentTimeMillis(); - } - //////////////////////////////////////////////////////////////////////////////////////////// - if (!minimalData) { - setMemberServices(member); - } - if (MemberModel.Statuses.MEMBER.equals(member.status)) { - room.members.add(member); - } else if (MemberModel.Statuses.ADMIN.equals(member.status) || MemberModel.Statuses.OWNER.equals(member.status)) { - room.admins.add(member); - } else if (MemberModel.Statuses.REMOVED.equals(member.status)) { - room.removed.add(member); + MemberTable.Column.ROOM_ID + " = '" + room.id + "'" + + " ORDER BY " + MemberTable.Column.UPDATE + " DESC" ); + //////////////////////////////////////////////////////////////////////////////////////////// + // TEST TEST TEST + if (BuildConfig.DEBUG) { + //Timber.i("######## TEST_POINT_"+(minimalData? 7 : 6) +": getObsChatRoomsFiltered - setRoomData ->getMembersByRoom 1: " + (System.currentTimeMillis() - time) + ", forList= " + minimalData); + time = System.currentTimeMillis(); + } + //////////////////////////////////////////////////////////////////////////////////////////// + if (cursor != null) { + while (cursor.moveToNext()) { + MemberModel member = MemberTable.parseCursor(cursor); + getMemberFeatures(member); + //////////////////////////////////////////////////////////////////////////////////////////// + // TEST TEST TEST + if (BuildConfig.DEBUG) { + //Timber.i("######## TEST_POINT_"+(minimalData? 7 : 6) +": getObsChatRoomsFiltered - setRoomData ->getMembersByRoom 2: " + (System.currentTimeMillis() - time) + ", forList= " + minimalData); + time = System.currentTimeMillis(); + } + //////////////////////////////////////////////////////////////////////////////////////////// + if (!minimalData) { + setMemberServices(member); + } + if (MemberModel.Statuses.MEMBER.equals(member.status)) { + room.members.add(member); + } else if (MemberModel.Statuses.ADMIN.equals(member.status) || MemberModel.Statuses.OWNER.equals(member.status)) { + room.admins.add(member); + } else if (MemberModel.Statuses.REMOVED.equals(member.status)) { + room.removed.add(member); + } } } - cursor.close(); + } finally { + if (cursor != null) { + cursor.close(); + } } } } @@ -2854,14 +3086,20 @@ public class DbHelper { private List getRoomLinks(String roomIds) { ArrayList links = new ArrayList<>(); if (StringUtils.isNotEmpty(roomIds)) { - final Cursor cursor = mDb.query("SELECT * FROM " + LinkTable.TABLE_NAME + " WHERE " + - LinkTable.Column.ROOM_ID + " IN (" + roomIds + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final LinkModel link = LinkTable.parseCursor(cursor); - links.add(link); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + LinkTable.TABLE_NAME + " WHERE " + + LinkTable.Column.ROOM_ID + " IN (" + roomIds + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final LinkModel link = LinkTable.parseCursor(cursor); + links.add(link); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return links; @@ -2870,15 +3108,21 @@ public class DbHelper { public List getRoomLinksByType(String roomIds, BertAtom type) { ArrayList links = new ArrayList<>(); if (StringUtils.isNotEmpty(roomIds)) { - final Cursor cursor = mDb.query("SELECT * FROM " + LinkTable.TABLE_NAME + " WHERE " + - LinkTable.Column.ROOM_ID + " IN (" + roomIds + ") AND " + LinkTable.Column.TYPE + - " = '" + type.atom + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - final LinkModel link = LinkTable.parseCursor(cursor); - links.add(link); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + LinkTable.TABLE_NAME + " WHERE " + + LinkTable.Column.ROOM_ID + " IN (" + roomIds + ") AND " + LinkTable.Column.TYPE + + " = '" + type.atom + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + final LinkModel link = LinkTable.parseCursor(cursor); + links.add(link); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return links; @@ -2974,7 +3218,6 @@ public class DbHelper { status = DbQueryStatuses.UPDATE; } mDb.update(tableName, SQLiteDatabase.CONFLICT_NONE, cv, where); - if (!cursor.isClosed()) cursor.close(); } else { insertId = mDb.insert(tableName, SQLiteDatabase.CONFLICT_REPLACE, cv); status = DbQueryStatuses.INSERT; @@ -3066,12 +3309,18 @@ public class DbHelper { builder.append(where); } String query = builder.toString(); - Cursor cursor = mDb.query(query); - if (cursor != null) { - if (cursor.getCount() > 0) { - cntRows = mDb.update(tableName, SQLiteDatabase.CONFLICT_NONE, cv, where); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + if (cursor.getCount() > 0) { + cntRows = mDb.update(tableName, SQLiteDatabase.CONFLICT_NONE, cv, where); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return cntRows; } @@ -3108,14 +3357,20 @@ public class DbHelper { private List getRoomsById(String ids) { List rooms = new ArrayList<>(); - Cursor cursor = mDb.query("SELECT * FROM " + RoomTable.TABLE_NAME + - " WHERE " + RoomTable.Column._ID + " IN (" + ids + ")"); - if (cursor != null) { - while (cursor.moveToNext()) { - final RoomModel room = RoomTable.parseCursor(cursor); - rooms.add(room); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + RoomTable.TABLE_NAME + + " WHERE " + RoomTable.Column._ID + " IN (" + ids + ")"); + if (cursor != null) { + while (cursor.moveToNext()) { + final RoomModel room = RoomTable.parseCursor(cursor); + rooms.add(room); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } setRoomData(rooms, false); return rooms; @@ -3861,14 +4116,20 @@ public class DbHelper { private List getStaticMessages(String query, int type) { List list = new ArrayList<>(); - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - MessageModel message = StaticMessagesTable.parseCursor(cursor); - list.add(message); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + MessageModel message = StaticMessagesTable.parseCursor(cursor); + list.add(message); + } + setStaticMessagesDesc(list, type); + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); - setStaticMessagesDesc(list, type); } return list; } @@ -4037,13 +4298,19 @@ public class DbHelper { String query = "SELECT * FROM " + JobTable.TABLE_NAME + " WHERE " + JobTable.Column.STATUS + " IN (" + statusesDelim + ") " + " ORDER BY " + JobTable.Column.TIME + " DESC"; - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - JobModel job = JobTable.parseCursor(cursor); - jobs.add(job); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + JobModel job = JobTable.parseCursor(cursor); + jobs.add(job); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return setJobsData(jobs); @@ -4084,13 +4351,19 @@ public class DbHelper { " AND " + MessagesTable.TABLE_NAME + "." + MessagesTable.Column.FROM + " = '" + rosterId + "'" + " ORDER BY " + MessagesTable.Column.CREATED + " DESC"; if (limit > 0) query += " LIMIT " + limit; - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - DescModel desc = DescTable.parseCursor(cursor); - descs.add(desc); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + DescModel desc = DescTable.parseCursor(cursor); + descs.add(desc); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } setDescFeatures(descs); return descs; @@ -4106,13 +4379,19 @@ public class DbHelper { " AND " + MessagesTable.TABLE_NAME + "." + MessagesTable.Column.FROM + " = '" + rosterId + "'" + " ORDER BY " + MessagesTable.Column.CREATED + " DESC"; if (limit > 0) query += " LIMIT " + limit; - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - DescModel desc = DescTable.parseCursor(cursor); - descs.add(desc); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + DescModel desc = DescTable.parseCursor(cursor); + descs.add(desc); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } setDescFeatures(descs); return descs; @@ -4132,13 +4411,19 @@ public class DbHelper { " WHERE " + DescTable.Column.MIME + " = '" + DescModel.MimeTypes.Thumb + "'" + " AND " + DescTable.Column.TARGET_TYPE + " = " + DescTable.TYPE_MESSAGE + " AND " + DescTable.Column.TARGET_ID + " IN (" + ids + ")"; - Cursor cursor = mDb.query(query); - if (cursor != null) { - while (cursor.moveToNext()) { - DescModel desc = DescTable.parseCursor(cursor); - thumbList.add(desc); + Cursor cursor = null; + try { + cursor = mDb.query(query); + if (cursor != null) { + while (cursor.moveToNext()) { + DescModel desc = DescTable.parseCursor(cursor); + thumbList.add(desc); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } setDescFeatures(mediaList); setDescFeatures(thumbList); @@ -4215,19 +4500,26 @@ public class DbHelper { private void setStickerPackDescs(StickerPackModel stickerPack) { String stickerPackId = String.valueOf(stickerPack.serverId); - Cursor cursorDescs = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + - DescTable.Column.TARGET_TYPE + " = '" + DescTable.TYPE_STICKER_PACK + "' AND " + - DescTable.Column.TARGET_ID + " = '" + stickerPackId + "'"); - List descList = new ArrayList<>(); - if (cursorDescs != null) { - while (cursorDescs.moveToNext()) { - DescModel desc = DescTable.parseCursor(cursorDescs); - descList.add(desc); + Cursor cursorDescs = null; + try { + cursorDescs = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + + DescTable.Column.TARGET_TYPE + " = '" + DescTable.TYPE_STICKER_PACK + "' AND " + + DescTable.Column.TARGET_ID + " = '" + stickerPackId + "'"); + List descList = new ArrayList<>(); + if (cursorDescs != null) { + while (cursorDescs.moveToNext()) { + DescModel desc = DescTable.parseCursor(cursorDescs); + descList.add(desc); + } + cursorDescs.close(); + } + stickerPack.stickers.clear(); + stickerPack.stickers.addAll(descList); + } finally { + if (cursorDescs != null) { + cursorDescs.close(); } - cursorDescs.close(); } - stickerPack.stickers.clear(); - stickerPack.stickers.addAll(descList); } private void setStickerPackDescFeatures(DescModel stickerPackDesc) { @@ -4249,36 +4541,48 @@ public class DbHelper { public List getRecentStickers(Context context, ArrayList stickerIdentificators) { List result = new ArrayList<>(); for (String stickerIdentificator : stickerIdentificators) { - Cursor cursorDesc = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + - DescTable.Column.MIME + " = '" + DescModel.MimeTypes.Sticker + "' AND " + - DescTable.Column.TARGET_TYPE + " = '" + DescTable.TYPE_STICKER_PACK + "' AND " + - DescTable.Column.UNIQUE_ID + " = '" + stickerIdentificator + "'"); - DescModel stickerDesc = null; - if (cursorDesc != null) { - while (cursorDesc.moveToNext()) { - stickerDesc = DescTable.parseCursor(cursorDesc); + Cursor cursorDesc = null; + try { + cursorDesc = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + + DescTable.Column.MIME + " = '" + DescModel.MimeTypes.Sticker + "' AND " + + DescTable.Column.TARGET_TYPE + " = '" + DescTable.TYPE_STICKER_PACK + "' AND " + + DescTable.Column.UNIQUE_ID + " = '" + stickerIdentificator + "'"); + DescModel stickerDesc = null; + if (cursorDesc != null) { + while (cursorDesc.moveToNext()) { + stickerDesc = DescTable.parseCursor(cursorDesc); + } } - cursorDesc.close(); - } - if (stickerDesc != null) { - List features = new ArrayList<>(); - Cursor cursorFeatures = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_STICKER + "'" + - " AND " + FeatureTable.Column.TARGET_ID + " = '" + stickerDesc.id + "'"); - if (cursorFeatures != null) { - while (cursorFeatures.moveToNext()) { - FeatureModel feature = FeatureTable.parseCursor(cursorFeatures); - features.add(feature); + if (stickerDesc != null) { + List features = new ArrayList<>(); + Cursor cursorFeatures = null; + try { + cursorFeatures = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_STICKER + "'" + + " AND " + FeatureTable.Column.TARGET_ID + " = '" + stickerDesc.id + "'"); + if (cursorFeatures != null) { + while (cursorFeatures.moveToNext()) { + FeatureModel feature = FeatureTable.parseCursor(cursorFeatures); + features.add(feature); + } + } + } finally { + if (cursorFeatures != null) { + cursorFeatures.close(); + } } - cursorFeatures.close(); + stickerDesc.data.clear(); + stickerDesc.data.addAll(features); } - stickerDesc.data.clear(); - stickerDesc.data.addAll(features); - } - if (stickerDesc != null) { - Sticker sticker = DescManager.getStickerFromDesc(context, stickerDesc); - if (sticker != null) { - result.add(sticker); + if (stickerDesc != null) { + Sticker sticker = DescManager.getStickerFromDesc(context, stickerDesc); + if (sticker != null) { + result.add(sticker); + } + } + } finally { + if (cursorDesc != null) { + cursorDesc.close(); } } } @@ -4287,13 +4591,19 @@ public class DbHelper { public StickerPackModel getLastStickerPack() { StickerPackModel stickerPack = null; - Cursor cursorStickerPack = mDb.query("SELECT * FROM " + StickerPacksTable.TABLE_NAME + - " ORDER BY " + StickerPacksTable.Column.STICKER_PACK_UPDATED + - " DESC LIMIT 1"); - if (cursorStickerPack != null) { - if (cursorStickerPack.moveToFirst()) - stickerPack = StickerPacksTable.parseCursor(cursorStickerPack); - cursorStickerPack.close(); + Cursor cursorStickerPack = null; + try { + cursorStickerPack = mDb.query("SELECT * FROM " + StickerPacksTable.TABLE_NAME + + " ORDER BY " + StickerPacksTable.Column.STICKER_PACK_UPDATED + + " DESC LIMIT 1"); + if (cursorStickerPack != null) { + if (cursorStickerPack.moveToFirst()) + stickerPack = StickerPacksTable.parseCursor(cursorStickerPack); + } + } finally { + if (cursorStickerPack != null) { + cursorStickerPack.close(); + } } return stickerPack; } @@ -4790,27 +5100,39 @@ public class DbHelper { + HistoryRangeTable.TABLE_NAME + " WHERE " + HistoryRangeTable.Column.CHAT_ID + " = '" + chatId + "' AND " + HistoryRangeTable.Column.TYPE + " = '" + type.toLowerCase() + "'"; - Cursor cursor = mDb.query(args); - if (cursor != null) { - if (cursor.moveToFirst()) { - result = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryRangeTable.Column.IS_ACTUAL_START)) == 1; + Cursor cursor = null; + try { + cursor = mDb.query(args); + if (cursor != null) { + if (cursor.moveToFirst()) { + result = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryRangeTable.Column.IS_ACTUAL_START)) == 1; + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return result; } public boolean isReachEndInHistoryRange(String chatId, String type) { boolean result = false; - Cursor cursor = mDb.query("SELECT " + HistoryRangeTable.Column.IS_REACH_END + " FROM " - + HistoryRangeTable.TABLE_NAME + " WHERE " - + HistoryRangeTable.Column.CHAT_ID + " = '" + chatId + "' AND " - + HistoryRangeTable.Column.TYPE + " = '" + type.toLowerCase() + "'"); - if (cursor != null) { - if (cursor.moveToFirst()) { - result = (cursor.getInt(cursor.getColumnIndexOrThrow(HistoryRangeTable.Column.IS_REACH_END)) == 1); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT " + HistoryRangeTable.Column.IS_REACH_END + " FROM " + + HistoryRangeTable.TABLE_NAME + " WHERE " + + HistoryRangeTable.Column.CHAT_ID + " = '" + chatId + "' AND " + + HistoryRangeTable.Column.TYPE + " = '" + type.toLowerCase() + "'"); + if (cursor != null) { + if (cursor.moveToFirst()) { + result = (cursor.getInt(cursor.getColumnIndexOrThrow(HistoryRangeTable.Column.IS_REACH_END)) == 1); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } return result; } @@ -4885,14 +5207,20 @@ public class DbHelper { private List getContactDataList(String accountId) { ArrayList contactInfo = new ArrayList<>(); if (StringUtils.isNotEmpty(accountId)) { - final Cursor cursor = mDb.query("SELECT * FROM " + ContactInfoTable.TABLE_NAME + " WHERE " + - ContactInfoTable.Column.ACCOUNT_ID + " = '" + accountId + "'"); - if (cursor != null) { - while (cursor.moveToNext()) { - final UserContactData contactData = ContactInfoTable.parseCursor(cursor); - contactInfo.add(contactData); + Cursor cursor = null; + try { + cursor = mDb.query("SELECT * FROM " + ContactInfoTable.TABLE_NAME + " WHERE " + + ContactInfoTable.Column.ACCOUNT_ID + " = '" + accountId + "'"); + if (cursor != null) { + while (cursor.moveToNext()) { + final UserContactData contactData = ContactInfoTable.parseCursor(cursor); + contactInfo.add(contactData); + } + } + } finally { + if (cursor != null) { + cursor.close(); } - cursor.close(); } } return contactInfo; @@ -4926,18 +5254,22 @@ public class DbHelper { public IAccount getAccount() { AccountImpl account = null; + Cursor cursor = null; try { - Cursor cursor = mDb.query("SELECT * FROM " + AccountTable.TABLE_NAME); + cursor = mDb.query("SELECT * FROM " + AccountTable.TABLE_NAME); if (cursor != null) { if (cursor.getCount() > 0) { cursor.moveToFirst(); account = AccountTable.parseCursor(cursor); account.setContactsInfo(getContactDataList(account.getAccountId())); } - cursor.close(); } } catch (Exception e) { Timber.e(e, "Error get account"); + } finally { + if (cursor != null) { + cursor.close(); + } } return account; } @@ -4956,17 +5288,21 @@ public class DbHelper { public String getRefreshToken() { String token = ""; + Cursor cursor = null; try { - final Cursor cursor = mDb.query("SELECT * FROM " + RefreshTokenTable.TABLE_NAME); + cursor = mDb.query("SELECT * FROM " + RefreshTokenTable.TABLE_NAME); if (cursor != null) { while (cursor.moveToNext()) { token = RefreshTokenTable.parseCursor(cursor); } - cursor.close(); return token; } } catch (Exception e) { Timber.e(e, "Error get token"); + } finally { + if (cursor != null) { + cursor.close(); + } } return ""; } -- GitLab From d8cbc0cef2326cf25f49108d1e724d2ed4865535 Mon Sep 17 00:00:00 2001 From: Ergyun Syuleyman Date: Tue, 26 May 2020 13:09:27 +0300 Subject: [PATCH 02/21] -initial UI of NY-8442: [AN]: Implement Call Pickup --- .../data/sdk/ConferenceSDKPresenter.java | 2 + .../data/sdk/calls/ConferenceSDKListener.java | 2 + .../data/sdk/calls/ConferenceSDKModule.java | 62 +++++-- .../mvp/presenters/BasePresenter.java | 9 + .../mvp/presenters/MainActivityPresenter.kt | 31 +++- .../mvp/view/MainActivityView.java | 4 + .../ui/activities/MainActivity.java | 172 +++++++++++------- app/src/main/res/layout/activity_home.xml | 33 +++- .../main/res/layout/partial_call_pickup.xml | 75 ++++++++ app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 3 + 11 files changed, 308 insertions(+), 87 deletions(-) create mode 100644 app/src/main/res/layout/partial_call_pickup.xml diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java index 9c1ae7305c..7c7444708a 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java @@ -51,6 +51,8 @@ public abstract class ConferenceSDKPresenter extends Bas @Override public void onStateChangedForCall(NYNCall iConference) {} + @Override public void onAcceptedElsewhereConference(String conferenceId) {} + @Override public void onCreateVideoCallReady(ActiveConferenceCall activeConferenceCall) {} @Override public void onScreenShareState(boolean active) {} diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java index 4710d6de07..76c67924f8 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java @@ -36,6 +36,8 @@ public interface ConferenceSDKListener { void onStateChangedForCall(NYNCall iConference); + void onAcceptedElsewhereConference(String conferenceId); + void onCreateVideoCallReady(ActiveConferenceCall activeConferenceCall); void onScreenShareState(boolean active); diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java index b00746dd83..89a6005aae 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java @@ -26,7 +26,6 @@ import com.nynja.mobile.communicator.R; import com.nynja.mobile.communicator.data.ProfileSyncManager; import com.nynja.mobile.communicator.data.audio.NynjaSoundManager; import com.nynja.mobile.communicator.data.conference.ActiveCallBase; -import com.nynja.mobile.communicator.data.conference.ConferenceVideoModule; import com.nynja.mobile.communicator.data.db.DbHelper; import com.nynja.mobile.communicator.data.models.SettingNotifications; import com.nynja.mobile.communicator.data.models.StateDevice; @@ -77,7 +76,6 @@ import java.util.Map; import java.util.Timer; import java.util.TimerTask; -import kotlin.jvm.Synchronized; import timber.log.Timber; import static com.nynja.sdk.NYNCallEndReason.NYNCallEndReasonFailed; @@ -544,6 +542,31 @@ public class ConferenceSDKModule extends BaseSDKModule { } } + public boolean hasCallForPickup() { + if (mMyAcceptedElsewhereCalls.size() == 0) { + return false; + } + return true; + } + public synchronized String callPickupText() { + String text = ""; + synchronized (mMyAcceptedElsewhereCalls) { + for (String callId : mMyAcceptedElsewhereCalls.keySet()) { + NYNCall call = mCallManager.getCallById(callId); + if (call != null) { + if (StringUtils.isNotEmpty(text)) { + text += ", "; + } + if (!call.isConference()) { + String id = call.isOutgoing() ? call.callee() : call.caller(); + // TODO: get local contact OR ROOM name by ID + text += (call.getExternalInfo()); + } + } + } + } + return text; + } public boolean isCameraRunning() { if (!hasCreatedActiveCall()) return false; @@ -1075,6 +1098,8 @@ public class ConferenceSDKModule extends BaseSDKModule { conferenceId + "\' " + (result ? "succeed" : "failed!!!")); synchronized (mActiveConference.mData) { mActiveConference.mData.mParticipantArray = mActiveConference.mConference.getParticipants(); + Timber.d("Request conference member with members size=\'" + + mActiveConference.mData.mParticipantArray.size()); } // update chatRoomId @@ -1177,9 +1202,14 @@ public class ConferenceSDKModule extends BaseSDKModule { NYNCallState state = call.callState(); boolean isActive = !NYNCallState.NYNCallStateClosed.equals(state); if (StringUtils.isNotEmpty(roomId)) { - //if (!mMyAcceptedElsewhereCalls.containsKey(roomId) && isActive) { - // mMyAcceptedElsewhereCalls.put(roomId, callId); - //} else + if (NYNCallState.NYNCallStateConnected.equals(state) && + !mMyAcceptedElsewhereCalls.containsKey(callId)) { + if (!((hasCreatedActiveCall() && mActiveConference.mConference != null + && mActiveConference.mConference.callId().contentEquals(callId)) || + call.isStartedOnThisDevice())) { + mMyAcceptedElsewhereCalls.put(callId, roomId); + } + } if (!forceFireEvent) { if ((hasCreatedActiveCall() && mActiveConference.mConference != null && mActiveConference.mConference.callId().contentEquals(callId))) { @@ -1199,14 +1229,15 @@ public class ConferenceSDKModule extends BaseSDKModule { private void onCallEndedHandle(NYNCall call, boolean forceFireEvent) { if (call != null) { + String callId = call.callId(); String roomId = (call.isConference() ? call.getChatRoomId() : (call.isOutgoing() ? call.callee() : call.caller())); - //if (mMyAcceptedElsewhereCalls.containsKey(roomId)) { - // mMyAcceptedElsewhereCalls.remove(roomId); - //} else + if (mMyAcceptedElsewhereCalls.containsKey(callId)) { + mMyAcceptedElsewhereCalls.remove(callId); + } if (!forceFireEvent) { if (!(hasCreatedActiveCall() && mActiveConference.mConference != null - && mActiveConference.mConference.callId().contentEquals(call.callId()))) { + && mActiveConference.mConference.callId().contentEquals(callId))) { return; } } @@ -1423,7 +1454,7 @@ public class ConferenceSDKModule extends BaseSDKModule { @Override public void receivedAcceptedElsewhere(String conferenceId) { - onAcceptedElsewhereConferenceRinging(conferenceId); + onAcceptedElsewhereConference(conferenceId); } @Override @@ -2342,7 +2373,7 @@ public class ConferenceSDKModule extends BaseSDKModule { public boolean hasRunningCallWithRoom(String roomId) { return (mCallManager.hasRunningCallWithRoom(roomId) || - (//mMyAcceptedElsewhereCalls.containsKey(roomId) && + (//mMyAcceptedElsewhereCalls.containsValue(roomId) && mCallManager.hasRunningCallWithContact(roomId))); } @@ -3041,7 +3072,7 @@ public class ConferenceSDKModule extends BaseSDKModule { } } - private void onAcceptedElsewhereConferenceRinging(String conferenceId) { + private void onAcceptedElsewhereConference(String conferenceId) { if (!hasCreatedActiveCall()) return; if (mActiveConference.mConference == null) return; @@ -3051,7 +3082,12 @@ public class ConferenceSDKModule extends BaseSDKModule { && mActiveConference.isOutgoingCall) { // Nothing to do when is my outgoing call - may need check when allow multiple login } else { - //mMyAcceptedElsewhereCalls.put(mActiveConference.mEndPointId, conferenceId); + if (isP2P()) { + mMyAcceptedElsewhereCalls.put(conferenceId, mActiveConference.mEndPointId); + for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { + conferenceSDKListener.onAcceptedElsewhereConference(conferenceId); + } + } onConferenceEnded(conferenceId); } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java index fd01699566..c0b8a8a169 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java @@ -266,6 +266,15 @@ public abstract class BasePresenter extends MvpPresenter< mDataManager.getConferenceSDK().isScreenShareAllowed = allowed; } + public boolean hasCallForPickup() { + return mDataManager.getConferenceSDK().hasCallForPickup(); + } + + public String callPickupText() { + if (!hasCallForPickup()) return ""; + return mDataManager.getConferenceSDK().callPickupText(); + } + @Override public void showDefaultError(@NotNull Object data, @StringRes int errorRes) { getViewState().showDefaultServerError(errorRes); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt index 923269e60c..d5d3fd7fa2 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt @@ -36,6 +36,7 @@ import com.nynja.mobile.communicator.utils.StringUtils import com.nynja.mobile.communicator.utils.navigation.Screen import com.nynja.mobile.communicator.utils.navigation.navigators.HomeNavigator import com.nynja.mobile.communicator.utils.navigation.navigators.NynjaNavigator +import com.nynja.sdk.NYNCall import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.functions.Function import io.reactivex.schedulers.Schedulers @@ -126,6 +127,7 @@ class MainActivityPresenter : ConferenceSDKPresenter() { viewState.onInitWheel(mIsConferenceActive) val activeCall = mDataManager.conferenceSDK.activeConference if (activeCall != null) onConferenceStateChanged(activeCall) + onAcceptedElsewhereConference(""); } fun continueToJojnGroup() { @@ -620,16 +622,20 @@ class MainActivityPresenter : ConferenceSDKPresenter() { override fun activeConference(activeConferenceCall: ActiveConferenceCall) {} override fun timeAway(videoEnabled: Boolean, time: String) { + if (attachedViews.size == 0) return viewState.onConferenceTimeChange(time) } override fun conferenceEnded() { - viewState.onConferenceEnded() + if (attachedViews.size > 0) { + viewState.onConferenceEnded() + } invalidateWheelAfterCallStateChaged() clearIncomingCallNotification() } override fun onConferenceRinging() { + if (attachedViews.size == 0) return viewState.onConferenceRinging() } @@ -638,21 +644,40 @@ class MainActivityPresenter : ConferenceSDKPresenter() { } override fun onConferenceJoinFailed(reason: String) { - viewState.onConferenceJoinFailed(reason) + if (attachedViews.size > 0) { + viewState.onConferenceJoinFailed(reason) + } invalidateWheelAfterCallStateChaged() } override fun onConferenceStateChanged(activeConferenceCall: ActiveConferenceCall) { + if (attachedViews.size == 0) return viewState.onConferenceStateChanged(activeConferenceCall) } + override fun onStateChangedForCall(iConference: NYNCall?) { + if (attachedViews.size == 0) return + if (iConference != null) { + viewState.onStateChangedForCall(iConference.callId()) + } + } + + override fun onAcceptedElsewhereConference(conferenceId: String) { + if (attachedViews.size == 0) return + if (conferenceId != null) { + viewState.onAcceptedElsewhereConference(conferenceId) + } + } + override fun showPurchaseDialog(isModerator: Boolean, message: String?) { if (attachedViews.size == 0) return viewState.showPurchaseDialog(isModerator, message) } fun openActiveConference() { - viewState.openActiveConference() + if (attachedViews.size > 0) { + viewState.openActiveConference() + } mRouter.backTo(HomeNavigator.CHAT) } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java b/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java index 4ecb0e41d9..750054749c 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java @@ -41,6 +41,10 @@ public interface MainActivityView extends JoinGroupView { void onConferenceStateChanged(ActiveConferenceCall activeConferenceCall); + void onStateChangedForCall(String callId); + + void onAcceptedElsewhereConference(String conferenceId); + void openActiveConference(); void onConferenceRinging(); diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java index cc4a659d41..a8aa689d13 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java @@ -102,27 +102,23 @@ public class MainActivity extends BaseActivity implements MainActivityView, private static final String OPEN_SCREEN_KEY = "open_screen_key"; private static final String FILE_TYPE = "file"; - @BindView(R.id.nynja_navigation_view) - NynjaNavigationView mNynjaNavigationView; - @BindView(R.id.chat_active_video) - SurfaceViewRenderer video; - @BindView(R.id.chat_audio_layout) - View chatAudioLayout; - @BindView(R.id.chat_audio_name) - TextView chatAudioName; - @BindView(R.id.chat_audio_duration) - TextView duration; - @BindView(R.id.chat_return_text) - TextView headerStatusText; - @BindView(R.id.chat_audio_photo) - ImageView audioAvatar; - @BindView(R.id.home_activity_container_cl) - CoordinatorLayout mHomeActivityContainerCl; - @BindView(R.id.a_home_container) - RelativeLayout mHomeContainer; + @BindView(R.id.nynja_navigation_view) NynjaNavigationView mNynjaNavigationView; + @BindView(R.id.chat_active_video) SurfaceViewRenderer video; + @BindView(R.id.chat_audio_layout) View chatAudioLayout; + @BindView(R.id.chat_audio_name) TextView chatAudioName; + @BindView(R.id.chat_audio_duration) TextView duration; + @BindView(R.id.chat_return_text) TextView headerStatusText; + @BindView(R.id.chat_audio_photo) ImageView audioAvatar; + @BindView(R.id.home_activity_container_cl) CoordinatorLayout mHomeActivityContainerCl; + @BindView(R.id.a_home_container) RelativeLayout mHomeContainer; //Second Keyboard Container - @BindView(R.id.a_home_keyboard_container) - ViewGroup mSecondKeyboardContainer; + @BindView(R.id.a_home_keyboard_container) ViewGroup mSecondKeyboardContainer; + + // Call pickup banner + @BindView(R.id.call_pickup_layout) View callPickupLayout; + @BindView(R.id.call_pickup_name) TextView callPickupName; + @BindView(R.id.call_pickup_count) TextView callPickupCount; + @BindView(R.id.call_pickup_title_text) TextView callPickupHeaderText; @InjectPresenter MainActivityPresenter mPresenter; @@ -190,7 +186,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, mContainer = new Container(this); mContainer.setOnScreenChangedListener(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - params.addRule(RelativeLayout.BELOW, R.id.chat_audio_layout); + params.addRule(RelativeLayout.BELOW, R.id.call_top_banner_layout); mHomeContainer.addView(mContainer, params); mNavigator = new HomeNavigator(this); @@ -591,14 +587,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, @Override public void onConferenceEnded() { - mHandler.postDelayed(() -> releaseWakeLock(), Consts.DELAY_500); - runOnUiThread(() -> { - video.setVisibility(View.GONE); - chatAudioLayout.setVisibility(View.GONE); - duration.setText(""); - headerStatusText.setText(R.string.call_connecting); - chatAudioName.setText(""); - }); + onCallEnded(); } @Override @@ -609,41 +598,23 @@ public class MainActivity extends BaseActivity implements MainActivityView, @Override public void onConferenceStateChanged(ActiveConferenceCall activeConferenceCall) { - if (activeConferenceCall == null) return; - if (!mPresenter.isConferenceActive()) return; - if (!activeConferenceCall.isCallInProgress() - && !activeConferenceCall.isRinging - && !activeConferenceCall.isWaiting()) return; - if (activeConferenceCall.mConference != null && - activeConferenceCall.mConference.callState() == NYNCallState.NYNCallStateConnected) { - mHandler.post(() -> wakeLock()); - } + onCallStateChanged(activeConferenceCall); + } + + @Override + public void onStateChangedForCall(String callId) { runOnUiThread(() -> { - video.setVisibility(View.GONE); - if (activeConferenceCall != null && activeConferenceCall.isWaiting()) { - chatAudioLayout.setBackgroundResource(R.color.waiting_call_bg); - headerStatusText.setText(R.string.call_waiting_period); - } else { - chatAudioLayout.setBackgroundResource(R.color.active_call_bg); - } - chatAudioLayout.setVisibility(View.VISIBLE); - mPresenter.requestUser(); - //TODO: video feeds support in next features - //if (!activeConferenceCall.mData.isOwnStreamActive || !activeConferenceCall.hasRemoteVideoTrack) { - // video.setVisibility(View.GONE); - // chatAudioLayout.setVisibility(View.VISIBLE); - // mPresenter.requestUser(); - // if (activeConferenceCall.mConference != null) - // activeConferenceCall.mConference.setVideoRendererForTrack(video); - //} else { - // video.setVisibility(View.VISIBLE); - // chatAudioLayout.setVisibility(View.GONE); - // if (activeConferenceCall.mConference != null) { - // activeConferenceCall.mConference.setVideoRendererForTrack(null); - // } - //} - } - ); + onCallsStateChanged(); + }); + + } + + @Override + public void onAcceptedElsewhereConference(String conferenceId) { + runOnUiThread(() -> { + onCallsStateChanged(); + }); + } @Override @@ -1003,4 +974,79 @@ public class MainActivity extends BaseActivity implements MainActivityView, } ); } + + private void onCallStateChanged(ActiveConferenceCall activeConferenceCall) { + if ((activeConferenceCall == null) || + (!mPresenter.isConferenceActive()) || + (!activeConferenceCall.isCallInProgress() + && !activeConferenceCall.isRinging + && !activeConferenceCall.isWaiting())) { + runOnUiThread(() -> { + onCallsStateChanged(); + }); + return; + } + if (activeConferenceCall.mConference != null && + activeConferenceCall.mConference.callState() == NYNCallState.NYNCallStateConnected) { + mHandler.post(() -> wakeLock()); + } + runOnUiThread(() -> { + onActiveCallStateChanged(activeConferenceCall); + }); + } + + private void onCallEnded() { + mHandler.postDelayed(() -> releaseWakeLock(), Consts.DELAY_500); + runOnUiThread(() -> { + onActiveCallEnded(); + }); + } + + private void onActiveCallStateChanged(ActiveConferenceCall activeConferenceCall) { + video.setVisibility(View.GONE); + if (activeConferenceCall != null && activeConferenceCall.isWaiting()) { + chatAudioLayout.setBackgroundResource(R.color.waiting_call_bg); + headerStatusText.setText(R.string.call_waiting_period); + } else { + chatAudioLayout.setBackgroundResource(R.color.active_call_bg); + } + callPickupLayout.setVisibility(View.GONE); + chatAudioLayout.setVisibility(View.VISIBLE); + mPresenter.requestUser(); + //TODO: video feeds support in next features + //if (!activeConferenceCall.mData.isOwnStreamActive || !activeConferenceCall.hasRemoteVideoTrack) { + // video.setVisibility(View.GONE); + // chatAudioLayout.setVisibility(View.VISIBLE); + // mPresenter.requestUser(); + // if (activeConferenceCall.mConference != null) + // activeConferenceCall.mConference.setVideoRendererForTrack(video); + //} else { + // video.setVisibility(View.VISIBLE); + // chatAudioLayout.setVisibility(View.GONE); + // if (activeConferenceCall.mConference != null) { + // activeConferenceCall.mConference.setVideoRendererForTrack(null); + // } + //} + } + + private void onActiveCallEnded() { + video.setVisibility(View.GONE); + chatAudioLayout.setVisibility(View.GONE); + duration.setText(""); + headerStatusText.setText(R.string.call_connecting); + chatAudioName.setText(""); + + onCallsStateChanged(); + } + + private void onCallsStateChanged() { + if (mPresenter.hasCallForPickup()) { + //callPickupCount.setText(mPresenter.callPickupCount()); + callPickupLayout.setVisibility(View.VISIBLE); + callPickupName.setText(mPresenter.callPickupText()); + } else { + callPickupLayout.setVisibility(View.GONE); + } + } + } diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 31948f8463..3b17c6014a 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -1,11 +1,11 @@ - + android:orientation="vertical" + xmlns:tools="http://schemas.android.com/tools"> + android:layout_below="@+id/call_top_banner_layout"/> - + android:orientation="vertical"> + + + + + + diff --git a/app/src/main/res/layout/partial_call_pickup.xml b/app/src/main/res/layout/partial_call_pickup.xml new file mode 100644 index 0000000000..97bf17fd92 --- /dev/null +++ b/app/src/main/res/layout/partial_call_pickup.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 70dc74265c..38dfadc534 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -99,4 +99,6 @@ #A6ffffff #00000000 + #676BB9 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 398d5866d8..9fdb634ef2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1338,4 +1338,7 @@ Cannot start screen share because it has been already started by another participant Start camera is not available for groups + + Call pickup + -- GitLab From 889aa37168d29ab4d632ba7e8be715ff3fa1160e Mon Sep 17 00:00:00 2001 From: Ergyun Syuleyman Date: Wed, 27 May 2020 15:20:31 +0300 Subject: [PATCH 03/21] NY-8292: Profile Picture is not updating in Android App. --- .../data/sdk/account/AccountSDKModule.kt | 21 ++++++- .../presenters/AccountSettingsPresenter.kt | 59 ++++++++++++++++--- .../profile/AccountSettingsFragment.kt | 26 ++++++-- .../communicator/utils/DialogFactory.java | 11 +++- 4 files changed, 100 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/account/AccountSDKModule.kt b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/account/AccountSDKModule.kt index d037ed03cf..1ce8434952 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/account/AccountSDKModule.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/account/AccountSDKModule.kt @@ -12,6 +12,8 @@ import com.nynja.mobile.communicator.data.profile.UserContactData.CREATOR.CONTAC import com.nynja.mobile.communicator.data.profile.UserContactData.CREATOR.CONTACT_PHONE import com.nynja.mobile.communicator.data.profile.UserContactData.CREATOR.CONTACT_TWITTER import com.nynja.mobile.communicator.data.sdk.BaseSDKModule +import com.nynja.mobile.communicator.data.sdk.SDKErrors +import com.nynja.mobile.communicator.data.sdk.data.AccountRole import com.nynja.mobile.communicator.data.sdk.data.AccountStatus import com.nynja.mobile.communicator.data.sdk.data.data_impl.AccountImpl import com.nynja.mobile.communicator.data.sdk.data.data_impl.SDKError @@ -330,7 +332,7 @@ class AccountSDKModule(context: Context, communicator: NynjaCommunicator) : Base account.lastName, account.username, generateSDKAccountStatus(account.accountStatus), - generateSDKRoles(), + generateSDKRoles(),//account.accountRoles), generateSDKDate(account.birthday)) } @@ -453,7 +455,10 @@ class AccountSDKModule(context: Context, communicator: NynjaCommunicator) : Base fun deliverAccountResult(error: NYNError?, action: (ManageProfileSDKListener) -> Unit) { val sdkError = if (error != null) { val errorCode = error?.code?.let { AccountManager.errorCode(it) } - SDKError(errorCode.toString(), error.description) + val errorDesc = if (error.description.isNotEmpty()) error.description + else context.getString(SDKErrors.getProperResForErrorCode(errorCode.toString())) + + SDKError(errorCode.toString(), errorDesc) } else null deliverResult(mManageProfileListeners, sdkError, action) @@ -554,8 +559,18 @@ class AccountSDKModule(context: Context, communicator: NynjaCommunicator) : Base } private fun generateSDKRoles(): NYNAccountRoles { + return generateSDKRoles(null) + } + + private fun generateSDKRoles(accountRoles: ArrayList?): NYNAccountRoles { val roles = NYNAccountRoles() - roles.addRole(NYNAccountRole.NYN_AR_UNKNOWN) + if (accountRoles != null) { + for (role in accountRoles) { + roles.addRole(AccountRole.toSdkRole(role)) + } + } else { + roles.addRole(NYNAccountRole.NYN_AR_UNKNOWN) + } return roles } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/AccountSettingsPresenter.kt b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/AccountSettingsPresenter.kt index c1d3f1f2c3..58c9402704 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/AccountSettingsPresenter.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/AccountSettingsPresenter.kt @@ -18,6 +18,7 @@ import com.nynja.mobile.communicator.data.models.mqtt.Io import com.nynja.mobile.communicator.data.models.mqtt.Roster import com.nynja.mobile.communicator.data.models.nynjamodels.ProfileModel import com.nynja.mobile.communicator.data.models.nynjamodels.RosterModel +import com.nynja.mobile.communicator.data.sdk.SDKErrors import com.nynja.mobile.communicator.data.sdk.data.data_interfaces.IAccount import com.nynja.mobile.communicator.data.sdk.listeners.DefaultAccountSDKListener import com.nynja.mobile.communicator.mvp.view.AccountSettingsView @@ -39,6 +40,7 @@ import java.io.File class AccountSettingsPresenter : BasePresenter() { private var handledResponsesCount = 0 private var avatar: String? = null + private var uploadedAvatar: String? = null private val mHandler: Handler = Handler(Looper.getMainLooper()) @@ -71,6 +73,8 @@ class AccountSettingsPresenter : BasePresenter() { if (serverMessage.model is Roster) run { if (serverMessage.isSuccess(filter)) { handledResponsesCount++ + val roster = serverMessage.model as Roster + onUpdateddAvatar(roster.avatar) } } else if (serverMessage.model is Io) { @@ -85,16 +89,26 @@ class AccountSettingsPresenter : BasePresenter() { } } + override fun onFirstViewAttach() { + super.onFirstViewAttach() + mDataManager.accountSDK.attachManageProfileCallback(profileCallback) + } - override fun detachView(view: AccountSettingsView?) { + override fun onDestroy() { + super.onDestroy() mDataManager.accountSDK.detachManageProfileCallback(profileCallback) + } + + override fun detachView(view: AccountSettingsView?) { + //mDataManager.accountSDK.detachManageProfileCallback(profileCallback) + viewState.hideProgressDialog() super.detachView(view) } override fun attachView(view: AccountSettingsView?) { super.attachView(view) - mDataManager.accountSDK.attachManageProfileCallback(profileCallback) + //mDataManager.accountSDK.attachManageProfileCallback(profileCallback) setupContent() } @@ -114,13 +128,19 @@ class AccountSettingsPresenter : BasePresenter() { } fun setUserAvatar(filePath: String) { - mDataManager.saveAvatar(filePath) - mDataManager.saveUploadedAvatar(filePath) + //mDataManager.saveAvatar(filePath) mDataManager.uploadFile(NynjaAwsManager.TRANSFER_KEY_USER_AVATAR, File(filePath), object : AwsTransferWrapper() { override fun onComplete(transfer: AwsTransfer) { val avatarUrl : String? = transfer.awsTransferTasks[0].awsPayload - avatar = if (StringUtils.isNotEmpty(avatarUrl)) avatarUrl else null - //mDataManager.updateRosterAvatar(avatarUrl) + onUploadAvatarComplete(avatarUrl) + viewState.hideProgressDialog() + } + override fun onCanceled(transfer: AwsTransfer) { + viewState.hideProgressDialog() + } + + override fun onError(transfer: AwsTransfer?) { + viewState.hideProgressDialog() } }) } @@ -165,9 +185,25 @@ class AccountSettingsPresenter : BasePresenter() { } } + @Synchronized + private fun onUploadAvatarComplete(avatarUrl : String?) { + if (StringUtils.isEmpty(avatarUrl)) return; + avatar = avatarUrl + uploadedAvatar = avatarUrl + mDataManager.saveAvatar(avatarUrl) + } + @Synchronized + private fun onUpdateddAvatar(avatarUrl : String?) { + if (StringUtils.isEmpty(avatarUrl)) return; + //mDataManager.updateRosterAvatar(avatarUrl) + mDataManager.saveAvatar(avatarUrl) + mDataManager.saveUploadedAvatar(avatarUrl) + } + + @Synchronized private fun updateProfile(firstName: String, lastName: String, username: String) { mDataProvider.updateAccount( - avatar, null, null, + uploadedAvatar, null, null, firstName, lastName, username, null, null) } @@ -191,18 +227,23 @@ class AccountSettingsPresenter : BasePresenter() { }) } + @Synchronized private fun setAccountSettings(profile: ProfileModel) { val roster = profile.roster ?: return // TODO make decision for all values with "" val avatarUrl = roster.avatar ?: "" + val uploadedAvatarUrl = roster.uploadedAvatar ?: "" val inactiveTimeout = "" val firstName = roster.names ?: "" val lastName = roster.surnames ?: "" val username = roster.nick ?: "" val email = roster.email ?: "" - avatar = if (StringUtils.isNotEmpty(avatarUrl)) avatarUrl else null + avatar = if (StringUtils.isNotEmpty(avatarUrl) && + avatar == null) avatarUrl else avatar + uploadedAvatar = if (StringUtils.isNotEmpty(uploadedAvatarUrl) && + uploadedAvatar == null) uploadedAvatarUrl else uploadedAvatar val accountSettings = Content(avatarUrl, inactiveTimeout, firstName, lastName, username, email) viewState?.setContent(accountSettings) profile.account?.let { @@ -254,6 +295,8 @@ class AccountSettingsPresenter : BasePresenter() { } override fun onGetAccountInfoFinished(accountDetails: IAccount?) { + viewState.hideProgressDialog() + viewState.hideLocalProgress() mDataProvider.saveAccount(accountDetails!!) mHandler.postDelayed({ mDataManager.sendLocalEvent(AccountGetFinishedEvent()) diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/fragments/profile/AccountSettingsFragment.kt b/app/src/main/java/com/nynja/mobile/communicator/ui/fragments/profile/AccountSettingsFragment.kt index 2cccdda5f0..da429ef4ff 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/fragments/profile/AccountSettingsFragment.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/fragments/profile/AccountSettingsFragment.kt @@ -2,6 +2,8 @@ package com.nynja.mobile.communicator.ui.fragments.profile import android.Manifest import android.os.Bundle +import android.os.Handler +import android.os.Looper import android.support.v4.content.ContextCompat import android.view.LayoutInflater import android.view.View @@ -12,6 +14,8 @@ import android.widget.TextView import butterknife.BindView import butterknife.OnClick import com.arellomobile.mvp.presenter.InjectPresenter +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions import com.jakewharton.rxbinding2.widget.RxTextView import com.nynja.mobile.communicator.R import com.nynja.mobile.communicator.camera.data.CameraMedia @@ -64,6 +68,7 @@ class AccountSettingsFragment : BaseFragment(), AccountSettingsView { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + enableSaveButton(false) addDisposable(RxTextView.afterTextChangeEvents(mFirstName) .map { textViewAfterTextChangeEvent -> textViewAfterTextChangeEvent.view().text.toString() } .subscribeOn(Schedulers.io()) @@ -85,12 +90,20 @@ class AccountSettingsFragment : BaseFragment(), AccountSettingsView { } override fun setContent(content: AccountSettingsPresenter.Content) { - ImageUtils.loadAvatarImage(content.avatarUrl, mUserAvatar) + if (mUserAvatar != null && StringUtils.isNotEmpty(content.avatarUrl)) { + Glide.with(mUserAvatar.getContext()) + .load(content.avatarUrl) + .apply(RequestOptions() + .circleCrop()) + .into(mUserAvatar) + } else { + ImageUtils.loadAvatarImage(null, mUserAvatar) + } // mInactiveTimeout.setText(content.inactiveTimeout) - mFirstName.setText(content.firstName) - mLastName.setText(content.lastName) - mUsername.setText(content.username) + if (!(mFirstName.text.toString().contentEquals(content.firstName))) mFirstName.setText(content.firstName) + if (!(mLastName.text.toString().contentEquals(content.lastName))) mLastName.setText(content.lastName) + if (!(mUsername.text.toString().contentEquals(content.username))) mUsername.setText(content.username) // mEmail.setText(content.email) } @@ -104,7 +117,10 @@ class AccountSettingsFragment : BaseFragment(), AccountSettingsView { override fun onPickedMedia(resultData: CameraMedia) { if (resultData.file != null) { - mPresenter.setUserAvatar(resultData.file.path) + Handler(Looper.getMainLooper()).post( { + showProgressDialog() + mPresenter.setUserAvatar(resultData.file.path) + }) } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java b/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java index ea23d5bb11..fe1e330efe 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java @@ -66,7 +66,16 @@ public class DialogFactory { public static void hideProgressDialog() { try { - if (progressDialog != null && progressDialog.isShowing()) progressDialog.dismiss(); + final ProgressDialog[] dialog = {progressDialog}; + progressDialog = null; + if (dialog[0] != null) { + if (dialog[0].isShowing()) { + dialog[0].setOnDismissListener(dialogInterface -> dialog[0] = null); + dialog[0].dismiss(); + } else { + dialog[0] = null; + } + } } catch (Exception ex) { Timber.e(ex); } -- GitLab From 222891e13171acfdb12d990938a254f258eb6525 Mon Sep 17 00:00:00 2001 From: Ergyun Syuleyman Date: Wed, 27 May 2020 15:58:38 +0300 Subject: [PATCH 04/21] NY-9856: AN: Start video conference call from a group or from the wheel Group chat - point 2. --- .../com/nynja/mobile/communicator/ui/wheel/entity/Factory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/wheel/entity/Factory.java b/app/src/main/java/com/nynja/mobile/communicator/ui/wheel/entity/Factory.java index 047e26a48a..2c829addaa 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/wheel/entity/Factory.java +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/wheel/entity/Factory.java @@ -595,7 +595,7 @@ public class Factory { .wheelAction(ChatActions.CallAction) .text(R.string.call) .icons(R.drawable.ic_calls, 0) -// .subItems(getCallSubItems()) + .subItems(getCallSubItems()) .state(callOptionsEnabled ? ENABLE : DISABLE) .build()); } -- GitLab From bbc34950ad63e67a9b3bdfb2fbcc84e5cf4f7c80 Mon Sep 17 00:00:00 2001 From: Rafael da Veiga Cabral Date: Wed, 27 May 2020 17:59:55 -0300 Subject: [PATCH 05/21] NY9868: [AN]: Move the deletion to after the cursor is closed. --- .../com/nynja/mobile/communicator/data/db/DbHelper.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java b/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java index a98c8f51af..a3daa30e3c 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java @@ -356,16 +356,15 @@ public class DbHelper { while (cursor.moveToNext()) { tables[i++] = cursor.getString(0); } - - for (String table : tables) { - String dropQuery = "DELETE FROM " + table; - mDb.execute(dropQuery); - } } finally { if (cursor != null) { cursor.close(); } } + for (String table : tables) { + String dropQuery = "DELETE FROM " + table; + mDb.execute(dropQuery); + } }); } -- GitLab From af399c552ad1093b69879625e99b7fdfced0a07c Mon Sep 17 00:00:00 2001 From: Rafael da Veiga Cabral Date: Wed, 27 May 2020 18:01:50 -0300 Subject: [PATCH 06/21] NY9868: [AN]: Prevent nested cursors --- .../mobile/communicator/data/db/DbHelper.java | 173 +++++++++--------- 1 file changed, 87 insertions(+), 86 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java b/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java index a3daa30e3c..8ed7216650 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/db/DbHelper.java @@ -347,14 +347,13 @@ public class DbHelper { public Completable clearTables() { return Completable.fromAction(() -> { Cursor cursor = null; + List tables = new ArrayList(); try { cursor = mDb.query("SELECT name FROM sqlite_master WHERE type IS 'table'" + " AND name NOT IN ('sqlite_master', 'sqlite_sequence', 'android_metadata')"); if (cursor == null) return; - String[] tables = new String[cursor.getCount()]; - int i = 0; while (cursor.moveToNext()) { - tables[i++] = cursor.getString(0); + tables.add(cursor.getString(0)); } } finally { if (cursor != null) { @@ -377,7 +376,6 @@ public class DbHelper { if (cursor.getCount() > 0) { cursor.moveToFirst(); auth = AuthTable.parseCursor(cursor); - auth.settings = getAuthFeatures(auth); } } } finally { @@ -385,6 +383,7 @@ public class DbHelper { cursor.close(); } } + auth.settings = getAuthFeatures(auth); return auth; } @@ -1811,18 +1810,18 @@ public class DbHelper { while (cursor.moveToNext()) { contacts.add(ContactsTable.parseCursor(cursor)); } - if (!isForCotacts) { - contacts = getMyContactsMessagesWithFilters(rosterId, contacts, true, newerThan); - } - if (!onlyTimeline) { - setContactsData(contacts, !isForCotacts); - } } } finally { if (cursor != null) { cursor.close(); } } + if (!isForCotacts) { + contacts = getMyContactsMessagesWithFilters(rosterId, contacts, true, newerThan); + } + if (!onlyTimeline) { + setContactsData(contacts, !isForCotacts); + } return contacts; } @@ -2053,18 +2052,19 @@ public class DbHelper { list.add(message); } setMessagesDesc(list); - if (!minimalData) { - checkStarMessage(list); - if (isAddReplied) { - addRepliedToMessage(list); - } - } } } finally { if (cursor != null) { cursor.close(); } } + if (!minimalData) { + checkStarMessage(list); + if (isAddReplied) { + addRepliedToMessage(list); + } + } + return list; } @@ -2078,11 +2078,6 @@ public class DbHelper { if (cursor.getCount() > 0) { cursor.moveToFirst(); message = MessagesTable.parseCursor(cursor); - setMessageDesc(message); - checkStarMessage(message); - if (isAddReplied && message.isReply()) { - addRepliedToMessage(message); - } } } } finally { @@ -2090,6 +2085,11 @@ public class DbHelper { cursor.close(); } } + setMessageDesc(message); + checkStarMessage(message); + if (isAddReplied && message.isReply()) { + addRepliedToMessage(message); + } return message; } @@ -2257,23 +2257,23 @@ public class DbHelper { ids.add(String.valueOf(star.messageId)); list.add(star); } - if (!list.isEmpty()) { - List messages = getStaticMessageByIds(TextUtils.join(", ", ids), MessageModel.StaticTypes.STAR); - for (StarModel star : list) { - for (MessageModel message : messages) { - if (message.serverId != null && message.serverId.equals(star.messageId)) { - star.message = message; - break; - } - } - } - } } } finally { if (cursor != null) { cursor.close(); } } + if (!list.isEmpty()) { + List messages = getStaticMessageByIds(TextUtils.join(", ", ids), MessageModel.StaticTypes.STAR); + for (StarModel star : list) { + for (MessageModel message : messages) { + if (message.serverId != null && message.serverId.equals(star.messageId)) { + star.message = message; + break; + } + } + } + } return list; } @@ -2831,24 +2831,26 @@ public class DbHelper { MemberModel member = getMember(cursor); members.add(member); } - if (!minimalData) { - getMemberFeatures(members); - setMemberServices(members); - } else if (loadMemberFeatures) { - getMemberFeatures(members); - } } } finally { if (cursor != null) { cursor.close(); } } + if (!minimalData) { + getMemberFeatures(members); + setMemberServices(members); + } else if (loadMemberFeatures) { + getMemberFeatures(members); + } + } return members; } private void getMembersByRoom(RoomModel room, boolean minimalData) { if (room != null) { + List members = new ArrayList(); long time = System.currentTimeMillis(); Cursor cursor = null; @@ -2866,25 +2868,7 @@ public class DbHelper { //////////////////////////////////////////////////////////////////////////////////////////// if (cursor != null) { while (cursor.moveToNext()) { - MemberModel member = MemberTable.parseCursor(cursor); - getMemberFeatures(member); - //////////////////////////////////////////////////////////////////////////////////////////// - // TEST TEST TEST - if (BuildConfig.DEBUG) { - //Timber.i("######## TEST_POINT_"+(minimalData? 7 : 6) +": getObsChatRoomsFiltered - setRoomData ->getMembersByRoom 2: " + (System.currentTimeMillis() - time) + ", forList= " + minimalData); - time = System.currentTimeMillis(); - } - //////////////////////////////////////////////////////////////////////////////////////////// - if (!minimalData) { - setMemberServices(member); - } - if (MemberModel.Statuses.MEMBER.equals(member.status)) { - room.members.add(member); - } else if (MemberModel.Statuses.ADMIN.equals(member.status) || MemberModel.Statuses.OWNER.equals(member.status)) { - room.admins.add(member); - } else if (MemberModel.Statuses.REMOVED.equals(member.status)) { - room.removed.add(member); - } + members.add(MemberTable.parseCursor(cursor)); } } } finally { @@ -2892,6 +2876,26 @@ public class DbHelper { cursor.close(); } } + for (MemberModel member : members) { + getMemberFeatures(member); + //////////////////////////////////////////////////////////////////////////////////////////// + // TEST TEST TEST + if (BuildConfig.DEBUG) { + //Timber.i("######## TEST_POINT_"+(minimalData? 7 : 6) +": getObsChatRoomsFiltered - setRoomData ->getMembersByRoom 2: " + (System.currentTimeMillis() - time) + ", forList= " + minimalData); + time = System.currentTimeMillis(); + } + //////////////////////////////////////////////////////////////////////////////////////////// + if (!minimalData) { + setMemberServices(member); + } + if (MemberModel.Statuses.MEMBER.equals(member.status)) { + room.members.add(member); + } else if (MemberModel.Statuses.ADMIN.equals(member.status) || MemberModel.Statuses.OWNER.equals(member.status)) { + room.admins.add(member); + } else if (MemberModel.Statuses.REMOVED.equals(member.status)) { + room.removed.add(member); + } + } } } @@ -4123,13 +4127,13 @@ public class DbHelper { MessageModel message = StaticMessagesTable.parseCursor(cursor); list.add(message); } - setStaticMessagesDesc(list, type); } } finally { if (cursor != null) { cursor.close(); } } + setStaticMessagesDesc(list, type); return list; } @@ -4510,7 +4514,6 @@ public class DbHelper { DescModel desc = DescTable.parseCursor(cursorDescs); descList.add(desc); } - cursorDescs.close(); } stickerPack.stickers.clear(); stickerPack.stickers.addAll(descList); @@ -4541,47 +4544,45 @@ public class DbHelper { List result = new ArrayList<>(); for (String stickerIdentificator : stickerIdentificators) { Cursor cursorDesc = null; + DescModel stickerDesc = null; try { cursorDesc = mDb.query("SELECT * FROM " + DescTable.TABLE_NAME + " WHERE " + DescTable.Column.MIME + " = '" + DescModel.MimeTypes.Sticker + "' AND " + DescTable.Column.TARGET_TYPE + " = '" + DescTable.TYPE_STICKER_PACK + "' AND " + DescTable.Column.UNIQUE_ID + " = '" + stickerIdentificator + "'"); - DescModel stickerDesc = null; if (cursorDesc != null) { while (cursorDesc.moveToNext()) { stickerDesc = DescTable.parseCursor(cursorDesc); } } - if (stickerDesc != null) { - List features = new ArrayList<>(); - Cursor cursorFeatures = null; - try { - cursorFeatures = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + - FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_STICKER + "'" + - " AND " + FeatureTable.Column.TARGET_ID + " = '" + stickerDesc.id + "'"); - if (cursorFeatures != null) { - while (cursorFeatures.moveToNext()) { - FeatureModel feature = FeatureTable.parseCursor(cursorFeatures); - features.add(feature); - } - } - } finally { - if (cursorFeatures != null) { - cursorFeatures.close(); + } finally { + if (cursorDesc != null) { + cursorDesc.close(); + } + } + if (stickerDesc != null) { + List features = new ArrayList<>(); + Cursor cursorFeatures = null; + try { + cursorFeatures = mDb.query("SELECT * FROM " + FeatureTable.TABLE_NAME + " WHERE " + + FeatureTable.Column.TYPE + " = '" + FeatureTable.TYPE_STICKER + "'" + + " AND " + FeatureTable.Column.TARGET_ID + " = '" + stickerDesc.id + "'"); + if (cursorFeatures != null) { + while (cursorFeatures.moveToNext()) { + FeatureModel feature = FeatureTable.parseCursor(cursorFeatures); + features.add(feature); } } - stickerDesc.data.clear(); - stickerDesc.data.addAll(features); - } - if (stickerDesc != null) { - Sticker sticker = DescManager.getStickerFromDesc(context, stickerDesc); - if (sticker != null) { - result.add(sticker); + } finally { + if (cursorFeatures != null) { + cursorFeatures.close(); } } - } finally { - if (cursorDesc != null) { - cursorDesc.close(); + stickerDesc.data.clear(); + stickerDesc.data.addAll(features); + Sticker sticker = DescManager.getStickerFromDesc(context, stickerDesc); + if (sticker != null) { + result.add(sticker); } } } -- GitLab From b071654688de17fee7c04d628be300e77b04ffa0 Mon Sep 17 00:00:00 2001 From: Rafael da Veiga Cabral Date: Wed, 27 May 2020 18:18:38 -0300 Subject: [PATCH 07/21] NY-9844 [AN]: DownloadFileService IllegalStateException on stopService fix --- .../communicator/data/DownloadFileService.kt | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt b/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt index ece5081bd9..d33b077baf 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/data/DownloadFileService.kt @@ -50,16 +50,13 @@ class DownloadFileService : Service() { } fun stopServıce(context: Context) { - context.startService(getStopIntent(context)) + context.stopService(getStopIntent(context)) } } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { if (intent != null && START_DOWNLOAD_FOREGROUND_ACTION == intent.action) { startForeground(START_DOWNLOAD_FOREGROUND_ACTION) - return START_NOT_STICKY - } else if (intent != null && STOP_DOWNLOAD_FOREGROUND_ACTION == intent.action) { - stopForeground(STOP_DOWNLOAD_FOREGROUND_ACTION) } return START_NOT_STICKY @@ -84,17 +81,18 @@ class DownloadFileService : Service() { } } - @Synchronized - private fun stopForeground(action: String?) { - if (action != null && STOP_DOWNLOAD_FOREGROUND_ACTION == action) { - stopForeground(true) - mStarted = false - stopSelf() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - mNotificationHelper.clearNotificationById(ONGOING_NOTIFICATION_ID) - } + private fun clearNotification() { + stopForeground(true) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + mNotificationHelper.clearNotificationById(ONGOING_NOTIFICATION_ID) } } + override fun onDestroy() { + mStarted = false + clearNotification() + super.onDestroy() + } + override fun onBind(intent: Intent?) = null } \ No newline at end of file -- GitLab From 91f8fcdaccac882e437267005a9a1f64f8674f83 Mon Sep 17 00:00:00 2001 From: Rafael da Veiga Cabral Date: Fri, 29 May 2020 09:19:54 -0300 Subject: [PATCH 08/21] NY-9867: [AN]: android.app.RemoteServiceException (did not then call Service.startForeground()) Note: This complements same issue found in the Download Service (NY-9844) --- .../data/sdk/calls/ConferenceSDKModule.java | 4 ++-- .../data/sdk/calls/ConferenceService.java | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java index b00746dd83..61d8b06193 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java @@ -414,7 +414,7 @@ public class ConferenceSDKModule extends BaseSDKModule { } private void stopCallService() { - getContext().startService(ConferenceService.getStopIntent(getContext())); + getContext().stopService(ConferenceService.getStopIntent(getContext())); } public void togleFullScreen() { @@ -3212,7 +3212,7 @@ public class ConferenceSDKModule extends BaseSDKModule { conferenceSDKListener.onConferenceFailed(reason); } } - getContext().startService(ConferenceService.getStopIntent(getContext())); + getContext().stopService(ConferenceService.getStopIntent(getContext())); }, Consts.DELAY_50); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java index 125887423e..67abe8e9b6 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceService.java @@ -95,8 +95,6 @@ public class ConferenceService extends Service implements SensorEventListener { boolean tryWakeLock = (intent.hasExtra(START_CONFERENCE_WAKE_LOCK_ACTION) && intent.getBooleanExtra(START_CONFERENCE_WAKE_LOCK_ACTION, false)); startForeground(intent.getAction(), tryWakeLock); - } else if (intent != null && STOP_CONFERENCE_FOREGROUND_ACTION.equalsIgnoreCase(intent.getAction())) { - stopForeground(STOP_CONFERENCE_FOREGROUND_ACTION); } else if (intent != null && START_CONFERENCE_WAKE_LOCK_ACTION.equalsIgnoreCase(intent.getAction())) { tryStartyWakeLock(); } @@ -168,14 +166,9 @@ public class ConferenceService extends Service implements SensorEventListener { } } - @Synchronized - private void stopForeground(@Nullable String action) { - if (action != null && STOP_CONFERENCE_FOREGROUND_ACTION.equalsIgnoreCase(action)) { - stopForeground(true); - stopSelf(); - mForegroundStarted = false; - mNotificationHelper.clearCallPush(ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); - } + private void clearConferenceCall() { + stopForeground(true); + mNotificationHelper.clearCallPush(ActiveConferenceCall.ANDROID_10_PUSH_CALL_NTFN_ID); } private void safetyProximityWakeLockRelease() { @@ -209,6 +202,9 @@ public class ConferenceService extends Service implements SensorEventListener { @Override public void onDestroy() { Timber.d("onDestroy"); + mForegroundStarted = false; + clearConferenceCall(); + if (!mCommunication.isBinded()) mDataManager.disconnectConference(); if (mProximity != null) { -- GitLab From 109ade1330fae8811d8532e59613d4fe72d6cb36 Mon Sep 17 00:00:00 2001 From: Ergyun Syuleyman Date: Sun, 31 May 2020 19:32:04 +0300 Subject: [PATCH 09/21] -first alpha version of call pickup :) --- app/build.gradle | 2 +- .../data/sdk/ConferenceSDKPresenter.java | 3 + .../data/sdk/NynjaSDKManager.java | 2 +- .../data/sdk/calls/ConferenceSDKListener.java | 2 + .../data/sdk/calls/ConferenceSDKModule.java | 181 ++++++++++++++++-- .../mvp/presenters/BasePresenter.java | 54 ++++++ .../mvp/presenters/MainActivityPresenter.kt | 20 +- .../mvp/view/MainActivityView.java | 2 + .../ui/activities/MainActivity.java | 85 +++++++- .../communicator/utils/DialogFactory.java | 48 ++++- .../main/res/layout/partial_call_pickup.xml | 10 +- app/src/main/res/values-en/strings.xml | 5 + app/src/main/res/values-es/strings.xml | 5 + app/src/main/res/values-ko/strings.xml | 5 + app/src/main/res/values-zh-rCN/strings.xml | 5 + app/src/main/res/values-zh/strings.xml | 5 + app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 2 + 18 files changed, 399 insertions(+), 39 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dec91bee46..c87335eaef 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -679,7 +679,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // Conference, Calls mobile SDK - implementation 'com.nynja.sdk:NynjaSdk:1.21.5@aar' + implementation 'com.nynja.sdk:NynjaSdk:1.21.5.1@aar' //implementation(name: 'NynjaSdk-1.21.5', ext: 'aar') //ExoPlayer diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java index 63e96f550c..9e3b3ee8cc 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/ConferenceSDKPresenter.java @@ -102,4 +102,7 @@ public abstract class ConferenceSDKPresenter extends Bas @Override public void showPurchaseDialog(boolean isModerator, final String message) {} @Override public void onPurchaseFinished() {} + + @Override public void pickupCallWhileAnotherActiveCall() {} + } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/NynjaSDKManager.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/NynjaSDKManager.java index a4db15d106..7678e9d28a 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/NynjaSDKManager.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/NynjaSDKManager.java @@ -66,7 +66,7 @@ public class NynjaSDKManager { } else { communicator = NynjaCommunicator.newInstance(); } - communicator.setDeviceId(Utils.getAndroidId(mContext)); + communicator.setDeviceId(Utils.getDeviceId(mContext));//)getAndroidId(mContext)); mAccountSDKModule = new AccountSDKModule(mContext, communicator); mConferenceSDKModule = new ConferenceSDKModule(context, communicator, NynjaApp.getComponent().dbHelper(), mPreferenceHelper.getSettingNotifications(), new StateDevice(false), diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java index 21600b1296..4b7d023f76 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKListener.java @@ -87,4 +87,6 @@ public interface ConferenceSDKListener { void showPurchaseDialog(boolean isModerator, final String message); void onPurchaseFinished(); + + void pickupCallWhileAnotherActiveCall(); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java index b663a25c0b..6b735b34d2 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java +++ b/app/src/main/java/com/nynja/mobile/communicator/data/sdk/calls/ConferenceSDKModule.java @@ -61,6 +61,7 @@ import com.nynja.sdk.NYNCallParticipant; import com.nynja.sdk.NYNCallParticipantArray; import com.nynja.sdk.NYNCallRoomType; import com.nynja.sdk.NYNCallState; +import com.nynja.sdk.NYNCallsArray; import com.nynja.sdk.NYNConfMemberOption; import com.nynja.sdk.NYNError; import com.nynja.sdk.NynjaCallHistoryManager; @@ -140,7 +141,8 @@ public class ConferenceSDKModule extends BaseSDKModule { private boolean isSpeakerPhoneForced = false; private HashMap mConferenceRoomLimits = new HashMap<>(); private HashMap mConferenceWaitingRoomLNames = new HashMap<>(); - private HashMap mMyAcceptedElsewhereCalls = new HashMap<>(); + //private HashMap mMyAcceptedElsewhereCalls = new HashMap<>(); + private HashMap mMyAcceptedElsewhereCalls = new HashMap<>(); private int mLastPhoneCallState = TelephonyManager.CALL_STATE_IDLE; @@ -529,18 +531,20 @@ public class ConferenceSDKModule extends BaseSDKModule { } return true; } + public synchronized String callPickupText() { String text = ""; synchronized (mMyAcceptedElsewhereCalls) { for (String callId : mMyAcceptedElsewhereCalls.keySet()) { - NYNCall call = mCallManager.getCallById(callId); +// NYNCall call = mCallManager.getCallById(callId); + NYNCall call = mMyAcceptedElsewhereCalls.get(callId); if (call != null) { if (StringUtils.isNotEmpty(text)) { text += ", "; } if (!call.isConference()) { - String id = call.isOutgoing() ? call.callee() : call.caller(); // TODO: get local contact OR ROOM name by ID + //String id = call.isOutgoing() ? call.callee() : call.caller(); text += (call.getExternalInfo()); } } @@ -549,6 +553,85 @@ public class ConferenceSDKModule extends BaseSDKModule { return text; } + public synchronized HashMap pickupCallsInfo() { + HashMap pickupeCalls = new HashMap<>(); + synchronized (mMyAcceptedElsewhereCalls) { + for (String callId : mMyAcceptedElsewhereCalls.keySet()) { + NYNCall call = mCallManager.getCallById(callId); + if (call != null) { + pickupeCalls.put(callId, call.getExternalInfo()); + } + } + } + return pickupeCalls; + } + + public synchronized HashMap pickupCalls() { + return mMyAcceptedElsewhereCalls; + } + + public synchronized boolean callPickup(String callId) { + if (callId == null) { + Timber.w("callPickup(): try to pickup with callId=null!!!"); + return false; + } + if (hasCreatedActiveCall()) { + if (mActiveConference.mConference != null && + callId.contentEquals(mActiveConference.mConference.callId())) { + Timber.w("callPickup(): try to pickup the same already pickingUP call - ID=%s",callId); + return false; + } + if (mActiveConference.mConference != null) { + Timber.w("callPickup(): while has another active call!! callID=%s", + mActiveConference.mConference.callId()); + mHandler.postDelayed(() -> { + synchronized (mConferenceSDKListener) { + for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { + conferenceSDKListener.pickupCallWhileAnotherActiveCall(); + } + } + }, Consts.DELAY_50); + return false; + } + } + NYNCall call = mCallManager.pickupCall(Utils.generateUUID(), callId); + if (call != null) { + mConferenceDetails = new ConferenceDetails(getDeviceId(), callId); + mActiveConference = createActiveConference(call); + if (hasCreatedActiveCall()) { + initConferenceCall(false); + mActiveConference.isCallInProgress = true; + //startConferenceActivity(); + return true; + } + } + return false; + } + + public void loadPickupCalls() { + new Handler(Looper.getMainLooper()).postDelayed(() -> { + if (!isLoggedIn()) return; + NYNCallsArray pickups = mCallManager.callsActiveElsewhere(); + if (pickups != null) { + if (pickups.size() == 0) return; + mMyAcceptedElsewhereCalls.clear(); + for (int index = 0; index< pickups.size(); index++) { + NYNCall call = pickups.get(index); + if (call != null && StringUtils.isNotEmpty(call.callId())) { + mMyAcceptedElsewhereCalls.put(call.callId(), call); + } + } + mHandler.postDelayed(() -> { + synchronized (mConferenceSDKListener) { + for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { + conferenceSDKListener.onConferenceStateChanged(mActiveConference); + } + } + }, Consts.DELAY_50); + } + },Consts.DELAY_200); + } + public boolean isCameraRunning() { if (!hasCreatedActiveCall()) return false; if (mActiveConference.mConference == null) return false; @@ -1192,7 +1275,8 @@ public class ConferenceSDKModule extends BaseSDKModule { if (!((hasCreatedActiveCall() && mActiveConference.mConference != null && mActiveConference.mConference.callId().contentEquals(callId)) || call.isStartedOnThisDevice())) { - mMyAcceptedElsewhereCalls.put(callId, roomId); + //mMyAcceptedElsewhereCalls.put(callId, roomId); + mMyAcceptedElsewhereCalls.put(callId, mCallManager.getCallById(callId)); } } if (!forceFireEvent) { @@ -1429,6 +1513,7 @@ public class ConferenceSDKModule extends BaseSDKModule { @Override public void receivedRingingCall(NYNCall call) { + Timber.d("receivedRingingCall(): call with \'CallId\'=\'%s", (call !=null ? call.callId(): "null")); onIncomingConference(call); } @@ -1439,6 +1524,7 @@ public class ConferenceSDKModule extends BaseSDKModule { @Override public void receivedAcceptedElsewhere(String conferenceId) { + Timber.d("receivedAcceptedElsewhere(): call with \'CallId\'=\'%s", conferenceId); onAcceptedElsewhereConference(conferenceId); } @@ -1469,6 +1555,7 @@ public class ConferenceSDKModule extends BaseSDKModule { @Override public void conferenceIdByLinkIdFinished(NYNError err, String requestId, String confId) { + Timber.d("conferenceIdByLinkIdFinished(): call with \'CallId\'=\'%s", confId); if (onJoinConferenceByLinkIdFailed(confId, err)) { return; } @@ -1477,17 +1564,20 @@ public class ConferenceSDKModule extends BaseSDKModule { @Override public void joinConferenceByLinkIdFinished(NYNError err, String requestId, String confId) { + Timber.d("joinConferenceByLinkIdFinished(): call with \'CallId\'=\'%s", confId); onJoinConferenceByLinkIdFinished(err, confId); } @Override public void receivedAcceptedCall(NYNCall call) { + Timber.d("receivedAcceptedCall(): call with \'CallId\'=\'%s", (call !=null ? call.callId(): "null")); onAcceptedCall(call); } @Override public void receivedCompletedCall(NYNCall call) { - String callId = call.callId(); + String callId = (call != null ? call.callId(): null); + Timber.d("receivedCompletedCall(): call with \'CallId\'=\'%s", callId); onCallEndedHandle(call, true); if (call != null && callId != null && hasCreatedActiveCall() && mActiveConference.mConference != null @@ -1539,6 +1629,11 @@ public class ConferenceSDKModule extends BaseSDKModule { onEscalateConferenceFinished(err, replaceRef, roomId, conferenceId); } + @Override + public void pickupCallFinished(String requestId, String callId, boolean success) { + onPickupCallFinished(requestId, callId, success); + } + @Override public void signalCallCompleted(NYNCall call) { onSignalCallCompleted(call); @@ -1549,6 +1644,12 @@ public class ConferenceSDKModule extends BaseSDKModule { onCallTimedOut(call); } + @Override + public void elsewhereCallFinished(NYNCall call) { + if (call == null) return; + onElsewhereCallFinished(call.callId()); + } + }; mCallManager.setListener(mCallManagerListener); } @@ -2987,10 +3088,13 @@ public class ConferenceSDKModule extends BaseSDKModule { createIncomingConference(iConference, true); } + private boolean isP2P(NYNCall call) { + return (call != null && !call.isConference()); + } + public synchronized boolean isP2P() { return (mActiveConference != null - && mActiveConference.mConference != null - && !mActiveConference.mConference.isConference() + && isP2P(mActiveConference.mConference) ); } @@ -3064,26 +3168,71 @@ public class ConferenceSDKModule extends BaseSDKModule { } private void onAcceptedElsewhereConference(String conferenceId) { - if (!hasCreatedActiveCall()) return; - if (mActiveConference.mConference == null) return; + if (StringUtils.isNotEmpty(conferenceId)) { + NYNCall call = mCallManager.getCallById(conferenceId); + if (call != null) { + if (isP2P(call)) { + //String roomId = (call.isConference() ? call.getChatRoomId() : + // (call.isOutgoing() ? call.callee() : call.caller())); + //mMyAcceptedElsewhereCalls.put(conferenceId, roomId); + mMyAcceptedElsewhereCalls.put(conferenceId, call); + for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { + conferenceSDKListener.onAcceptedElsewhereConference(conferenceId); + } + } + } + } - if (mActiveConference.mConference.callId().contentEquals(conferenceId)) { + if (mActiveConference != null && + mActiveConference.mConference != null && + mActiveConference.mConference.callId().contentEquals(conferenceId)) { mActiveConference.isRinging = false; if (mActiveConference.mConference.isOutgoing() && mActiveConference.isOutgoingCall) { // Nothing to do when is my outgoing call - may need check when allow multiple login } else { - if (isP2P()) { - mMyAcceptedElsewhereCalls.put(conferenceId, mActiveConference.mEndPointId); - for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { - conferenceSDKListener.onAcceptedElsewhereConference(conferenceId); - } - } + //if (isP2P() && !mActiveConference.isCallRinging()) return; onConferenceEnded(conferenceId); } } } + private synchronized void removeCallFromElsewhereCallsList(String callId, boolean fireEvent) { + if (mMyAcceptedElsewhereCalls.containsKey(callId)) { + //String roomId = (call.isConference() ? call.getChatRoomId() : + // (call.isOutgoing() ? call.callee() : call.caller())); + //mMyAcceptedElsewhereCalls.put(conferenceId, roomId); + mMyAcceptedElsewhereCalls.remove(callId); + if (!fireEvent) return; + for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { + conferenceSDKListener.onAcceptedElsewhereConference(callId); + } + } + } + + private void onPickupCallFinished(String requestId, String callId, boolean success) { + Timber.d("onPickupCallFinished(): callId=%s, result=%s", + callId, success ? "true" : "false"); + if (success) { + removeCallFromElsewhereCallsList(callId, false); + if (mActiveConference != null && + mActiveConference.mConference != null && + mActiveConference.mConference.callId().contentEquals(callId)) { + initConferenceCall(true); + mActiveConference.isCallInProgress = true; + mActiveConference.mConference.hangup(); + } + } else { + onConferenceFailedInternal("Pickup failed.", false); + } + } + + private void onElsewhereCallFinished(String callId) { + if (callId == null) return; + Timber.d("onElsewhereCallFinished(): callId=%s", callId); + removeCallFromElsewhereCallsList(callId, true); + } + private synchronized void onStateChangedForCall(NYNCall iConference) { onCallStateHandle(iConference, false); for (ConferenceSDKListener conferenceSDKListener : mConferenceSDKListener) { diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java index c0b8a8a169..0c1edb32e6 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/BasePresenter.java @@ -31,9 +31,13 @@ import com.nynja.mobile.communicator.utils.navigation.NynjaRouter; import com.nynja.mobile.communicator.utils.navigation.Screen; import com.nynja.mobile.communicator.utils.navigation.navigators.HomeNavigator; import com.nynja.mobile.communicator.utils.navigation.navigators.NynjaNavigator; +import com.nynja.sdk.NYNCall; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.HashMap; + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; @@ -275,6 +279,56 @@ public abstract class BasePresenter extends MvpPresenter< return mDataManager.getConferenceSDK().callPickupText(); } + public synchronized String callPickupsText() { + if (!hasCallForPickup()) return ""; + String text = ""; + HashMap myAcceptedElsewhereCalls = mDataManager.getConferenceSDK().pickupCalls(); + synchronized (myAcceptedElsewhereCalls) { + for (String callId : myAcceptedElsewhereCalls.keySet()) { +// NYNCall call = mCallManager.getCallById(callId); + NYNCall call = myAcceptedElsewhereCalls.get(callId); + if (call != null) { + if (StringUtils.isNotEmpty(text)) { + text += ", "; + } + if (!call.isConference()) { + text += (call.getExternalInfo()); + } + } + } + } + return text; + } + + public synchronized ArrayList callPickupsAvatar() { + ArrayList avatars = new ArrayList<>(); + HashMap myAcceptedElsewhereCalls = mDataManager.getConferenceSDK().pickupCalls(); + synchronized (myAcceptedElsewhereCalls) { + for (String callId : myAcceptedElsewhereCalls.keySet()) { +// NYNCall call = mCallManager.getCallById(callId); + NYNCall call = myAcceptedElsewhereCalls.get(callId); + if (call != null) { + String caller = call.caller(); + if (caller != null) { + ContactModel contact = mDataManager.getContactByChatId(caller); + if (contact != null) { + avatars.add(contact.avatar); + } + } + } + } + } + return avatars; + } + + public synchronized HashMap pickupCallsInfo() { + return mDataManager.getConferenceSDK().pickupCallsInfo(); + } + + public synchronized HashMap pickupCalls() { + return mDataManager.getConferenceSDK().pickupCalls(); + } + @Override public void showDefaultError(@NotNull Object data, @StringRes int errorRes) { getViewState().showDefaultServerError(errorRes); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt index 263ba8e86b..16a97299db 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/presenters/MainActivityPresenter.kt @@ -632,9 +632,9 @@ class MainActivityPresenter : ConferenceSDKPresenter() { } override fun conferenceEnded() { - if (attachedViews.size > 0) { + //if (attachedViews.size > 0) { viewState.onConferenceEnded() - } + //} invalidateWheelAfterCallStateChaged() clearIncomingCallNotification() } @@ -655,7 +655,7 @@ class MainActivityPresenter : ConferenceSDKPresenter() { invalidateWheelAfterCallStateChaged() } - override fun onConferenceStateChanged(activeConferenceCall: ActiveConferenceCall) { + override fun onConferenceStateChanged(activeConferenceCall: ActiveConferenceCall?) { if (attachedViews.size == 0) return viewState.onConferenceStateChanged(activeConferenceCall) } @@ -788,6 +788,10 @@ class MainActivityPresenter : ConferenceSDKPresenter() { } + override fun pickupCallWhileAnotherActiveCall() { + //if (attachedViews.size == 0) return + viewState.pickupCallWhileAnotherActiveCall() + } private fun showActiveCallDialog() { viewState.showActiveCallDialog() @@ -923,4 +927,14 @@ class MainActivityPresenter : ConferenceSDKPresenter() { } } } + + fun callPickup(callId: String?) { + if (mDataManager.conferenceSDK.callPickup(callId)) { + mRouter.navigateTo(NynjaNavigator.ACTIVE_CALL) + } + } + + fun loadPickupCalls() { + mDataManager.conferenceSDK.loadPickupCalls(); + } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java b/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java index 750054749c..604679b0e0 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java +++ b/app/src/main/java/com/nynja/mobile/communicator/mvp/view/MainActivityView.java @@ -80,4 +80,6 @@ public interface MainActivityView extends JoinGroupView { void tryStartCall(boolean createNew, boolean isGroup, boolean isVideo, Parcelable prevModel); void showAlertMessage(int res); + + void pickupCallWhileAnotherActiveCall(); } diff --git a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java index cf2788f8fb..0cae776017 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java +++ b/app/src/main/java/com/nynja/mobile/communicator/ui/activities/MainActivity.java @@ -6,6 +6,7 @@ import android.app.NotificationManager; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.media.AudioManager; import android.net.Uri; @@ -60,6 +61,7 @@ import com.nynja.mobile.communicator.ui.wheel.entity.actions.WheelMenuKey; import com.nynja.mobile.communicator.ui.wheel.entity.adapters.WheelChatAdapter; import com.nynja.mobile.communicator.ui.wheel.entity.items.BaseWheelItem; import com.nynja.mobile.communicator.ui.wheel.entity.items.WheelChatItem; +import com.nynja.mobile.communicator.utils.ActionSheetDialog; import com.nynja.mobile.communicator.utils.CallUtils; import com.nynja.mobile.communicator.utils.Consts; import com.nynja.mobile.communicator.utils.DefaultWheelClickListener; @@ -71,13 +73,16 @@ import com.nynja.mobile.communicator.utils.Utils; import com.nynja.mobile.communicator.utils.iap.InAppPurchaseManager; import com.nynja.mobile.communicator.utils.navigation.header.NynjaStatusHeaderView; import com.nynja.mobile.communicator.utils.navigation.navigators.HomeNavigator; +import com.nynja.sdk.NYNCall; import com.nynja.sdk.NYNCallState; import org.webrtc.SurfaceViewRenderer; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Set; import butterknife.BindView; import butterknife.OnClick; @@ -119,6 +124,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, @BindView(R.id.call_pickup_name) TextView callPickupName; @BindView(R.id.call_pickup_count) TextView callPickupCount; @BindView(R.id.call_pickup_title_text) TextView callPickupHeaderText; + @BindView(R.id.call_pickup_photo) ImageView allPickupAvatar; @InjectPresenter MainActivityPresenter mPresenter; @@ -210,6 +216,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, } catch (Exception ex) { Timber.e(ex); } + mPresenter.loadPickupCalls(); } @Override @@ -976,6 +983,15 @@ public class MainActivity extends BaseActivity implements MainActivityView, ); } + @Override + public void pickupCallWhileAnotherActiveCall() { + Dialog createdDialog = DialogFactory.createOkNoDialog(this, R.string.call_pickup_alert_while_another_call, + (dialog, which) -> { + }, null); + createdDialog.show(); + DialogFactory.changeMessageTextSize(createdDialog); + } + private void onCallStateChanged(ActiveConferenceCall activeConferenceCall) { if ((activeConferenceCall == null) || (!mPresenter.isConferenceActive()) || @@ -983,6 +999,7 @@ public class MainActivity extends BaseActivity implements MainActivityView, && !activeConferenceCall.isRinging && !activeConferenceCall.isWaiting())) { runOnUiThread(() -> { + onActiveCallStateChanged(null); onCallsStateChanged(); }); return; @@ -1005,15 +1022,19 @@ public class MainActivity extends BaseActivity implements MainActivityView, private void onActiveCallStateChanged(ActiveConferenceCall activeConferenceCall) { video.setVisibility(View.GONE); - if (activeConferenceCall != null && activeConferenceCall.isWaiting()) { - chatAudioLayout.setBackgroundResource(R.color.waiting_call_bg); - headerStatusText.setText(R.string.call_waiting_period); + if (activeConferenceCall != null) { + if (activeConferenceCall.isWaiting()) { + chatAudioLayout.setBackgroundResource(R.color.waiting_call_bg); + headerStatusText.setText(R.string.call_waiting_period); + } else { + chatAudioLayout.setBackgroundResource(R.color.active_call_bg); + } + hideCallPickupLayout(); + chatAudioLayout.setVisibility(View.VISIBLE); + mPresenter.requestUser(); } else { - chatAudioLayout.setBackgroundResource(R.color.active_call_bg); + chatAudioLayout.setVisibility(View.VISIBLE); } - callPickupLayout.setVisibility(View.GONE); - chatAudioLayout.setVisibility(View.VISIBLE); - mPresenter.requestUser(); //TODO: video feeds support in next features //if (!activeConferenceCall.mData.isOwnStreamActive || !activeConferenceCall.hasRemoteVideoTrack) { // video.setVisibility(View.GONE); @@ -1040,13 +1061,59 @@ public class MainActivity extends BaseActivity implements MainActivityView, onCallsStateChanged(); } + private void onClickCallPickup() { + final HashMap calls = mPresenter.pickupCallsInfo(); + ArrayList keys = new ArrayList(calls.keySet()); + String[] values = (new ArrayList<>(calls.values())).toArray(new String[0]); + //{"Ergun Y8", "Ergun Y2", "Ergun Y3", "Ergun Y4"};// + final Context context = this; +// DialogFactory.showActionSheetDialog(this, itemPosition -> { +// if (itemPosition < keys.size()) { +// String callId = keys.get(itemPosition); +// mPresenter.callPickup(callId); +// //Toast.makeText(context, ("Start Pickup with ID: "+ callId), Toast.LENGTH_LONG).show(); +// } +// }, values); + + DialogFactory.createContextPopupDialog(this, R.string.call_pickup_alert_title_text, values, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + if (i < keys.size()) { + String callId = keys.get(i); + mPresenter.callPickup(callId); + //Toast.makeText(context, ("Start Pickup with ID: "+ callId), Toast.LENGTH_LONG).show(); + } + + } + }).show(); + } + + private void hideCallPickupLayout() { + callPickupLayout.setOnClickListener(null); + callPickupLayout.setVisibility(View.GONE); + } + + private void onCallsStateChanged() { if (mPresenter.hasCallForPickup()) { + callPickupLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + onClickCallPickup(); + } + }); //callPickupCount.setText(mPresenter.callPickupCount()); callPickupLayout.setVisibility(View.VISIBLE); - callPickupName.setText(mPresenter.callPickupText()); + callPickupName.setText(mPresenter.callPickupsText()); + ArrayList avatars = mPresenter.callPickupsAvatar(); + if (avatars.size() > 0) { + ImageUtils.loadAvatarImage(avatars.get(0), allPickupAvatar); + allPickupAvatar.setVisibility(View.VISIBLE); + } else { + allPickupAvatar.setVisibility(View.GONE); + } } else { - callPickupLayout.setVisibility(View.GONE); + hideCallPickupLayout(); } } diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java b/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java index 4354878781..a24e190b50 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java @@ -34,6 +34,7 @@ import com.nynja.mobile.communicator.R; import com.nynja.mobile.communicator.utils.iap.InAppPurchaseManager; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; +import java.util.ArrayList; import java.util.List; import timber.log.Timber; @@ -231,11 +232,17 @@ public class DialogFactory { public static AlertDialog createContextDialog(Activity activity, @ArrayRes List itemsRes, DialogInterface.OnClickListener onClickListener) { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Nynja_Context_Dialog); String[] items = new String[itemsRes.size()]; for (int i = 0; i < itemsRes.size(); i++) { items[i] = activity.getString(itemsRes.get(i)); } + return createContextDialog(activity, items, onClickListener); + } + + public static AlertDialog createContextDialog(Activity activity, + String[] items, + DialogInterface.OnClickListener onClickListener) { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Nynja_Context_Dialog); dialogBuilder.setItems(items, onClickListener); return dialogBuilder.create(); } @@ -243,16 +250,27 @@ public class DialogFactory { public static AlertDialog createContextPopupDialog(Activity activity, @ArrayRes List itemsRes, DialogInterface.OnClickListener onClickListener) { + String[] items = new String[itemsRes.size()]; + for (int i = 0; i < itemsRes.size(); i++) { + items[i] = (activity.getString(itemsRes.get(i))); + } + return createContextPopupDialog(activity, items, onClickListener); + } + + public static AlertDialog createContextPopupDialog(Activity activity, + String[] items, + DialogInterface.OnClickListener onClickListener) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, R.style.Nynja_PopupMenu_AlertDialog); + final ArrayAdapter arrayAdapter = new ArrayAdapter(activity, R.layout.li_alert_popup_menu_item); - for (int i = 0; i < itemsRes.size(); i++) { - arrayAdapter.add(activity.getString(itemsRes.get(i))); - } + arrayAdapter.addAll(items); dialogBuilder.setAdapter(arrayAdapter, onClickListener); AlertDialog dialog = dialogBuilder.create(); ListView listView = dialog.getListView(); - listView.setDivider(new ColorDrawable(ContextCompat.getColor(activity, R.color.lite_grey))); + listView.setDivider(new ColorDrawable(ContextCompat.getColor(activity, R.color.grey))); + listView.setHeaderDividersEnabled(true); + listView.setFooterDividersEnabled(false); listView.setDividerHeight(1); @@ -279,6 +297,26 @@ public class DialogFactory { return dialog; } + public static AlertDialog createContextPopupDialog(Activity activity, int title, + String[] items, + DialogInterface.OnClickListener onClickListener) { + AlertDialog dialog = createContextPopupDialog(activity, items, onClickListener); + if (title > 0) { + dialog.setTitle(title); + } + return dialog; + } + + public static AlertDialog createContextPopupDialog(Activity activity, String title, + String[] items, + DialogInterface.OnClickListener onClickListener) { + AlertDialog dialog = createContextPopupDialog(activity, items, onClickListener); + if (StringUtils.isNotEmpty(title)) { + dialog.setTitle(title); + } + return dialog; + } + public static AlertDialog createContextPopupDialog(Activity activity, int title, int message, diff --git a/app/src/main/res/layout/partial_call_pickup.xml b/app/src/main/res/layout/partial_call_pickup.xml index 97bf17fd92..7697cd4028 100644 --- a/app/src/main/res/layout/partial_call_pickup.xml +++ b/app/src/main/res/layout/partial_call_pickup.xml @@ -23,7 +23,6 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginEnd="@dimen/margin_normal" android:layout_marginStart="@dimen/margin_normal" android:layout_weight="1" android:orientation="vertical"> @@ -48,9 +47,13 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" + android:ellipsize="end" + android:lines="1" + android:maxLines="1" + android:singleLine="true" android:textColor="@color/white" android:textSize="@dimen/text_size_normal" - tools:text="Shorty Design"/> + tools:text="Shorty Design" /> + tools:text="1"/> @@ -68,6 +71,7 @@ android:id="@+id/call_pickup_photo" android:layout_width="42dp" android:layout_height="42dp" + android:layout_marginStart="@dimen/margin_normal" android:layout_gravity="center" tools:ignore="ContentDescription" tools:src="@drawable/avatar_placeholder_circle" diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 4b8c7a2ef6..8da13b5fc2 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -1341,4 +1341,9 @@ To start your camera, you need to stop screen sharing first. Continue + + Call pickup + Choose call to pickup + You can\'t call when you are talking + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a93d6de9c0..cc31e962dc 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1340,4 +1340,9 @@ To start your camera, you need to stop screen sharing first. Continue + + Call pickup + Choose call to pickup + You can\'t call when you are talking + diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 3fb29a0c69..58547c814f 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -1340,4 +1340,9 @@ To start your camera, you need to stop screen sharing first. Continue + + Call pickup + Choose call to pickup + You can\'t call when you are talking + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4716478128..c2bf97f05a 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -1340,4 +1340,9 @@ To start your camera, you need to stop screen sharing first. Continue + + Call pickup + Choose call to pickup + You can\'t call when you are talking + diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 4716478128..c2bf97f05a 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1340,4 +1340,9 @@ To start your camera, you need to stop screen sharing first. Continue + + Call pickup + Choose call to pickup + You can\'t call when you are talking + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 38dfadc534..e43dd50e49 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -99,6 +99,6 @@ #A6ffffff #00000000 - #676BB9 + #F3AF22 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49e43700b7..7930de99a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1344,5 +1344,7 @@ Call pickup + Choose call to pickup + You can\'t call when you are talking -- GitLab From 5b5e24ceb934d8b887949ebf91c55a35a5a65c8f Mon Sep 17 00:00:00 2001 From: Ergyun Syuleyman Date: Mon, 1 Jun 2020 00:01:11 +0300 Subject: [PATCH 10/21] -Nynja black styled popup pickup dialog --- .../com/nynja/mobile/communicator/utils/DialogFactory.java | 4 +--- app/src/main/res/layout/li_alert_popup_menu_item.xml | 2 +- app/src/main/res/values/styles.xml | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java b/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java index a24e190b50..18e2aa172b 100644 --- a/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java +++ b/app/src/main/java/com/nynja/mobile/communicator/utils/DialogFactory.java @@ -268,9 +268,7 @@ public class DialogFactory { dialogBuilder.setAdapter(arrayAdapter, onClickListener); AlertDialog dialog = dialogBuilder.create(); ListView listView = dialog.getListView(); - listView.setDivider(new ColorDrawable(ContextCompat.getColor(activity, R.color.grey))); - listView.setHeaderDividersEnabled(true); - listView.setFooterDividersEnabled(false); + listView.setDivider(new ColorDrawable(ContextCompat.getColor(activity, R.color.colorScheduleBackground))); listView.setDividerHeight(1); diff --git a/app/src/main/res/layout/li_alert_popup_menu_item.xml b/app/src/main/res/layout/li_alert_popup_menu_item.xml index 19e4bfb0d7..c118f92f87 100644 --- a/app/src/main/res/layout/li_alert_popup_menu_item.xml +++ b/app/src/main/res/layout/li_alert_popup_menu_item.xml @@ -3,7 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/dialog_popup_menu_item_selector" + android:background="@color/colorContextMenuSeparator" android:ellipsize="marquee" android:gravity="center" android:paddingBottom="@dimen/padding_small" diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 61669101ef..83cd4e10db 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -43,7 +43,7 @@