Skip to content

Commit 9da8492

Browse files
committed
improve UI
1 parent bfbab60 commit 9da8492

File tree

5 files changed

+134
-65
lines changed

5 files changed

+134
-65
lines changed

app/src/main/java/com/duy/pascal/frontend/autocomplete/autofix/AutoFixHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,15 @@ public static ArrayList<AutoFixCommand> buildCommands(Exception e) {
560560
//add missing const
561561
commands.add(declareConst((UnknownIdentifierException) e));
562562
//add missing function
563-
commands.add(declareFunction((UnknownIdentifierException) e));
563+
//commands.add(declareFunction((UnknownIdentifierException) e));
564564
//add missing procedure
565-
commands.add(declareProcedure((UnknownIdentifierException) e));
565+
//commands.add(declareProcedure((UnknownIdentifierException) e));
566566
} else if (e instanceof VariableIdentifierExpectException) {
567567
commands.add(declareVar((VariableIdentifierExpectException) e));
568568

569569
} else if (e instanceof UnConvertibleTypeException) {
570-
UnConvertibleTypeException exception = (UnConvertibleTypeException) e;
571-
fixUnConvertType(commands, exception);
570+
fixUnConvertType(commands, (UnConvertibleTypeException) e);
571+
572572
} else if (e instanceof MissingTokenException) {
573573
commands.add(insertToken((MissingTokenException) e));
574574

app/src/main/java/com/duy/pascal/frontend/autocomplete/autofix/adapters/CommandAdapter.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818

1919
import android.content.Context;
2020
import android.graphics.Typeface;
21-
import android.support.annotation.LayoutRes;
2221
import android.support.annotation.NonNull;
23-
import android.support.annotation.Nullable;
22+
import android.support.v7.widget.RecyclerView;
2423
import android.view.LayoutInflater;
2524
import android.view.View;
2625
import android.view.ViewGroup;
27-
import android.widget.ArrayAdapter;
2826
import android.widget.TextView;
2927

3028
import com.duy.pascal.frontend.R;
@@ -36,37 +34,63 @@
3634
* Created by Duy on 9/28/2017.
3735
*/
3836

39-
public class CommandAdapter extends ArrayAdapter<AutoFixCommand> {
37+
public class CommandAdapter extends RecyclerView.Adapter<CommandAdapter.ViewHolder> {
4038
@NonNull
41-
private final Context context;
42-
private final int resource;
39+
private Context context;
4340
@NonNull
44-
private final List<AutoFixCommand> commandDescriptors;
41+
private List<AutoFixCommand> commandDescriptors;
4542
private LayoutInflater mInflater;
43+
private OnItemClickListener onItemClickListener;
4644

47-
public CommandAdapter(@NonNull Context context, @LayoutRes int resource,
48-
@NonNull List<AutoFixCommand> objects) {
49-
super(context, resource, objects);
45+
public CommandAdapter(@NonNull Context context, @NonNull List<AutoFixCommand> objects) {
5046
this.context = context;
51-
this.resource = resource;
5247
this.commandDescriptors = objects;
5348
this.mInflater = LayoutInflater.from(context);
5449
}
5550

56-
@NonNull
51+
5752
@Override
58-
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
59-
if (convertView == null) {
60-
convertView = mInflater.inflate(R.layout.list_item_quick_fix, parent, false);
61-
}
62-
TextView txtContent = convertView.findViewById(R.id.txt_content);
53+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
54+
View v = mInflater.inflate(R.layout.list_item_quick_fix, parent, false);
55+
return new ViewHolder(v);
56+
}
57+
58+
@Override
59+
public void onBindViewHolder(ViewHolder holder, final int position) {
60+
TextView txtContent = holder.txtContent;
6361
txtContent.setTypeface(Typeface.MONOSPACE);
64-
txtContent.setText(commandDescriptors.get(position).getTitle(getContext()));
65-
return convertView;
62+
txtContent.setText(commandDescriptors.get(position).getTitle(context));
63+
holder.root.setOnClickListener(new View.OnClickListener() {
64+
@Override
65+
public void onClick(View v) {
66+
if (onItemClickListener != null) {
67+
onItemClickListener.onClick(commandDescriptors.get(position));
68+
}
69+
}
70+
});
6671
}
6772

6873
@Override
69-
public int getCount() {
74+
public int getItemCount() {
7075
return commandDescriptors.size();
7176
}
77+
78+
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
79+
this.onItemClickListener = onItemClickListener;
80+
}
81+
82+
public interface OnItemClickListener {
83+
void onClick(AutoFixCommand command);
84+
}
85+
86+
static class ViewHolder extends RecyclerView.ViewHolder {
87+
TextView txtContent;
88+
View root;
89+
90+
public ViewHolder(View itemView) {
91+
super(itemView);
92+
txtContent = itemView.findViewById(R.id.txt_content);
93+
root = itemView.findViewById(R.id.root);
94+
}
95+
}
7296
}

app/src/main/java/com/duy/pascal/frontend/autocomplete/autofix/dialog/ErrorAndQuickFixDialog.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import android.support.annotation.Nullable;
2121
import android.support.design.widget.BottomSheetDialogFragment;
2222
import android.support.v7.view.ContextThemeWrapper;
23-
import android.support.v7.widget.ListViewCompat;
23+
import android.support.v7.widget.DividerItemDecoration;
24+
import android.support.v7.widget.LinearLayoutManager;
25+
import android.support.v7.widget.RecyclerView;
2426
import android.util.Log;
2527
import android.view.LayoutInflater;
2628
import android.view.View;
2729
import android.view.ViewGroup;
28-
import android.widget.AdapterView;
2930
import android.widget.TextView;
3031

3132
import com.duy.pascal.frontend.R;
@@ -75,17 +76,28 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
7576
TextView txtMsg = view.findViewById(R.id.txt_message);
7677
txtMsg.setText(exceptionManager.getMessage(exception));
7778

79+
view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
80+
@Override
81+
public void onClick(View v) {
82+
dismiss();
83+
}
84+
});
85+
7886
if (exception instanceof ParsingException && ((ParsingException) exception).canQuickFix()) {
79-
ListViewCompat listCommand = view.findViewById(R.id.list_command);
87+
RecyclerView listCommand = view.findViewById(R.id.list_command);
88+
listCommand.setLayoutManager(new LinearLayoutManager(getActivity()));
89+
listCommand.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
8090
final ArrayList<AutoFixCommand> commands = AutoFixHelper.buildCommands(exception);
81-
CommandAdapter commandAdapter = new CommandAdapter(getActivity(), R.layout.list_item_quick_fix, commands);
91+
CommandAdapter commandAdapter = new CommandAdapter(getActivity(), commands);
8292
listCommand.setAdapter(commandAdapter);
83-
listCommand.setOnItemClickListener(new AdapterView.OnItemClickListener() {
93+
commandAdapter.setOnItemClickListener(new CommandAdapter.OnItemClickListener() {
8494
@Override
85-
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
86-
executeCommand(commands.get(position));
95+
public void onClick(AutoFixCommand command) {
96+
executeCommand(command);
8797
}
8898
});
99+
100+
view.findViewById(R.id.txt_hint).setVisibility(View.VISIBLE);
89101
}
90102
}
91103

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

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,85 @@
1515
-->
1616

1717
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
1819
android:layout_width="match_parent"
1920
android:layout_height="wrap_content"
2021
android:background="?android:windowBackground"
21-
android:orientation="vertical"
22-
android:padding="16dp">
22+
android:orientation="vertical">
2323

24-
<LinearLayout
24+
<android.support.v7.widget.CardView
2525
android:layout_width="match_parent"
2626
android:layout_height="wrap_content"
27-
android:orientation="horizontal">
27+
app:cardUseCompatPadding="true">
2828

29-
<TextView
30-
android:id="@+id/txt_name"
31-
android:layout_width="0dp"
32-
android:layout_height="match_parent"
33-
android:layout_marginBottom="8dp"
34-
android:layout_weight="1"
35-
android:paddingTop="8dp"
36-
android:text="@string/compile_error"
37-
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
38-
39-
<android.support.v7.widget.AppCompatImageButton
40-
android:id="@+id/btn_cancel"
41-
android:layout_width="wrap_content"
29+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
30+
android:layout_width="match_parent"
4231
android:layout_height="wrap_content"
43-
android:src="@drawable/ic_action_navigation_close_inverted"
44-
android:text="@string/close" />
32+
android:orientation="vertical"
33+
android:padding="8dp">
4534

46-
</LinearLayout>
35+
<LinearLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:orientation="horizontal">
4739

48-
<TextView
49-
android:id="@+id/txt_message"
50-
android:layout_width="match_parent"
51-
android:layout_height="wrap_content"
52-
android:layout_marginBottom="8dp"
53-
android:text="@string/editor_create_unknown_exception" />
40+
<android.support.v7.widget.AppCompatTextView
41+
android:id="@+id/txt_name"
42+
android:layout_width="0dp"
43+
android:layout_height="match_parent"
44+
android:layout_marginBottom="8dp"
45+
android:layout_weight="1"
46+
android:paddingTop="8dp"
47+
android:text="@string/compile_error"
48+
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
49+
50+
<android.support.v7.widget.AppCompatImageView
51+
android:id="@+id/btn_cancel"
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
android:foreground="?selectableItemBackground"
55+
android:padding="4dp"
56+
android:src="@drawable/ic_action_navigation_close_inverted"
57+
android:text="@string/close" />
58+
59+
</LinearLayout>
5460

55-
<TextView
61+
<android.support.v7.widget.AppCompatTextView
62+
android:id="@+id/txt_message"
63+
android:layout_width="match_parent"
64+
android:layout_height="wrap_content"
65+
android:layout_marginBottom="8dp"
66+
android:text="@string/editor_create_unknown_exception" />
67+
68+
</LinearLayout>
69+
</android.support.v7.widget.CardView>
70+
71+
<android.support.v7.widget.CardView
5672
android:layout_width="match_parent"
5773
android:layout_height="wrap_content"
58-
android:text="@string/some_suggestion"
59-
android:textColor="?colorAccent" />
74+
app:cardUseCompatPadding="true">
6075

61-
<android.support.v7.widget.ListViewCompat
62-
android:id="@+id/list_command"
63-
android:layout_width="match_parent"
64-
android:layout_height="wrap_content">
76+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
77+
android:layout_width="match_parent"
78+
android:layout_height="wrap_content"
79+
android:orientation="vertical"
80+
android:padding="8dp">
81+
82+
<android.support.v7.widget.AppCompatTextView
83+
android:id="@+id/txt_hint"
84+
android:layout_width="match_parent"
85+
android:layout_height="wrap_content"
86+
android:text="@string/some_suggestion"
87+
android:textColor="?colorAccent"
88+
android:visibility="gone" />
6589

66-
</android.support.v7.widget.ListViewCompat>
90+
<android.support.v7.widget.RecyclerView
91+
android:id="@+id/list_command"
92+
android:layout_width="match_parent"
93+
android:layout_height="wrap_content">
6794

95+
</android.support.v7.widget.RecyclerView>
6896

97+
</LinearLayout>
98+
</android.support.v7.widget.CardView>
6999
</LinearLayout>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
-->
1616

1717
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:id="@+id/root"
1819
android:layout_width="match_parent"
1920
android:layout_height="wrap_content"
21+
android:clickable="true"
22+
android:foreground="?selectableItemBackground"
2023
android:orientation="vertical">
2124

2225
<TextView

0 commit comments

Comments
 (0)