Skip to content

Commit 8419486

Browse files
committed
refactor code
1 parent 120fa77 commit 8419486

File tree

15 files changed

+229
-104
lines changed

15 files changed

+229
-104
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/duy/ccppcompiler/ide/editor/CodeEditorActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {
8787
}
8888

8989
@Override
90-
protected void populaceDiagnostic(@NonNull DiagnosticPresenter diagnosticPresenter) {
90+
protected void populateDiagnostic(@NonNull DiagnosticPresenter diagnosticPresenter) {
9191
PatternAwareOutputParser[] parsers = {
9292
new CppCheckOutputParser(),
9393
new GccOutputParser()

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
}
1111
}
1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:3.1.2'
13+
classpath 'com.android.tools.build:gradle:3.1.3'
1414
classpath 'com.google.gms:google-services:3.2.0'
1515
classpath 'io.fabric.tools:gradle:1.25.1'
1616
// NOTE: Do not place your application dependencies here; they belong

lib-n-ide/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ android {
88
minSdkVersion rootProject.ext.minSdkVersion
99
targetSdkVersion rootProject.ext.targetSdkVersion
1010
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
11+
vectorDrawables.useSupportLibrary = true
1112
}
1213

1314
testOptions {

lib-n-ide/src/main/java/com/duy/file/explorer/util/FileUtils.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,31 @@ public static boolean createNewFile(File file) throws IOException {
172172
}
173173
return false;
174174
}
175+
176+
public static boolean isSameFile(File file1, File file2) {
177+
final boolean file1Exists = file1.exists();
178+
if (file1Exists != file2.exists()) {
179+
return false;
180+
}
181+
182+
if (!file1Exists) {
183+
// two not existing files are equal
184+
return true;
185+
}
186+
187+
if (file1.length() != file2.length()) {
188+
// lengths differ, cannot be equal
189+
return false;
190+
}
191+
192+
try {
193+
if (file1.getCanonicalFile().equals(file2.getCanonicalFile())) {
194+
// same file
195+
return true;
196+
}
197+
} catch (IOException e) {
198+
e.printStackTrace();
199+
}
200+
return false;
201+
}
175202
}

lib-n-ide/src/main/java/com/duy/ide/core/IdeActivity.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import com.duy.common.StoreUtil;
5252
import com.duy.file.explorer.FileExplorerActivity;
53+
import com.duy.ide.database.SQLHelper;
5354
import com.duy.ide.diagnostic.DiagnosticPresenter;
5455
import com.duy.ide.diagnostic.view.DiagnosticFragment;
5556
import com.duy.ide.editor.editor.BuildConfig;
@@ -75,7 +76,6 @@
7576
import com.jecelyin.editor.v2.manager.MenuManager;
7677
import com.jecelyin.editor.v2.manager.RecentFilesManager;
7778
import com.jecelyin.editor.v2.manager.TabManager;
78-
import com.duy.ide.database.SQLHelper;
7979
import com.jecelyin.editor.v2.widget.SymbolBarLayout;
8080
import com.jecelyin.editor.v2.widget.menu.MenuDef;
8181
import com.jecelyin.editor.v2.widget.menu.MenuFactory;
@@ -128,6 +128,7 @@ protected void onCreate(Bundle savedInstanceState) {
128128

129129
mEditorPager = findViewById(R.id.editor_view_pager);
130130
mDrawerLayout = findViewById(R.id.drawer_layout);
131+
mDrawerLayout.setKeepScreenOn(mPreferences.isKeepScreenOn());
131132
mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
132133
@Override
133134
public void onDrawerOpened(View drawerView) {
@@ -136,8 +137,7 @@ public void onDrawerOpened(View drawerView) {
136137
}
137138
});
138139
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
139-
this, mDrawerLayout, mToolbar, R.string.open_drawer, R.string.close_drawer
140-
);
140+
this, mDrawerLayout, mToolbar, R.string.open_drawer, R.string.close_drawer);
141141
mDrawerLayout.addDrawerListener(actionBarDrawerToggle);
142142
actionBarDrawerToggle.syncState();
143143

