From fa7f1715f44fa4ec5525349a8ebbb808a01fd468 Mon Sep 17 00:00:00 2001 From: darshanbhanushali Date: Mon, 22 Feb 2021 16:02:51 +0530 Subject: [PATCH] Android UI Kit v2.1.11 --- README.md | 2 +- app/build.gradle | 14 +- .../pro/androiduikit/AppTestSuite.java | 19 ++ .../app/ComponentActivityTest.java | 246 ++++++++++++++++ .../app/CreateUserActivityTest.java | 128 +++++++++ .../androiduikit/app/MainActivityTest.java | 266 ++++++++++++++++++ .../androiduikit/app/SelectActivityTest.java | 66 +++++ .../pro/androiduikit/utils/AssertHelper.java | 27 ++ .../utils/AvatarBorderMatcher.java | 65 +++++ .../utils/EspressoTestMatcher.java | 12 + .../utils/RecyclerViewAssertion.java | 29 ++ .../ComponentFragments/AvatarFragment.java | 5 +- .../BadgeCountFragment.java | 4 +- .../CallListViewFragment.java | 25 +- .../ConversationListViewFragment.java | 9 +- .../GroupListViewFragment.java | 10 +- .../StatusIndicatorFragment.java | 2 + .../UserListViewFragment.java | 7 +- .../androiduikit/ComponentLoadActivity.java | 24 +- .../pro/androiduikit/CreateUserActivity.java | 2 +- .../pro/androiduikit/LoginActivity.java | 3 +- .../pro/androiduikit/MainActivity.java | 3 +- .../pro/androiduikit/SelectActivity.java | 5 +- .../pro/androiduikit/UIKitApplication.java | 2 +- .../res/layout/activity_component_list.xml | 3 +- .../main/res/layout/activity_create_user.xml | 1 - app/src/main/res/layout/activity_login.xml | 4 +- app/src/main/res/layout/activity_select.xml | 6 +- .../main/res/layout/activity_user_list.xml | 2 +- app/src/main/res/layout/fragment_avatar.xml | 2 +- .../main/res/layout/fragment_badge_count.xml | 2 +- .../res/layout/fragment_status_indicator.xml | 2 +- app/src/main/res/values/strings.xml | 6 +- uikit/build.gradle | 2 +- .../CometChatStartCallActivity.java | 4 +- .../chats/CometChatConversationList.java | 9 + .../create_group/CometChatCreateGroup.java | 33 +-- .../message_list/CometChatMessageList.java | 12 +- .../messages/message_list/MessageAdapter.java | 65 +++-- .../cometchatAvatar/CometChatAvatar.java | 3 + .../CometChatConversationsAdapter.java | 3 +- .../callHistroy/CallHistoryAdapter.java | 2 +- .../pro/uikit/ui_resources/utils/Utils.java | 34 +++ 43 files changed, 1050 insertions(+), 120 deletions(-) create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AssertHelper.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AvatarBorderMatcher.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/EspressoTestMatcher.java create mode 100644 app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java diff --git a/README.md b/README.md index ab3b446b..0e4305db 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Learn more about how to integrate [UI Kit](https://github.com/cometchat-pro/andr ## Troubleshooting -- To read the full dcoumentation on UI Kit integration visit our [Documentation](https://prodocs.cometchat.com/docs/android-ui-kit) . +- To read the full documentation on UI Kit integration visit our [Documentation](https://prodocs.cometchat.com/docs/android-ui-kit) . - Facing any issues while integrating or installing the UI Kit please connect with us via real time support present in CometChat Dashboard.. diff --git a/app/build.gradle b/app/build.gradle index 4aa6bab3..bfa4878c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,6 +52,18 @@ dependencies { testImplementation 'junit:junit:4.12' implementation 'androidx.recyclerview:recyclerview:1.0.0' + // Core library + androidTestImplementation 'androidx.test:core:1.3.0' + // Espresso dependencies + + androidTestImplementation 'androidx.test:rules:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0' + // Assertions + + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0' + androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' implementation project(path: ':uikit') @@ -60,5 +72,5 @@ dependencies { implementation 'com.facebook.shimmer:shimmer:0.4.0' // - implementation 'com.cometchat:pro-android-chat-sdk:2.1.7-beta3' + implementation 'com.cometchat:pro-android-chat-sdk:2.2.0' } diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java new file mode 100644 index 00000000..0a03faa2 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/AppTestSuite.java @@ -0,0 +1,19 @@ +package com.cometchat.pro.androiduikit; + +import com.cometchat.pro.androiduikit.app.ComponentActivityTest; +import com.cometchat.pro.androiduikit.app.MainActivityTest; +import com.cometchat.pro.androiduikit.app.SelectActivityTest; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses( + { + MainActivityTest.class, + CreateUserActivity.class, + SelectActivityTest.class, + ComponentActivityTest.class + }) + +public class AppTestSuite {} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java new file mode 100644 index 00000000..a630eadd --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/ComponentActivityTest.java @@ -0,0 +1,246 @@ +package com.cometchat.pro.androiduikit.app; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import android.view.View; + +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.PerformException; +import androidx.test.espresso.ViewAssertion; +import androidx.test.espresso.ViewInteraction; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.assertion.ViewAssertions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.ComponentListActivity; +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.androiduikit.utils.RecyclerViewAssertion; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static androidx.test.espresso.action.ViewActions.clearText; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; +import static androidx.test.espresso.action.ViewActions.pressBack; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withParent; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static org.hamcrest.core.AllOf.allOf; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ComponentActivityTest { + + + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private UiDevice mDevice; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(ComponentListActivity.class, true, false); + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + Espresso.onView(ViewMatchers.withId(R.id.componentLaunch)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.componentLaunch)).perform(ViewActions.click()); + } + + @Test + public void A_checkAvatar() { + + //Check Components + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_avatar)).perform(ViewActions.scrollTo()); + Espresso.onView(withId(R.id.cometchat_avatar)).perform(click()); + Espresso.onView(withId(R.id.borderWidth)).perform(ViewActions.typeText("5")) + .perform(closeSoftKeyboard()); + Thread.sleep(2000); + Espresso.onView(withId(R.id.borderWidth)).perform(pressBack()); + mDevice.pressBack(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void B_checkBadgeCount() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_badge_count)).perform(ViewActions.scrollTo()); + Espresso.onView(withId(R.id.cometchat_badge_count)).perform(click()); + Espresso.onView(withId(R.id.badgeCount_edt)).perform(clearText()) + .perform(ViewActions.typeText("9999")); + Thread.sleep(2000); + Espresso.onView(withId(R.id.countSize)).perform(clearText()) + .perform(ViewActions.typeText("12")) + .perform(closeSoftKeyboard()); + Thread.sleep(2000); + Espresso.onView(withId(R.id.countSize)).perform(pressBack()); + mDevice.pressBack(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void C_checkStatusIndicator() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_status_indicator)).perform(ViewActions.scrollTo()); + Espresso.onView(withId(R.id.cometchat_status_indicator)).perform(click()); + Espresso.onView(withId(R.id.offline)).perform(click()); + Espresso.onView(withId(R.id.offline)).check(matches(ViewMatchers.isChecked())); + + Espresso.onView(withId(R.id.online)).perform(click()); + Espresso.onView(withId(R.id.online)).check(matches(ViewMatchers.isChecked())) + .perform(closeSoftKeyboard()).perform(pressBack()); + mDevice.pressBack(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void J_checkCallList() { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).perform(ViewActions.scrollTo()); + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).check(matches(isDisplayed())); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).perform(click()); + } catch (AssertionError e) { + Log.e("D_checkCallList: ",e.getMessage() ); + } catch (NoMatchingViewException e) { + Log.e("D_checkCallList: ",e.getMessage() ); + } + try { + + Espresso.onView(ViewMatchers.withId(R.id.callList_rv)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (PerformException e) { + Assert.assertTrue("View Not loaded",true); + } catch (Exception e) { + Assert.fail(); + } + } + + @Test + public void K_checkCallList_2Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_callList)).perform(click()); + Thread.sleep(2000); + Espresso.onView(ViewMatchers.withId(R.id.callList_rv)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void D_checkUserList() { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(click()); + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchatUserList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (PerformException e) { + Assert.assertTrue("View not loaded",true); + } catch (Exception e) { + Assert.fail(); + } + } + + @Test + public void E_checkUserList_2Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_user_view)).perform(ViewActions.click()); + Thread.sleep(2000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatUserList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void F_checkGroupList() { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.cometchatGroupList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } + + @Test + public void G_checkGroupList_2Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_group_view)).perform(ViewActions.click()); + Thread.sleep(2000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatGroupList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void H_checkConversationList() { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.click()); + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchatConversationList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (PerformException e) { + Assert.assertTrue("View not loaded",true); + } catch (Exception e) { + Assert.fail(); + } + } + + @Test + public void I_checkConversationList_2Sec() { + try { + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.cometchat_conversation_view)).perform(ViewActions.click()); + Thread.sleep(2000); + Espresso.onView(ViewMatchers.withId(R.id.cometchatConversationList)) + .perform(RecyclerViewActions.actionOnItemAtPosition(1, click())); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +// RecyclerView callRv = activityRule.getActivity().findViewById(R.id.cometchat_callList); +// int itemCount = callRv.getAdapter().getItemCount(); +// if (itemCount>0) { +// Espresso.onView(withId(R.id.cometchat_callList)).perform(click()); +// } + +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java new file mode 100644 index 00000000..4b3bd4fb --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/CreateUserActivityTest.java @@ -0,0 +1,128 @@ +package com.cometchat.pro.androiduikit.app; + + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import androidx.test.espresso.Espresso; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.assertion.ViewAssertions; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.ComponentListActivity; +import com.cometchat.pro.androiduikit.CreateUserActivity; +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.Random; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +public class CreateUserActivityTest { + + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static String UID = "superhero1"; + + private static String NAME = "IronMan"; + + private UiDevice mDevice; + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(CreateUserActivity.class, true, false); + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + if (CometChat.getLoggedInUser()!=null) { + CometChat.logout(new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.e("onSuccess: ",s ); + } + + @Override + public void onError(CometChatException e) { + Log.e( "onError: ",e.getMessage()); + } + }); + } + } + + @Test + public void A_createUserWithExistingUID() { + try { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(UID)); + Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText(NAME)); + Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); + Thread.sleep(5000); + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void B_createUserWithRandomUID() { + try { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(Utils.generateRandomString(25))); + Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("TestCase User")); + Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); + Thread.sleep(5000); + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void C_createUserWithEmptyName() { + try { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.create_user)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)).perform(ViewActions.clearText()).perform(ViewActions.typeText(Utils.generateRandomString(25))); + Espresso.onView(ViewMatchers.withId(R.id.etName)).perform(ViewActions.clearText()).perform(ViewActions.typeText("")); + Espresso.onView(ViewMatchers.withId(R.id.create_user_btn)).perform(ViewActions.click()); + Thread.sleep(5000); + try { + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).check(ViewAssertions.matches(ViewMatchers.isDisplayed())); + Assert.fail("Failed: Able to create user without authentication"); + } catch (AssertionError e) { + Assert.assertTrue(true); + } catch (NoMatchingViewException e) { + Assert.assertTrue(true); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java new file mode 100644 index 00000000..cd1dd84a --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/MainActivityTest.java @@ -0,0 +1,266 @@ +package com.cometchat.pro.androiduikit.app; + +import android.Manifest; +import android.app.Activity; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.SystemClock; +import android.util.Log; +import android.view.View; +import android.widget.ProgressBar; + +import androidx.lifecycle.Lifecycle; +import androidx.test.core.app.ActivityScenario; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.UiController; +import androidx.test.espresso.ViewAction; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.intent.Intents; +import androidx.test.espresso.intent.matcher.ComponentNameMatchers; +import androidx.test.espresso.intent.matcher.IntentMatchers; +import androidx.test.espresso.intent.rule.IntentsTestRule; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.rule.GrantPermissionRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + +import com.cometchat.pro.androiduikit.MainActivity; +import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.androiduikit.UIKitApplication; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; + +import junit.framework.AssertionFailedError; + +import org.hamcrest.Matcher; +import org.hamcrest.core.AllOf; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import java.util.ArrayList; + +import static androidx.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static androidx.test.espresso.action.ViewActions.scrollTo; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.intent.Intents.init; +import static androidx.test.espresso.intent.Intents.intended; +import static androidx.test.espresso.intent.matcher.ComponentNameMatchers.hasClassName; +import static androidx.test.espresso.intent.matcher.ComponentNameMatchers.hasShortClassName; +import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent; +import static androidx.test.espresso.intent.matcher.IntentMatchers.toPackage; +import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.junit.Assert.*; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class MainActivityTest { + + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + @Rule + public GrantPermissionRule internetRule = GrantPermissionRule.grant( + Manifest.permission.INTERNET,Manifest.permission.ACCESS_WIFI_STATE, + Manifest.permission.ACCESS_NETWORK_STATE); + + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(MainActivity.class, true, false); + + + @After + public void tearDown() { + Intents.release(); + } + + @Before + public void startMainActivityFromHomeScreen() { + Intents.init(); + CometChat.logout(new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.e("onSuccess: ",s ); + } + + @Override + public void onError(CometChatException e) { + Log.e("Error: ",e.getMessage()); + } + }); +// new UIKitApplication().setTestCasesRun(true); + ArrayList permissions = new ArrayList<>(); + permissions.add(Manifest.permission.INTERNET); + permissions.add(Manifest.permission.ACCESS_WIFI_STATE); + permissions.add(Manifest.permission.ACCESS_NETWORK_STATE); + //add here your other permissions + + for (int i = 0; i < permissions.size(); i++) { + String command = String.format("pm grant %s %s", getInstrumentation().getContext().getPackageName(), permissions.get(i)); + getInstrumentation().getUiAutomation().executeShellCommand(command); + // wait a bit until the command is finished + SystemClock.sleep(1000); + } +// } +// Initialize UiDevice instance + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + } + + @Test + public void A_sameActivity3Sec() { + if (CometChat.getLoggedInUser()==null) { + ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); + // Type text and then press the button. + Espresso.onView(ViewMatchers.withId(R.id.superhero1)).perform(ViewActions.click()); + try { + Thread.sleep(3000); + Espresso.onView(ViewMatchers.withId(R.id.logout)).perform(scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.logout)).perform(ViewActions.click()); + Thread.sleep(3000); + } catch (Exception e) { + Assert.fail("login_sameActivity:Failed in 3 Sec- "+e.getMessage()); + } + } else { + Log.e( "login_sameActivity: ","User already logged IN" ); + } + } + + @Test + public void B_sameActivity7Sec() { + if (CometChat.getLoggedInUser()==null) { + ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); + // Type text and then press the button. + Espresso.onView(ViewMatchers.withId(R.id.superhero2)).perform(ViewActions.click()); + try { + Thread.sleep(7000); + Espresso.onView(ViewMatchers.withId(R.id.logout)).perform(scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.logout)).perform(ViewActions.click()); + Thread.sleep(3000); + } catch (Exception e) { + Assert.fail("login_sameActivity:Failed in 7 Sec - "+e.getMessage()); + } + } else { + Log.e( "login_sameActivity: ","User already logged IN" ); + } + } + + @Test + public void C_sameActivity15Sec() { + if (CometChat.getLoggedInUser()==null) { + ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); + activityScenario.moveToState(Lifecycle.State.RESUMED); + // Type text and then press the button. + Espresso.onView(ViewMatchers.withId(R.id.superhero3)).perform(ViewActions.click()); + try { + Thread.sleep(15000); + Espresso.onView(ViewMatchers.withId(R.id.logout)).perform(scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.logout)).perform(ViewActions.click()); + Thread.sleep(3000); + } catch (Exception e) { + Assert.fail("login_sameActivity:Failed in 15 Sec- "+e.getMessage()); + } + } else { + Log.e( "login_sameActivity: ","User already logged IN" ); + } + } + + @Test + public void D_goToLoginActivity() { + ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); + if (CometChat.getLoggedInUser()==null) { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)) + .perform(ViewActions.typeText("superhero4")) + .perform(ViewActions.pressImeActionButton()); + } + Log.e( "goToLoginActivity: ","User already loggedIn" ); + } + + @Test + public void E_failLoginActivity() { + ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); + if (CometChat.getLoggedInUser()==null) { + Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click()); + Espresso.onView(ViewMatchers.withId(R.id.etUID)) + .perform(ViewActions.typeText("")) + .perform(ViewActions.pressImeActionButton()); + try { + Espresso.onView(ViewMatchers.withId(R.id.logout)).check(matches(isDisplayed())); + Assert.fail("Failed: Enter to Select Activity without login"); + } catch (AssertionFailedError e) { + Assert.assertTrue(true); + } catch (NoMatchingViewException e) { + Assert.assertTrue(true); + } + } else { + Assert.assertTrue(true); + Log.e("goToLoginActivity: ", "User already loggedIn"); + } + } + + /** + * Uses package manager to find the package name of the device launcher. Usually this package + * is "com.android.launcher" but can be different at times. This is a generic solution which + * works on all platforms.` + */ + private String getLauncherPackageName() { + // Create launcher Intent + final Intent intent = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_HOME); + + // Use PackageManager to get the launcher package name + PackageManager pm = ApplicationProvider.getApplicationContext().getPackageManager(); + ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); + return resolveInfo.activityInfo.packageName; + } + + + private static ViewAction setProgressBarVisibitity(final boolean value) { + return new ViewAction() { + @Override + public Matcher getConstraints() { + return isAssignableFrom(ProgressBar.class); + } + + @Override + public void perform(UiController uiController, View view) { + view.setVisibility(value ? View.VISIBLE : View.GONE); + } + + @Override + public String getDescription() { + return "Show / Hide View"; + } + }; + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java new file mode 100644 index 00000000..42fe7d78 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/app/SelectActivityTest.java @@ -0,0 +1,66 @@ +package com.cometchat.pro.androiduikit.app; + +import android.content.Context; +import android.content.Intent; +import android.view.View; + +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.Espresso; +import androidx.test.espresso.ViewAssertion; +import androidx.test.espresso.action.ViewActions; +import androidx.test.espresso.assertion.ViewAssertions; +import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.Until; + + +import com.cometchat.pro.androiduikit.R; + +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SelectActivityTest { + + private static final String BASIC_SAMPLE_PACKAGE + = "com.cometchat.pro.androiduikit"; + + private static final int LAUNCH_TIMEOUT = 5000; + + private static final String STRING_TO_BE_TYPED = "superhero5"; + + private UiDevice mDevice; + + @Before + public void setup() { + mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + Context context = getInstrumentation().getContext(); + Intent intent = context.getPackageManager() + .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Clear out any previous instances + context.startActivity(intent); + mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT); + } + + @Test + public void launchUnifiedTest() { + Espresso.onView(ViewMatchers.withId(R.id.directLaunch)).perform(ViewActions.click()); + } + + @Test + public void launchComponentTest() { + Espresso.onView(ViewMatchers.withId(R.id.componentLaunch)).perform(ViewActions.scrollTo()); + Espresso.onView(ViewMatchers.withId(R.id.componentLaunch)).perform(ViewActions.click()); + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AssertHelper.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AssertHelper.java new file mode 100644 index 00000000..52214345 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AssertHelper.java @@ -0,0 +1,27 @@ +package com.cometchat.pro.androiduikit.utils; + +import android.util.Log; + +import org.junit.Assert; + +public class AssertHelper { + static String TAG = "AssertHelper"; + public static void assertTrue(String desc,boolean condition) { + try { + Assert.assertTrue(desc,condition); + Log.e(TAG, desc+" Success"); + } catch (Exception e) { + Log.e(TAG, "Failed"+e.getMessage()); + Assert.fail(desc); + } + } + + public static void assertFailed(String desc) { + try { + Assert.fail(desc); + Log.e(TAG, desc+" Failed"); + } catch (Exception e) { + Log.e(TAG, e.getMessage()); + } + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AvatarBorderMatcher.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AvatarBorderMatcher.java new file mode 100644 index 00000000..cd6ef831 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/AvatarBorderMatcher.java @@ -0,0 +1,65 @@ +package com.cometchat.pro.androiduikit.utils; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.view.View; +import android.widget.ImageView; + +import com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; + +public class AvatarBorderMatcher extends TypeSafeMatcher { + + private final int borderWidth; + private String resourceName; + private int resourceId; + Context context; + static final int EMPTY = -1; + static final int ANY = -2; + + AvatarBorderMatcher(Context context, int borderWidth, int resourceId) { + super(View.class); + this.borderWidth = borderWidth; + this.context = context; + } + + @Override + protected boolean matchesSafely(View target) { + if (!(target instanceof ImageView)) { + return false; + } + ImageView imageView = (ImageView) target; + if (borderWidth == EMPTY) { + return imageView.getDrawable() == null; + } + if (borderWidth == ANY) { + return imageView.getDrawable() != null; + } + Resources resources = target.getContext().getResources(); + Drawable expectedDrawable = resources.getDrawable(resourceId); + resourceName = resources.getResourceEntryName(resourceId); + + if (expectedDrawable == null) { + return false; + } + CometChatAvatar avatarA = new CometChatAvatar(context); + avatarA.setImageDrawable(imageView.getDrawable()); + CometChatAvatar avatarB = new CometChatAvatar(context); + avatarB.setImageDrawable(expectedDrawable); + return avatarA.getBorderWidth()==avatarB.getBorderWidth()?true:false; + } + + @Override + public void describeTo(Description description) { + description.appendText("with drawable from resource id: "); + description.appendValue(resourceId); + if (resourceName != null) { + description.appendText("["); + description.appendText(resourceName); + description.appendText("]"); + } + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/EspressoTestMatcher.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/EspressoTestMatcher.java new file mode 100644 index 00000000..af90a0c1 --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/EspressoTestMatcher.java @@ -0,0 +1,12 @@ +package com.cometchat.pro.androiduikit.utils; + +import android.content.Context; +import android.view.View; + +import org.hamcrest.Matcher; + +public class EspressoTestMatcher { + public static Matcher withDrawable(Context context, final int borderWidth, final int resourceId) { + return new AvatarBorderMatcher(context,borderWidth,resourceId); + } +} diff --git a/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java new file mode 100644 index 00000000..47a93f4c --- /dev/null +++ b/app/src/androidTest/java/com/cometchat/pro/androiduikit/utils/RecyclerViewAssertion.java @@ -0,0 +1,29 @@ +package com.cometchat.pro.androiduikit.utils; + +import android.view.View; + +import androidx.recyclerview.widget.RecyclerView; +import androidx.test.espresso.NoMatchingViewException; +import androidx.test.espresso.ViewAssertion; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; + +public class RecyclerViewAssertion implements ViewAssertion { + private final int expectedCount; + + public RecyclerViewAssertion(int expectedCount) { + this.expectedCount = expectedCount; + } + + @Override + public void check(View view, NoMatchingViewException noViewFoundException) { + if (noViewFoundException != null) { + throw noViewFoundException; + } + + RecyclerView recyclerView = (RecyclerView) view; + RecyclerView.Adapter adapter = recyclerView.getAdapter(); + MatcherAssert.assertThat(adapter.getItemCount(), Matchers.is(expectedCount)); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/AvatarFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/AvatarFragment.java index fd3db74a..2484ea3e 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/AvatarFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/AvatarFragment.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,13 +15,15 @@ import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import com.cometchat.pro.androiduikit.ColorPickerDialog; import com.cometchat.pro.androiduikit.R; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; -import com.cometchat.pro.uikit.ui_resources.utils.Utils; +import java.util.Random; public class AvatarFragment extends Fragment { diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/BadgeCountFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/BadgeCountFragment.java index f23987f7..ff7cbfe4 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/BadgeCountFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/BadgeCountFragment.java @@ -7,15 +7,17 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.RadioGroup; +import android.widget.Toast; import androidx.fragment.app.Fragment; import com.cometchat.pro.androiduikit.R; import com.cometchat.pro.uikit.ui_components.shared.cometchatBadgeCount.CometChatBadgeCount; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; -import com.cometchat.pro.uikit.ui_resources.utils.Utils; public class BadgeCountFragment extends Fragment { diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/CallListViewFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/CallListViewFragment.java index 7e74941c..d9da14e0 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/CallListViewFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/CallListViewFragment.java @@ -15,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.cometchat.pro.androiduikit.R; +import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.Call; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.core.MessagesRequest; @@ -22,19 +23,19 @@ import com.cometchat.pro.models.BaseMessage; import com.cometchat.pro.models.Group; import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.ui_components.calls.call_list.CometChatCallList; +import com.cometchat.pro.uikit.ui_components.groups.group_details.CometChatGroupDetailActivity; import com.cometchat.pro.uikit.ui_components.shared.cometchatCalls.CometChatCalls; +import com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; +import com.cometchat.pro.uikit.ui_resources.utils.CallUtils; +import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; import com.facebook.shimmer.ShimmerFrameLayout; import com.google.android.material.snackbar.Snackbar; import java.util.Collections; import java.util.List; -import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; -import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; -import com.cometchat.pro.uikit.ui_components.groups.group_details.CometChatGroupDetailActivity; -import com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity; -import com.cometchat.pro.uikit.ui_resources.utils.CallUtils; - public class CallListViewFragment extends Fragment { private CometChatCalls rvCallList; @@ -49,7 +50,7 @@ public class CallListViewFragment extends Fragment { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_call_list, container, false); - rvCallList = view.findViewById(com.cometchat.pro.uikit.R.id.callList_rv); + rvCallList = view.findViewById(R.id.callList_rv); linearLayoutManager = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false ); rvCallList.setLayoutManager(linearLayoutManager); @@ -58,7 +59,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c rvCallList.setItemClickListener(new OnItemClickListener() { @Override public void OnItemClick(Call var, int position) { - if (var.getReceiverType().equals(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER)) { + if (var.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { User user; if (var.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { user = ((User)var.getCallReceiver()); @@ -100,16 +101,16 @@ public void OnItemClick(Call var, int position) { @Override public void onSuccess(Call call) { Log.e( "onSuccess: ",call.toString()); - if (var.getReceiverType().equals(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER)) { + if (var.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { User user; if (var.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { user = ((User) var.getCallReceiver()); } else { user = var.getSender(); } - CallUtils.startCallIntent(getContext(), user, com.cometchat.pro.constants.CometChatConstants.CALL_TYPE_AUDIO, true, call.getSessionId()); + CallUtils.startCallIntent(getContext(), user, CometChatConstants.CALL_TYPE_AUDIO, true, call.getSessionId()); } else - CallUtils.startGroupCallIntent(getContext(),((Group)call.getCallReceiver()), com.cometchat.pro.constants.CometChatConstants.CALL_TYPE_AUDIO,true,call.getSessionId()); + CallUtils.startGroupCallIntent(getContext(),((Group)call.getCallReceiver()),CometChatConstants.CALL_TYPE_AUDIO,true,call.getSessionId()); } @Override @@ -138,7 +139,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat private void getCallList() { if (messagesRequest == null) { - messagesRequest = new MessagesRequest.MessagesRequestBuilder().setCategory(com.cometchat.pro.constants.CometChatConstants.CATEGORY_CALL).setLimit(30).build(); + messagesRequest = new MessagesRequest.MessagesRequestBuilder().setCategory(CometChatConstants.CATEGORY_CALL).setLimit(30).build(); } messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/ConversationListViewFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/ConversationListViewFragment.java index 6ee76caa..2e33dbf8 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/ConversationListViewFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/ConversationListViewFragment.java @@ -13,18 +13,19 @@ import com.cometchat.pro.androiduikit.R; import com.cometchat.pro.androiduikit.databinding.FragmentConversationListBinding; +import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.core.ConversationsRequest; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.Conversation; import com.cometchat.pro.models.Group; import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; +import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; import java.util.List; -import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; -import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; -import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; public class ConversationListViewFragment extends Fragment { @@ -49,7 +50,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, public void OnItemClick(Conversation conversation, int position) { Intent intent = new Intent(getContext(), CometChatMessageListActivity.class); intent.putExtra(UIKitConstants.IntentStrings.TYPE,conversation.getConversationType()); - if (conversation.getConversationType().equals(com.cometchat.pro.constants.CometChatConstants.CONVERSATION_TYPE_GROUP)) + if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_GROUP)) { intent.putExtra(UIKitConstants.IntentStrings.NAME,((Group)conversation.getConversationWith()).getName()); intent.putExtra(UIKitConstants.IntentStrings.GUID,((Group)conversation.getConversationWith()).getGuid()); diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/GroupListViewFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/GroupListViewFragment.java index 895ed0aa..f6e33a87 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/GroupListViewFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/GroupListViewFragment.java @@ -14,16 +14,16 @@ import com.cometchat.pro.androiduikit.R; import com.cometchat.pro.androiduikit.databinding.FragmentGroupListBinding; +import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.core.GroupsRequest; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.Group; - -import java.util.List; - +import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; -import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; + +import java.util.List; public class GroupListViewFragment extends Fragment { @@ -45,7 +45,7 @@ public void OnItemClick(Group group, int position) { intent.putExtra(UIKitConstants.IntentStrings.GUID,group.getGuid()); intent.putExtra(UIKitConstants.IntentStrings.AVATAR,group.getIcon()); intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE,group.getGroupType()); - intent.putExtra(UIKitConstants.IntentStrings.TYPE, com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_GROUP); + intent.putExtra(UIKitConstants.IntentStrings.TYPE,CometChatConstants.RECEIVER_TYPE_GROUP); intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT,group.getMembersCount()); intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC,group.getDescription()); intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD,group.getPassword()); diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/StatusIndicatorFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/StatusIndicatorFragment.java index 67e8d6b5..2958203b 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/StatusIndicatorFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/StatusIndicatorFragment.java @@ -1,5 +1,7 @@ package com.cometchat.pro.androiduikit.ComponentFragments; +import android.content.Context; +import android.net.Uri; import android.os.Bundle; import androidx.fragment.app.Fragment; diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/UserListViewFragment.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/UserListViewFragment.java index 9bdcaa4c..3f352af4 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/UserListViewFragment.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentFragments/UserListViewFragment.java @@ -12,17 +12,18 @@ import com.cometchat.pro.androiduikit.R; import com.cometchat.pro.androiduikit.databinding.FragmentUserListBinding; +import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.core.UsersRequest; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.User; import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; +import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; import com.facebook.shimmer.ShimmerFrameLayout; import java.util.List; -import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; -import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; public class UserListViewFragment extends Fragment { @@ -47,7 +48,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void OnItemClick(User user, int position) { Intent intent = new Intent(getContext(), CometChatMessageListActivity.class); - intent.putExtra(UIKitConstants.IntentStrings.TYPE, com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER); + intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER); intent.putExtra(UIKitConstants.IntentStrings.NAME,user.getName()); intent.putExtra(UIKitConstants.IntentStrings.UID,user.getUid()); intent.putExtra(UIKitConstants.IntentStrings.AVATAR,user.getAvatar()); diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentLoadActivity.java b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentLoadActivity.java index 877dbc5e..b21b524a 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/ComponentLoadActivity.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/ComponentLoadActivity.java @@ -20,24 +20,24 @@ import com.cometchat.pro.androiduikit.ComponentFragments.GroupListViewFragment; import com.cometchat.pro.androiduikit.ComponentFragments.StatusIndicatorFragment; import com.cometchat.pro.androiduikit.ComponentFragments.UserListViewFragment; +import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.Conversation; import com.cometchat.pro.models.Group; import com.cometchat.pro.models.User; - -import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; -import com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.CustomAlertDialogHelper; -import com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.OnAlertDialogButtonClickListener; -import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; -import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; import com.cometchat.pro.uikit.ui_components.calls.call_list.CometChatCallList; +import com.cometchat.pro.uikit.ui_components.chats.CometChatConversationList; import com.cometchat.pro.uikit.ui_components.groups.group_list.CometChatGroupList; import com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity; import com.cometchat.pro.uikit.ui_components.userprofile.CometChatUserProfile; import com.cometchat.pro.uikit.ui_components.users.user_list.CometChatUserList; +import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; +import com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.CustomAlertDialogHelper; +import com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.OnAlertDialogButtonClickListener; +import com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener; -public class ComponentLoadActivity extends AppCompatActivity implements OnAlertDialogButtonClickListener { +public class ComponentLoadActivity extends AppCompatActivity implements OnAlertDialogButtonClickListener { private ProgressDialog progressDialog; private String groupPassword; @@ -88,13 +88,13 @@ public void OnItemClick(Group var, int position) { if (group.isJoined()) { startGroupIntent(group); } else { - if (group.getGroupType().equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PASSWORD)) { + if (group.getGroupType().equals(CometChatConstants.GROUP_TYPE_PASSWORD)) { View dialogview = getLayoutInflater().inflate(R.layout.cc_dialog, null); TextView tvTitle = dialogview.findViewById(R.id.textViewDialogueTitle); tvTitle.setText(""); new CustomAlertDialogHelper(ComponentLoadActivity.this, "Password", dialogview, "Join", "", "Cancel", ComponentLoadActivity.this, 1, false); - } else if (group.getGroupType().equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PUBLIC)) { + } else if (group.getGroupType().equals(CometChatConstants.GROUP_TYPE_PUBLIC)) { joinGroup(group); } } @@ -105,7 +105,7 @@ public void OnItemClick(Group var, int position) { CometChatConversationList.setItemClickListener(new OnItemClickListener() { @Override public void OnItemClick(Conversation conversation, int position) { - if (conversation.getConversationType().equals(com.cometchat.pro.constants.CometChatConstants.CONVERSATION_TYPE_GROUP)) { + if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_GROUP)) { startGroupIntent(((Group) conversation.getConversationWith())); } else { User user = ((User) conversation.getConversationWith()); @@ -132,7 +132,7 @@ public void userIntent(User user) { intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar()); intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus()); intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName()); - intent.putExtra(UIKitConstants.IntentStrings.TYPE, com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER); + intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER); startActivity(intent); } @@ -144,7 +144,7 @@ private void startGroupIntent(Group group) { intent.putExtra(UIKitConstants.IntentStrings.AVATAR, group.getIcon()); intent.putExtra(UIKitConstants.IntentStrings.NAME, group.getName()); intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE,group.getGroupType()); - intent.putExtra(UIKitConstants.IntentStrings.TYPE, com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_GROUP); + intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_GROUP); intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT,group.getMembersCount()); intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC,group.getDescription()); intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD,group.getPassword()); diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/CreateUserActivity.java b/app/src/main/java/com/cometchat/pro/androiduikit/CreateUserActivity.java index f5df9ab9..342b2f31 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/CreateUserActivity.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/CreateUserActivity.java @@ -14,12 +14,12 @@ import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import com.google.android.material.button.MaterialButton; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; -import com.cometchat.pro.uikit.ui_resources.utils.Utils; public class CreateUserActivity extends AppCompatActivity { diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/LoginActivity.java b/app/src/main/java/com/cometchat/pro/androiduikit/LoginActivity.java index b4d68ea1..a9a6e9af 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/LoginActivity.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/LoginActivity.java @@ -14,13 +14,12 @@ import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; import com.cometchat.pro.androiduikit.constants.AppConfig; -import com.cometchat.pro.uikit.ui_resources.utils.Utils; - public class LoginActivity extends AppCompatActivity { private TextInputLayout inputLayout; diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/MainActivity.java b/app/src/main/java/com/cometchat/pro/androiduikit/MainActivity.java index bd615c31..311d6404 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/MainActivity.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/MainActivity.java @@ -12,11 +12,10 @@ import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.User; import com.cometchat.pro.androiduikit.constants.AppConfig; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import com.google.android.material.button.MaterialButton; import com.google.android.material.card.MaterialCardView; -import com.cometchat.pro.uikit.ui_resources.utils.Utils; - public class MainActivity extends AppCompatActivity { diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/SelectActivity.java b/app/src/main/java/com/cometchat/pro/androiduikit/SelectActivity.java index 9c0810ce..f488eae0 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/SelectActivity.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/SelectActivity.java @@ -5,6 +5,7 @@ import androidx.cardview.widget.CardView; import android.app.Dialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; @@ -18,12 +19,12 @@ import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.listener.CometChatCallListener; import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI; +import com.cometchat.pro.uikit.ui_resources.utils.Utils; import com.google.android.material.button.MaterialButton; import com.google.android.material.snackbar.Snackbar; -import com.cometchat.pro.uikit.ui_components.calls.call_manager.listener.CometChatCallListener; -import com.cometchat.pro.uikit.ui_resources.utils.Utils;; public class SelectActivity extends AppCompatActivity { diff --git a/app/src/main/java/com/cometchat/pro/androiduikit/UIKitApplication.java b/app/src/main/java/com/cometchat/pro/androiduikit/UIKitApplication.java index 3a91a526..8b6a857b 100644 --- a/app/src/main/java/com/cometchat/pro/androiduikit/UIKitApplication.java +++ b/app/src/main/java/com/cometchat/pro/androiduikit/UIKitApplication.java @@ -12,9 +12,9 @@ import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.androiduikit.constants.AppConfig; +import com.cometchat.pro.uikit.ui_components.calls.call_manager.listener.CometChatCallListener; import com.cometchat.pro.uikit.ui_settings.UIKitSettings; -import com.cometchat.pro.uikit.ui_components.calls.call_manager.listener.CometChatCallListener; public class UIKitApplication extends Application { diff --git a/app/src/main/res/layout/activity_component_list.xml b/app/src/main/res/layout/activity_component_list.xml index a9218d39..d086e743 100644 --- a/app/src/main/res/layout/activity_component_list.xml +++ b/app/src/main/res/layout/activity_component_list.xml @@ -152,7 +152,8 @@ android:layout_marginTop="16dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" - android:id="@+id/cometchat_user_view" + android:id=" + @+id/cometchat_user_view" app:cardElevation="4dp" android:clickable="true" android:foreground="?attr/selectableItemBackground" diff --git a/app/src/main/res/layout/activity_create_user.xml b/app/src/main/res/layout/activity_create_user.xml index b083f2ff..88bd5ac2 100644 --- a/app/src/main/res/layout/activity_create_user.xml +++ b/app/src/main/res/layout/activity_create_user.xml @@ -6,7 +6,6 @@ android:layout_height="match_parent" android:orientation="vertical" android:fillViewport="true" - tools:context="com.cometchat.pro.uikit.ui_components.groups.group_list.CometChatGroupList" tools:ignore="MissingDefaultResource"> + android:fillViewport="true"> @@ -90,7 +90,7 @@ style="@style/TextAppearance.MaterialComponents.Headline5" android:layout_marginTop="16dp" android:layout_gravity="center_horizontal" - android:text="UI Screens" + android:text="UI Components" android:layout_width="wrap_content" android:layout_height="wrap_content"/> diff --git a/app/src/main/res/layout/activity_user_list.xml b/app/src/main/res/layout/activity_user_list.xml index 7d8ec631..a8f0e24d 100644 --- a/app/src/main/res/layout/activity_user_list.xml +++ b/app/src/main/res/layout/activity_user_list.xml @@ -10,7 +10,7 @@ diff --git a/app/src/main/res/layout/fragment_avatar.xml b/app/src/main/res/layout/fragment_avatar.xml index e0c798bd..1100288b 100644 --- a/app/src/main/res/layout/fragment_avatar.xml +++ b/app/src/main/res/layout/fragment_avatar.xml @@ -30,7 +30,7 @@ android:text="@string/avatar_description" android:layout_width="wrap_content" android:layout_height="wrap_content"/> - - - This component will be the class of RecyclerView which is customizable to display list of recent conversation \u00A9 2019 CometChat Inc. channel_description - UI Unified directly launches a fully function chat experience within your app. It contains all the features a standard chat application has and reduces the development time and effort considerably. - UI Screens are individual screens that can be used independently within your app to suit your requirements. These screens are fully function stand-alone screens which can be used to achieve specific use cases and reduce the development efforts considerably. + CometChat UI directly launches a fully function chat experience within your app. It contains all the features a standard chat application has and reduces the development time and effort considerably. + UI Components are individual components that can be used independently within your app to suit your requirements. These components are fully function which can be used to achieve specific use cases and reduce the development efforts considerably. circle - It show\'s list of component which users can use at their end to create thier own chat app within minutes. + It show\'s list of core component which users can use at their end to create thier own chat app within minutes. This component will be the class of RecyclerView which is customizable to display list of calls. diff --git a/uikit/build.gradle b/uikit/build.gradle index eed3fbac..b67c5947 100644 --- a/uikit/build.gradle +++ b/uikit/build.gradle @@ -90,6 +90,6 @@ dependencies { implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0' //cometchat - compileOnly 'com.cometchat:pro-android-chat-sdk:2.1.7-beta3' + compileOnly 'com.cometchat:pro-android-chat-sdk:2.2.0' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0' } diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/call_manager/CometChatStartCallActivity.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/call_manager/CometChatStartCallActivity.java index 15bedfa2..a530e438 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/call_manager/CometChatStartCallActivity.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/call_manager/CometChatStartCallActivity.java @@ -64,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) { callSettings = new CallSettings.CallSettingsBuilder(this,mainView) .setSessionId(sessionID) .build(); - Log.e("onStartActivity ", SettingsRepo.getSettings().getWEBRTCHost()); + Log.e( "startCallActivity: ",sessionID+" "+type); CometChat.startCall(callSettings, new CometChat.OngoingCallListener() { @Override public void onUserJoined(User user) { @@ -102,7 +102,7 @@ public void onSuccess(Call call) { @Override public void onError(CometChatException e) { - Toast.makeText(CometChatStartCallActivity.this, "Error:" + e.getCode(), Toast.LENGTH_SHORT).show(); + Toast.makeText(CometChatStartCallActivity.this, "Error:" + e.getCode()+" "+e.getMessage(), Toast.LENGTH_SHORT).show(); } }); } else { diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java index f2b6f459..f92b6c33 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java @@ -61,6 +61,8 @@ public class CometChatConversationList extends Fragment implements TextWatcher { private ConversationsRequest conversationsRequest; //Uses to fetch Conversations. + private String conversationListType = null; + private static OnItemClickListener events; private EditText searchEdit; //Uses to perform search operations. @@ -146,6 +148,10 @@ private void checkDarkMode() { } } + + public void setConversationListType(String conversationListType) { + this.conversationListType = conversationListType; + } /** * This method is used to retrieve list of conversations you have done. * For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-messaging-retrieve-conversations" } @@ -156,6 +162,9 @@ private void makeConversationList() { if (conversationsRequest == null) { conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder().setLimit(50).build(); + if (conversationListType!=null) + conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder() + .setConversationType(conversationListType).setLimit(50).build(); } conversationsRequest.fetchNext(new CometChat.CallbackListener>() { @Override diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/groups/create_group/CometChatCreateGroup.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/groups/create_group/CometChatCreateGroup.java index fef14c8a..6ef8a2db 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/groups/create_group/CometChatCreateGroup.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/groups/create_group/CometChatCreateGroup.java @@ -30,6 +30,8 @@ import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants; import com.cometchat.pro.uikit.ui_resources.utils.Utils; +import static com.cometchat.pro.uikit.ui_resources.utils.Utils.generateRandomString; + /** * Purpose - CometChatCreateGroup class is a fragment used to create a group. User just need to enter * group name. All other information like guid, groupIcon are set by this class. @@ -175,37 +177,10 @@ private void checkDarkMode() { etGroupCnfPassword.setTextColor(getResources().getColor(R.color.primaryTextColor)); } } - - /** - * This method is used to create group when called from layout. It uses Random.nextInt() - * to generate random number to use with group id and group icon. Any Random number between 10 to - * 1000 are choosen. - * - */ - - public static String generateRandomString(int length) { - if (length < 1) throw new IllegalArgumentException(); - StringBuilder sb = new StringBuilder(length); - for (int i = 0; i < length; i++) { - // 0-62 (exclusive), random returns 0-61 - SecureRandom random = new SecureRandom(); - String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz"; - String CHAR_UPPER = CHAR_LOWER.toUpperCase(); - String NUMBER = "0123456789"; - String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; - int rndCharAt = random.nextInt(DATA_FOR_RANDOM_STRING.length()); - char rndChar = DATA_FOR_RANDOM_STRING.charAt(rndCharAt); - // debug - System.out.format("%d\t:\t%c%n", rndCharAt, rndChar); - sb.append(rndChar); - } - return sb.toString(); - } - private void createGroup() { if (!etGroupName.getText().toString().isEmpty()) { if(groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PUBLIC) || groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PRIVATE)) { - Group group = new Group("group" + generateRandomString(95), etGroupName.getText().toString(), groupType, ""); + Group group = new Group("group" + generateRandomString(25), etGroupName.getText().toString(), groupType, ""); createGroup(group); } else if (groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PASSWORD)) { @@ -214,7 +189,7 @@ else if (groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_T else if (etGroupCnfPassword.getText().toString().isEmpty()) etGroupCnfPassword.setError(getResources().getString(R.string.fill_this_field)); else if(etGroupPassword.getText().toString().equals(etGroupCnfPassword.getText().toString())) { - Group group = new Group("group" + generateRandomString(95), etGroupName.getText().toString(), groupType, etGroupPassword.getText().toString()); + Group group = new Group("group" + generateRandomString(25), etGroupName.getText().toString(), groupType, etGroupPassword.getText().toString()); createGroup(group); } else diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java index a8f5bf80..20c7a195 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java @@ -558,7 +558,12 @@ private void checkOnGoingCall() { @Override public void onClick(View v) { onGoingCallView.setVisibility(View.GONE); - CallUtils.joinOnGoingCall(context,CometChat.getActiveCall()); + if (CometChat.getActiveCall()!=null) + CallUtils.joinOnGoingCall(context,CometChat.getActiveCall()); + else { + Toast.makeText(context,getString(R.string.call_ended),Toast.LENGTH_LONG).show(); + onGoingCallView.setVisibility(View.GONE); + } } }); } @@ -842,7 +847,7 @@ else if (option2Text.getText().toString().trim().isEmpty()) jsonObject.put("options", optionJson); jsonObject.put("receiver", Id); jsonObject.put("receiverType", type); - CometChat.callExtension("polls", "POST", "/v1/create", + CometChat.callExtension("polls", "POST", "/v2/create", jsonObject, new CometChat.CallbackListener() { @Override public void onSuccess(JSONObject jsonObject) { @@ -952,7 +957,8 @@ private void sendCustomMessage(String customType, JSONObject customData) { @Override public void onSuccess(CustomMessage customMessage) { if (customType.equalsIgnoreCase(UIKitConstants.IntentStrings.GROUP_CALL)) - CallUtils.startDirectCall(context,Utils.getDirectCallData(customMessage)); + if (CometChat.getActiveCall()==null) + CallUtils.startDirectCall(context,Utils.getDirectCallData(customMessage)); if (messageAdapter != null) { messageAdapter.addMessage(customMessage); diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.java index 3835a31f..56c2bff0 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.java @@ -53,6 +53,7 @@ import com.cometchat.pro.models.TextMessage; import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity; import com.cometchat.pro.uikit.ui_resources.utils.pattern_utils.PatternUtils; import com.cometchat.pro.uikit.ui_settings.UISettings; import com.google.android.material.button.MaterialButton; @@ -669,26 +670,31 @@ private void setPollsData(PollMessageViewHolder viewHolder, int i) { @Override public void onClick(View v) { try { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("vote",finalK+1); - jsonObject.put("id",baseMessage.getId()); - CometChat.callExtension("polls", "POST", "/v1/vote", - jsonObject,new CometChat.CallbackListener() { - @Override - public void onSuccess(JSONObject jsonObject) { - // Voted successfully - viewHolder.loadingProgress.setVisibility(View.VISIBLE); - viewHolder.totalCount.setText("0 Votes"); - Log.e(TAG, "onSuccess: "+jsonObject.toString()); - Toast.makeText(context,"Voted Success",Toast.LENGTH_LONG).show(); - } - - @Override - public void onError(CometChatException e) { - // Some error occured - Log.e(TAG, "onErrorExtension: "+e.getMessage()+"\n"+e.getCode()); - } - }); + String pollsId=null; + if (jsonObject.has("id")) + pollsId = jsonObject.getString("id"); + else + pollsId = baseMessage.getId()+""; + JSONObject pollsJsonObject = new JSONObject(); + pollsJsonObject.put("vote",finalK+1); + pollsJsonObject.put("id", pollsId); + CometChat.callExtension("polls", "POST", "/v2/vote", + pollsJsonObject, new CometChat.CallbackListener() { + @Override + public void onSuccess(JSONObject jsonObject) { + // Voted successfully + viewHolder.loadingProgress.setVisibility(View.VISIBLE); + viewHolder.totalCount.setText("0 Votes"); + Log.e(TAG, "onSuccess: " + jsonObject.toString()); + Toast.makeText(context, "Voted Success", Toast.LENGTH_LONG).show(); + } + + @Override + public void onError(CometChatException e) { + // Some error occured + Log.e(TAG, "onErrorExtension: " + e.getMessage() + "\n" + e.getCode()); + } + }); } catch (Exception e) { Log.e(TAG, "onError: "+e.getMessage()); } @@ -758,7 +764,24 @@ else if (baseMessage.getReceiverType().equals(com.cometchat.pro.constants.CometC @Override public void onClick(View v) { if (((CustomMessage)baseMessage).getCustomData()!=null) { - CallUtils.startDirectCall(context, Utils.getDirectCallData(baseMessage)); + if (CometChat.getActiveCall()==null) + CallUtils.startDirectCall(context, Utils.getDirectCallData(baseMessage)); + else { + AlertDialog.Builder alert = new AlertDialog.Builder(context); + alert.setTitle(context.getResources().getString(R.string.ongoing_call)) + .setMessage(context.getResources().getString(R.string.ongoing_call_message)) + .setPositiveButton(context.getResources().getString(R.string.join), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + CallUtils.joinOnGoingCall(context,CometChat.getActiveCall()); + } + }).setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }).create().show(); + } } } }); diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatAvatar/CometChatAvatar.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatAvatar/CometChatAvatar.java index cf6351d9..f14682e0 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatAvatar/CometChatAvatar.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatAvatar/CometChatAvatar.java @@ -393,6 +393,9 @@ public void setInitials(@NonNull String name) { setImageDrawable(drawable); } + public float getBorderWidth() { + return borderWidth; + } public Drawable getDrawable() { return drawable; diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatConversations/CometChatConversationsAdapter.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatConversations/CometChatConversationsAdapter.java index 3ea44c1f..8c9819b4 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatConversations/CometChatConversationsAdapter.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatConversations/CometChatConversationsAdapter.java @@ -299,7 +299,8 @@ public void update(Conversation conversation) { if (filterConversationList.contains(conversation)) { Conversation oldConversation = filterConversationList.get(filterConversationList.indexOf(conversation)); filterConversationList.remove(oldConversation); - conversation.setUnreadMessageCount(oldConversation.getUnreadMessageCount() + 1); + if (conversation.getLastMessage().getCategory().equalsIgnoreCase(CometChatConstants.CATEGORY_MESSAGE)) + conversation.setUnreadMessageCount(oldConversation.getUnreadMessageCount() + 1); filterConversationList.add(0, conversation); } else { filterConversationList.add(0, conversation); diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/users/user_details/callHistroy/CallHistoryAdapter.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/users/user_details/callHistroy/CallHistoryAdapter.java index 7d87c6ac..7105321f 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/users/user_details/callHistroy/CallHistoryAdapter.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_components/users/user_details/callHistroy/CallHistoryAdapter.java @@ -154,7 +154,7 @@ public void onBindViewHolder(@NonNull CallViewHolder callViewHolder, int positio } callViewHolder.callHistoryRowBinding.callTimeTv.setText(Utils.getHeaderDate(call.getInitiatedAt()*1000)); callViewHolder.callHistoryRowBinding.callInfoTv.setText(callMessageText); - callViewHolder.callHistoryRowBinding.callDateTv.setText(Utils.getDate(call.getSentAt()*1000L)); + callViewHolder.callHistoryRowBinding.callDateTv.setText(Utils.getCallDate(call.getSentAt()*1000)); callViewHolder.callHistoryRowBinding.getRoot().setTag(R.string.call, call); diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/Utils.java b/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/Utils.java index 8d7de52b..ba6310e1 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/Utils.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/ui_resources/utils/Utils.java @@ -55,6 +55,7 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Collections; @@ -122,6 +123,12 @@ public static String getDateId(long var0) { return DateFormat.format("ddMMyyyy", var2).toString(); } + public static String getCallDate(long var0) { + Calendar var2 = Calendar.getInstance(Locale.ENGLISH); + var2.setTimeInMillis(var0); + return DateFormat.format("dd MMM yy", var2).toString(); + } + public static String getDate(long var0) { Calendar var2 = Calendar.getInstance(Locale.ENGLISH); var2.setTimeInMillis(var0); @@ -305,6 +312,33 @@ public static String getLastMessageDate(long timestamp) { } + + /** + * This method is used to create group when called from layout. It uses Random.nextInt() + * to generate random number to use with group id and group icon. Any Random number between 10 to + * 1000 are choosen. + * + */ + + public static String generateRandomString(int length) { + if (length < 1) throw new IllegalArgumentException(); + StringBuilder sb = new StringBuilder(length); + for (int i = 0; i < length; i++) { + // 0-62 (exclusive), random returns 0-61 + SecureRandom random = new SecureRandom(); + String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz"; + String CHAR_UPPER = CHAR_LOWER.toUpperCase(); + String NUMBER = "0123456789"; + String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; + int rndCharAt = random.nextInt(DATA_FOR_RANDOM_STRING.length()); + char rndChar = DATA_FOR_RANDOM_STRING.charAt(rndCharAt); + // debug + System.out.format("%d\t:\t%c%n", rndCharAt, rndChar); + sb.append(rndChar); + } + return sb.toString(); + } + public static String getReceiptDate(long timestamp) { String lastMessageTime = new SimpleDateFormat("h:mm a").format(new java.util.Date(timestamp * 1000)); String lastMessageDate = new SimpleDateFormat("dd MMMM h:mm a").format(new java.util.Date(timestamp * 1000));