77import android .content .DialogInterface ;
88import android .database .Cursor ;
99import android .os .Bundle ;
10+ import android .support .annotation .Nullable ;
1011import android .support .v4 .app .DialogFragment ;
1112import android .support .v4 .widget .SimpleCursorAdapter ;
1213import android .text .TextUtils ;
1516import android .view .LayoutInflater ;
1617import android .view .View ;
1718import android .view .View .OnClickListener ;
19+ import android .view .ViewGroup ;
20+ import android .view .Window ;
1821import android .view .WindowManager ;
1922import android .widget .AutoCompleteTextView ;
2023import android .widget .EditText ;
@@ -28,10 +31,11 @@ public class ComposeDialog extends DialogFragment {
2831 ZulipApp app ;
2932 private MessageType type ;
3033
31- private View view ;
3234 private AutoCompleteTextView recipient ;
3335 private AutoCompleteTextView subject ;
36+ private View threadSeparator ;
3437 private EditText body ;
38+ private View view ;
3539
3640 public static ComposeDialog newInstance (MessageType type , String stream ,
3741 String topic , String pmRecipients ) {
@@ -56,16 +60,14 @@ public ComposeDialog() {
5660 */
5761 protected void switchToPersonal () {
5862 subject .setVisibility (View .GONE );
59- recipient . setGravity ( Gravity . FILL_HORIZONTAL );
63+ threadSeparator . setVisibility ( View . GONE );
6064 recipient .setHint (R .string .pm_prompt );
6165 }
6266
6367 /**
6468 * Switches the compose window's state to compose a stream message.
6569 */
6670 protected void switchToStream () {
67- subject .setVisibility (View .VISIBLE );
68- recipient .setGravity (Gravity .NO_GRAVITY );
6971 recipient .setHint (R .string .stream );
7072 }
7173
@@ -88,31 +90,39 @@ protected boolean requireFilled(EditText field, String fieldName) {
8890
8991 @ Override
9092 public Dialog onCreateDialog (Bundle savedInstanceState ) {
93+ setupView (LayoutInflater .from (getActivity ()), null );
9194 AlertDialog .Builder builder = new AlertDialog .Builder (getActivity ());
92- LayoutInflater inflater = getActivity ().getLayoutInflater ();
93- view = inflater .inflate (R .layout .compose , null );
95+ AlertDialog dialog = builder
96+ .setView (view )
97+ .setPositiveButton (R .string .send , null )
98+ .setNegativeButton (android .R .string .cancel , null )
99+ .create ();
100+
101+ dialog .requestWindowFeature (Window .FEATURE_NO_TITLE );
102+ dialog .getWindow ().setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_STATE_VISIBLE );
103+
104+ return dialog ;
105+ }
106+
107+ private void setupView (LayoutInflater inflater , ViewGroup container ) {
108+ view = inflater .inflate (R .layout .compose , container , false );
94109
95110 Bundle bundle = getArguments ();
96111 type = (MessageType ) bundle .getSerializable ("type" );
97112 final String stream = bundle .getString ("stream" );
98113 final String topic = bundle .getString ("topic" );
99114 final String pmRecipients = bundle .getString ("pmRecipients" );
100115
101- Log .i ("onCreateDialog" , "" + type + " " + stream + " " + topic + " "
102- + pmRecipients );
116+ Log .i ("onCreateDialog" , "" + type + " " + stream + " " + topic + " " + pmRecipients );
103117
104- recipient = (AutoCompleteTextView ) view
105- .findViewById (R .id .composeRecipient );
118+ recipient = (AutoCompleteTextView ) view .findViewById (R .id .composeRecipient );
106119 subject = (AutoCompleteTextView ) view .findViewById (R .id .composeTopic );
107120 body = (EditText ) view .findViewById (R .id .composeText );
121+ threadSeparator = view .findViewById (R .id .separator );
108122
109123 activity = ((ZulipActivity ) getActivity ());
110124 app = activity .app ;
111125
112- AlertDialog dialog = builder .setView (view ).setTitle ("Compose" )
113- .setPositiveButton (R .string .send , null )
114- .setNegativeButton (android .R .string .cancel , null ).create ();
115-
116126 if (type == MessageType .STREAM_MESSAGE ) {
117127 this .switchToStream ();
118128
@@ -145,15 +155,14 @@ public Cursor runQuery(CharSequence charSequence) {
145155 getActivity (), R .layout .stream_tile , null ,
146156 new String []{Message .SUBJECT_FIELD },
147157 new int []{R .id .name }, 0 );
148- subjectAdapter
149- .setCursorToStringConverter (new SimpleCursorAdapter .CursorToStringConverter () {
150- @ Override
151- public CharSequence convertToString (Cursor cursor ) {
152- int index = cursor
153- .getColumnIndex (Message .SUBJECT_FIELD );
154- return cursor .getString (index );
155- }
156- });
158+ subjectAdapter .setCursorToStringConverter (new SimpleCursorAdapter .CursorToStringConverter () {
159+ @ Override
160+ public CharSequence convertToString (Cursor cursor ) {
161+ int index = cursor
162+ .getColumnIndex (Message .SUBJECT_FIELD );
163+ return cursor .getString (index );
164+ }
165+ });
157166 subjectAdapter .setFilterQueryProvider (new FilterQueryProvider () {
158167 @ Override
159168 public Cursor runQuery (CharSequence charSequence ) {
@@ -188,23 +197,22 @@ public Cursor runQuery(CharSequence charSequence) {
188197 new String []{Person .EMAIL_FIELD },
189198 new int []{R .id .name }, 0 );
190199 recipient .setAdapter (emailAdapter );
191- emailAdapter
192- .setCursorToStringConverter (new SimpleCursorAdapter .CursorToStringConverter () {
193- @ Override
194- public CharSequence convertToString (Cursor cursor ) {
195- String text = recipient .getText ().toString ();
196- String prefix ;
197- int lastIndex = text .lastIndexOf ("," );
198- if (lastIndex != -1 ) {
199- prefix = text .substring (0 , lastIndex + 1 );
200- } else {
201- prefix = "" ;
202- }
203- int index = cursor
204- .getColumnIndex (Person .EMAIL_FIELD );
205- return prefix + cursor .getString (index );
206- }
207- });
200+ emailAdapter .setCursorToStringConverter (new SimpleCursorAdapter .CursorToStringConverter () {
201+ @ Override
202+ public CharSequence convertToString (Cursor cursor ) {
203+ String text = recipient .getText ().toString ();
204+ String prefix ;
205+ int lastIndex = text .lastIndexOf ("," );
206+ if (lastIndex != -1 ) {
207+ prefix = text .substring (0 , lastIndex + 1 );
208+ } else {
209+ prefix = "" ;
210+ }
211+ int index = cursor
212+ .getColumnIndex (Person .EMAIL_FIELD );
213+ return prefix + cursor .getString (index );
214+ }
215+ });
208216 emailAdapter .setFilterQueryProvider (new FilterQueryProvider () {
209217 @ Override
210218 public Cursor runQuery (CharSequence charSequence ) {
@@ -225,10 +233,6 @@ public Cursor runQuery(CharSequence charSequence) {
225233 }
226234 }
227235
228- dialog .getWindow ().setSoftInputMode (
229- WindowManager .LayoutParams .SOFT_INPUT_STATE_VISIBLE );
230-
231- return dialog ;
232236 }
233237
234238 /**
0 commit comments