1616import androidx .recyclerview .widget .LinearLayoutManager ;
1717import androidx .recyclerview .widget .RecyclerView ;
1818
19+ import com .cometchat .pro .constants .CometChatConstants ;
1920import com .cometchat .pro .core .Call ;
2021import com .cometchat .pro .core .CometChat ;
2122import com .cometchat .pro .core .MessagesRequest ;
2829import com .cometchat .pro .uikit .R ;
2930import com .cometchat .pro .uikit .ui_resources .utils .CometChatError ;
3031import com .cometchat .pro .uikit .ui_resources .utils .Utils ;
32+ import com .cometchat .pro .uikit .ui_settings .FeatureRestriction ;
3133import com .google .android .material .snackbar .Snackbar ;
3234
3335import java .util .Arrays ;
@@ -57,9 +59,15 @@ public class AllCall extends Fragment {
5759 private MessagesRequest messagesRequest ;
5860
5961 private LinearLayoutManager linearLayoutManager ;
62+
63+ private boolean videoCallEnabled ;
64+ private boolean audioCallEnabled ;
65+
6066 @ Override
6167 public View onCreateView (@ NonNull LayoutInflater inflater , @ Nullable ViewGroup container , @ Nullable Bundle savedInstanceState ) {
6268 View view = inflater .inflate (R .layout .fragment_cometchat_all_call , container , false );
69+ fetchSettings ();
70+ CometChatError .init (getContext ());
6371 rvCallList = view .findViewById (R .id .callList_rv );
6472 linearLayoutManager = new LinearLayoutManager (getContext (),LinearLayoutManager .VERTICAL ,false
6573 );
@@ -68,7 +76,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
6876 rvCallList .setItemClickListener (new OnItemClickListener <Call >() {
6977 @ Override
7078 public void OnItemClick (Call var , int position ) {
71- if (var .getReceiverType ().equals (com . cometchat . pro . constants . CometChatConstants .RECEIVER_TYPE_USER )) {
79+ if (var .getReceiverType ().equals (CometChatConstants .RECEIVER_TYPE_USER )) {
7280 User user ;
7381 if (((User )var .getCallInitiator ()).getUid ().equals (CometChat .getLoggedInUser ().getUid ())) {
7482 user = ((User )var .getCallReceiver ());
@@ -81,6 +89,7 @@ public void OnItemClick(Call var, int position) {
8189 intent .putExtra (UIKitConstants .IntentStrings .NAME , user .getName ());
8290 intent .putExtra (UIKitConstants .IntentStrings .AVATAR , user .getAvatar ());
8391 intent .putExtra (UIKitConstants .IntentStrings .STATUS , user .getStatus ());
92+ intent .putExtra (UIKitConstants .IntentStrings .LINK ,user .getLink ());
8493 intent .putExtra (UIKitConstants .IntentStrings .IS_BLOCKED_BY_ME , user .isBlockedByMe ());
8594 intent .putExtra (UIKitConstants .IntentStrings .FROM_CALL_LIST ,true );
8695 startActivity (intent );
@@ -121,7 +130,7 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
121130 }
122131
123132 private void checkOnGoingCall (Call var ) {
124- if (CometChat .getActiveCall ()!=null && CometChat .getActiveCall ().getCallStatus ().equals (com . cometchat . pro . constants . CometChatConstants .CALL_STATUS_ONGOING ) && CometChat .getActiveCall ().getSessionId ()!=null )
133+ if (CometChat .getActiveCall ()!=null && CometChat .getActiveCall ().getCallStatus ().equals (CometChatConstants .CALL_STATUS_ONGOING ) && CometChat .getActiveCall ().getSessionId ()!=null )
125134 {
126135 AlertDialog .Builder alert = new AlertDialog .Builder (getContext ());
127136 alert .setTitle (getContext ().getResources ().getString (R .string .ongoing_call ))
@@ -139,22 +148,28 @@ public void onClick(DialogInterface dialog, int which) {
139148 }).create ().show ();
140149 }
141150 else {
142- AlertDialog .Builder alertDialog = new AlertDialog .Builder (getContext ());
143- alertDialog .setMessage (getString (R .string .initiate_a_call ));
144- alertDialog .setPositiveButton (getString (R .string .audio_call ), new DialogInterface .OnClickListener () {
145- @ Override
146- public void onClick (DialogInterface dialogInterface , int i ) {
147- initiateCall (var , com .cometchat .pro .constants .CometChatConstants .CALL_TYPE_AUDIO );
151+ if (audioCallEnabled || videoCallEnabled ) {
152+ AlertDialog .Builder alertDialog = new AlertDialog .Builder (getContext ());
153+ alertDialog .setMessage (getString (R .string .initiate_a_call ));
154+ if (audioCallEnabled ) {
155+ alertDialog .setPositiveButton (getString (R .string .audio_call ), new DialogInterface .OnClickListener () {
156+ @ Override
157+ public void onClick (DialogInterface dialogInterface , int i ) {
158+ initiateCall (var , CometChatConstants .CALL_TYPE_AUDIO );
159+ }
160+ });
148161 }
149- });
150- alertDialog .setNegativeButton (getString (R .string .video_call ), new DialogInterface .OnClickListener () {
151- @ Override
152- public void onClick (DialogInterface dialogInterface , int i ) {
153- initiateCall (var , com .cometchat .pro .constants .CometChatConstants .CALL_TYPE_VIDEO );
162+ if (videoCallEnabled ) {
163+ alertDialog .setNegativeButton (getString (R .string .video_call ), new DialogInterface .OnClickListener () {
164+ @ Override
165+ public void onClick (DialogInterface dialogInterface , int i ) {
166+ initiateCall (var , CometChatConstants .CALL_TYPE_VIDEO );
167+ }
168+ });
154169 }
155- } );
156- alertDialog .create ();
157- alertDialog . show ();
170+ alertDialog . create ( );
171+ alertDialog .show ();
172+ }
158173 }
159174
160175 }
@@ -164,7 +179,7 @@ private void initiateCall(Call var,String callType) {
164179 @ Override
165180 public void onSuccess (Call call ) {
166181 Log .e ("onSuccess: " , call .toString ());
167- if (call .getReceiverType ().equals (com . cometchat . pro . constants . CometChatConstants .RECEIVER_TYPE_USER )) {
182+ if (call .getReceiverType ().equals (CometChatConstants .RECEIVER_TYPE_USER )) {
168183 User user ;
169184 if (((User ) call .getCallInitiator ()).getUid ().equals (CometChat .getLoggedInUser ().getUid ())) {
170185 user = ((User ) call .getCallReceiver ());
@@ -192,7 +207,7 @@ private void getCallList() {
192207 if (messagesRequest == null )
193208 {
194209 messagesRequest = new MessagesRequest .MessagesRequestBuilder ().
195- setCategories (Arrays .asList (com . cometchat . pro . constants . CometChatConstants .CATEGORY_CALL )).setLimit (30 ).build ();
210+ setCategories (Arrays .asList (CometChatConstants .CATEGORY_CALL )).setLimit (30 ).build ();
196211 }
197212
198213 messagesRequest .fetchPrevious (new CometChat .CallbackListener <List <BaseMessage >>() {
@@ -229,4 +244,19 @@ public void setMenuVisibility(boolean menuVisible) {
229244 public void onResume () {
230245 super .onResume ();
231246 }
247+
248+ private void fetchSettings () {
249+ FeatureRestriction .isOneOnOneVideoCallEnabled (new FeatureRestriction .OnSuccessListener () {
250+ @ Override
251+ public void onSuccess (Boolean booleanVal ) {
252+ videoCallEnabled = booleanVal ;
253+ }
254+ });
255+ FeatureRestriction .isOneOnOneAudioCallEnabled (new FeatureRestriction .OnSuccessListener () {
256+ @ Override
257+ public void onSuccess (Boolean booleanVal ) {
258+ audioCallEnabled = booleanVal ;
259+ }
260+ });
261+ }
232262}
0 commit comments