Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit bd8a7ab

Browse files
committed
Clean up look of compose dialog
1 parent f32b3e8 commit bd8a7ab

File tree

2 files changed

+74
-59
lines changed

2 files changed

+74
-59
lines changed

app/src/main/java/com/zulip/android/ComposeDialog.java

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.DialogInterface;
88
import android.database.Cursor;
99
import android.os.Bundle;
10+
import android.support.annotation.Nullable;
1011
import android.support.v4.app.DialogFragment;
1112
import android.support.v4.widget.SimpleCursorAdapter;
1213
import android.text.TextUtils;
@@ -15,6 +16,8 @@
1516
import android.view.LayoutInflater;
1617
import android.view.View;
1718
import android.view.View.OnClickListener;
19+
import android.view.ViewGroup;
20+
import android.view.Window;
1821
import android.view.WindowManager;
1922
import android.widget.AutoCompleteTextView;
2023
import 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
/**

app/src/main/res/layout/compose.xml

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,62 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="fill_parent"
4-
android:layout_height="fill_parent"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
55
android:background="#ffffff"
6-
android:orientation="vertical" >
7-
8-
<LinearLayout
9-
android:layout_width="match_parent"
10-
android:layout_height="wrap_content" >
6+
android:orientation="vertical"
7+
android:padding="16dp"
8+
>
119

1210
<AutoCompleteTextView
1311
android:id="@+id/composeRecipient"
14-
android:layout_width="0dp"
12+
android:layout_width="match_parent"
1513
android:layout_height="wrap_content"
16-
android:layout_weight="0.30"
1714
android:ems="10"
1815
android:hint="@string/stream"
1916
android:inputType="textNoSuggestions"
2017
android:maxLines="1"
21-
android:dropDownWidth="fill_parent"
18+
android:dropDownWidth="match_parent"
2219
android:completionThreshold="1">
2320

2421
<requestFocus />
2522
</AutoCompleteTextView>
2623

24+
<LinearLayout
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:orientation="horizontal"
28+
android:layout_marginStart="8dp"
29+
android:layout_marginLeft="8dp"
30+
>
31+
32+
<TextView
33+
android:id="@+id/separator"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:text="@string/arrow"
37+
/>
2738
<AutoCompleteTextView
2839
android:id="@+id/composeTopic"
29-
android:layout_width="0dp"
40+
android:layout_width="match_parent"
3041
android:layout_height="wrap_content"
31-
android:layout_weight="0.70"
3242
android:ems="10"
3343
android:hint="@string/topic"
3444
android:inputType="textNoSuggestions"
3545
android:maxLines="1"
3646
android:completionThreshold="1"
3747
android:dropDownWidth="fill_parent"/>
48+
3849
</LinearLayout>
3950

4051
<EditText
4152
android:id="@+id/composeText"
4253
android:layout_width="fill_parent"
4354
android:layout_height="wrap_content"
44-
android:layout_gravity="center"
4555
android:hint="@string/compose_hint"
4656
android:inputType="textCapSentences|textAutoCorrect|textMultiLine"
47-
android:lines="3"
48-
android:textColor="#000000" />
57+
android:layout_gravity="bottom"
58+
android:layout_marginTop="8dp"
59+
/>
4960

5061
<LinearLayout
5162
android:id="@+id/composeStatus"

0 commit comments

Comments
 (0)