fixes acording to code review

fixes moreacording to code review

fixed link handling once more
This commit is contained in:
Christian Schabesberger 2018-08-24 17:42:35 +02:00
parent 2003f51d49
commit b1429366da
7 changed files with 23 additions and 22 deletions

View file

@ -71,7 +71,7 @@ public class NewPipeSettings {
}
public static File getVideoDownloadFolder(Context context) {
return getFolder(context, R.string.download_path_key, Environment.DIRECTORY_MOVIES);
return getDir(context, R.string.download_path_key, Environment.DIRECTORY_MOVIES);
}
public static String getVideoDownloadPath(Context context) {
@ -81,7 +81,7 @@ public class NewPipeSettings {
}
public static File getAudioDownloadFolder(Context context) {
return getFolder(context, R.string.download_path_audio_key, Environment.DIRECTORY_MUSIC);
return getDir(context, R.string.download_path_audio_key, Environment.DIRECTORY_MUSIC);
}
public static String getAudioDownloadPath(Context context) {
@ -90,21 +90,21 @@ public class NewPipeSettings {
return prefs.getString(key, Environment.DIRECTORY_MUSIC);
}
private static File getFolder(Context context, int keyID, String defaultDirectoryName) {
private static File getDir(Context context, int keyID, String defaultDirectoryName) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final String key = context.getString(keyID);
String downloadPath = prefs.getString(key, null);
if ((downloadPath != null) && (!downloadPath.isEmpty())) return new File(downloadPath.trim());
final File folder = getFolder(defaultDirectoryName);
final File dir = getDir(defaultDirectoryName);
SharedPreferences.Editor spEditor = prefs.edit();
spEditor.putString(key, new File(folder, "NewPipe").getAbsolutePath());
spEditor.putString(key, getNewPipeChildFolderPathForDir(dir));
spEditor.apply();
return folder;
return dir;
}
@NonNull
private static File getFolder(String defaultDirectoryName) {
private static File getDir(String defaultDirectoryName) {
return new File(Environment.getExternalStorageDirectory(), defaultDirectoryName);
}
@ -115,9 +115,12 @@ public class NewPipeSettings {
}
private static void resetDownloadFolder(SharedPreferences prefs, String key, String defaultDirectoryName) {
final File folder = getFolder(defaultDirectoryName);
SharedPreferences.Editor spEditor = prefs.edit();
spEditor.putString(key, new File(folder, "NewPipe").getAbsolutePath());
spEditor.putString(key, getNewPipeChildFolderPathForDir(getDir(defaultDirectoryName)));
spEditor.apply();
}
private static String getNewPipeChildFolderPathForDir(File dir) {
return new File(dir, "NewPipe").getAbsolutePath();
}
}