fixed media saved to wrong place

This commit is contained in:
Mariotaku Lee 2015-04-19 02:09:36 +08:00
parent 939f6751ea
commit 86ec5e3f4f
3 changed files with 4 additions and 16 deletions

View File

@ -684,17 +684,13 @@ public final class MediaViewerActivity extends ThemedActionBarActivity implement
final Pair<String, String> urlAndType = mVideoUrlAndType;
final boolean hasVideo = file != null && file.exists() && urlAndType != null;
if (!hasVideo) return;
final String name = file.getName();
final String mimeType = urlAndType.second;
final MimeTypeMap map = MimeTypeMap.getSingleton();
final String extension = map.getExtensionFromMimeType(mimeType);
if (extension == null) return;
final String nameToSave = name.contains(".") ? name : name + "." + extension;
final File pubDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
final File saveDir = new File(pubDir, "Twidere");
final File saveFile = new File(saveDir, nameToSave);
mSaveFileTask = AsyncTaskUtils.executeTask(new SaveFileTask(getActivity(), file, mimeType, saveFile));
mSaveFileTask = AsyncTaskUtils.executeTask(new SaveFileTask(getActivity(), file, mimeType, saveDir));
}
@Override

View File

@ -438,7 +438,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final Bundle args = new Bundle();
args.putLong(EXTRA_ACCOUNT_ID, status.account_id);
args.putLong(EXTRA_STATUS_ID, status.retweet_id > 0 ? status.retweet_id : status.id);
args.putString(EXTRA_SCREEN_NAME, status.user_screen_name);
args.putString(EXTRA_SCREEN_NAME, status.retweet_id > 0 ? status.retweeted_by_screen_name : status.user_screen_name);
if (mRepliesLoaderInitialized) {
getLoaderManager().restartLoader(LOADER_ID_STATUS_REPLIES, args, mRepliesLoaderCallback);
return;

View File

@ -55,16 +55,13 @@ public class SaveFileTask extends AsyncTask<Object, Object, File> implements Con
}
public static SaveFileTask saveImage(final Activity activity, final File source) {
final String name = source.getName();
final String mimeType = Utils.getImageMimeType(source);
final MimeTypeMap map = MimeTypeMap.getSingleton();
final String extension = map.getExtensionFromMimeType(mimeType);
if (extension == null) return null;
final String nameToSave = name.contains(".") ? name : name + "." + extension;
final File pubDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
final File saveDir = new File(pubDir, "Twidere");
final File saveFile = new File(saveDir, nameToSave);
return new SaveFileTask(activity, source, mimeType, saveFile);
return new SaveFileTask(activity, source, mimeType, saveDir);
}
@Override
@ -116,12 +113,7 @@ public class SaveFileTask extends AsyncTask<Object, Object, File> implements Con
if (extension == null) return null;
final String nameToSave = name.contains(".") ? name : name + "." + extension;
if (!destination.isDirectory() && !destination.mkdirs()) return null;
final File saveFile;
if (destination.isDirectory()) {
saveFile = new File(destination, nameToSave);
} else {
saveFile = destination;
}
final File saveFile = new File(destination, nameToSave);
FileUtils.copyFile(source, saveFile);
if (mimeType != null) {
MediaScannerConnection.scanFile(context, new String[]{saveFile.getPath()},