Skip to content

Commit 95fa902

Browse files
committed
Change theme when user select theme
1 parent 593110b commit 95fa902

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.view.Menu;
3434
import android.view.MenuItem;
3535
import android.view.View;
36+
import android.widget.Toast;
3637

3738
import com.duy.file.explorer.io.JecFile;
3839
import com.duy.file.explorer.io.LocalFile;
@@ -41,7 +42,6 @@
4142
import com.duy.ide.editor.editor.R;
4243
import com.duy.ide.editor.editor.databinding.ActivityFileExplorerBinding;
4344
import com.jecelyin.common.utils.IOUtils;
44-
import com.jecelyin.common.utils.UIUtils;
4545
import com.jecelyin.editor.v2.Preferences;
4646
import com.jecelyin.editor.v2.ThemeSupportActivity;
4747

@@ -139,7 +139,7 @@ protected void onCreate(Bundle savedInstanceState) {
139139

140140
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
141141
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
142-
setTitle(mMode == MODE_PICK_FILE ? R.string.open_file : R.string.save_file);
142+
setTitle(mMode == MODE_PICK_FILE ? R.string.select_file : R.string.select_path);
143143

144144
mLastPath = Preferences.getInstance(this).getLastOpenPath();
145145
if (TextUtils.isEmpty(mLastPath)) {
@@ -161,7 +161,7 @@ protected void onCreate(Bundle savedInstanceState) {
161161
}
162162

163163
initFileView();
164-
binding.saveBtn.setOnClickListener(this);
164+
binding.btnSelect.setOnClickListener(this);
165165
binding.fileEncodingTextView.setOnClickListener(this);
166166

167167
String encoding = intent.getStringExtra("encoding");
@@ -291,7 +291,7 @@ boolean onSelectFile(JecFile file) {
291291
@Override
292292
public void onClick(View v) {
293293
int id = v.getId();
294-
if (id == R.id.save_btn) {
294+
if (id == R.id.btn_select) {
295295
onSave();
296296
} else if (id == R.id.file_encoding_textView) {
297297
onShowEncodingList();
@@ -350,20 +350,18 @@ private void onSave() {
350350
f = f.getParentFile();
351351
}
352352

353-
final File newFile = new File(f, fileName);
354-
if (newFile.exists()) {
355-
UIUtils.showConfirmDialog(this, getString(R.string.override_file_prompt, fileName), new UIUtils.OnClickCallback() {
356-
@Override
357-
public void onOkClick() {
358-
saveAndFinish(newFile);
359-
}
360-
});
361-
} else {
362-
saveAndFinish(newFile);
353+
try {
354+
File newFile = new File(fileName);
355+
if (!newFile.exists()) {
356+
newFile = new File(f, fileName);
357+
}
358+
setResult(newFile);
359+
} catch (Exception e) {
360+
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
363361
}
364362
}
365363

366-
private void saveAndFinish(File file) {
364+
private void setResult(File file) {
367365
Intent it = new Intent();
368366
it.putExtra("file", file.getPath());
369367
it.putExtra("encoding", fileEncoding);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ public void doCommand(Command command) {
433433
case CLEAR_WARNING:
434434
clearWarningSpan();
435435
break;
436+
case REFRESH_THEME:
437+
if (mEditText != null) {
438+
mEditText.setTheme(Preferences.getInstance(mContext).getEditorTheme());
439+
}
440+
break;
436441
}
437442
}
438443

lib-n-ide/src/main/java/com/jecelyin/editor/v2/common/Command.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public enum CommandEnum {
6060
HIGHLIGHT_ERROR,
6161
SHARE_CODE,
6262
FORMAT_SOURCE,
63-
6463
CLEAR_ERROR,
65-
CLEAR_WARNING
64+
CLEAR_WARNING,
65+
REFRESH_THEME
6666
}
6767
}

lib-n-ide/src/main/res-file-expoler/layout/activity_file_explorer.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
tools:text="Sdcard/JavaNIDE" />
5656

5757
<android.support.v7.widget.AppCompatButton
58-
android:id="@+id/save_btn"
58+
android:id="@+id/btn_select"
5959
style="@style/Base.Widget.AppCompat.Button.Colored"
6060
android:layout_width="wrap_content"
6161
android:layout_height="match_parent"
6262
android:gravity="center"
6363
android:minWidth="50dp"
64-
android:text="@string/file_save"
64+
android:text="@string/select"
6565
android:textSize="12sp" />
6666
</LinearLayout>
6767

lib-n-ide/src/main/res/layout/activity_default_ide.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
124124
android:layout_width="match_parent"
125125
android:layout_height="wrap_content"
126+
android:layout_marginTop="-6dp"
126127
android:indeterminate="true"
127128
android:visibility="gone" />
128129

lib-n-ide/src/main/res/layout/fragment_editor_default.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
android:layout_height="match_parent"
66
android:orientation="horizontal">
77

8+
89
<com.duy.ide.editor.view.GutterView
910
android:id="@+id/gutter_view"
1011
android:layout_width="0dp"

lib-n-ide/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@
233233
<string name="formatting">Formatting</string>
234234
<string name="auto_pair">Auto pair</string>
235235
<string name="pref_desc_auto_pair">Auto add close bracket, e.g. when you type { editor will be auto add }</string>
236+
<string name="select_file">Select file</string>
237+
<string name="select_path">Select path</string>
236238

237239
</resources>

0 commit comments

Comments
 (0)