mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
Merge branch 'v/crypto-input-parcel' of github.com:open-keychain/open-keychain into v/crypto-input-parcel
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesFragment.java
This commit is contained in:
commit
19ecd5f427
@ -126,7 +126,7 @@ public class CreateKeyEmailFragment extends Fragment {
|
||||
if (mAdditionalEmailModels == null) {
|
||||
mAdditionalEmailModels = new ArrayList<>();
|
||||
if (mCreateKeyActivity.mAdditionalEmails != null) {
|
||||
setAdditionalEmails(mCreateKeyActivity.mAdditionalEmails);
|
||||
mEmailAdapter.addAll(mCreateKeyActivity.mAdditionalEmails);
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,12 +209,6 @@ public class CreateKeyEmailFragment extends Fragment {
|
||||
return emails;
|
||||
}
|
||||
|
||||
private void setAdditionalEmails(ArrayList<String> emails) {
|
||||
for (String email : emails) {
|
||||
mAdditionalEmailModels.add(new EmailAdapter.ViewModel(email));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -244,8 +238,7 @@ public class CreateKeyEmailFragment extends Fragment {
|
||||
// Provide a reference to the views for each data item
|
||||
// Complex data items may need more than one view per item, and
|
||||
// you provide access to all the views for a data item in a view holder
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
// each data item is just a string in this case
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView mTextView;
|
||||
public ImageButton mDeleteButton;
|
||||
|
||||
@ -289,7 +282,10 @@ public class CreateKeyEmailFragment extends Fragment {
|
||||
// Replace the contents of a view (invoked by the layout manager)
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
if (holder instanceof ViewHolder) {
|
||||
if (holder instanceof FooterHolder) {
|
||||
FooterHolder thisHolder = (FooterHolder) holder;
|
||||
thisHolder.mAddButton.setOnClickListener(mFooterOnClickListener);
|
||||
} else if (holder instanceof ViewHolder) {
|
||||
ViewHolder thisHolder = (ViewHolder) holder;
|
||||
// - get element from your dataset at this position
|
||||
// - replace the contents of the view with that element
|
||||
@ -302,9 +298,6 @@ public class CreateKeyEmailFragment extends Fragment {
|
||||
remove(model);
|
||||
}
|
||||
});
|
||||
} else if (holder instanceof FooterHolder) {
|
||||
FooterHolder thisHolder = (FooterHolder) holder;
|
||||
thisHolder.mAddButton.setOnClickListener(mFooterOnClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,6 +325,12 @@ public class CreateKeyEmailFragment extends Fragment {
|
||||
notifyItemInserted(mDataset.size() - 1);
|
||||
}
|
||||
|
||||
private void addAll(ArrayList<String> emails) {
|
||||
for (String email : emails) {
|
||||
mDataset.add(new EmailAdapter.ViewModel(email));
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(ViewModel model) {
|
||||
int position = mDataset.indexOf(model);
|
||||
mDataset.remove(position);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2014-2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -17,7 +17,6 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
@ -28,15 +27,17 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
@ -50,6 +51,7 @@ import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.SpacesItemDecoration;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
@ -61,9 +63,8 @@ import org.sufficientlysecure.keychain.util.ShareHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
@ -93,12 +94,12 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
private long mSigningKeyId = Constants.key.none;
|
||||
private Passphrase mPassphrase = new Passphrase();
|
||||
|
||||
private ArrayList<Uri> mInputUris = new ArrayList<>();
|
||||
private ArrayList<Uri> mOutputUris = new ArrayList<>();
|
||||
|
||||
private ListView mSelectedFiles;
|
||||
private SelectedFilesAdapter mAdapter = new SelectedFilesAdapter();
|
||||
private final Map<Uri, Bitmap> thumbnailCache = new HashMap<>();
|
||||
private RecyclerView mSelectedFiles;
|
||||
|
||||
ArrayList<FilesAdapter.ViewModel> mFilesModels;
|
||||
FilesAdapter mFilesAdapter;
|
||||
|
||||
/**
|
||||
* Creates new instance of this fragment
|
||||
@ -146,17 +147,28 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.encrypt_files_fragment, container, false);
|
||||
mSelectedFiles = (RecyclerView) view.findViewById(R.id.selected_files_list);
|
||||
|
||||
View addView = inflater.inflate(R.layout.file_list_entry_add, null);
|
||||
addView.setOnClickListener(new View.OnClickListener() {
|
||||
mSelectedFiles.addItemDecoration(new SpacesItemDecoration(
|
||||
FormattingUtils.dpToPx(getActivity(), 4)));
|
||||
mSelectedFiles.setHasFixedSize(true);
|
||||
mSelectedFiles.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mSelectedFiles.setItemAnimator(new DefaultItemAnimator());
|
||||
|
||||
mFilesModels = new ArrayList<>();
|
||||
mFilesAdapter = new FilesAdapter(getActivity(), mFilesModels, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
addInputUri();
|
||||
}
|
||||
});
|
||||
mSelectedFiles = (ListView) view.findViewById(R.id.selected_files_list);
|
||||
mSelectedFiles.addFooterView(addView);
|
||||
mSelectedFiles.setAdapter(mAdapter);
|
||||
|
||||
ArrayList<Uri> inputUris = getArguments().getParcelableArrayList(ARG_URIS);
|
||||
if (inputUris != null) {
|
||||
mFilesAdapter.addAll(inputUris);
|
||||
}
|
||||
mUseArmor = getArguments().getBoolean(ARG_USE_ASCII_ARMOR);
|
||||
mSelectedFiles.setAdapter(mFilesAdapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
@ -165,17 +177,14 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
mInputUris = getArguments().getParcelableArrayList(ARG_URIS);
|
||||
mUseArmor = getArguments().getBoolean(ARG_USE_ASCII_ARMOR);
|
||||
}
|
||||
|
||||
private void addInputUri() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
FileHelper.openDocument(EncryptFilesFragment.this, "*/*", true, REQUEST_CODE_INPUT);
|
||||
} else {
|
||||
FileHelper.openFile(EncryptFilesFragment.this, mInputUris.isEmpty() ?
|
||||
null : mInputUris.get(mInputUris.size() - 1),
|
||||
FileHelper.openFile(EncryptFilesFragment.this, mFilesModels.isEmpty() ?
|
||||
null : mFilesModels.get(mFilesModels.size() - 1).inputUri,
|
||||
"*/*", REQUEST_CODE_INPUT);
|
||||
}
|
||||
}
|
||||
@ -185,32 +194,27 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mInputUris.contains(inputUri)) {
|
||||
if (mFilesAdapter.getAsArrayList().contains(inputUri)) {
|
||||
Notify.create(getActivity(),
|
||||
getActivity().getString(R.string.error_file_added_already, FileHelper.getFilename(getActivity(), inputUri)),
|
||||
Notify.Style.ERROR).show();
|
||||
return;
|
||||
}
|
||||
|
||||
mInputUris.add(inputUri);
|
||||
mSelectedFiles.requestFocus();
|
||||
}
|
||||
|
||||
private void delInputUri(int position) {
|
||||
mInputUris.remove(position);
|
||||
mFilesAdapter.add(inputUri);
|
||||
mSelectedFiles.requestFocus();
|
||||
}
|
||||
|
||||
private void showOutputFileDialog() {
|
||||
if (mInputUris.size() > 1 || mInputUris.isEmpty()) {
|
||||
if (mFilesModels.size() > 1 || mFilesModels.isEmpty()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
Uri inputUri = mInputUris.get(0);
|
||||
FilesAdapter.ViewModel model = mFilesModels.get(0);
|
||||
String targetName =
|
||||
(mEncryptFilenames ? "1" : FileHelper.getFilename(getActivity(), inputUri))
|
||||
(mEncryptFilenames ? "1" : FileHelper.getFilename(getActivity(), model.inputUri))
|
||||
+ (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
File file = new File(inputUri.getPath());
|
||||
File file = new File(model.inputUri.getPath());
|
||||
File parentDir = file.exists() ? file.getParentFile() : Constants.Path.APP_DIR;
|
||||
File targetFile = new File(parentDir, targetName);
|
||||
FileHelper.saveFile(this, getString(R.string.title_encrypt_to_file),
|
||||
@ -221,40 +225,48 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
}
|
||||
|
||||
private void encryptClicked(boolean share) {
|
||||
if (mInputUris.isEmpty()) {
|
||||
Notify.create(getActivity(), R.string.error_no_file_selected, Notify.Style.ERROR).show();
|
||||
if (mFilesModels.isEmpty()) {
|
||||
Notify.create(getActivity(), R.string.error_no_file_selected,
|
||||
Notify.Style.ERROR).show();
|
||||
return;
|
||||
}
|
||||
if (share) {
|
||||
mOutputUris.clear();
|
||||
int filenameCounter = 1;
|
||||
for (Uri uri : mInputUris) {
|
||||
for (FilesAdapter.ViewModel model : mFilesModels) {
|
||||
String targetName =
|
||||
(mEncryptFilenames ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), uri))
|
||||
(mEncryptFilenames ? String.valueOf(filenameCounter) : FileHelper.getFilename(getActivity(), model.inputUri))
|
||||
+ (mUseArmor ? Constants.FILE_EXTENSION_ASC : Constants.FILE_EXTENSION_PGP_MAIN);
|
||||
mOutputUris.add(TemporaryStorageProvider.createFile(getActivity(), targetName));
|
||||
filenameCounter++;
|
||||
}
|
||||
startEncrypt(true);
|
||||
} else {
|
||||
if (mInputUris.size() > 1) {
|
||||
Notify.create(getActivity(), R.string.error_multi_not_supported, Notify.Style.ERROR).show();
|
||||
if (mFilesModels.size() > 1) {
|
||||
Notify.create(getActivity(), R.string.error_multi_not_supported,
|
||||
Notify.Style.ERROR).show();
|
||||
return;
|
||||
}
|
||||
showOutputFileDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public boolean handleClipData(Intent data) {
|
||||
if (data.getClipData() != null && data.getClipData().getItemCount() > 0) {
|
||||
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
|
||||
Uri uri = data.getClipData().getItemAt(i).getUri();
|
||||
if (uri != null) addInputUri(uri);
|
||||
public void addFile(Intent data) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
addInputUri(data.getData());
|
||||
} else {
|
||||
if (data.getClipData() != null && data.getClipData().getItemCount() > 0) {
|
||||
for (int i = 0; i < data.getClipData().getItemCount(); i++) {
|
||||
Uri uri = data.getClipData().getItemAt(i).getUri();
|
||||
if (uri != null) {
|
||||
addInputUri(uri);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// fallback, try old method to get single uri
|
||||
addInputUri(data.getData());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -284,22 +296,18 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
}
|
||||
case R.id.check_use_armor: {
|
||||
mUseArmor = item.isChecked();
|
||||
// notifyUpdate();
|
||||
break;
|
||||
}
|
||||
case R.id.check_delete_after_encrypt: {
|
||||
mDeleteAfterEncrypt = item.isChecked();
|
||||
// notifyUpdate();
|
||||
break;
|
||||
}
|
||||
case R.id.check_enable_compression: {
|
||||
mUseCompression = item.isChecked();
|
||||
// onNotifyUpdate();
|
||||
break;
|
||||
}
|
||||
case R.id.check_encrypt_filenames: {
|
||||
mEncryptFilenames = item.isChecked();
|
||||
// onNotifyUpdate();
|
||||
break;
|
||||
}
|
||||
// case R.id.check_hidden_recipients: {
|
||||
@ -317,15 +325,15 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
protected boolean inputIsValid() {
|
||||
// file checks
|
||||
|
||||
if (mInputUris.isEmpty()) {
|
||||
if (mFilesModels.isEmpty()) {
|
||||
Notify.create(getActivity(), R.string.no_file_selected, Notify.Style.ERROR)
|
||||
.show();
|
||||
return false;
|
||||
} else if (mInputUris.size() > 1 && !mShareAfterEncrypt) {
|
||||
} else if (mFilesModels.size() > 1 && !mShareAfterEncrypt) {
|
||||
Log.e(Constants.TAG, "Aborting: mInputUris.size() > 1 && !mShareAfterEncrypt");
|
||||
// This should be impossible...
|
||||
return false;
|
||||
} else if (mInputUris.size() != mOutputUris.size()) {
|
||||
} else if (mFilesModels.size() != mOutputUris.size()) {
|
||||
Log.e(Constants.TAG, "Aborting: mInputUris.size() != mOutputUris.size()");
|
||||
// This as well
|
||||
return false;
|
||||
@ -363,8 +371,8 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
|
||||
public void onEncryptSuccess(final SignEncryptResult result) {
|
||||
if (mDeleteAfterEncrypt) {
|
||||
final Uri[] inputUris = mInputUris.toArray(new Uri[mInputUris.size()]);
|
||||
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(inputUris);
|
||||
DeleteFileDialogFragment deleteFileDialog =
|
||||
DeleteFileDialogFragment.newInstance(mFilesAdapter.getAsArrayList());
|
||||
deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {
|
||||
|
||||
@Override
|
||||
@ -381,8 +389,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
});
|
||||
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
||||
|
||||
mInputUris.clear();
|
||||
onNotifyUpdate();
|
||||
mFilesModels.clear();
|
||||
} else {
|
||||
if (mShareAfterEncrypt) {
|
||||
// Share encrypted message/file
|
||||
@ -398,7 +405,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
// fill values for this action
|
||||
SignEncryptParcel data = new SignEncryptParcel();
|
||||
|
||||
data.addInputUris(mInputUris);
|
||||
data.addInputUris(mFilesAdapter.getAsArrayList());
|
||||
data.addOutputUris(mOutputUris);
|
||||
|
||||
if (mUseCompression) {
|
||||
@ -536,9 +543,7 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_INPUT: {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || !handleClipData(data)) {
|
||||
addInputUri(data.getData());
|
||||
}
|
||||
addFile(data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -547,7 +552,6 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
mOutputUris.clear();
|
||||
mOutputUris.add(data.getData());
|
||||
onNotifyUpdate();
|
||||
startEncrypt(false);
|
||||
}
|
||||
return;
|
||||
@ -561,66 +565,167 @@ public class EncryptFilesFragment extends CryptoOperationFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void onNotifyUpdate() {
|
||||
// Clear cache if needed
|
||||
for (Uri uri : new HashSet<>(thumbnailCache.keySet())) {
|
||||
if (!mInputUris.contains(uri)) {
|
||||
thumbnailCache.remove(uri);
|
||||
public static class FilesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private Activity mActivity;
|
||||
private List<ViewModel> mDataset;
|
||||
private View.OnClickListener mFooterOnClickListener;
|
||||
private static final int TYPE_FOOTER = 0;
|
||||
private static final int TYPE_ITEM = 1;
|
||||
|
||||
public static class ViewModel {
|
||||
Uri inputUri;
|
||||
Bitmap thumbnail;
|
||||
String filename;
|
||||
long fileSize;
|
||||
|
||||
ViewModel(Uri inputUri, Bitmap thumbnail, String filename, long fileSize) {
|
||||
this.inputUri = inputUri;
|
||||
this.thumbnail = thumbnail;
|
||||
this.filename = filename;
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return inputUri.toString();
|
||||
}
|
||||
}
|
||||
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
// Provide a reference to the views for each data item
|
||||
// Complex data items may need more than one view per item, and
|
||||
// you provide access to all the views for a data item in a view holder
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView filename;
|
||||
public TextView fileSize;
|
||||
public View removeButton;
|
||||
public ImageView thumbnail;
|
||||
|
||||
private class SelectedFilesAdapter extends BaseAdapter {
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mInputUris.size();
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
filename = (TextView) itemView.findViewById(R.id.filename);
|
||||
fileSize = (TextView) itemView.findViewById(R.id.filesize);
|
||||
removeButton = itemView.findViewById(R.id.action_remove_file_from_list);
|
||||
thumbnail = (ImageView) itemView.findViewById(R.id.thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mInputUris.get(position);
|
||||
class FooterHolder extends RecyclerView.ViewHolder {
|
||||
public Button mAddButton;
|
||||
|
||||
public FooterHolder(View itemView) {
|
||||
super(itemView);
|
||||
mAddButton = (Button) itemView.findViewById(R.id.file_list_entry_add);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return getItem(position).hashCode();
|
||||
// Provide a suitable constructor (depends on the kind of dataset)
|
||||
public FilesAdapter(Activity activity, List<ViewModel> myDataset, View.OnClickListener onFooterClickListener) {
|
||||
mActivity = activity;
|
||||
mDataset = myDataset;
|
||||
mFooterOnClickListener = onFooterClickListener;
|
||||
}
|
||||
|
||||
// Create new views (invoked by the layout manager)
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
Uri inputUri = mInputUris.get(position);
|
||||
View view;
|
||||
if (convertView == null) {
|
||||
view = getActivity().getLayoutInflater().inflate(R.layout.file_list_entry, null);
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == TYPE_FOOTER) {
|
||||
View v = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.file_list_entry_add, parent, false);
|
||||
return new FooterHolder(v);
|
||||
} else {
|
||||
view = convertView;
|
||||
//inflate your layout and pass it to view holder
|
||||
View v = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.file_list_entry, parent, false);
|
||||
return new ViewHolder(v);
|
||||
}
|
||||
((TextView) view.findViewById(R.id.filename)).setText(FileHelper.getFilename(getActivity(), inputUri));
|
||||
long size = FileHelper.getFileSize(getActivity(), inputUri);
|
||||
if (size == -1) {
|
||||
((TextView) view.findViewById(R.id.filesize)).setText("");
|
||||
} else {
|
||||
((TextView) view.findViewById(R.id.filesize)).setText(FileHelper.readableFileSize(size));
|
||||
}
|
||||
view.findViewById(R.id.action_remove_file_from_list).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
delInputUri(position);
|
||||
}
|
||||
|
||||
// Replace the contents of a view (invoked by the layout manager)
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
if (holder instanceof FooterHolder) {
|
||||
FooterHolder thisHolder = (FooterHolder) holder;
|
||||
thisHolder.mAddButton.setOnClickListener(mFooterOnClickListener);
|
||||
} else if (holder instanceof ViewHolder) {
|
||||
ViewHolder thisHolder = (ViewHolder) holder;
|
||||
// - get element from your dataset at this position
|
||||
// - replace the contents of the view with that element
|
||||
final ViewModel model = mDataset.get(position);
|
||||
|
||||
thisHolder.filename.setText(model.filename);
|
||||
if (model.fileSize == -1) {
|
||||
thisHolder.fileSize.setText("");
|
||||
} else {
|
||||
thisHolder.fileSize.setText(FileHelper.readableFileSize(model.fileSize));
|
||||
}
|
||||
thisHolder.removeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
remove(model);
|
||||
}
|
||||
});
|
||||
if (model.thumbnail != null) {
|
||||
thisHolder.thumbnail.setImageBitmap(model.thumbnail);
|
||||
} else {
|
||||
thisHolder.thumbnail.setImageResource(R.drawable.ic_doc_generic_am);
|
||||
}
|
||||
});
|
||||
int px = FormattingUtils.dpToPx(getActivity(), 48);
|
||||
if (!thumbnailCache.containsKey(inputUri)) {
|
||||
thumbnailCache.put(inputUri, FileHelper.getThumbnail(getActivity(), inputUri, new Point(px, px)));
|
||||
}
|
||||
Bitmap bitmap = thumbnailCache.get(inputUri);
|
||||
if (bitmap != null) {
|
||||
((ImageView) view.findViewById(R.id.thumbnail)).setImageBitmap(bitmap);
|
||||
} else {
|
||||
((ImageView) view.findViewById(R.id.thumbnail)).setImageResource(R.drawable.ic_doc_generic_am);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
// Return the size of your dataset (invoked by the layout manager)
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataset.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (isPositionFooter(position)) {
|
||||
return TYPE_FOOTER;
|
||||
} else {
|
||||
return TYPE_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPositionFooter(int position) {
|
||||
return position == mDataset.size();
|
||||
}
|
||||
|
||||
public void add(Uri inputUri) {
|
||||
mDataset.add(createModel(inputUri));
|
||||
notifyItemInserted(mDataset.size() - 1);
|
||||
}
|
||||
|
||||
public void addAll(ArrayList<Uri> inputUris) {
|
||||
if (inputUris != null) {
|
||||
for (Uri inputUri : inputUris) {
|
||||
mDataset.add(createModel(inputUri));
|
||||
}
|
||||
}
|
||||
// TODO: notifyItemInserted?
|
||||
}
|
||||
|
||||
private ViewModel createModel(Uri inputUri) {
|
||||
int px = FormattingUtils.dpToPx(mActivity, 48);
|
||||
Bitmap thumbnail = FileHelper.getThumbnail(mActivity, inputUri, new Point(px, px));
|
||||
String filename = FileHelper.getFilename(mActivity, inputUri);
|
||||
long size = FileHelper.getFileSize(mActivity, inputUri);
|
||||
return new ViewModel(inputUri, thumbnail, filename, size);
|
||||
}
|
||||
|
||||
public void remove(ViewModel model) {
|
||||
int position = mDataset.indexOf(model);
|
||||
mDataset.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
|
||||
public ArrayList<Uri> getAsArrayList() {
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
for (ViewModel model : mDataset) {
|
||||
uris.add(model.inputUri);
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class EncryptModeAsymmetricFragment extends Fragment {
|
||||
private IAsymmetric mEncryptInterface;
|
||||
|
||||
// @Override
|
||||
// public void onNotifyUpdate() {
|
||||
// public void updateUi() {
|
||||
// if (mSign != null) {
|
||||
// mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey());
|
||||
// }
|
||||
|
@ -147,6 +147,8 @@ public class KeyAdapter extends CursorAdapter {
|
||||
mStatus.setVisibility(View.GONE);
|
||||
if (mSlingerButton.hasOnClickListeners()) {
|
||||
mSlinger.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mSlinger.setVisibility(View.GONE);
|
||||
}
|
||||
mMainUserId.setTextColor(context.getResources().getColor(R.color.black));
|
||||
mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.black));
|
||||
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.adapter;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* https://gist.github.com/yrom/3b4bcbc2370ca2290434
|
||||
*/
|
||||
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private int space;
|
||||
private int spanCount;
|
||||
private int lastItemInFirstLane = -1;
|
||||
|
||||
public SpacesItemDecoration(int space) {
|
||||
this(space, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param space
|
||||
* @param spanCount spans count of one lane
|
||||
*/
|
||||
public SpacesItemDecoration(int space, int spanCount) {
|
||||
this.space = space;
|
||||
this.spanCount = spanCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
|
||||
final int position = params.getViewPosition();
|
||||
final int spanSize;
|
||||
final int index;
|
||||
if (params instanceof GridLayoutManager.LayoutParams) {
|
||||
GridLayoutManager.LayoutParams gridParams = (GridLayoutManager.LayoutParams) params;
|
||||
spanSize = gridParams.getSpanSize();
|
||||
index = gridParams.getSpanIndex();
|
||||
} else {
|
||||
spanSize = 1;
|
||||
index = position % spanCount;
|
||||
}
|
||||
// invalid value
|
||||
if (spanSize < 1 || index < 0) return;
|
||||
|
||||
if (spanSize == spanCount) { // full span
|
||||
outRect.left = space;
|
||||
outRect.right = space;
|
||||
} else {
|
||||
if (index == 0) { // left one
|
||||
outRect.left = space;
|
||||
}
|
||||
// spanCount >= 1
|
||||
if (index == spanCount - 1) { // right one
|
||||
outRect.right = space;
|
||||
}
|
||||
if (outRect.left == 0) {
|
||||
outRect.left = space / 2;
|
||||
}
|
||||
if (outRect.right == 0) {
|
||||
outRect.right = space / 2;
|
||||
}
|
||||
}
|
||||
// set top to all in first lane
|
||||
if (position < spanCount && spanSize <= spanCount) {
|
||||
if (lastItemInFirstLane < 0) { // lay out at first time
|
||||
lastItemInFirstLane = position + spanSize == spanCount ? position : lastItemInFirstLane;
|
||||
outRect.top = space;
|
||||
} else if (position <= lastItemInFirstLane) { // scroll to first lane again
|
||||
outRect.top = space;
|
||||
}
|
||||
}
|
||||
outRect.bottom = space;
|
||||
|
||||
}
|
||||
}
|
@ -44,11 +44,24 @@ public class DeleteFileDialogFragment extends DialogFragment {
|
||||
/**
|
||||
* Creates new instance of this delete file dialog fragment
|
||||
*/
|
||||
public static DeleteFileDialogFragment newInstance(Uri... deleteUris) {
|
||||
public static DeleteFileDialogFragment newInstance(ArrayList<Uri> deleteUris) {
|
||||
DeleteFileDialogFragment frag = new DeleteFileDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
|
||||
args.putParcelableArray(ARG_DELETE_URIS, deleteUris);
|
||||
args.putParcelableArrayList(ARG_DELETE_URIS, deleteUris);
|
||||
|
||||
frag.setArguments(args);
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
public static DeleteFileDialogFragment newInstance(Uri deleteUri) {
|
||||
DeleteFileDialogFragment frag = new DeleteFileDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
|
||||
ArrayList<Uri> list = new ArrayList<>();
|
||||
list.add(deleteUri);
|
||||
args.putParcelableArrayList(ARG_DELETE_URIS, list);
|
||||
|
||||
frag.setArguments(args);
|
||||
|
||||
@ -62,7 +75,7 @@ public class DeleteFileDialogFragment extends DialogFragment {
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final FragmentActivity activity = getActivity();
|
||||
|
||||
final Uri[] deleteUris = (Uri[]) getArguments().getParcelableArray(ARG_DELETE_URIS);
|
||||
final ArrayList<Uri> deleteUris = getArguments().getParcelableArrayList(ARG_DELETE_URIS);
|
||||
|
||||
final StringBuilder deleteFileNames = new StringBuilder();
|
||||
//Retrieving file names after deletion gives unexpected results
|
||||
@ -127,7 +140,7 @@ public class DeleteFileDialogFragment extends DialogFragment {
|
||||
// NOTE: Use Toasts, not Snackbars. When sharing to another application snackbars
|
||||
// would not show up!
|
||||
Toast.makeText(getActivity(), getActivity().getString(R.string.file_delete_successful,
|
||||
deleteUris.length - failedFileNameList.size(), deleteUris.length, failedFileNames.toString()),
|
||||
deleteUris.size() - failedFileNameList.size(), deleteUris.size(), failedFileNames.toString()),
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
if (onDeletedListener != null) {
|
||||
|
@ -4,15 +4,11 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ListView
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/selected_files_list"
|
||||
android:dividerHeight="4dip"
|
||||
android:divider="@android:color/transparent"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
|
@ -1,60 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dip"
|
||||
android:background="@drawable/attachment_bg_holo">
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dip"
|
||||
android:background="@drawable/attachment_bg_holo">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:scaleType="center"
|
||||
android:layout_width="48dip"
|
||||
android:layout_height="48dip"/>
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:scaleType="center"
|
||||
android:layout_width="48dip"
|
||||
android:layout_height="48dip" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/thumbnail"
|
||||
android:layout_centerVertical="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/filename"
|
||||
android:layout_marginLeft="8dip"
|
||||
android:layout_marginRight="32dip"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/thumbnail"
|
||||
android:layout_centerVertical="true">
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/filename"
|
||||
android:layout_marginLeft="8dip"
|
||||
android:layout_marginRight="32dip"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:ellipsize="end"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/filesize"
|
||||
android:layout_marginLeft="8dip"
|
||||
android:layout_marginRight="32dip"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textSize="12sp"
|
||||
android:ellipsize="end"/>
|
||||
android:id="@+id/filesize"
|
||||
android:layout_marginLeft="8dip"
|
||||
android:layout_marginRight="32dip"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textSize="12sp"
|
||||
android:ellipsize="end" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/action_remove_file_from_list"
|
||||
android:layout_width="48dip"
|
||||
android:layout_height="48dip"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingRight="16dip"
|
||||
android:paddingLeft="16dip"
|
||||
android:src="@drawable/ic_close_grey_24dp"
|
||||
android:clickable="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="?android:selectableItemBackground"/>
|
||||
android:id="@+id/action_remove_file_from_list"
|
||||
android:layout_width="48dip"
|
||||
android:layout_height="48dip"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingRight="16dip"
|
||||
android:paddingLeft="16dip"
|
||||
android:src="@drawable/ic_close_grey_24dp"
|
||||
android:clickable="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="?android:selectableItemBackground" />
|
||||
</RelativeLayout>
|
@ -1,21 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:padding="4dp"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
style="?android:attr/borderlessButtonStyle">
|
||||
android:minHeight="16dp"
|
||||
android:orientation="horizontal"
|
||||
android:singleLine="true">
|
||||
|
||||
<TextView
|
||||
<Button
|
||||
android:id="@+id/file_list_entry_add"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/btn_add_files"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:drawableLeft="@drawable/ic_folder_grey_24dp"
|
||||
android:drawablePadding="8dp"
|
||||
android:gravity="center" />
|
||||
</FrameLayout>
|
||||
android:drawablePadding="16dp"
|
||||
android:gravity="left|center_vertical" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user