Fixed dir settings

This commit is contained in:
David 2016-04-25 08:07:45 -03:00
parent 0156a4f39e
commit 6940021293
6 changed files with 50 additions and 120 deletions

View file

@ -28,6 +28,8 @@ import android.support.annotation.NonNull;
import java.io.File;
import us.shandian.giga.util.Utility;
/**
* Helper for global settings
*/
@ -46,10 +48,34 @@ public class NewPipeSettings {
return getFolder(context, R.string.download_path_key, Environment.DIRECTORY_MOVIES);
}
public static String getVideoDownloadPath(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final String key = context.getString(R.string.download_path_key);
String downloadPath = prefs.getString(key, Environment.DIRECTORY_MOVIES);
return downloadPath;
}
public static File getAudioDownloadFolder(Context context) {
return getFolder(context, R.string.download_path_audio_key, Environment.DIRECTORY_MUSIC);
}
public static String getAudioDownloadPath(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final String key = context.getString(R.string.download_path_audio_key);
String downloadPath = prefs.getString(key, Environment.DIRECTORY_MUSIC);
return downloadPath;
}
public static String getDownloadPath(Context context, String fileName)
{
if(Utility.isVideoFile(fileName)) {
return NewPipeSettings.getVideoDownloadPath(context);
}
return NewPipeSettings.getAudioDownloadPath(context);
}
private static File getFolder(Context context, int keyID, String defaultDirectoryName) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final String key = context.getString(keyID);

View file

@ -28,7 +28,6 @@ import android.widget.Toast;
import org.schabi.newpipe.R;
import org.schabi.newpipe.VideoItemDetailActivity;
import org.schabi.newpipe.VideoItemListActivity;
import java.io.File;
import java.io.IOException;
@ -139,7 +138,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
.replace(R.id.frame, mFragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
private void showUrlDialog() {
@ -297,7 +295,8 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
NavUtils.navigateUpTo(this, intent);
return true;
} else {
return false;
return mFragment.onOptionsItemSelected(item) ||
super.onOptionsItemSelected(item);
}
}