Skip to content

Commit

Permalink
Fixed error opening file. Improved file renaming. Fixed folder copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciotogneri committed Oct 1, 2016
1 parent 6749401 commit 1c1ea4e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -255,7 +259,17 @@ private void openFile(FileInfo fileInfo)
intent.setDataAndType(fileInfo.uri(), fileInfo.mimeType());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);
PackageManager manager = getContext().getPackageManager();
List<ResolveInfo> resolveInfo = manager.queryIntentActivities(intent, 0);

if (resolveInfo.size() > 0)
{
startActivity(intent);
}
else
{
Toast.makeText(getContext(), R.string.open_unable, Toast.LENGTH_SHORT).show();
}
}

public void onCut()
Expand Down Expand Up @@ -348,12 +362,41 @@ public void onClick(DialogInterface dialogInterface, int i)

nameField.setText(fileInfo.name());
nameField.requestFocus();
nameField.selectAll();

int dotIndex = fileInfo.name().lastIndexOf(".");

if (dotIndex != -1)
{
nameField.setSelection(0, dotIndex);
}
else
{
nameField.selectAll();
}

nameField.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}

@Override
public void afterTextChanged(Editable text)
{
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(text.length() != 0);
}
});

nameField.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
public boolean onEditorAction(TextView view, int actionId, KeyEvent event)
{
if (actionId == EditorInfo.IME_ACTION_DONE)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ public boolean paste(FileInfo target)
{
for (FileInfo fileInfo : items)
{
allPasted &= fileInfo.copy(target);

if (mode == Mode.CUT)
{
fileInfo.delete();
}
allPasted &= fileInfo.copy(target, mode == Mode.CUT);
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean rename(String newName)
return !newFile.exists() && file.renameTo(newFile);
}

public boolean copy(FileInfo target)
public boolean copy(FileInfo target, boolean delete)
{
if (isDirectory())
{
Expand All @@ -80,16 +80,29 @@ public boolean copy(FileInfo target)
if (currentFile != null)
{
FileInfo fileInfo = new FileInfo(currentFile);
File newTarget = new File(target.file, file.getName());

allCopied &= fileInfo.copy(target);
allCopied &= (newTarget.exists() || newTarget.mkdirs()) && fileInfo.copy(new FileInfo(newTarget), delete);
}
}

if (delete && allCopied)
{
delete();
}

return allCopied;
}
else
{
return copy(file, target.file);
boolean copied = copy(file, target.file);

if (delete && copied)
{
delete();
}

return copied;
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/dialog_rename.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:textColor="@color/gray2"/>
android:textColor="@color/gray1"
android:textColorHighlight="@color/gray4"/>

</LinearLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

<string name="rename.error">Error renaming</string>

<string name="open.unable">Cannot open file</string>

<string name="clipboard.cut">Moving…</string>
<string name="clipboard.copy">Copying…</string>

<string name="delete.confirm">Do you want to delete the selected items?</string>
<string name="delete.confirm">Delete selected items?</string>
<string name="delete.deleting">Deleting…</string>
<string name="delete.error">Error deleting</string>

Expand Down

0 comments on commit 1c1ea4e

Please sign in to comment.