Skip to content

Commit aa8bd85

Browse files
Initial commit
1 parent 1388512 commit aa8bd85

File tree

6 files changed

+60
-93
lines changed

6 files changed

+60
-93
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AndroidZip/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies {
3030
implementation 'androidx.appcompat:appcompat:1.5.0'
3131
implementation 'com.google.android.material:material:1.6.1'
3232

33-
implementation 'com.github.buggysofts-com:StreamZip:v1.0.2'
33+
implementation 'com.github.buggysofts-com:StreamZip:v1.0.0'
3434

3535
testImplementation 'junit:junit:4.13.2'
3636
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

AndroidZip/src/main/java/com/buggysofts/androidzip/AndroidZip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void close() throws IOException {
5151
* Get a list of all the entries available in the zip file.
5252
*/
5353
@Override
54-
public List<ZipEntry> entries() throws Exception {
54+
public List<ZipEntry> entries() {
5555
return super.entries();
5656
}
5757

README.md

Lines changed: 46 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# BottomSheetMenu [![Release](https://jitpack.io/v/buggysofts-com/BottomSheetMenu.svg)](https://jitpack.io/#buggysofts-com/BottomSheetMenu)
2-
3-
A powerful &amp; customizable menu implementation for android. It supports any level of nested menu structures along with custom header and footer views, and much more. Follow the steps below to import the library to your project. You will also find some sample codes.
1+
# AndroidZip [![](https://jitpack.io/v/buggysofts-com/AndroidZip.svg)](https://jitpack.io/#buggysofts-com/AndroidZip)
2+
A zip explorer library for android that takes <b>DocumentFile</b> object as its source. It uses my **StreamZip** library as its base.
43

54
<br />
65

@@ -34,7 +33,7 @@ Finally, add this dependency to your app/module level build.gradle file
3433
3534
dependencies {
3635
...
37-
implementation 'com.github.buggysofts-com:BottomSheetMenu:v1.0.4'
36+
implementation 'com.github.buggysofts-com:AndroidZip:1.0.0'
3837
}
3938
```
4039
And you are done importing the library.
@@ -43,97 +42,61 @@ And you are done importing the library.
4342

4443
## Sample codes
4544

46-
To create a minimal bottom sheet menu...
47-
```
48-
BottomSheetMenu bottomSheetMenu = new BottomSheetMenu(
49-
MainActivity.this,
50-
R.menu.sample_menu,
51-
new BottomSheetMenu.MenuItemClickListener() {
52-
@Override
53-
public void onClick(MenuItem item) {
54-
Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
55-
}
56-
}
57-
).show();
58-
```
59-
<br />
60-
61-
You can use methods that follow builder pattern to set properties of different components of the menu. For example the following code snippet sets background, divider, menu icon place holder (in case a menu item does not have an icon), expand icon (for indicating submenu of a menu item), a title and finally it shows the menu. There are other constructors where you can set these properties all at once.
62-
```
63-
bottomSheetMenu
64-
.menuBackground(
65-
AppCompatResources.getDrawable(
66-
MainActivity.this,
67-
R.drawable.menu_bg
68-
)
69-
)
70-
.dividerDrawable(
71-
BottomSheetMenu.getSystemDefaultDivider(
72-
MainActivity.this
73-
)
74-
)
75-
.menuIconPlaceHolder(
76-
AppCompatResources.getDrawable(
77-
MainActivity.this,
78-
R.drawable.ic_menu_item
79-
)
80-
)
81-
.menuExpandIcon(
82-
AppCompatResources.getDrawable(
83-
MainActivity.this,
84-
R.drawable.ic_arrow_forward
85-
)
86-
)
87-
.menuTitle("Property Setting Demo")
88-
.show();
89-
```
90-
You can obtain various default properties with the static methods available in the BottomSheetMenu class, for example ```BottomSheetMenu.getDefaultExpandIcon(context)``` returns the default drawable used as the expand icon. There are other methods for other properties as well. But you don't need to explicitly call these methods, these properties are set by default.
91-
92-
<br />
45+
To create an instance do something like...
9346

94-
The menu supports custom header and footer views. You can select different header and footer views for different menu items, and also for initial call to ```show()```. There may be many use cases for different header and footer views, such as description of the the submenu of a menu item can be placed as the footer view. See the code snippet below to know how you can define these selectors.
9547
```
96-
bottomSheetMenu
97-
.headerViewSelector(
98-
new BottomSheetMenu.ViewSelector() {
99-
@Nullable
100-
@Override
101-
public View getInitialView() {
102-
return getLayoutInflater().inflate(R.layout.initial_menu_header, null);
103-
}
104-
105-
@Nullable
106-
@Override
107-
public View selectViewForItem(MenuItem item) {
108-
int itemId = item.getItemId();
109-
if (itemId == R.id.menu_image) {
110-
return getLayoutInflater().inflate(R.layout.image_info_layout, null);
111-
} else if (itemId == R.id.menu_video) {
112-
return getLayoutInflater().inflate(R.layout.video_info_layout, null);
113-
} else {
114-
return getLayoutInflater().inflate(R.layout.raw_file_info_layout, null);
115-
}
116-
}
48+
AndroidZip zip = null;
49+
try {
50+
zip = new AndroidZip(MainActivity.this, documentFile);
51+
} catch (Exception e) {
52+
e.printStackTrace();
53+
} finally {
54+
if(zip != null){
55+
List<ZipEntry> entries = zip.entries();
56+
for (int i = 0; i < entries.size(); i++) {
57+
// do something
11758
}
118-
)
119-
.menuTitle("View Selecting Demo")
120-
.show();
59+
}
60+
}
12161
```
122-
The above code selects different views for different selected menu item(having submenu). Also, it selects an initial header view. Similarly, you can set footer views with ```footerViewSelector(...)``` method.
12362

12463
<br />
12564

126-
## Images
127-
Here are some example images of the menu containing a header and a footer view. The one above the top divider line is the header view, and the one below the bottom divider line is the footer view. You can select your desider header or footer views, or customize the menu styles and behaviours by following the topics above. Note, the styling applied to the menu does not apply on header and footer views, they are external views and you should apply necessary styling to them before using them in the menu.
65+
Then you can use different methods that are similar to the standard java ZipFile class. For example here are the
66+
publicly available methods.
12867

129-
Root menu:
130-
![Root menu](/app/src/main/res/drawable/root_menu.png)
68+
- ```size()``` Returns the total number of available entries.
69+
- ```getComment()``` Returns the principal comment of the zip file.
70+
- ```entries()``` Returns all the available entries as a list of <b>ZipEntry</b>.
71+
- ```getInputStream(...)``` Opens(and returns) a bounded input stream currently positioning at the start of the
72+
requested entry's data block.
73+
- ```close()``` Closes the zip file, and any subsequent call to <b>getInputStream(...)</b> will throw an exception.
74+
However, other methods of the class that are saved in memory will still be available after call to <b>close()</b>.
13175

132-
Nested submenu:
133-
![Nested submenu](/app/src/main/res/drawable/menu_level_2.png)
76+
**Please Note**
13477

78+
- The **ZipEntry** we mentioned above is a part of this library and has similar methods as the standard **ZipEntry**
79+
class
80+
in java jdk.
81+
- If you do not have a **ZipEntry** instance, and only have the name of the entry, you can use the minimal
82+
constructor (
83+
i.e. ```ZipEntry(String name)```) to obtain an input stream. Of course, you would get an exception if the entry does
84+
not
85+
exist.
13586

13687
<br />
88+
89+
### Performance
90+
91+
The performance is similar to the Standard **ZipFile** class. Before this, the only way to read a zip file in this kind
92+
of situation was to use the **ZipInputStream** class which basically reads every byte in its way to get to the next
93+
entry. That is, to list, or to get data of all the entries of a zip file, it is equivalent of reading the whole file.
94+
Imagine you have to read some metadata within some big zip files, may be 100 zip files, think how much time it would
95+
take!
96+
Of course, you can use some caching technique, which I was doing for a long time, in fact there is still a library in
97+
the git repo, which does exactly that. But in any way, that is not enough, it takes a lot of memory, and the performance
98+
is limited to many constraints.
99+
137100
<br />
138101

139102
Please share & rate the library if you find it useful.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
3535

3636
implementation project(':AndroidZip')
37-
implementation 'com.github.buggysofts-com:StreamZip:v1.0.2'
37+
implementation 'com.github.buggysofts-com:StreamZip:v1.0.0'
3838

3939
testImplementation 'junit:junit:4.13.2'
4040
androidTestImplementation 'androidx.test.ext:junit:1.1.3'

app/src/main/java/com/buggysofts/androidzipimpl/MainActivity.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
3030
DocumentFile.fromSingleUri(MainActivity.this, uri) :
3131
null;
3232

33-
AndroidZip zip = null;
34-
try {
35-
zip = new AndroidZip(MainActivity.this, documentFile);
36-
} catch (Exception e) {
37-
e.printStackTrace();
38-
} finally {
33+
if(documentFile != null){
34+
AndroidZip zip = null;
3935
try {
36+
zip = new AndroidZip(MainActivity.this, documentFile);
37+
4038
List<ZipEntry> entries = zip.entries();
4139
long e = System.currentTimeMillis();
42-
for (int i = 0; i < entries.size(); ++i) {
40+
for (int i = 0; entries != null && i < entries.size(); ++i) {
4341
ZipEntry zipEntry = entries.get(i);
4442
if (!zipEntry.isDirectory()) {
4543
Log.d(

0 commit comments

Comments
 (0)