7
7
import android .content .DialogInterface ;
8
8
import android .database .Cursor ;
9
9
import android .os .Bundle ;
10
+ import android .support .annotation .Nullable ;
10
11
import android .support .v4 .app .DialogFragment ;
11
12
import android .support .v4 .widget .SimpleCursorAdapter ;
12
13
import android .text .TextUtils ;
15
16
import android .view .LayoutInflater ;
16
17
import android .view .View ;
17
18
import android .view .View .OnClickListener ;
19
+ import android .view .ViewGroup ;
20
+ import android .view .Window ;
18
21
import android .view .WindowManager ;
19
22
import android .widget .AutoCompleteTextView ;
20
23
import android .widget .EditText ;
@@ -28,10 +31,11 @@ public class ComposeDialog extends DialogFragment {
28
31
ZulipApp app ;
29
32
private MessageType type ;
30
33
31
- private View view ;
32
34
private AutoCompleteTextView recipient ;
33
35
private AutoCompleteTextView subject ;
36
+ private View threadSeparator ;
34
37
private EditText body ;
38
+ private View view ;
35
39
36
40
public static ComposeDialog newInstance (MessageType type , String stream ,
37
41
String topic , String pmRecipients ) {
@@ -56,16 +60,14 @@ public ComposeDialog() {
56
60
*/
57
61
protected void switchToPersonal () {
58
62
subject .setVisibility (View .GONE );
59
- recipient . setGravity ( Gravity . FILL_HORIZONTAL );
63
+ threadSeparator . setVisibility ( View . GONE );
60
64
recipient .setHint (R .string .pm_prompt );
61
65
}
62
66
63
67
/**
64
68
* Switches the compose window's state to compose a stream message.
65
69
*/
66
70
protected void switchToStream () {
67
- subject .setVisibility (View .VISIBLE );
68
- recipient .setGravity (Gravity .NO_GRAVITY );
69
71
recipient .setHint (R .string .stream );
70
72
}
71
73
@@ -88,31 +90,39 @@ protected boolean requireFilled(EditText field, String fieldName) {
88
90
89
91
@ Override
90
92
public Dialog onCreateDialog (Bundle savedInstanceState ) {
93
+ setupView (LayoutInflater .from (getActivity ()), null );
91
94
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 );
94
109
95
110
Bundle bundle = getArguments ();
96
111
type = (MessageType ) bundle .getSerializable ("type" );
97
112
final String stream = bundle .getString ("stream" );
98
113
final String topic = bundle .getString ("topic" );
99
114
final String pmRecipients = bundle .getString ("pmRecipients" );
100
115
101
- Log .i ("onCreateDialog" , "" + type + " " + stream + " " + topic + " "
102
- + pmRecipients );
116
+ Log .i ("onCreateDialog" , "" + type + " " + stream + " " + topic + " " + pmRecipients );
103
117
104
- recipient = (AutoCompleteTextView ) view
105
- .findViewById (R .id .composeRecipient );
118
+ recipient = (AutoCompleteTextView ) view .findViewById (R .id .composeRecipient );
106
119
subject = (AutoCompleteTextView ) view .findViewById (R .id .composeTopic );
107
120
body = (EditText ) view .findViewById (R .id .composeText );
121
+ threadSeparator = view .findViewById (R .id .separator );
108
122
109
123
activity = ((ZulipActivity ) getActivity ());
110
124
app = activity .app ;
111
125
112
- AlertDialog dialog = builder .setView (view ).setTitle ("Compose" )
113
- .setPositiveButton (R .string .send , null )
114
- .setNegativeButton (android .R .string .cancel , null ).create ();
115
-
116
126
if (type == MessageType .STREAM_MESSAGE ) {
117
127
this .switchToStream ();
118
128
@@ -145,15 +155,14 @@ public Cursor runQuery(CharSequence charSequence) {
145
155
getActivity (), R .layout .stream_tile , null ,
146
156
new String []{Message .SUBJECT_FIELD },
147
157
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
+ });
157
166
subjectAdapter .setFilterQueryProvider (new FilterQueryProvider () {
158
167
@ Override
159
168
public Cursor runQuery (CharSequence charSequence ) {
@@ -188,23 +197,22 @@ public Cursor runQuery(CharSequence charSequence) {
188
197
new String []{Person .EMAIL_FIELD },
189
198
new int []{R .id .name }, 0 );
190
199
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
+ });
208
216
emailAdapter .setFilterQueryProvider (new FilterQueryProvider () {
209
217
@ Override
210
218
public Cursor runQuery (CharSequence charSequence ) {
@@ -225,10 +233,6 @@ public Cursor runQuery(CharSequence charSequence) {
225
233
}
226
234
}
227
235
228
- dialog .getWindow ().setSoftInputMode (
229
- WindowManager .LayoutParams .SOFT_INPUT_STATE_VISIBLE );
230
-
231
- return dialog ;
232
236
}
233
237
234
238
/**
0 commit comments