@@ -153,20 +153,24 @@ public void onClick(View v, String text) {
153153
}
154154
});
155155

156-
bindPreferences();
157156
setScreenOrientation();
158157

159158
TextView versionView = findViewById(R.id.versionTextView);
160159
versionView.setText(SysUtils.getVersionName(this));
161-
mEditorPager.setVisibility(View.VISIBLE);
160+
162161
mTabManager = new TabManager(this);
163162

164163
initMenuView();
165164
intiDiagnosticView();
166165
processIntent();
166+
167+
mPreferences.registerOnSharedPreferenceChangeListener(this);
167168
}
168169

169170
private void intiDiagnosticView() {
171+
if (mTabManager == null) {
172+
throw new RuntimeException("Create TabManager before call intiDiagnosticView");
173+
}
170174

171175
final View toggleView = findViewById(R.id.btn_toggle_panel);
172176
mSlidingUpPanelLayout = findViewById(R.id.diagnostic_panel);
@@ -188,16 +192,15 @@ public void onPanelSlide(View panel, float slideOffset) {
188192
.replace(R.id.container_diagnostic_list_view, diagnosticFragment, tag)
189193
.commit();
190194
mDiagnosticPresenter = new DiagnosticPresenter(diagnosticFragment, this, mTabManager, mHandler);
191-
populaceDiagnostic(mDiagnosticPresenter);
195+
populateDiagnostic(mDiagnosticPresenter);
192196
}
193197

194-
protected abstract void populaceDiagnostic(@NonNull DiagnosticPresenter diagnosticPresenter);
195-
198+
/**
199+
* Called when create diagnostic view
200+
*/
201+
protected abstract void populateDiagnostic(@NonNull DiagnosticPresenter diagnosticPresenter);
196202

197203
private void bindPreferences() {
198-
mDrawerLayout.setKeepScreenOn(mPreferences.isKeepScreenOn());
199-
mSymbolBarLayout.setVisibility(mPreferences.isReadOnly() ? View.GONE : View.VISIBLE);
200-
mPreferences.registerOnSharedPreferenceChangeListener(this);
201204
}
202205

203206
@Override
@@ -218,7 +221,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
218221

219222
private void setScreenOrientation() {
220223
int orgi = mPreferences.getScreenOrientation();
221-
222224
if (Preferences.SCREEN_ORIENTATION_AUTO == orgi) {
223225
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
224226
} else if (Preferences.SCREEN_ORIENTATION_LANDSCAPE == orgi) {
@@ -229,18 +231,16 @@ private void setScreenOrientation() {
229231
}
230232

231233
private void initMenuView() {
232-
if (mMenuManager == null) {
233-
mMenuManager = new MenuManager(this);
234-
NavigationView rightMenu = findViewById(R.id.menuNavView);
235-
Menu menu = rightMenu.getMenu();
236-
onCreateNavigationMenu(menu);
237-
rightMenu.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
238-
@Override
239-
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
240-
return onOptionsItemSelected(item);
241-
}
242-
});
243-
}
234+
mMenuManager = new MenuManager(this);
235+
NavigationView rightMenu = findViewById(R.id.menuNavView);
236+
Menu menu = rightMenu.getMenu();
237+
onCreateNavigationMenu(menu);
238+
rightMenu.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
239+
@Override
240+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
241+
return onOptionsItemSelected(item);
242+
}
243+
});
244244
}
245245

246246

lib-n-ide/src/main/java/com/duy/ide/editor/view/CodeEditor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.duy.ide.editor.view;
1919

2020
import android.content.Context;
21+
import android.graphics.Rect;
2122
import android.util.AttributeSet;
2223
import android.view.ActionMode;
2324

@@ -38,4 +39,9 @@ public CodeEditor(Context context, AttributeSet attrs, int defStyleAttr) {
3839
public void setCustomSelectionActionModeCallback(ActionMode.Callback actionModeCallback) {
3940
super.setCustomSelectionActionModeCallback(actionModeCallback);
4041
}
42+
43+
@Override
44+
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
45+
return super.requestFocus(direction, previouslyFocusedRect);
46+
}
4147
}

