Move uploader behavior pref to AppPreferences

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2019-03-06 22:45:40 +00:00
parent 599566363e
commit 78833ef911
No known key found for this signature in database
GPG key ID: 98BF5BA2F3BB4D28
3 changed files with 24 additions and 21 deletions

View file

@ -92,6 +92,20 @@ public interface AppPreferences {
boolean isShowMediaScanNotifications();
void setShowMediaScanNotifications(boolean showMediaScanNotification);
/**
* Gets the uploader behavior which the user has set last.
*
* @return uploader behavior the uploader behavior
*/
int getUploaderBehaviour();
/**
* Saves the uploader behavior which the user has set last.
*
* @param uploaderBehaviour the uploader behavior
*/
void setUploaderBehaviour(int uploaderBehaviour);
float getGridColumns();
void setGridColumns(float gridColumns);

View file

@ -439,24 +439,14 @@ public final class PreferenceManager implements AppPreferences {
saveBooleanPreference(context, PREF__AUTO_UPLOAD_SPLIT_OUT, splitOut);
}
/**
* Gets the uploader behavior which the user has set last.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return uploader behavior the uploader behavior
*/
public static int getUploaderBehaviour(Context context) {
return getDefaultSharedPreferences(context).getInt(AUTO_PREF__UPLOADER_BEHAVIOR, 1);
@Override
public int getUploaderBehaviour() {
return preferences.getInt(AUTO_PREF__UPLOADER_BEHAVIOR, 1);
}
/**
* Saves the uploader behavior which the user has set last.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param uploaderBehaviour the uploader behavior
*/
public static void setUploaderBehaviour(Context context, int uploaderBehaviour) {
saveIntPreference(context, AUTO_PREF__UPLOADER_BEHAVIOR, uploaderBehaviour);
@Override
public void setUploaderBehaviour(int uploaderBehaviour) {
preferences.edit().putInt(AUTO_PREF__UPLOADER_BEHAVIOR, uploaderBehaviour).apply();
}
/**

View file

@ -180,7 +180,7 @@ public class UploadFilesActivity extends FileActivity implements
mUploadBtn.getBackground().setColorFilter(ThemeUtils.primaryColor(this, true), PorterDuff.Mode.SRC_ATOP);
mUploadBtn.setOnClickListener(this);
int localBehaviour = PreferenceManager.getUploaderBehaviour(this);
int localBehaviour = preferences.getUploaderBehaviour();
// file upload spinner
mBehaviourSpinner = findViewById(R.id.upload_files_spinner_behaviour);
@ -479,7 +479,7 @@ public class UploadFilesActivity extends FileActivity implements
data.putExtra(EXTRA_CHOSEN_FILES, new String[]{filesToUpload[0]});
setResult(RESULT_OK_AND_MOVE, data);
PreferenceManager.setUploaderBehaviour(getApplicationContext(), FileUploader.LOCAL_BEHAVIOUR_MOVE);
preferences.setUploaderBehaviour(FileUploader.LOCAL_BEHAVIOUR_MOVE);
} else {
data.putExtra(EXTRA_CHOSEN_FILES, mFileListFragment.getCheckedFilePaths());
@ -499,8 +499,7 @@ public class UploadFilesActivity extends FileActivity implements
}
// store behaviour
PreferenceManager.setUploaderBehaviour(getApplicationContext(),
mBehaviourSpinner.getSelectedItemPosition());
preferences.setUploaderBehaviour(mBehaviourSpinner.getSelectedItemPosition());
}
finish();
@ -586,7 +585,7 @@ public class UploadFilesActivity extends FileActivity implements
if (canWriteIntoFolder) {
textView.setText(getString(R.string.uploader_upload_files_behaviour));
int localBehaviour = PreferenceManager.getUploaderBehaviour(this);
int localBehaviour = preferences.getUploaderBehaviour();
mBehaviourSpinner.setSelection(localBehaviour);
} else {
mBehaviourSpinner.setSelection(1);