Skip to content

Commit 51f62b0

Browse files
committed
implement diagnostic view
1 parent 8791a15 commit 51f62b0

File tree

12 files changed

+359
-11
lines changed

12 files changed

+359
-11
lines changed

app/src/main/java/com/duy/ccppcompiler/compiler/diagnostic/Diagnostic.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.duy.ccppcompiler.compiler.diagnostic;
1818

19+
import android.content.Context;
20+
1921
/**
2022
* Created by Duy on 28-Apr-18.
2123
*/
@@ -97,6 +99,6 @@ public interface Diagnostic<S> {
9799
*/
98100
String getCode();
99101

100-
102+
String getMessage(Context context);
101103

102104
}

app/src/main/java/com/duy/ccppcompiler/compiler/diagnostic/SimpleDiagnostic.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
package com.duy.ccppcompiler.compiler.diagnostic;
1818

19+
import android.content.Context;
20+
1921
import java.io.File;
2022

2123
/**
2224
* Created by Duy on 28-Apr-18.
2325
*/
2426

25-
public class SimpleDiagnostic implements Diagnostic {
27+
public class SimpleDiagnostic implements Diagnostic<File> {
2628
private final Kind kind;
2729
private final String filePath;
2830
private final int line;
@@ -43,7 +45,7 @@ public Kind getKind() {
4345
}
4446

4547
@Override
46-
public Object getSource() {
48+
public File getSource() {
4749
return new File(filePath);
4850
}
4951

@@ -87,4 +89,34 @@ public long getColumnNumber() {
8789
public String getCode() {
8890
throw new UnsupportedOperationException();
8991
}
92+
93+
@Override
94+
public String getMessage(Context context) {
95+
return message;
96+
}
97+
98+
@Override
99+
public boolean equals(Object o) {
100+
if (this == o) return true;
101+
if (!(o instanceof SimpleDiagnostic)) return false;
102+
103+
SimpleDiagnostic that = (SimpleDiagnostic) o;
104+
105+
if (line != that.line) return false;
106+
if (col != that.col) return false;
107+
if (getKind() != that.getKind()) return false;
108+
if (filePath != null ? !filePath.equals(that.filePath) : that.filePath != null)
109+
return false;
110+
return message != null ? message.equals(that.message) : that.message == null;
111+
}
112+
113+
@Override
114+
public int hashCode() {
115+
int result = getKind() != null ? getKind().hashCode() : 0;
116+
result = 31 * result + (filePath != null ? filePath.hashCode() : 0);
117+
result = 31 * result + line;
118+
result = 31 * result + col;
119+
result = 31 * result + (message != null ? message.hashCode() : 0);
120+
return result;
121+
}
90122
}

app/src/main/java/com/jecelyin/editor/v2/ui/activities/EditorActivity.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.jecelyin.editor.v2.ui.widget.menu.MenuFactory;
7676
import com.jecelyin.editor.v2.ui.widget.menu.MenuItemInfo;
7777
import com.jecelyin.editor.v2.utils.DBHelper;
78+
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
7879

7980
import org.gjt.sp.jedit.Catalog;
8081

@@ -111,6 +112,7 @@ public class EditorActivity extends FullScreenActivity
111112
private MenuManager mMenuManager;
112113
private FolderChooserDialog.FolderCallback findFolderCallback;
113114
private long mExitTime;
115+
private SlidingUpPanelLayout mSlidingUpPanelLayout;
114116

115117
@Override
116118
protected void onRestoreInstanceState(Bundle savedInstanceState) {
@@ -231,23 +233,27 @@ private void initUI() {
231233
if (mMenuManager == null) {
232234
mMenuManager = new MenuManager(this);
233235
}
236+
final View toggleView = findViewById(R.id.btn_toggle_panel);
237+
mSlidingUpPanelLayout = findViewById(R.id.diagnostic_panel);
238+
mSlidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.SimplePanelSlideListener() {
239+
@Override
240+
public void onPanelSlide(View panel, float slideOffset) {
241+
toggleView.animate().rotation(180 * slideOffset).start();
242+
}
243+
});
234244
}
235245

236246
private void initToolbar() {
237-
238-
239247
Resources res = getResources();
240-
241248
mToolbar.setNavigationIcon(R.drawable.ic_drawer_raw);
242249
mToolbar.setNavigationContentDescription(R.string.tab);
243250

244251
Menu menu = mToolbar.getMenu();
245-
List<MenuItemInfo> menuItemInfos = MenuFactory.getInstance(this).getToolbarIcon();
246-
for (MenuItemInfo item : menuItemInfos) {
252+
List<MenuItemInfo> items = MenuFactory.getInstance(this).getToolbarIcon();
253+
for (MenuItemInfo item : items) {
247254
MenuItem menuItem = menu.add(MenuDef.GROUP_TOOLBAR, item.getItemId(), Menu.NONE, item.getTitleResId());
248255
menuItem.setIcon(MenuManager.makeToolbarNormalIcon(res, item.getIconResId()));
249256

250-
//menuItem.setShortcut()
251257
menuItem.setOnMenuItemClickListener(this);
252258
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
253259
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2018 Mr Duy
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.jecelyin.editor.v2.ui.diagnostic;
18+
19+
import com.duy.ccppcompiler.compiler.diagnostic.Diagnostic;
20+
21+
import java.util.List;
22+
23+
/**
24+
* Created by Duy on 28-Apr-18.
25+
*/
26+
27+
public class DiagnosticContract {
28+
public interface View {
29+
void show(List<Diagnostic> diagnostics);
30+
31+
void remove(Diagnostic diagnostic);
32+
33+
void add(Diagnostic diagnostic);
34+
35+
void clear();
36+
}
37+
38+
public interface Presenter {
39+
void onDiagnosticClick(View view, Diagnostic diagnostic);
40+
}
41+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.jecelyin.editor.v2.ui.diagnostic;
2+
3+
import android.content.Context;
4+
import android.support.annotation.NonNull;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.TextView;
10+
11+
import com.duy.ccppcompiler.R;
12+
import com.duy.ccppcompiler.compiler.diagnostic.Diagnostic;
13+
14+
import java.io.File;
15+
import java.util.List;
16+
17+
/**
18+
* Created by Duy on 28-Apr-18.
19+
*/
20+
21+
public class FileDiagnosticAdapter extends RecyclerView.Adapter<FileDiagnosticAdapter.ViewHolder> {
22+
private List<Diagnostic<File>> diagnostics;
23+
private Context context;
24+
25+
public FileDiagnosticAdapter(List<Diagnostic<File>> diagnostics, Context context) {
26+
this.diagnostics = diagnostics;
27+
this.context = context;
28+
}
29+
30+
@NonNull
31+
@Override
32+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
33+
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_diagnostic, parent, false);
34+
return new ViewHolder(view);
35+
}
36+
37+
@Override
38+
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
39+
Diagnostic<File> diagnostic = diagnostics.get(position);
40+
if (diagnostic.getLineNumber() != Diagnostic.NOPOS) {
41+
holder.txtLine.setText(String.valueOf(diagnostic.getLineNumber()));
42+
if (diagnostic.getColumnNumber() != Diagnostic.NOPOS) {
43+
holder.txtCol.setText(String.valueOf(diagnostic.getColumnNumber()));
44+
} else {
45+
holder.txtCol.getEditableText().clear();
46+
}
47+
} else {
48+
holder.txtLine.getEditableText().clear();
49+
holder.txtCol.getEditableText().clear();
50+
}
51+
52+
holder.txtFile.setText(diagnostic.getSource().getName());
53+
holder.txtMessage.setText(diagnostic.getMessage(context));
54+
}
55+
56+
@Override
57+
public int getItemCount() {
58+
return diagnostics.size();
59+
}
60+
61+
static class ViewHolder extends RecyclerView.ViewHolder {
62+
TextView txtLine, txtCol, txtMessage, txtFile;
63+
View root;
64+
65+
ViewHolder(View itemView) {
66+
super(itemView);
67+
txtLine = itemView.findViewById(R.id.txt_line);
68+
txtCol = itemView.findViewById(R.id.txt_col);
69+
txtMessage = itemView.findViewById(R.id.txt_message);
70+
txtFile = itemView.findViewById(R.id.txt_file);
71+
root = itemView;
72+
}
73+
}
74+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2018 Mr Duy
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.jecelyin.editor.v2.ui.diagnostic;
18+
19+
import android.support.v7.widget.RecyclerView;
20+
21+
import com.duy.ccppcompiler.compiler.diagnostic.Diagnostic;
22+
import com.jecelyin.editor.v2.ui.activities.EditorActivity;
23+
import com.jecelyin.editor.v2.ui.manager.TabManager;
24+
25+
/**
26+
* Created by Duy on 28-Apr-18.
27+
*/
28+
29+
public class FileDiagnosticPresenter implements DiagnosticContract.Presenter {
30+
private final RecyclerView recyclerView;
31+
private final EditorActivity activity;
32+
private final TabManager tabManager;
33+
34+
public FileDiagnosticPresenter(RecyclerView recyclerView, EditorActivity activity, TabManager tabManager) {
35+
this.recyclerView = recyclerView;
36+
this.activity = activity;
37+
this.tabManager = tabManager;
38+
}
39+
40+
@Override
41+
public void onDiagnosticClick(DiagnosticContract.View view, Diagnostic diagnostic) {
42+
43+
}
44+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2018 Mr Duy
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.jecelyin.editor.v2.ui.diagnostic;
18+
19+
import android.support.v7.widget.RecyclerView;
20+
21+
import com.duy.ccppcompiler.compiler.diagnostic.Diagnostic;
22+
23+
import java.util.List;
24+
25+
/**
26+
* Created by Duy on 28-Apr-18.
27+
*/
28+
29+
public class FileDiagnosticView implements DiagnosticContract.View {
30+
private RecyclerView recyclerView;
31+
32+
public FileDiagnosticView(RecyclerView recyclerView) {
33+
this.recyclerView = recyclerView;
34+
}
35+
36+
@Override
37+
public void show(List<Diagnostic> diagnostics) {
38+
39+
}
40+
41+
@Override
42+
public void remove(Diagnostic diagnostic) {
43+
44+
}
45+
46+
@Override
47+
public void add(Diagnostic diagnostic) {
48+
49+
}
50+
51+
@Override
52+
public void clear() {
53+
54+
}
55+
56+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2018 Mr Duy
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.jecelyin.editor.v2.ui.manager;
18+
19+
import android.support.v7.widget.RecyclerView;
20+
21+
/**
22+
* Created by Duy on 28-Apr-18.
23+
*/
24+
25+
public class DiagnosticManager {
26+
private RecyclerView recyclerView;
27+
28+
public DiagnosticManager(RecyclerView recyclerView) {
29+
this.recyclerView = recyclerView;
30+
}
31+
}

app/src/main/java/com/jecelyin/editor/v2/ui/widget/menu/MenuFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public List<MenuItemInfo> getToolbarIcon() {
9898
}
9999

100100
private void initAllMenuItem() {
101+
menuItemInfos.add(new MenuItemInfo(MenuGroup.OTHER, R.id.action_run, Command.CommandEnum.NONE, R.drawable.ic_play_arrow_white_24dp, R.string.run));
101102
menuItemInfos.add(new MenuItemInfo(MenuGroup.FILE, R.id.m_new, Command.CommandEnum.NONE, R.drawable.ic_add_white_24dp, R.string.new_file));
102103
menuItemInfos.add(new MenuItemInfo(MenuGroup.FILE, R.id.m_open, Command.CommandEnum.OPEN, R.drawable.ic_folder_open_white_24dp, R.string.open));
103104
menuItemInfos.add(new MenuItemInfo(MenuGroup.FILE, R.id.m_save, Command.CommandEnum.SAVE, R.drawable.ic_save_white_24dp, R.string.save));
@@ -124,7 +125,6 @@ private void initAllMenuItem() {
124125
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.m_highlight, Command.CommandEnum.NONE, R.drawable.ic_highlight_white_24dp, R.string.highlight_language));
125126
menuItemInfos.add(new MenuItemInfo(MenuGroup.VIEW, R.id.m_encoding, Command.CommandEnum.NONE, R.drawable.m_encoding, R.string.encoding));
126127

127-
menuItemInfos.add(new MenuItemInfo(MenuGroup.OTHER, R.id.action_run, Command.CommandEnum.NONE, R.drawable.ic_play_arrow_white_24dp, R.string.run));
128128
menuItemInfos.add(new MenuItemInfo(MenuGroup.OTHER, R.id.m_settings, Command.CommandEnum.NONE, R.drawable.ic_settings_white_24dp, R.string.settings));
129129
}
130130

0 commit comments

Comments
 (0)