Skip to content

Commit 103314d

Browse files
authored
Merge pull request #4 from Sparkleseditor/filetree-new
feat : added file tree (mainly undermantenance)
2 parents 9b7757b + 6b50a35 commit 103314d

47 files changed

Lines changed: 1807 additions & 12 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ android {
3535
release{
3636
isMinifyEnabled = false
3737
isShrinkResources = false
38-
proguardFiles(
39-
getDefaultProguardFile("proguard-android-optimize.txt"),
40-
"proguard-rules.pro"
41-
)
42-
signingConfig = signingConfigs.getByName("release")
38+
signingConfig = signingConfigs.getByName("release")
39+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") //returning for now
4340
}
4441
}
4542
compileOptions {
@@ -66,6 +63,7 @@ dependencies {
6663
implementation(libs.transition)
6764
implementation(libs.fragment)
6865
implementation(libs.activity)
66+
implementation(project(":filetree"))
6967

7068

7169

app/proguard-rules.pro

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
23+
-keep public class * extends com.sparkleseditor.fragments.BaseFragment
24+
-keep class com.sparkleseditor.fragments.** { *; }
25+
-keep class com.zyron.filetree.** { *; }
26+
-dontwarn com.zyron.filetree.**
27+
-keep class com.sparkleseditor.MainActivity { *; }

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools">
44

5+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
7+
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
8+
59
<application
610
android:allowBackup="true"
711
android:dataExtractionRules="@xml/data_extraction_rules"

app/src/main/java/com/sparkleseditor/fragments/BaseFragment.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

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

9+
import java.io.File;
10+
911

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

12-
public class BaseFragment extends Fragment {
14+
public abstract class BaseFragment extends Fragment {
1315
@Override
1416
public void onCreate(Bundle b) {
1517
super.onCreate(null);
@@ -18,4 +20,6 @@ public void onCreate(Bundle b) {
1820
setExitTransition(new MaterialSharedAxis(MaterialSharedAxis.X, true));
1921
setReenterTransition(new MaterialSharedAxis(MaterialSharedAxis.X, false));
2022
}
23+
24+
2125
}

app/src/main/java/com/sparkleseditor/fragments/MainFragment.java

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,84 @@
11
package com.sparkleseditor.fragments;
22

33
import android.annotation.SuppressLint;
4+
import android.content.Intent;
45
import android.graphics.Color;
6+
import android.net.Uri;
57
import android.os.Bundle;
8+
import android.os.Environment;
9+
import android.provider.DocumentsContract;
10+
import android.util.Log;
611
import android.view.LayoutInflater;
712
import android.view.View;
813
import android.view.ViewGroup;
14+
import android.widget.Toast;
915

16+
import com.zyron.filetree.events.FileTreeEventListener;
17+
18+
import androidx.activity.result.ActivityResultCallback;
19+
import androidx.activity.result.ActivityResultLauncher;
20+
import androidx.activity.result.contract.ActivityResultContracts;
1021
import androidx.annotation.NonNull;
11-
import androidx.appcompat.app.ActionBarDrawerToggle;
1222
import androidx.core.view.GravityCompat;
13-
import androidx.core.view.ViewCompat;
1423
import androidx.drawerlayout.widget.DrawerLayout;
1524
import androidx.fragment.app.Fragment;
25+
import androidx.transition.TransitionManager;
1626

27+
import com.google.android.material.snackbar.Snackbar;
28+
import com.google.android.material.transition.MaterialSharedAxis;
1729
import com.sparkleseditor.R;
1830
import com.sparkleseditor.components.ExpandableLayout;
1931
import com.sparkleseditor.databinding.FragmentMainBinding;
2032
import com.sparkleseditor.navigation.Navigator;
33+
import com.zyron.filetree.events.FileTreeEventListener;
34+
import com.zyron.filetree.provider.FileTreeIconProvider;
35+
36+
import java.io.File;
2137

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

24-
public class MainFragment extends BaseFragment {
40+
public class MainFragment extends BaseFragment implements FileTreeEventListener {
41+
42+
43+
private final ActivityResultLauncher<Uri> folderPickerLauncher =
44+
registerForActivityResult(
45+
new ActivityResultContracts.OpenDocumentTree(),
46+
treeUri -> {
47+
if (treeUri == null) return;
48+
49+
int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION |
50+
Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
51+
52+
requireContext().getContentResolver()
53+
.takePersistableUriPermission(treeUri, flags);
54+
55+
path = getRealPathFromUri(treeUri);
56+
setupFileTree();
57+
Toast.makeText(requireContext(), "Folder selected!", Toast.LENGTH_LONG).show();
58+
59+
}
60+
);
61+
private String getRealPathFromUri(Uri treeUri) {
62+
String docId = DocumentsContract.getTreeDocumentId(treeUri);
63+
String[] split = docId.split(":");
64+
String type = split[0];
65+
String relativePath = split.length > 1 ? split[1] : "";
66+
if ("primary".equalsIgnoreCase(type)) {
67+
return Environment.getExternalStorageDirectory() + "/" + relativePath;
68+
} else {
69+
String externalStorage = System.getenv("SECONDARY_STORAGE");
70+
if (externalStorage == null) {
71+
externalStorage = System.getenv("EXTERNAL_STORAGE");
72+
}
73+
return externalStorage + "/" + relativePath;
74+
}
75+
}
2576

2677
private FragmentMainBinding binding;
78+
private FileTreeIconProvider fileIconProvider;
79+
private String path ="";
80+
81+
private static final int REQUEST_CODE_OPEN_DIRECTORY = 1001;
2782

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

97+
public interface FileTreeEventListener {
98+
void onFileClick(File file);
99+
void onFolderClick(File folder);
100+
}
101+
42102
@Override
43103
public View onCreateView(
44104
@NonNull LayoutInflater inflater, ViewGroup container,
@@ -52,14 +112,50 @@ public View onCreateView(
52112

53113
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
54114
super.onViewCreated(view, savedInstanceState);
115+
116+
//AppStruct
55117
setupToolbar();
56118
setupToolbox();
57119
setupInputView();
58120
setupTabLayoutTemp();
59121
slideXDrawer();
122+
drawerLeftContent();
60123
binding.fab.setTranslationY(-12);
124+
}
61125

126+
private void drawerLeftContent() {
127+
128+
binding.fileTree.setVisibility(View.VISIBLE);
129+
binding.contentGit.setVisibility(View.GONE);
130+
binding.btmOptions.setOnNavigationItemSelectedListener(
131+
item -> {
132+
var sharedAxis = new MaterialSharedAxis(MaterialSharedAxis.X, true);
133+
TransitionManager.beginDelayedTransition(binding.container, sharedAxis);
134+
if (item.getItemId() == R.id.option_file_tree) {
135+
binding.contentGit.setVisibility(View.GONE);
136+
binding.fileTree.setVisibility(View.VISIBLE);
137+
} else if (item.getItemId() == R.id.option_git) {
138+
binding.contentGit.setVisibility(View.VISIBLE);
139+
binding.fileTree.setVisibility(View.GONE);
140+
}
141+
return true;
142+
}
143+
);
144+
setupFileTree();
145+
}
62146

147+
private void setupFileTree() {
148+
if (path != null && !path.isEmpty()) {
149+
binding.contentFileTree.setVisibility(View.VISIBLE);
150+
binding.requireFolder.setVisibility(View.GONE);
151+
binding.fileTreeView.initializeFileTree(path, this , fileIconProvider);
152+
}else{
153+
binding.contentFileTree.setVisibility(View.GONE);
154+
binding.requireFolder.setVisibility(View.VISIBLE);
155+
binding.openFolder.setOnClickListener(v -> {
156+
folderPickerLauncher.launch(null);
157+
});
158+
}
63159
}
64160

65161
private void slideXDrawer() {
@@ -189,6 +285,27 @@ public void onDestroyView() {
189285
binding = null;
190286
}
191287

288+
public void onFileClick(File file) {
289+
}
290+
291+
292+
public void onFolderClick(File folder) {}
293+
294+
295+
public boolean onFileLongClick(File file) {
296+
return true;
297+
}
298+
299+
300+
public boolean onFolderLongClick(File folder) {
301+
302+
return true;
303+
}
304+
305+
306+
public void onFileTreeViewUpdated(int startPosition, int itemCount) {}
307+
308+
192309

193310

194311

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:width="24dp"
5+
android:height="24dp"
6+
android:viewportHeight="24"
7+
android:viewportWidth="24"
8+
android:tint="?colorOnSurface">
9+
10+
<path
11+
android:fillColor="#ff000000"
12+
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"/>
13+
14+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorOnSurface">
7+
<path
8+
android:fillColor="@android:color/white"
9+
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"/>
10+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorOnSurface"
7+
android:autoMirrored="true">
8+
<path
9+
android:fillColor="@android:color/white"
10+
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"/>
11+
</vector>

0 commit comments

Comments
 (0)