Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
HanzoDev1375 committed Jun 29, 2024
1 parent 77d5be5 commit 60b4c46
Show file tree
Hide file tree
Showing 18 changed files with 823 additions and 847 deletions.
136 changes: 75 additions & 61 deletions app/src/main/java/Ninja/coder/Ghostemane/code/IdeEditor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Ninja.coder.Ghostemane.code;

import Ninja.coder.Ghostemane.code.config.LOG;
import Ninja.coder.Ghostemane.code.interfaces.CallBackErrorManager;
import Ninja.coder.Ghostemane.code.marco.CommentList;
import Ninja.coder.Ghostemane.code.marco.editorface.IEditor;
Expand All @@ -16,6 +17,7 @@
import android.view.View;
import android.view.animation.*;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flask.colorpicker.OnColorSelectedListener;
import com.flask.colorpicker.builder.ColorPickerClickListener;
Expand All @@ -26,6 +28,12 @@
import com.google.android.material.shape.ShapeAppearanceModel;
import io.github.rosemoe.sora.event.ContentChangeEvent;
import io.github.rosemoe.sora.interfaces.EditorLanguage;
import io.github.rosemoe.sora.langs.xml.XMLLanguage;
import io.github.rosemoe.sora.langs.xml.XMLLexer;
import java.io.StringReader;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
import io.github.rosemoe.sora.text.FormatThread;
import io.github.rosemoe.sora.util.KeyboardUtils;
import io.github.rosemoe.sora.widget.CodeEditor;
Expand All @@ -46,7 +54,6 @@ public class IdeEditor extends CodeEditor implements IEditor {
private boolean isSoftKbdEnabled;
private CommentList listitem;
private ToolTipHelper toolTipHelper;


// for test
private Pattern URL_PATTERN =
Expand Down Expand Up @@ -80,61 +87,12 @@ public IdeEditor init() {
setLineInfoTextSize(18f);
setScalable(true);
setCursorWidth(4.0f);



setNonPrintablePaintingFlags(
FLAG_DRAW_WHITESPACE_LEADING
| FLAG_DRAW_WHITESPACE_INNER
| FLAG_DRAW_WHITESPACE_FOR_EMPTY_LINE);

// getTextAnalyzeResult
subscribeEvent(
ContentChangeEvent.class,
(event, subscribe) -> {
/// Code for saving file
if (!(event.getAction() == ContentChangeEvent.ACTION_SET_NEW_TEXT)) {
if (accumulatedText.contains(listitem.stopSearch)) {
getSearcher().stopSearch();
accumulatedText = "";
} else if (accumulatedText.contains(listitem.showPopWindows)) {
getTextActionWindow().show();
accumulatedText = "";
} else if (accumulatedText.contains(listitem.showColorPi)) {
ColorPickerDialogBuilder.with(getContext())
.setTitle("SetColor")
.density(20)
.showColorEdit(true)
.setOnColorSelectedListener(
new OnColorSelectedListener() {
@Override
public void onColorSelected(int selectedColor) {}
})
.setPositiveButton(
"Ok",
new ColorPickerClickListener() {
@Override
public void onClick(
DialogInterface dialog, int selectedColor, Integer[] allColors) {
String rgs = Integer.toHexString(selectedColor);
SymbolChannel sys = createNewSymbolChannel();
sys.insertSymbol("#" + rgs.replace("####", "#"), 1);
}
})
.setNegativeButton(
"No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
})
.build()
.show();
accumulatedText = "";
} else {

}
}
});
subscribeEvent(ContentChangeEvent.class, ((event, unsubscribe) -> handleContentChange(event)));

return this;
}
Expand Down Expand Up @@ -223,16 +181,6 @@ public void onFormatSucceed(CharSequence originalText, CharSequence newText) {
}
}

public void TEXT(TextView textView, String data, Result result, View fab) {
subscribeEvent(
ContentChangeEvent.class,
(event, subscribe) -> {
/// Code for saving file

result.onTextEnd(data);
});
}

public String code() {
return getText().toString();
}
Expand Down Expand Up @@ -395,4 +343,70 @@ public final void run() {
}
}
}

private void handleContentChange(@NonNull ContentChangeEvent event) {

if (event.getAction() == ContentChangeEvent.ACTION_INSERT) {
final var editor = event.getEditor();
final var content = event.getChangedText();
final var endLine = event.getChangeEnd().line;
final var endColumn = event.getChangeEnd().column;
if (getEditorLanguage() instanceof XMLLanguage) {
boolean isOpen = false;
try {
isOpen = editor.getText().charAt(editor.getCursor().getLeft() - 2) == '<';
} catch (Throwable th) {
}

if (isOpen && "/".contentEquals(content)) {
closeCurrentTag(editor.getText().toString(), endLine, endColumn);
}
}
}
}

