Skip to content

Commit 8004eec

Browse files
committed
Feat : added new filetree
1 parent 9b7757b commit 8004eec

46 files changed

Lines changed: 1796 additions & 6 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dependencies {
6666
implementation(libs.transition)
6767
implementation(libs.fragment)
6868
implementation(libs.activity)
69+
implementation(project(":filetree"))
6970

7071

7172

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>

app/src/main/res/layout/fragment_main.xml

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,125 @@
133133
app:srcCompat="@drawable/ic_play_arrow_rounded_filled_24dp" />
134134

135135

136-
137136
</androidx.coordinatorlayout.widget.CoordinatorLayout>
138137

139138
<com.google.android.material.navigation.NavigationView
140139
android:layout_width="wrap_content"
141140
android:layout_height="match_parent"
142141
android:layout_gravity="start"
143-
android:id="@+id/left_drawer_menu"/>
142+
android:id="@+id/left_drawer_menu">
143+
144+
<LinearLayout
145+
android:id="@+id/content_drawer"
146+
android:layout_width="match_parent"
147+
android:layout_height="wrap_content"
148+
android:layout_marginBottom="4dp"
149+
android:clickable="true"
150+
android:orientation="vertical"
151+
android:fitsSystemWindows="true">
152+
<!-- the old sidesheet layout goes here -->
153+
<LinearLayout
154+
android:layout_height="wrap_content"
155+
android:layout_width="match_parent"
156+
android:gravity="end"
157+
android:orientation="horizontal">
158+
<TextView
159+
android:layout_height="match_parent"
160+
android:layout_width="match_parent"
161+
android:text="@string/app_name"
162+
android:textSize="18sp"
163+
android:gravity="left|center_vertical"
164+
android:layout_gravity="start"
165+
android:layout_weight="1"
166+
android:paddingLeft="16dp" />
167+
<Button
168+
android:id="@+id/hide"
169+
style="?attr/materialIconButtonStyle"
170+
android:layout_width="wrap_content"
171+
android:layout_height="wrap_content"
172+
android:layout_margin="8dp"
173+
app:icon="@drawable/ic_menu_open_rounded_filled_24dp"
174+
app:iconTint="?attr/colorOnSurfaceVariant" />
175+
</LinearLayout>
176+
<com.google.android.material.bottomnavigation.BottomNavigationView
177+
android:layout_height="60dp"
178+
android:layout_width="match_parent"
179+
app:menu="@menu/sheet_options_menu"
180+
android:background="@android:color/transparent"
181+
android:id="@+id/btm_options"
182+
app:labelVisibilityMode="unlabeled" />
183+
<FrameLayout
184+
android:layout_height="match_parent"
185+
android:layout_width="match_parent"
186+
android:orientation="vertical"
187+
android:id="@+id/container">
188+
189+
<LinearLayout
190+
android:id="@+id/file_tree"
191+
android:layout_width="match_parent"
192+
android:layout_height="match_parent"
193+
android:orientation="horizontal">
194+
<HorizontalScrollView
195+
android:layout_height="match_parent"
196+
android:layout_width="wrap_content"
197+
android:fillViewport="false">
198+
<androidx.core.widget.NestedScrollView
199+
android:layout_height="match_parent"
200+
android:layout_width="match_parent"
201+
android:gravity="center"
202+
android:id="@+id/content_file_tree"
203+
android:fillViewport="false">
204+
<!-- Where the file tree goes -->
205+
<com.zyron.filetree.widget.FileTreeView
206+
android:id="@+id/file_tree_view"
207+
android:layout_width="wrap_content"
208+
android:layout_height="match_parent" />
209+
</androidx.core.widget.NestedScrollView>
210+
</HorizontalScrollView>
211+
<LinearLayout
212+
android:layout_width="match_parent"
213+
android:layout_height="match_parent"
214+
android:gravity="center"
215+
android:id="@+id/require_folder"
216+
android:orientation="vertical">
217+
<TextView
218+
android:layout_width="wrap_content"
219+
android:layout_height="wrap_content"
220+
android:text="No Workspace currently Set"/>
221+
<com.google.android.material.button.MaterialButton
222+
android:layout_width="wrap_content"
223+
android:layout_height="wrap_content"
224+
android:text="Open Folder"
225+
android:id="@+id/open_folder"
226+
app:icon="@drawable/ic_folder_rounded_filled_24dp"/>
227+
</LinearLayout>
228+
</LinearLayout>
229+
<LinearLayout
230+
android:layout_height="match_parent"
231+
android:layout_width="match_parent"
232+
android:gravity="center"
233+
android:id="@+id/content_git">
234+
<!-- Where the Git goes -->
235+
<TextView
236+
android:layout_height="wrap_content"
237+
android:layout_width="wrap_content"
238+
android:text="The Git Client is Coming Soon!" />
239+
</LinearLayout>
240+
<LinearLayout
241+
android:layout_height="match_parent"
242+
android:layout_width="match_parent"
243+
android:gravity="center"
244+
android:id="@+id/content_toolbox">
245+
246+
</LinearLayout>
247+
</FrameLayout>
248+
249+
250+
</LinearLayout>
251+
252+
253+
254+
</com.google.android.material.navigation.NavigationView>
144255

145256
<com.google.android.material.navigation.NavigationView
146257
android:id="@+id/right_drawer_menu"

0 commit comments

Comments
 (0)