Skip to content

Commit 4ec5f92

Browse files
committed
bug fixed, it works now
1 parent 879c0c5 commit 4ec5f92

File tree

5 files changed

+55
-17
lines changed

5 files changed

+55
-17
lines changed

app/src/main/java/com/katcom/androidFileVault/FileVault.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import java.util.UUID;
99

1010
public class FileVault {
11-
private static String vaultDirectory = "FileVaultOne";
11+
public static String sVaultDirectory = "FileVaultOne";
1212
private static FileVault sVault;
1313
private List<ProtectedFile> mFiles;
1414
private FileVault(Context context){
1515
// Singleton
1616
File directory = context.getFilesDir();
17-
File vaultFolder = new File(directory, vaultDirectory);
17+
File vaultFolder = new File(directory, sVaultDirectory);
1818

1919
String[] files = vaultFolder.list();
2020

@@ -46,6 +46,6 @@ public ProtectedFile getFile(UUID id){
4646
}
4747

4848
public String getVaultDirectory(){
49-
return vaultDirectory;
49+
return sVaultDirectory;
5050
}
5151
}

app/src/main/java/com/katcom/androidFileVault/Utils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,25 @@ public class Utils {
1717
public static void copyFilesFromAsset(Context context,String source,String target){
1818
AssetManager assets = context.getAssets();
1919
String[] files = null;
20-
target = "/" + target + "/";
20+
target = context.getFilesDir()+"/"+target;
2121

2222
try{
2323
files = assets.list(source);
2424
}catch (IOException ioe){
2525
Log.e(TAG,"Could not list assets",ioe);
2626
}
27+
2728
if(files != null){
2829
InputStream in = null;
2930
OutputStream out = null;
3031

3132
for(String filename :files){
3233
try{
3334
String assetPath = source + "/"+ filename;
34-
String targetPath = "/" + target + "/" + filename;
35+
String targetPath = target + "/" + filename;
3536

3637
in = assets.open(assetPath);
37-
File file = new File(context.getFilesDir()+targetPath);
38+
File file = new File(targetPath);
3839

3940
if(file.exists()){
4041
continue;

app/src/main/java/com/katcom/androidFileVault/VaultFragment.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.katcom.androidFileVault;
22

33
import android.os.Bundle;
4-
import android.os.Handler;
54
import android.support.annotation.NonNull;
65
import android.support.design.widget.NavigationView;
76
import android.support.v4.app.Fragment;
@@ -14,6 +13,7 @@
1413
import android.view.MenuItem;
1514
import android.view.View;
1615
import android.view.ViewGroup;
16+
import android.widget.ImageView;
1717
import android.widget.TextView;
1818

1919
import java.io.File;
@@ -49,17 +49,21 @@ public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
4949
mFileRecyclerView = view.findViewById(R.id.vault_file_recycler_view);
5050
mFileRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
5151

52-
mVault = FileVault.get(getActivity());
53-
File file = new File(this.getContext().getFilesDir() + "/" + mVault.getVaultDirectory());
54-
if(!file.exists()){
55-
file.mkdir();
56-
}
57-
Utils.copyFilesFromAsset(this.getContext(),"sample_files","FileVaultOne");
52+
copySampleFiles();
5853

54+
mVault = FileVault.get(this.getContext());
5955
updateUI();
6056
return view;
6157
}
6258

59+
private void copySampleFiles() {
60+
File file = new File(this.getContext().getFilesDir() + "/" + FileVault.sVaultDirectory);
61+
if(!file.exists()){
62+
file.mkdir();
63+
}
64+
Utils.copyFilesFromAsset(this.getContext(),"sample_files",FileVault.sVaultDirectory);
65+
}
66+
6367
private void updateUI() {
6468
List<ProtectedFile> files = mVault.getFiles();
6569

@@ -83,14 +87,15 @@ public boolean onOptionsItemSelected(MenuItem item){
8387

8488
private class FileHolder extends RecyclerView.ViewHolder{
8589
public TextView mFileTextView;
86-
8790
public FileHolder(@NonNull View itemView) {
8891
super(itemView);
89-
mFileTextView = (TextView) itemView;
92+
mFileTextView = (TextView) itemView.findViewById(R.id.file_preview_filename_name_text_view);
93+
9094
}
9195
}
9296
private class FileAdapter extends RecyclerView.Adapter<FileHolder>{
9397
private List<ProtectedFile> mFiles;
98+
9499
public FileAdapter(List<ProtectedFile> files){
95100
mFiles = files;
96101
}
@@ -99,7 +104,7 @@ public FileAdapter(List<ProtectedFile> files){
99104
public FileHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
100105
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
101106
View view = layoutInflater
102-
.inflate(android.R.layout.simple_list_item_1,parent,false);
107+
.inflate(R.layout.item_file_preview_filename,parent,false);
103108

104109
return new FileHolder(view);
105110
}
@@ -108,7 +113,6 @@ public FileHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
108113
public void onBindViewHolder(@NonNull FileHolder fileHolder, int position) {
109114
ProtectedFile file = mFiles.get(position);
110115
fileHolder.mFileTextView.setText(file.getFilename());
111-
112116
}
113117

114118
@Override
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content">
6+
7+
<TextView
8+
android:id="@+id/file_preview_filename_name_text_view"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:text="TextView" />
12+
</LinearLayout>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="200dp"
6+
android:layout_height="200dp"
7+
android:orientation="vertical"
8+
android:gravity="center">
9+
10+
<ImageView
11+
android:id="@+id/file_preview_image_view"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:src="@drawable/ic_launcher_background"/>
15+
<TextView
16+
android:id="@+id/file_preview_filename_text_view"
17+
android:layout_below="@id/file_preview_image_view"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:text="sample"/>
21+
</LinearLayout>

0 commit comments

Comments
 (0)