mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-29 16:08:00 +01:00
do not close the renaming dialog if it failed
This commit is contained in:
parent
f626ee1843
commit
50bf296f89
1 changed files with 24 additions and 18 deletions
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.activities;
|
package com.simplemobiletools.gallery.activities;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -20,12 +19,11 @@ import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.simplemobiletools.gallery.Constants;
|
import com.simplemobiletools.gallery.Constants;
|
||||||
import com.simplemobiletools.gallery.Utils;
|
|
||||||
import com.simplemobiletools.gallery.MyViewPager;
|
import com.simplemobiletools.gallery.MyViewPager;
|
||||||
import com.simplemobiletools.gallery.R;
|
import com.simplemobiletools.gallery.R;
|
||||||
|
import com.simplemobiletools.gallery.Utils;
|
||||||
import com.simplemobiletools.gallery.adapters.MyPagerAdapter;
|
import com.simplemobiletools.gallery.adapters.MyPagerAdapter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -182,31 +180,39 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
final EditText extensionET = (EditText) renameFileView.findViewById(R.id.extension);
|
final EditText extensionET = (EditText) renameFileView.findViewById(R.id.extension);
|
||||||
extensionET.setText(extension);
|
extensionET.setText(extension);
|
||||||
|
|
||||||
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
alertDialog.setTitle(getResources().getString(R.string.rename_file));
|
builder.setTitle(getResources().getString(R.string.rename_file));
|
||||||
alertDialog.setView(renameFileView);
|
builder.setView(renameFileView);
|
||||||
|
|
||||||
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
builder.setPositiveButton("OK", null);
|
||||||
|
builder.setNegativeButton("Cancel", null);
|
||||||
|
|
||||||
|
final AlertDialog alertDialog = builder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(View v) {
|
||||||
final String fileName = fileNameET.getText().toString().trim();
|
final String fileName = fileNameET.getText().toString().trim();
|
||||||
final String extension = extensionET.getText().toString().trim();
|
final String extension = extensionET.getText().toString().trim();
|
||||||
final File newFile = new File(file.getParent(), fileName + "." + extension);
|
|
||||||
|
|
||||||
if (!fileName.isEmpty() && !extension.isEmpty() && file.renameTo(newFile)) {
|
if (!fileName.isEmpty() && !extension.isEmpty()) {
|
||||||
photos.set(pager.getCurrentItem(), newFile.getAbsolutePath());
|
final File newFile = new File(file.getParent(), fileName + "." + extension);
|
||||||
|
|
||||||
final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
|
if (file.renameTo(newFile)) {
|
||||||
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
|
photos.set(pager.getCurrentItem(), newFile.getAbsolutePath());
|
||||||
updateActionbarTitle();
|
|
||||||
|
final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
|
||||||
|
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
|
||||||
|
updateActionbarTitle();
|
||||||
|
alertDialog.dismiss();
|
||||||
|
} else {
|
||||||
|
Utils.showToast(getApplicationContext(), R.string.rename_file_error);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.rename_file_error), Toast.LENGTH_SHORT).show();
|
Utils.showToast(getApplicationContext(), R.string.rename_file_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
alertDialog.setNegativeButton("Cancel", null);
|
|
||||||
alertDialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadViewPager() {
|
private void reloadViewPager() {
|
||||||
|
|
Loading…
Reference in a new issue