Skip to content

Commit

Permalink
Merge pull request #1 from vishalkalra9/lock-image-pdf
Browse files Browse the repository at this point in the history
Lock image pdf
  • Loading branch information
vishalkalra9 authored Aug 2, 2018
2 parents 54243fc + 8f38b14 commit 7be1e9f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.balysv.materialripple.MaterialRippleLayout;
import com.itextpdf.text.pdf.PdfReader;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;

Expand Down Expand Up @@ -90,11 +93,24 @@ public void onBindViewHolder(@NonNull ViewFilesHolder holder, final int pos) {
final int position = holder.getAdapterPosition();
final File file = mFileList.get(position);

boolean isEncrypted = false;
try {
new PdfReader(file.getPath());
} catch (IOException e) {
isEncrypted=true;
}
holder.mFilename.setText(file.getName());
holder.mFilesize.setText(FileUtils.getFormattedSize(file));
holder.mFiledate.setText(getFormattedDate(file));
holder.checkBox.setChecked(mSelectedFiles.contains(position));

if (isEncrypted) {
holder.mEncryptionImage.setImageResource(R.drawable.lock_closed);
holder.mEncryptionImage.setVisibility(View.VISIBLE);
} else {
holder.mEncryptionImage.setVisibility(View.GONE);
}

holder.checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (!mSelectedFiles.contains(position)) {
Expand Down Expand Up @@ -343,6 +359,9 @@ public class ViewFilesHolder extends RecyclerView.ViewHolder {
TextView mFiledate;
@BindView(R.id.fileSize)
TextView mFilesize;
@BindView(R.id.encryptionImage)
ImageView mEncryptionImage;


ViewFilesHolder(View itemView) {
super(itemView);
Expand Down
Binary file added app/src/main/res/drawable-xxxhdpi/lock_closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 24 additions & 7 deletions app/src/main/res/layout/item_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,32 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/fileSize"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:padding="10dp"
android:text="@string/file_size_text"
android:textColor="@color/black_87"
android:textSize="12sp" />
android:orientation="horizontal">

<TextView
android:id="@+id/fileSize"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:maxLines="1"
android:padding="10dp"
android:text="@string/file_size_text"
android:textColor="@color/black_87"
android:textSize="12sp" />

<ImageView
android:id="@+id/encryptionImage"
android:layout_width="20dp"
android:layout_gravity="center_vertical"
android:layout_height="20dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:layout_marginLeft="15dp" />
</LinearLayout>


<TextView
android:id="@+id/fileDate"
Expand Down

0 comments on commit 7be1e9f

Please sign in to comment.