lib-n-ide/src/main/java/com/duy/ide/editor/view/EditActionSupportEditor.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.duy.ide.editor.content.UndoManager;
3131
import com.duy.ide.editor.model.EditorIndex;
3232

33-
public class EditActionSupportEditor extends ZoomSupportEditor {
33+
public class EditActionSupportEditor extends GestureSupportEditor {
3434
private IUndoManager mUndoManager;
3535
private ClipboardCompat mClipboard;
3636
private KeyListener mLastKeyListener;
@@ -81,17 +81,13 @@ public boolean doCopy() {
8181

8282
@Override
8383
public boolean doPaste() {
84-
if (!onTextContextMenuItem(android.R.id.paste)) {
85-
CharSequence clipboard = mClipboard.getClipboard();
86-
if (clipboard != null) {
87-
//clear all span
88-
89-
int selectionStart = getSelectionStart();
90-
selectionStart = Math.max(0, selectionStart);
91-
getText().insert(selectionStart, cleanupForPaste(clipboard));
92-
return true;
93-
}
94-
} else {
84+
CharSequence clipboard = mClipboard.getClipboard();
85+
if (clipboard != null) {
86+
//clear all span
87+
88+
int selectionStart = getSelectionStart();
89+
selectionStart = Math.max(0, selectionStart);
90+
getText().insert(selectionStart, cleanupForPaste(clipboard));
9591
return true;
9692
}
9793
return false;
@@ -111,8 +107,7 @@ private String cleanupForPaste(CharSequence clipboard) {
111107
public boolean onTextContextMenuItem(int id) {
112108
switch (id) {
113109
case android.R.id.paste:
114-
doPaste();
115-
return true;
110+
return doPaste();
116111
}
117112
return super.onTextContextMenuItem(id);
118113
}

lib-n-ide/src/main/java/com/duy/ide/editor/view/ZoomSupportEditor.java renamed to lib-n-ide/src/main/java/com/duy/ide/editor/view/GestureSupportEditor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.duy.ide.editor.model.EditorIndex;
3333
import com.jecelyin.editor.v2.Preferences;
3434

35-
public abstract class ZoomSupportEditor extends HighlightEditorView
35+
public abstract class GestureSupportEditor extends HighlightEditorView
3636
implements IEditAreaView, GestureDetector.OnGestureListener {
3737

3838
private final Rect mVisibleRect = new Rect();
@@ -48,16 +48,16 @@ public abstract class ZoomSupportEditor extends HighlightEditorView
4848
*/
4949
private boolean mIsTextScaling = false;
5050

51-
public ZoomSupportEditor(Context context) {
51+
public GestureSupportEditor(Context context) {
5252
this(context, null);
5353
}
5454

55-
public ZoomSupportEditor(Context context, AttributeSet attrs) {
55+
public GestureSupportEditor(Context context, AttributeSet attrs) {
5656
super(context, attrs);
5757
init(context);
5858
}
5959

60-
public ZoomSupportEditor(Context context, AttributeSet attrs, int defStyleAttr) {
60+
public GestureSupportEditor(Context context, AttributeSet attrs, int defStyleAttr) {
6161
super(context, attrs, defStyleAttr);
6262
init(context);
6363
}
@@ -151,7 +151,6 @@ public void computeScroll() {
151151
super.computeScroll();
152152
}
153153
}
154-
155154
/**
156155
* @see GestureDetector.OnGestureListener#onFling(MotionEvent,
157156
* MotionEvent, float, float)

lib-n-ide/src/main/java/com/duy/ide/editor/view/HighlightEditorView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public HighlightEditorView(Context context) {
8383
public HighlightEditorView(Context context, AttributeSet attrs) {
8484
super(context, attrs);
8585
init(context);
86-
8786
}
8887

8988
public HighlightEditorView(Context context, AttributeSet attrs, int defStyleAttr) {

0 commit comments

Comments
 (0)