Skip to content

Commit

Permalink
feat: Added some events and some code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Oct 24, 2023
1 parent 2577cdc commit c0bc2ff
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 14 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/android/code/editor/common/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "";
}
}
}
35 changes: 34 additions & 1 deletion app/src/main/java/builtin/files/CssFile.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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");
Expand All @@ -33,5 +35,36 @@ public CssFile() {
sb.append("}");

setRawCode(new String(sb.toString()));

ArrayList<Event> events = new ArrayList<Event>();

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);
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/builtin/files/HtmlFile.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -25,5 +27,17 @@ public HtmlFile() {
sb.append("</html>\n");

setRawCode(new String(sb.toString()));

ArrayList<Event> events = new ArrayList<Event>();

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);
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/builtin/files/JavascriptFile.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -13,5 +15,17 @@ public JavascriptFile() {
sb.append("\n");

setRawCode(new String(sb.toString()));

ArrayList<Event> events = new ArrayList<Event>();

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);
}
}
8 changes: 6 additions & 2 deletions app/src/main/java/com/dragon/ide/objects/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public class Event implements Serializable {
private String eventReplacer;

public ArrayList<Block> getBlocks() {
return this.blocks;
if (blocks != null) {
return this.blocks;
}
return new ArrayList<Block>();
}

public void setBlocks(ArrayList<Block> blocks) {
Expand Down Expand Up @@ -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());
}
Expand Down
28 changes: 23 additions & 5 deletions app/src/main/java/com/dragon/ide/ui/adapters/EventListAdapter.java
Original file line number Diff line number Diff line change
@@ -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<EventListAdapter.ViewHolder> {
Expand Down Expand Up @@ -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(
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
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) {
super(activity);
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) -> {});
}
}
6 changes: 4 additions & 2 deletions app/src/main/res/layout/layout_event_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="14sp" />
android:textSize="14sp"
android:id="@+id/title" />

<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="12sp" />
android:textSize="12sp"
android:id="@+id/desc" />

</LinearLayout>

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/layout_souce_code_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<editor.tsd.widget.CodeEditorLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/editor"
app:codeEditor="SoraCodeEditor"
app:setCode="" />
android:id="@+id/editor" />

</LinearLayout>

0 comments on commit c0bc2ff

Please sign in to comment.