private void closeCurrentTag(String text, int line, int col) {
try {
XMLLexer lexer = new XMLLexer(CharStreams.fromReader(new StringReader(text)));
Token token;
boolean wasSlash = false, wasOpen = false;
ArrayList<String> currentNames = new ArrayList<>();
while (((token = lexer.nextToken()) != null && token.getType() != token.EOF)) {
final int type = token.getType();
if (type == XMLLexer.OPEN) {
wasOpen = true;
} else if (type == XMLLexer.Name) {
if (wasOpen && wasSlash && currentNames.size() > 0) {
currentNames.remove(0);
} else if (wasOpen) {
currentNames.add(0, token.getText());
wasOpen = false;
}

} else if (type == XMLLexer.OPEN_SLASH) {
int l = token.getLine() - 1;
int c = token.getCharPositionInLine();
if (l == line && c == col) {
break;
} else if (currentNames.size() > 0) {
currentNames.remove(0);
}
} else if (type == XMLLexer.SLASH_CLOSE || type == XMLLexer.SPECIAL_CLOSE) {
if (currentNames.size() > 0 && token.getText().trim().endsWith("/>")) {
currentNames.remove(0);
}
} else if (type == XMLLexer.SLASH) {
wasSlash = true;
} else {
wasOpen = wasSlash = false;
}
}

if (currentNames.size() > 0) {
getText().insert(line, col + 2, currentNames.get(0));
}
} catch (Throwable th) {
LOG.error("Unable to close current tag", th.getLocalizedMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class AboutActivity extends BaseCompat implements DevAd.OnItemClick {
public class AboutActivity extends BaseCompat {
protected TextView tv_about_name;
protected RecyclerView rv_about_dev;
protected DevAd devAd;
protected List<DevModel> listModel = new ArrayList<>();
private RequestNetwork sazndeh;
private RequestNetwork.RequestListener _sazndeh_request_listener;
private RequestNetwork sazndeh, DevSazandeh;
private RequestNetwork.RequestListener devCallBack, DevUser;
private ImageView appicon;
public static String ApiURL = "https://api.github.com/users/HanzoDev1375";
public static String DevList = "https://api.github.com/repos/HanzoDev1375/Ghostide/contributors";

@Override
protected void onCreate(Bundle _savedInstanceState) {
Expand All @@ -46,25 +46,33 @@ private void start() {
appicon = findViewById(R.id.icon_glide_about);
tv_about_name = findViewById(R.id.tv_about_name);
rv_about_dev = findViewById(R.id.rv_about_dev);

listModel.add(new DevModel("Appt2 ", "main"));
listModel.add(new DevModel("BlueWhaleYT", "main"));
listModel.add(new DevModel("Mohammad Taha", "main"));
listModel.add(new DevModel("Ban Doroid", "marco"));
listModel.add(new DevModel("Mister Java", "macro"));
listModel.add(new DevModel("Psi", "Help to adding python"));
listModel.add(new DevModel("EUP", "marco"));
listModel.add(new DevModel("timscriptov", "Tanks for Library layout preview"));
GlideCompat.GlideNormal(appicon, R.mipmap.ghosticon);
devAd = new DevAd(listModel, this);
rv_about_dev.setAdapter(devAd);
rv_about_dev.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));

sazndeh = new RequestNetwork(this);
_sazndeh_request_listener =
DevSazandeh = new RequestNetwork(this);
DevUser =
new RequestNetwork.RequestListener() {
@Override
public void onResponse(String _param1, String respanse, HashMap<String, Object> _param3) {

listModel.add(new DevModel(getIconDev(respanse)));
devAd = new DevAd(listModel, (v, c) -> {});

rv_about_dev.setAdapter(devAd);
rv_about_dev.setLayoutManager(
new LinearLayoutManager(AboutActivity.this, RecyclerView.VERTICAL, false));
}

@Override
public void onErrorResponse(String _param1, String _param2) {}
};

devCallBack =
new RequestNetwork.RequestListener() {
@Override
public void onResponse(String _param1, String respanse, HashMap<String, Object> _param3) {
getElementUser(respanse);
// listModel.add(new DevModel(getIconDev(respanse)));
}

@Override
Expand All @@ -87,33 +95,8 @@ public void handleOnBackPressed() {
}

private void runview() {
sazndeh.startRequestNetwork(
RequestNetworkController.GET, ApiURL, "b", _sazndeh_request_listener);
}

@Override
public void onItemChange(View v, int pos) {
switch (pos) {
case 0:
openUrl("https://github.com/appt2");
break;
case 1:
openUrl("https://github.com/BlueWhaleYT");
break;
case 2, 4, 6:
Toast.makeText(getApplicationContext(), "User not found Github page", Toast.LENGTH_SHORT)
.show();
break;
case 3:
openUrl("https://github.com/BanDroid");
break;
case 5:
openUrl("https://github.com/PsiCodes");
break;
case 7:
openUrl("https://github.com/timscriptov");
break;
}
sazndeh.startRequestNetwork(RequestNetworkController.GET, ApiURL, "b", devCallBack);
DevSazandeh.startRequestNetwork(RequestNetworkController.GET, DevList, "B", DevUser);
}

void openUrl(String link) {
Expand All @@ -135,4 +118,17 @@ void getElementUser(String input) {

}
}

public String getIconDev(String input) {
try {
JSONArray aar = new JSONArray(input);
if (aar.length() > 0) {
JSONObject object = aar.getJSONObject(0);
return object.getString("avatar_url");
}
} catch (JSONException err) {

}
return null;
}
}
Loading

0 comments on commit 60b4c46

Please sign in to comment.