Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ android {
release{
isMinifyEnabled = false
isShrinkResources = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
signingConfig = signingConfigs.getByName("release")
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") //returning for now
}
}
compileOptions {
Expand All @@ -66,6 +63,7 @@ dependencies {
implementation(libs.transition)
implementation(libs.fragment)
implementation(libs.activity)
implementation(project(":filetree"))



Expand Down
8 changes: 7 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keep public class * extends com.sparkleseditor.fragments.BaseFragment
-keep class com.sparkleseditor.fragments.** { *; }
-keep class com.zyron.filetree.** { *; }
-dontwarn com.zyron.filetree.**
-keep class com.sparkleseditor.MainActivity { *; }
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import com.google.android.material.transition.MaterialSharedAxis;

import java.io.File;


/* Special Thanks to @yamenher for providing the class */

public class BaseFragment extends Fragment {
public abstract class BaseFragment extends Fragment {
@Override
public void onCreate(Bundle b) {
super.onCreate(null);
Expand All @@ -18,4 +20,6 @@ public void onCreate(Bundle b) {
setExitTransition(new MaterialSharedAxis(MaterialSharedAxis.X, true));
setReenterTransition(new MaterialSharedAxis(MaterialSharedAxis.X, false));
}


}
123 changes: 120 additions & 3 deletions app/src/main/java/com/sparkleseditor/fragments/MainFragment.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,84 @@
package com.sparkleseditor.fragments;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.zyron.filetree.events.FileTreeEventListener;

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.transition.TransitionManager;

import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.transition.MaterialSharedAxis;
import com.sparkleseditor.R;
import com.sparkleseditor.components.ExpandableLayout;
import com.sparkleseditor.databinding.FragmentMainBinding;
import com.sparkleseditor.navigation.Navigator;
import com.zyron.filetree.events.FileTreeEventListener;
import com.zyron.filetree.provider.FileTreeIconProvider;

import java.io.File;

import io.github.rosemoe.sora.widget.SymbolInputView;

public class MainFragment extends BaseFragment {
public class MainFragment extends BaseFragment implements FileTreeEventListener {


private final ActivityResultLauncher<Uri> folderPickerLauncher =
registerForActivityResult(
new ActivityResultContracts.OpenDocumentTree(),
treeUri -> {
if (treeUri == null) return;

int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION;

requireContext().getContentResolver()
.takePersistableUriPermission(treeUri, flags);

path = getRealPathFromUri(treeUri);
setupFileTree();
Toast.makeText(requireContext(), "Folder selected!", Toast.LENGTH_LONG).show();

}
);
private String getRealPathFromUri(Uri treeUri) {
String docId = DocumentsContract.getTreeDocumentId(treeUri);
String[] split = docId.split(":");
String type = split[0];
String relativePath = split.length > 1 ? split[1] : "";
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + relativePath;
} else {
String externalStorage = System.getenv("SECONDARY_STORAGE");
if (externalStorage == null) {
externalStorage = System.getenv("EXTERNAL_STORAGE");
}
return externalStorage + "/" + relativePath;
}
}

private FragmentMainBinding binding;
private FileTreeIconProvider fileIconProvider;
private String path ="";

private static final int REQUEST_CODE_OPEN_DIRECTORY = 1001;

public static final String[] SYMBOLS = {
"TAB","↵", "{", "}", "(", ")",
Expand All @@ -39,6 +94,11 @@ public class MainFragment extends BaseFragment {
">", "[", "]", ":"
};

public interface FileTreeEventListener {
void onFileClick(File file);
void onFolderClick(File folder);
}

@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container,
Expand All @@ -52,14 +112,50 @@ public View onCreateView(

public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

//AppStruct
setupToolbar();
setupToolbox();
setupInputView();
setupTabLayoutTemp();
slideXDrawer();
drawerLeftContent();
binding.fab.setTranslationY(-12);
}

private void drawerLeftContent() {

binding.fileTree.setVisibility(View.VISIBLE);
binding.contentGit.setVisibility(View.GONE);
binding.btmOptions.setOnNavigationItemSelectedListener(
item -> {
var sharedAxis = new MaterialSharedAxis(MaterialSharedAxis.X, true);
TransitionManager.beginDelayedTransition(binding.container, sharedAxis);
if (item.getItemId() == R.id.option_file_tree) {
binding.contentGit.setVisibility(View.GONE);
binding.fileTree.setVisibility(View.VISIBLE);
} else if (item.getItemId() == R.id.option_git) {
binding.contentGit.setVisibility(View.VISIBLE);
binding.fileTree.setVisibility(View.GONE);
}
return true;
}
);
setupFileTree();
}

private void setupFileTree() {
if (path != null && !path.isEmpty()) {
binding.contentFileTree.setVisibility(View.VISIBLE);
binding.requireFolder.setVisibility(View.GONE);
binding.fileTreeView.initializeFileTree(path, this , fileIconProvider);
}else{
binding.contentFileTree.setVisibility(View.GONE);
binding.requireFolder.setVisibility(View.VISIBLE);
binding.openFolder.setOnClickListener(v -> {
folderPickerLauncher.launch(null);
});
}
}

private void slideXDrawer() {
Expand Down Expand Up @@ -189,6 +285,27 @@ public void onDestroyView() {
binding = null;
}

public void onFileClick(File file) {
}


public void onFolderClick(File folder) {}


public boolean onFileLongClick(File file) {
return true;
}


public boolean onFolderLongClick(File folder) {

return true;
}


public void onFileTreeViewUpdated(int startPosition, int itemCount) {}





Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/git_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:tint="?colorOnSurface">

<path
android:fillColor="#ff000000"
android:pathData="M2.6,10.59L8.38,4.8L10.07,6.5C9.83,7.35 10.22,8.28 11,8.73V14.27C10.4,14.61 10,15.26 10,16A2,2 0,0 0,12 18A2,2 0,0 0,14 16C14,15.26 13.6,14.61 13,14.27V9.41L15.07,11.5C15,11.65 15,11.82 15,12A2,2 0,0 0,17 14A2,2 0,0 0,19 12A2,2 0,0 0,17 10C16.82,10 16.65,10 16.5,10.07L13.93,7.5C14.19,6.57 13.71,5.55 12.78,5.16C12.35,5 11.9,4.96 11.5,5.07L9.8,3.38L10.59,2.6C11.37,1.81 12.63,1.81 13.41,2.6L21.4,10.59C22.19,11.37 22.19,12.63 21.4,13.41L13.41,21.4C12.63,22.19 11.37,22.19 10.59,21.4L2.6,13.41C1.81,12.63 1.81,11.37 2.6,10.59Z"/>

</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_folder_rounded_filled_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorOnSurface">
<path
android:fillColor="@android:color/white"
android:pathData="M160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L367,160Q383,160 397.5,166Q412,172 423,183L480,240L800,240Q833,240 856.5,263.5Q880,287 880,320L880,720Q880,753 856.5,776.5Q833,800 800,800L160,800Z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_menu_open_rounded_filled_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorOnSurface"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M160,720Q143,720 131.5,708.5Q120,697 120,680Q120,663 131.5,651.5Q143,640 160,640L600,640Q617,640 628.5,651.5Q640,663 640,680Q640,697 628.5,708.5Q617,720 600,720L160,720ZM756,652L612,508Q600,496 600,480Q600,464 612,452L756,308Q767,297 784,297Q801,297 812,308Q823,319 823,336Q823,353 812,364L696,480L812,596Q823,607 823,624Q823,641 812,652Q801,663 784,663Q767,663 756,652ZM160,520Q143,520 131.5,508.5Q120,497 120,480Q120,463 131.5,451.5Q143,440 160,440L480,440Q497,440 508.5,451.5Q520,463 520,480Q520,497 508.5,508.5Q497,520 480,520L160,520ZM160,320Q143,320 131.5,308.5Q120,297 120,280Q120,263 131.5,251.5Q143,240 160,240L600,240Q617,240 628.5,251.5Q640,263 640,280Q640,297 628.5,308.5Q617,320 600,320L160,320Z"/>
</vector>
Loading