diff --git a/api/src/main/java/com/todoroo/andlib/utility/Preferences.java b/api/src/main/java/com/todoroo/andlib/utility/Preferences.java index f1bbc298b..8425a517f 100644 --- a/api/src/main/java/com/todoroo/andlib/utility/Preferences.java +++ b/api/src/main/java/com/todoroo/andlib/utility/Preferences.java @@ -46,15 +46,6 @@ public class Preferences { // --- preference fetching (string) - /** Gets an string value from a string preference. Returns null - * if the value is not set - * @return integer value, or null on error - */ - public static String getStringValue(String key) { - Context context = ContextManager.getContext(); - return getPrefs(context).getString(key, null); - } - /** Gets an integer value from a string preference. Returns null * if the value is not set or not an integer. * diff --git a/astrid/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/astrid/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 7c4359d82..e36d01570 100755 --- a/astrid/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/astrid/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -863,7 +863,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { return; } - File dst = new File(FileUtilities.getAttachmentsDirectory(getActivity()) + File.separator + src.getName()); + File dst = new File(FileUtilities.getAttachmentsDirectory(preferences, getActivity()) + File.separator + src.getName()); try { AndroidUtilities.copyFile(src, dst); } catch (Exception e) { @@ -890,7 +890,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { private void attachImage(Bitmap bitmap) { AtomicReference nameRef = new AtomicReference<>(); - String path = FileUtilities.getNewImageAttachmentPath(getActivity(), nameRef); + String path = FileUtilities.getNewImageAttachmentPath(preferences, getActivity(), nameRef); try { FileOutputStream fos = new FileOutputStream(path); diff --git a/astrid/src/main/java/com/todoroo/astrid/files/AACRecordingActivity.java b/astrid/src/main/java/com/todoroo/astrid/files/AACRecordingActivity.java index 91e9b155a..b82011455 100644 --- a/astrid/src/main/java/com/todoroo/astrid/files/AACRecordingActivity.java +++ b/astrid/src/main/java/com/todoroo/astrid/files/AACRecordingActivity.java @@ -5,7 +5,6 @@ */ package com.todoroo.astrid.files; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; @@ -16,10 +15,14 @@ import com.todoroo.astrid.voice.AACRecorder; import com.todoroo.astrid.voice.AACRecorder.AACRecorderCallbacks; import org.tasks.R; +import org.tasks.injection.InjectingActivity; +import org.tasks.preferences.Preferences; import java.util.concurrent.atomic.AtomicReference; -public class AACRecordingActivity extends Activity implements AACRecorderCallbacks { +import javax.inject.Inject; + +public class AACRecordingActivity extends InjectingActivity implements AACRecorderCallbacks { public static final String RESULT_OUTFILE = "outfile"; //$NON-NLS-1$ public static final String RESULT_FILENAME = "filename"; //$NON-NLS-1$ @@ -29,6 +32,8 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac private AtomicReference nameRef; private String tempFile; + @Inject Preferences preferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -38,7 +43,7 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac setupUi(); nameRef = new AtomicReference<>(); - tempFile = FileUtilities.getNewAudioAttachmentPath(this, nameRef); + tempFile = FileUtilities.getNewAudioAttachmentPath(preferences, this, nameRef); recorder = new AACRecorder(); recorder.setListener(this); diff --git a/astrid/src/main/java/com/todoroo/astrid/files/FileUtilities.java b/astrid/src/main/java/com/todoroo/astrid/files/FileUtilities.java index 147290e4b..56ed09869 100644 --- a/astrid/src/main/java/com/todoroo/astrid/files/FileUtilities.java +++ b/astrid/src/main/java/com/todoroo/astrid/files/FileUtilities.java @@ -9,10 +9,10 @@ import android.content.Context; import android.text.TextUtils; import com.todoroo.andlib.utility.DateUtilities; -import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.data.TaskAttachment; import org.tasks.R; +import org.tasks.preferences.Preferences; import java.io.File; import java.text.SimpleDateFormat; @@ -41,17 +41,17 @@ public class FileUtilities { return new SimpleDateFormat(value).format(date); } - public static String getNewImageAttachmentPath(Context context, AtomicReference nameReference) { - return getNewAttachmentPath(context, R.string.file_prefix_image, ".png", nameReference); //$NON-NLS-1$ + public static String getNewImageAttachmentPath(Preferences preferences, Context context, AtomicReference nameReference) { + return getNewAttachmentPath(preferences, context, R.string.file_prefix_image, ".png", nameReference); //$NON-NLS-1$ } - public static String getNewAudioAttachmentPath(Context context, AtomicReference nameReference) { - return getNewAttachmentPath(context, R.string.file_prefix_voice, ".m4a", nameReference); //$NON-NLS-1$ + public static String getNewAudioAttachmentPath(Preferences preferences, Context context, AtomicReference nameReference) { + return getNewAttachmentPath(preferences, context, R.string.file_prefix_voice, ".m4a", nameReference); //$NON-NLS-1$ } - private static String getNewAttachmentPath(Context context, int prefixId, String extension, AtomicReference nameReference) { + private static String getNewAttachmentPath(Preferences preferences, Context context, int prefixId, String extension, AtomicReference nameReference) { - String dir = getAttachmentsDirectory(context).getAbsolutePath(); + String dir = getAttachmentsDirectory(preferences, context).getAbsolutePath(); String name = getNonCollidingFileName(dir, context.getString(prefixId) + " " + getDateStringForFilename(context, newDate()), extension); @@ -62,9 +62,9 @@ public class FileUtilities { return dir + File.separator + name; } - public static File getAttachmentsDirectory(Context context) { + public static File getAttachmentsDirectory(Preferences preferences, Context context) { File directory = null; - String customDir = Preferences.getStringValue(TaskAttachment.FILES_DIRECTORY_PREF); + String customDir = preferences.getStringValue(TaskAttachment.FILES_DIRECTORY_PREF); if (!TextUtils.isEmpty(customDir)) { directory = new File(customDir); } diff --git a/astrid/src/main/java/org/tasks/injection/ActivityModule.java b/astrid/src/main/java/org/tasks/injection/ActivityModule.java index 1c97c4e48..3ed6fc973 100644 --- a/astrid/src/main/java/org/tasks/injection/ActivityModule.java +++ b/astrid/src/main/java/org/tasks/injection/ActivityModule.java @@ -17,6 +17,7 @@ import com.todoroo.astrid.core.CustomFilterActivity; import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.DefaultsPreferences; import com.todoroo.astrid.core.OldTaskPreferences; +import com.todoroo.astrid.files.AACRecordingActivity; import com.todoroo.astrid.gcal.CalendarAlarmListCreator; import com.todoroo.astrid.gcal.CalendarReminderActivity; import com.todoroo.astrid.gtasks.GtasksFilterExposer; @@ -65,7 +66,8 @@ import dagger.Provides; TagFilterExposer.class, BeastModePreferences.class, DefaultsPreferences.class, - ReminderPreferences.class + ReminderPreferences.class, + AACRecordingActivity.class }) public class ActivityModule {