@Override public void detailFragmentClick(int position) { Log.d(thisClass, position + " is choose"); ArrayList<UIFileInfo> children = UIFileInfo.addFileFrom(currentSelectedDir()); if (children != null) { if (position >= children.size()) { throw new RuntimeException("position < childrenCache.get(fatherIndex).size()"); } } else { throw new RuntimeException(""); } UIFileInfo UIFileInfo = children.get(position); if (UIFileInfo.isDir()) { folderFragment.clearListView(); folderFragment.addListView(children).notifyDataSetChanged(); updateDetailFileInfo(UIFileInfo.toFile()); } else { // decrypt file and show it FileEncryption fileEncryption; try { fileEncryption = new FileEncryption(UIFileInfo.toFile(), password); } catch (IOException e) { Log.e(thisClass, "can't read file" + e); return; } DecryptedFile decryptedFile; try { if (fileEncryption.largeLinkedSize()) { decryptedFile = fileEncryption.decryptPart(); } else { fileEncryption.decryptAll(true); } } catch (InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException | IOException | UnrecoverableEntryException e) { Log.e(thisClass, " failed: " + e.toString()); } // add file path of to be deleted file delPaths.add(fileEncryption.getEncryptedFilePath()); // start app to view different file // Intent intent = getMyImgIntent(this, fileEncryption); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType( Uri.parse(fileEncryption.getFileUri()), FileUtility.getMimeType(fileEncryption.getLinkedFilePath())); if (IntentUtil.intentSafe(intent, this)) { startActivity(intent); } } }
@Override public void folderFragmentClick(int position) { // TODO: 10/7/15 long time press listener Log.d(thisClass, position + " is choose"); // update chosen index fatherIndex = position; // update detail info ui UIFileInfo UIFileInfo = fatherDirInfos.get(position); updateDetailFileInfo(UIFileInfo.toFile()); }
private void updateDetailFileInfo(File dir) { ArrayList<UIFileInfo> files = UIFileInfo.addFileFrom(dir); // ArrayList<UIFileInfo> files = new ArrayList<>(); // addFileFrom(files, dir); detailFragment.clearListView(); detailFragment.addListView(files).notifyDataSetChanged(currentSelectedDir().getName()); }
@Override public void detailFragmentLongPress(int position) { Log.d(thisClass, position + " is choose"); UIFileInfo UIFileInfo = currentSelectedChildren(position); if (UIFileInfo.isDir()) { } else { FileEncryption fileEncryption; try { fileEncryption = new FileEncryption(UIFileInfo.toFile(), password); } catch (IOException e) { Log.e(thisClass, "can't read file" + e); return; } showMenuDialog(fileEncryption); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_with_fragment); Intent intent = getIntent(); if (password == null) { password = intent.getStringExtra(FirstActivity.PASSWORD); } if (password == null) { showPasswordDialog(); } // set the secretKey for this fragment to encrypt/decrypt fileChooserBL = new FileChooserBL(this); fileChooserBL.createAndInitDir(Category.values(), fatherDirInfos); // Check that the activity is using the layout version with // the fragment_container FrameLayout if (findViewById(R.id.folder_fragment_container) != null && findViewById(R.id.file_fragment_container) != null) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. if (savedInstanceState != null) { return; } folderFragment = FolderFragment.newInstance( fatherDirInfos, R.layout.with_icon, new String[] {UIFileInfo.LOGO, UIFileInfo.NAME}, new int[] {R.id.logo, R.id.desc1}); detailFragment = DetailFileFragment.newInstance( UIFileInfo.addFileFrom(currentSelectedDir()), currentSelectedDir().getName()); // In case this activity was started with special instructions from an // Intent, pass the Intent's extras to the fragment as arguments folderFragment.setArguments(getIntent().getExtras()); detailFragment.setArguments(getIntent().getExtras()); // Add the fragment to the '#fragment_container' FrameLayout FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.folder_fragment_container, folderFragment); fragmentTransaction.add(R.id.file_fragment_container, detailFragment).commit(); } }
private UIFileInfo currentSelectedChildren(int position) { return UIFileInfo.addFileFrom(currentSelectedDir()).get(position); }