1+ package com .cometchat .javasampleapp .fragments .shared .views ;
2+
3+ import android .os .Bundle ;
4+
5+ import androidx .fragment .app .Fragment ;
6+
7+ import android .view .LayoutInflater ;
8+ import android .view .View ;
9+ import android .view .ViewGroup ;
10+ import android .widget .LinearLayout ;
11+
12+ import com .cometchat .chat .constants .CometChatConstants ;
13+ import com .cometchat .chat .models .InteractionGoal ;
14+ import com .cometchat .chatuikit .shared .cometchatuikit .CometChatUIKit ;
15+ import com .cometchat .chatuikit .shared .constants .UIKitConstants ;
16+ import com .cometchat .chatuikit .shared .models .interactiveactions .APIAction ;
17+ import com .cometchat .chatuikit .shared .models .interactiveactions .URLNavigationAction ;
18+ import com .cometchat .chatuikit .shared .models .interactiveelements .ButtonElement ;
19+ import com .cometchat .chatuikit .shared .models .interactiveelements .CheckboxElement ;
20+ import com .cometchat .chatuikit .shared .models .interactiveelements .ElementEntity ;
21+ import com .cometchat .chatuikit .shared .models .interactiveelements .OptionElement ;
22+ import com .cometchat .chatuikit .shared .models .interactiveelements .PlaceHolder ;
23+ import com .cometchat .chatuikit .shared .models .interactiveelements .RadioButtonElement ;
24+ import com .cometchat .chatuikit .shared .models .interactiveelements .SingleSelectElement ;
25+ import com .cometchat .chatuikit .shared .models .interactiveelements .SpinnerElement ;
26+ import com .cometchat .chatuikit .shared .models .interactiveelements .TextInputElement ;
27+ import com .cometchat .chatuikit .shared .models .interactivemessage .FormMessage ;
28+ import com .cometchat .chatuikit .shared .resources .theme .CometChatTheme ;
29+ import com .cometchat .chatuikit .shared .views .CometChatFormbubble .CometChatFormBubble ;
30+ import com .cometchat .chatuikit .shared .views .CometChatFormbubble .FormBubbleStyle ;
31+ import com .cometchat .chatuikit .shared .views .CometChatSingleSelect .SingleSelectStyle ;
32+ import com .cometchat .javasampleapp .AppConstants ;
33+ import com .cometchat .javasampleapp .AppUtils ;
34+ import com .cometchat .javasampleapp .R ;
35+
36+ import org .json .JSONException ;
37+ import org .json .JSONObject ;
38+
39+ import java .util .ArrayList ;
40+ import java .util .Arrays ;
41+ import java .util .List ;
42+
43+ public class FormBubbleFragment extends Fragment {
44+ private LinearLayout parentLayout ;
45+ private CometChatFormBubble formBubble ;
46+
47+ @ Override
48+ public View onCreateView (LayoutInflater inflater , ViewGroup container ,
49+ Bundle savedInstanceState ) {
50+ View view = inflater .inflate (R .layout .fragment_form_bubble , container , false );
51+
52+ parentLayout = view .findViewById (R .id .parent_layout );
53+ formBubble = view .findViewById (R .id .form_bubble );
54+
55+
56+ CometChatTheme theme = CometChatTheme .getInstance (getContext ());
57+ //create style object for Form bubble
58+ FormBubbleStyle formBubbleStyle = new FormBubbleStyle ()
59+ .setTitleAppearance (theme .getTypography ().getHeading ())
60+ .setTitleColor (theme .getPalette ().getAccent ())
61+
62+ .setLabelAppearance (theme .getTypography ().getSubtitle1 ())
63+ .setLabelColor (theme .getPalette ().getAccent ())
64+
65+ .setInputTextAppearance (theme .getTypography ().getSubtitle1 ())
66+ .setInputTextColor (theme .getPalette ().getAccent ())
67+ .setInputHintColor (theme .getPalette ().getAccent500 ())
68+ .setErrorColor (theme .getPalette ().getError ())
69+ .setInputStrokeColor (theme .getPalette ().getAccent600 ())
70+ .setActiveInputStrokeColor (theme .getPalette ().getAccent ())
71+
72+ .setDefaultCheckboxButtonTint (theme .getPalette ().getAccent500 ())
73+ .setSelectedCheckboxButtonTint (theme .getPalette ().getPrimary ())
74+ .setErrorCheckboxButtonTint (theme .getPalette ().getError ())
75+ .setCheckboxTextColor (theme .getPalette ().getAccent ())
76+ .setCheckboxTextAppearance (theme .getTypography ().getSubtitle1 ())
77+
78+ .setButtonBackgroundColor (theme .getPalette ().getPrimary ())
79+ .setButtonTextColor (theme .getPalette ().getAccent900 ())
80+ .setButtonTextAppearance (theme .getTypography ().getSubtitle1 ())
81+ .setProgressBarTintColor (theme .getPalette ().getAccent900 ())
82+ .setRadioButtonTint (theme .getPalette ().getAccent500 ())
83+ .setRadioButtonTextColor (theme .getPalette ().getAccent ())
84+ .setRadioButtonTextAppearance (theme .getTypography ().getSubtitle1 ())
85+ .setSelectedRadioButtonTint (theme .getPalette ().getPrimary ())
86+
87+ .setSpinnerTextColor (theme .getPalette ().getAccent ())
88+ .setSpinnerTextAppearance (theme .getTypography ().getSubtitle1 ())
89+ .setSpinnerBackgroundColor (theme .getPalette ().getAccent500 ())
90+
91+ .setBackground (theme .getPalette ().getBackground ())
92+ .setBackground (theme .getPalette ().getGradientBackground ())
93+
94+ .setSingleSelectStyle (new SingleSelectStyle ()
95+ .setOptionTextAppearance (theme .getTypography ().getSubtitle1 ())
96+ .setOptionTextColor (theme .getPalette ().getAccent500 ())
97+ .setSelectedOptionTextAppearance (theme .getTypography ().getSubtitle1 ())
98+ .setSelectedOptionTextColor (theme .getPalette ().getAccent ())
99+ .setButtonStrokeColor (theme .getPalette ().getAccent600 ())
100+ .setTitleColor (theme .getPalette ().getAccent ())
101+ .setTitleAppearance (theme .getTypography ().getSubtitle1 ())
102+ );
103+ formBubble .setStyle (formBubbleStyle );
104+
105+ //create elements for form bubble
106+ List <ElementEntity > elementEntities = new ArrayList <>();
107+ TextInputElement textInputElement1 = new TextInputElement ("element1" , "Name" );
108+ textInputElement1 .setPlaceHolder (new PlaceHolder ("write your name here" ));
109+
110+ TextInputElement textInputElement2 = new TextInputElement ("element2" , "Last Name" );
111+ TextInputElement textInputElement3 = new TextInputElement ("element3" , "Address" );
112+ textInputElement3 .setMaxLines (5 );
113+ textInputElement1 .setDefaultValue ("vivek" );
114+ elementEntities .add (textInputElement1 );
115+ elementEntities .add (textInputElement2 );
116+ elementEntities .add (textInputElement3 );
117+
118+ List <OptionElement > optionElementList = new ArrayList <>();
119+ optionElementList .add (new OptionElement ("option1" , "INDIA" ));
120+ optionElementList .add (new OptionElement ("option2" , "AUSTRALIA" ));
121+ optionElementList .add (new OptionElement ("option3" , "RUSSIA" ));
122+ optionElementList .add (new OptionElement ("option4" , "AMERICA" ));
123+ SpinnerElement spinnerElement = new SpinnerElement ("element4" , "Country" , optionElementList , "option1" );
124+ elementEntities .add (spinnerElement );
125+
126+
127+ List <OptionElement > checkBox = new ArrayList <>();
128+ checkBox .add (new OptionElement ("option1" , "Garbage" ));
129+ checkBox .add (new OptionElement ("option2" , "Electricity Bill" ));
130+ checkBox .add (new OptionElement ("option3" , "Lift" ));
131+ CheckboxElement checkboxElement = new CheckboxElement ("element5" , "Services" , checkBox , new ArrayList <>(Arrays .asList ("option1" , "option2" )));
132+ elementEntities .add (checkboxElement );
133+
134+ List <OptionElement > optionElementList2 = new ArrayList <>();
135+ optionElementList2 .add (new OptionElement ("option1" , "A" ));
136+ optionElementList2 .add (new OptionElement ("option2" , "B" ));
137+
138+ SingleSelectElement singleSelectElement = new SingleSelectElement ("element6" , "Wing" , optionElementList2 , "option1" );
139+ elementEntities .add (singleSelectElement );
140+
141+ RadioButtonElement radioButtonElement = new RadioButtonElement ("element7" , "Country" , optionElementList , "option1" );
142+ elementEntities .add (radioButtonElement );
143+
144+ URLNavigationAction urlNavigationAction = new URLNavigationAction ("https://www.cometchat.com/" );
145+ ButtonElement submitButton = new ButtonElement ("element9" , "About us" , urlNavigationAction );
146+ submitButton .setDisableAfterInteracted (true );
147+ elementEntities .add (submitButton );
148+
149+ FormMessage formMessage = new FormMessage (AppUtils .getDefaultUser () != null ? AppUtils .getDefaultUser ().getUid () : AppUtils .getDefaultGroup () != null ? AppUtils .getDefaultGroup ().getGuid () : null , AppUtils .getDefaultUser () != null ? UIKitConstants .ReceiverType .USER : UIKitConstants .ReceiverType .GROUP , elementEntities , submitButton );
150+ formMessage .setTitle ("Society Survey" );
151+ formMessage .setAllowSenderInteraction (true );
152+ formMessage .setSender (CometChatUIKit .getLoggedInUser ());
153+ formMessage .setSentAt (System .currentTimeMillis () / 1000 );
154+ formMessage .setReceiver (AppUtils .getDefaultUser () != null ? AppUtils .getDefaultUser () : AppUtils .getDefaultGroup () != null ? AppUtils .getDefaultGroup () : null );
155+ formMessage .setInteractionGoal (new InteractionGoal (CometChatConstants .INTERACTION_TYPE_All_OF , Arrays .asList ("element8" , "element9" )));
156+
157+ formBubble .setFormMessage (formMessage );
158+ return view ;
159+ }
160+ }
0 commit comments