From c0bc2ff3430fc33565bf0eb01db09dbf424041cb Mon Sep 17 00:00:00 2001 From: DevKumar00001 Date: Tue, 24 Oct 2023 17:39:51 +0530 Subject: [PATCH] feat: Added some events and some code improvement --- .../code/editor/common/utils/FileUtils.java | 15 ++++++++ app/src/main/java/builtin/files/CssFile.java | 35 ++++++++++++++++++- app/src/main/java/builtin/files/HtmlFile.java | 14 ++++++++ .../java/builtin/files/JavascriptFile.java | 14 ++++++++ .../java/com/dragon/ide/objects/Event.java | 8 +++-- .../ide/ui/adapters/EventListAdapter.java | 28 ++++++++++++--- .../eventList/ShowSourceCodeDialog.java | 4 ++- .../res/layout/layout_event_list_item.xml | 6 ++-- .../res/layout/layout_souce_code_dialog.xml | 4 +-- 9 files changed, 114 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/android/code/editor/common/utils/FileUtils.java b/app/src/main/java/android/code/editor/common/utils/FileUtils.java index a812f87..093ee32 100644 --- a/app/src/main/java/android/code/editor/common/utils/FileUtils.java +++ b/app/src/main/java/android/code/editor/common/utils/FileUtils.java @@ -17,6 +17,9 @@ package android.code.editor.common.utils; +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.content.res.AssetManager; import java.io.BufferedReader; import java.io.IOException; @@ -44,4 +47,16 @@ public static String readFileFromAssets(AssetManager assetManager, String fileNa return stringBuilder.toString(); } + + public static String getDataDir(Context context) { + PackageManager pm = context.getPackageManager(); + String packageName = context.getPackageName(); + PackageInfo packageInfo; + try { + packageInfo = pm.getPackageInfo(packageName, 0); + return packageInfo.applicationInfo.dataDir; + } catch (PackageManager.NameNotFoundException e) { + return ""; + } + } } diff --git a/app/src/main/java/builtin/files/CssFile.java b/app/src/main/java/builtin/files/CssFile.java index 6c2d7fe..7a76c70 100644 --- a/app/src/main/java/builtin/files/CssFile.java +++ b/app/src/main/java/builtin/files/CssFile.java @@ -1,6 +1,8 @@ package builtin.files; +import com.dragon.ide.objects.Event; import com.dragon.ide.objects.WebFile; +import java.util.ArrayList; public class CssFile extends WebFile { public CssFile() { @@ -19,7 +21,7 @@ public CssFile() { sb.append("@media only screen and (min-width: 768px) and (max-width: 991px) {\n"); sb.append("\t/* CSS code for tablet devices */\n\n"); - sb.append("\t%%%% DragonIDE mobileDeviceCSSEventCode %%%%\n"); + sb.append("\t%%%% DragonIDE tabletDeviceCSSEventCode %%%%\n"); sb.append("}\n\n"); sb.append("@media only screen and (min-width: 992px) and (max-width: 1199px) {\n"); @@ -33,5 +35,36 @@ public CssFile() { sb.append("}"); setRawCode(new String(sb.toString())); + + ArrayList events = new ArrayList(); + + Event defaultStyle = new Event(); + defaultStyle.setName("DefaultStyle"); + defaultStyle.setDesc("Default style of page(Applies to all)"); + defaultStyle.setReplacer("eventCode"); + defaultStyle.setRawCode("%%%% DragonIDE eventCode %%%%"); + defaultStyle.setEventReplacer("defaultStyle"); + + events.add(defaultStyle); + + Event mobileDevice = new Event(); + mobileDevice.setName("MobileStyle"); + mobileDevice.setDesc("Stylesheet for mobile devices(Overrides main)"); + mobileDevice.setReplacer("eventCode"); + mobileDevice.setRawCode("%%%% DragonIDE eventCode %%%%"); + mobileDevice.setEventReplacer("mobileDeviceCSSEventCode"); + + events.add(mobileDevice); + + Event tabletDevice = new Event(); + tabletDevice.setName("TabletStyle"); + tabletDevice.setDesc("Stylesheet for tablet devices(Overrides main)"); + tabletDevice.setReplacer("eventCode"); + tabletDevice.setRawCode("%%%% DragonIDE eventCode %%%%"); + tabletDevice.setEventReplacer("tabletDeviceCSSEventCode"); + + events.add(tabletDevice); + + setEvents(events); } } diff --git a/app/src/main/java/builtin/files/HtmlFile.java b/app/src/main/java/builtin/files/HtmlFile.java index aa1e5ab..16078c3 100644 --- a/app/src/main/java/builtin/files/HtmlFile.java +++ b/app/src/main/java/builtin/files/HtmlFile.java @@ -1,6 +1,8 @@ package builtin.files; +import com.dragon.ide.objects.Event; import com.dragon.ide.objects.WebFile; +import java.util.ArrayList; public class HtmlFile extends WebFile { public HtmlFile() { @@ -25,5 +27,17 @@ public HtmlFile() { sb.append("\n"); setRawCode(new String(sb.toString())); + + ArrayList events = new ArrayList(); + + Event mainContent = new Event(); + mainContent.setName("MainPageView"); + mainContent.setDesc("Main contents of page"); + mainContent.setReplacer("eventMain"); + mainContent.setRawCode("%%%% DragonIDE eventMain %%%%"); + mainContent.setEventReplacer("mainContent"); + + events.add(mainContent); + setEvents(events); } } diff --git a/app/src/main/java/builtin/files/JavascriptFile.java b/app/src/main/java/builtin/files/JavascriptFile.java index 9265669..4cc1c14 100644 --- a/app/src/main/java/builtin/files/JavascriptFile.java +++ b/app/src/main/java/builtin/files/JavascriptFile.java @@ -1,6 +1,8 @@ package builtin.files; +import com.dragon.ide.objects.Event; import com.dragon.ide.objects.WebFile; +import java.util.ArrayList; public class JavascriptFile extends WebFile { public JavascriptFile() { @@ -13,5 +15,17 @@ public JavascriptFile() { sb.append("\n"); setRawCode(new String(sb.toString())); + + ArrayList events = new ArrayList(); + + Event mainEntry = new Event(); + mainEntry.setName("MainEntry"); + mainEntry.setDesc("Main Entry of javascript file"); + mainEntry.setReplacer("eventCode"); + mainEntry.setRawCode("%%%% DragonIDE eventCode %%%%"); + mainEntry.setEventReplacer("mainJavaScriptEvent"); + + events.add(mainEntry); + setEvents(events); } } diff --git a/app/src/main/java/com/dragon/ide/objects/Event.java b/app/src/main/java/com/dragon/ide/objects/Event.java index 716acb3..d545b75 100644 --- a/app/src/main/java/com/dragon/ide/objects/Event.java +++ b/app/src/main/java/com/dragon/ide/objects/Event.java @@ -14,7 +14,10 @@ public class Event implements Serializable { private String eventReplacer; public ArrayList getBlocks() { - return this.blocks; + if (blocks != null) { + return this.blocks; + } + return new ArrayList(); } public void setBlocks(ArrayList blocks) { @@ -54,7 +57,8 @@ public String getCode() { } } String eventFinalCode = new String(getRawCode()); - eventFinalCode = eventFinalCode.replaceAll(CodeReplacer.getReplacer(getReplacer()), eventCode.toString()); + eventFinalCode = + eventFinalCode.replaceAll(CodeReplacer.getReplacer(getReplacer()), eventCode.toString()); eventFinalCode = CodeReplacer.removeDragonIDEString(eventFinalCode); return new String(eventFinalCode.toString()); } diff --git a/app/src/main/java/com/dragon/ide/ui/adapters/EventListAdapter.java b/app/src/main/java/com/dragon/ide/ui/adapters/EventListAdapter.java index 320627d..4cf000e 100644 --- a/app/src/main/java/com/dragon/ide/ui/adapters/EventListAdapter.java +++ b/app/src/main/java/com/dragon/ide/ui/adapters/EventListAdapter.java @@ -1,12 +1,13 @@ package com.dragon.ide.ui.adapters; import android.app.Activity; +import android.content.Intent; import android.view.View; import android.view.ViewGroup; import androidx.recyclerview.widget.RecyclerView; -import com.dragon.ide.databinding.LayoutFileListItemBinding; +import com.dragon.ide.databinding.LayoutEventListItemBinding; import com.dragon.ide.objects.Event; -import com.dragon.ide.objects.WebFile; +import com.dragon.ide.ui.activities.EventEditorActivity; import java.util.ArrayList; public class EventListAdapter extends RecyclerView.Adapter { @@ -34,8 +35,8 @@ public EventListAdapter( @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - LayoutFileListItemBinding item = - LayoutFileListItemBinding.inflate(activity.getLayoutInflater()); + LayoutEventListItemBinding item = + LayoutEventListItemBinding.inflate(activity.getLayoutInflater()); View _v = item.getRoot(); RecyclerView.LayoutParams _lp = new RecyclerView.LayoutParams( @@ -45,7 +46,24 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { } @Override - public void onBindViewHolder(ViewHolder _holder, int _position) {} + public void onBindViewHolder(ViewHolder _holder, int _position) { + LayoutEventListItemBinding binding = LayoutEventListItemBinding.bind(_holder.itemView); + binding.title.setText(_data.get(_position).getName()); + binding.desc.setText(_data.get(_position).getDesc()); + binding + .getRoot() + .setOnClickListener( + (view) -> { + Intent i = new Intent(); + i.setClass(activity, EventEditorActivity.class); + i.putExtra("projectName", projectName); + i.putExtra("projectPath", projectPath); + i.putExtra("fileName", fileName); + i.putExtra("fileType", fileType); + i.putExtra("eventName", _data.get(_position).getName()); + activity.startActivity(i); + }); + } @Override public int getItemCount() { diff --git a/app/src/main/java/com/dragon/ide/ui/dialogs/eventList/ShowSourceCodeDialog.java b/app/src/main/java/com/dragon/ide/ui/dialogs/eventList/ShowSourceCodeDialog.java index b013f97..811fb1c 100644 --- a/app/src/main/java/com/dragon/ide/ui/dialogs/eventList/ShowSourceCodeDialog.java +++ b/app/src/main/java/com/dragon/ide/ui/dialogs/eventList/ShowSourceCodeDialog.java @@ -6,6 +6,7 @@ import com.dragon.ide.objects.WebFile; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import editor.tsd.tools.Themes; +import editor.tsd.widget.CodeEditorLayout; public class ShowSourceCodeDialog extends MaterialAlertDialogBuilder { public ShowSourceCodeDialog(Activity activity, String code, String language) { @@ -13,10 +14,11 @@ public ShowSourceCodeDialog(Activity activity, String code, String language) { LayoutSouceCodeDialogBinding binding = LayoutSouceCodeDialogBinding.inflate(activity.getLayoutInflater()); setTitle(R.string.source_code); - setView(binding.getRoot()); + binding.editor.setEditor(CodeEditorLayout.SoraCodeEditor); binding.editor.setCode(code); binding.editor.setTheme(Themes.SoraEditorTheme.Light.Quietlight); binding.editor.setLanguageMode(language); + setView(binding.getRoot()); setPositiveButton(R.string.cancel, (param1, param2) -> {}); } } diff --git a/app/src/main/res/layout/layout_event_list_item.xml b/app/src/main/res/layout/layout_event_list_item.xml index 2a81316..516759f 100644 --- a/app/src/main/res/layout/layout_event_list_item.xml +++ b/app/src/main/res/layout/layout_event_list_item.xml @@ -26,12 +26,14 @@ + android:textSize="14sp" + android:id="@+id/title" /> + android:textSize="12sp" + android:id="@+id/desc" /> diff --git a/app/src/main/res/layout/layout_souce_code_dialog.xml b/app/src/main/res/layout/layout_souce_code_dialog.xml index d4f9b07..10329fe 100644 --- a/app/src/main/res/layout/layout_souce_code_dialog.xml +++ b/app/src/main/res/layout/layout_souce_code_dialog.xml @@ -12,8 +12,6 @@ + android:id="@+id/editor" /> \ No newline at end of file