From f431aeaa566a92a1f35252477f6c3ab7287ce24a Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 12 Jan 2016 11:56:59 -0600 Subject: [PATCH] Rename DeviceInfo to Device --- .../astrid/actfm/ActFmCameraModule.java | 10 ++-- .../astrid/activity/TaskEditFragment.java | 6 +-- .../astrid/reminders/ReminderPreferences.java | 6 +-- .../todoroo/astrid/ui/ReminderControlSet.java | 10 ++-- .../tasks/dialogs/AddAttachmentDialog.java | 8 ++-- .../{DeviceInfo.java => Device.java} | 46 ++++++------------- .../preferences/HelpAndFeedbackActivity.java | 6 +-- 7 files changed, 36 insertions(+), 56 deletions(-) rename src/main/java/org/tasks/preferences/{DeviceInfo.java => Device.java} (81%) diff --git a/src/main/java/com/todoroo/astrid/actfm/ActFmCameraModule.java b/src/main/java/com/todoroo/astrid/actfm/ActFmCameraModule.java index 3e33c1405..a0e862679 100644 --- a/src/main/java/com/todoroo/astrid/actfm/ActFmCameraModule.java +++ b/src/main/java/com/todoroo/astrid/actfm/ActFmCameraModule.java @@ -15,7 +15,7 @@ import com.todoroo.astrid.activity.TaskEditFragment; import org.tasks.R; import org.tasks.activities.CameraActivity; import org.tasks.dialogs.DialogBuilder; -import org.tasks.preferences.DeviceInfo; +import org.tasks.preferences.Device; import java.util.ArrayList; import java.util.List; @@ -25,7 +25,7 @@ import javax.inject.Inject; public class ActFmCameraModule { private final Fragment fragment; - private DeviceInfo deviceInfo; + private Device device; private DialogBuilder dialogBuilder; public interface ClearImageCallback { @@ -33,9 +33,9 @@ public class ActFmCameraModule { } @Inject - public ActFmCameraModule(Fragment fragment, DeviceInfo deviceInfo, DialogBuilder dialogBuilder) { + public ActFmCameraModule(Fragment fragment, Device device, DialogBuilder dialogBuilder) { this.fragment = fragment; - this.deviceInfo = deviceInfo; + this.device = device; this.dialogBuilder = dialogBuilder; } @@ -43,7 +43,7 @@ public class ActFmCameraModule { final List runnables = new ArrayList<>(); List options = new ArrayList<>(); - final boolean cameraAvailable = deviceInfo.hasCamera(); + final boolean cameraAvailable = device.hasCamera(); if (cameraAvailable) { runnables.add(new Runnable() { @Override diff --git a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 4fa34a45e..a4c666bba 100755 --- a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -77,7 +77,7 @@ import org.tasks.location.GeofenceService; import org.tasks.location.PlacePicker; import org.tasks.notifications.NotificationManager; import org.tasks.preferences.ActivityPreferences; -import org.tasks.preferences.DeviceInfo; +import org.tasks.preferences.Device; import org.tasks.preferences.PermissionRequestor; import org.tasks.ui.DeadlineControlSet; import org.tasks.ui.MenuColorizer; @@ -168,7 +168,7 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot @Inject GeofenceService geofenceService; @Inject DialogBuilder dialogBuilder; @Inject PermissionRequestor permissionRequestor; - @Inject DeviceInfo deviceInfo; + @Inject Device device; // --- UI components @@ -313,7 +313,7 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot controlSetMap.put(getString(R.string.TEA_ctrl_notes_pref), notesControlSet); - reminderControlSet = new ReminderControlSet(alarmService, geofenceService, this, permissionRequestor, deviceInfo); + reminderControlSet = new ReminderControlSet(alarmService, geofenceService, this, permissionRequestor, device); controls.add(reminderControlSet); controlSetMap.put(getString(R.string.TEA_ctrl_reminders_pref), reminderControlSet); diff --git a/src/main/java/com/todoroo/astrid/reminders/ReminderPreferences.java b/src/main/java/com/todoroo/astrid/reminders/ReminderPreferences.java index 254a00bf5..88e30667f 100644 --- a/src/main/java/com/todoroo/astrid/reminders/ReminderPreferences.java +++ b/src/main/java/com/todoroo/astrid/reminders/ReminderPreferences.java @@ -18,7 +18,7 @@ import android.preference.PreferenceManager; import org.tasks.R; import org.tasks.activities.TimePickerActivity; import org.tasks.injection.InjectingPreferenceActivity; -import org.tasks.preferences.DeviceInfo; +import org.tasks.preferences.Device; import org.tasks.preferences.PermissionChecker; import org.tasks.preferences.PermissionRequestor; import org.tasks.scheduling.GeofenceSchedulingIntentService; @@ -37,7 +37,7 @@ public class ReminderPreferences extends InjectingPreferenceActivity { private static final int REQUEST_QUIET_END = 10002; private static final int REQUEST_DEFAULT_REMIND = 10003; - @Inject DeviceInfo deviceInfo; + @Inject Device device; @Inject PermissionRequestor permissionRequestor; @Inject PermissionChecker permissionChecker; @@ -75,7 +75,7 @@ public class ReminderPreferences extends InjectingPreferenceActivity { requires(atLeastJellybean(), R.string.p_rmd_notif_actions_enabled, R.string.p_notification_priority); requires(atLeastMarshmallow(), R.string.p_doze_notifications); - requires(deviceInfo.supportsLocationServices(), R.string.geolocation_reminders); + requires(device.supportsLocationServices(), R.string.geolocation_reminders); } private void rescheduleNotificationsOnChange(int... resIds) { diff --git a/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.java b/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.java index 0e2a2f7d8..ad2396c0d 100644 --- a/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.java +++ b/src/main/java/com/todoroo/astrid/ui/ReminderControlSet.java @@ -29,7 +29,7 @@ import org.tasks.activities.DateAndTimePickerActivity; import org.tasks.location.Geofence; import org.tasks.location.GeofenceService; import org.tasks.location.PlacePicker; -import org.tasks.preferences.DeviceInfo; +import org.tasks.preferences.Device; import org.tasks.preferences.PermissionRequestor; import org.tasks.ui.HiddenTopArrayAdapter; @@ -66,20 +66,20 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte private GeofenceService geofenceService; private TaskEditFragment taskEditFragment; private PermissionRequestor permissionRequestor; - private DeviceInfo deviceInfo; + private Device device; private List spinnerOptions = new ArrayList<>(); private ArrayAdapter remindAdapter; public ReminderControlSet(AlarmService alarmService, GeofenceService geofenceService, TaskEditFragment taskEditFragment, PermissionRequestor permissionRequestor, - DeviceInfo deviceInfo) { + Device device) { super(taskEditFragment.getActivity(), R.layout.control_set_reminders); this.alarmService = alarmService; this.geofenceService = geofenceService; this.taskEditFragment = taskEditFragment; this.permissionRequestor = permissionRequestor; - this.deviceInfo = deviceInfo; + this.device = device; } public int getValue() { @@ -170,7 +170,7 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte if (randomControlSet == null) { spinnerOptions.add(taskEditFragment.getString(R.string.randomly)); } - if (deviceInfo.supportsLocationServices()) { + if (device.supportsLocationServices()) { spinnerOptions.add(taskEditFragment.getString(R.string.pick_a_location)); } spinnerOptions.add(taskEditFragment.getString(R.string.pick_a_date_and_time)); diff --git a/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java b/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java index 67cf5e5f9..be9fda101 100644 --- a/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java +++ b/src/main/java/org/tasks/dialogs/AddAttachmentDialog.java @@ -6,7 +6,7 @@ import android.os.Bundle; import org.tasks.R; import org.tasks.injection.InjectingDialogFragment; -import org.tasks.preferences.DeviceInfo; +import org.tasks.preferences.Device; import java.util.List; @@ -25,7 +25,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment { } @Inject DialogBuilder dialogBuilder; - @Inject DeviceInfo deviceInfo; + @Inject Device device; private AddAttachmentCallback callback; private DialogInterface.OnCancelListener onCancelListener; @@ -34,7 +34,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { List entries = newArrayList(); final List actions = newArrayList(); - if (deviceInfo.hasCamera()) { + if (device.hasCamera()) { entries.add(getString(R.string.take_a_picture)); actions.add(new Runnable() { @Override @@ -43,7 +43,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment { } }); } - if (deviceInfo.hasGallery()) { + if (device.hasGallery()) { entries.add(getString(R.string.pick_from_gallery)); actions.add(new Runnable() { @Override diff --git a/src/main/java/org/tasks/preferences/DeviceInfo.java b/src/main/java/org/tasks/preferences/Device.java similarity index 81% rename from src/main/java/org/tasks/preferences/DeviceInfo.java rename to src/main/java/org/tasks/preferences/Device.java index 4b093116c..bb1688df4 100644 --- a/src/main/java/org/tasks/preferences/DeviceInfo.java +++ b/src/main/java/org/tasks/preferences/Device.java @@ -16,30 +16,33 @@ import org.tasks.injection.ForApplication; import java.util.List; import javax.inject.Inject; -import javax.inject.Singleton; import timber.log.Timber; import static java.util.Arrays.asList; -@Singleton -public class DeviceInfo { +public class Device { private Context context; - private Boolean isPlayStoreAvailable; - private String debugInfo; @Inject - public DeviceInfo(@ForApplication Context context) { + public Device(@ForApplication Context context) { this.context = context; } public boolean isPlayStoreAvailable() { - if (isPlayStoreAvailable == null) { - isPlayStoreAvailable = checkForPlayStore(); + try { + PackageManager packageManager = context.getPackageManager(); + List packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES); + for (PackageInfo packageInfo : packages) { + if ("com.google.market".equals(packageInfo.packageName) || "com.android.vending".equals(packageInfo.packageName)) { + return true; + } + } + } catch(Exception e) { + Timber.e(e, e.getMessage()); } - - return isPlayStoreAvailable; + return false; } public boolean hasCamera() { @@ -57,14 +60,6 @@ public class DeviceInfo { } public String getDebugInfo() { - if (debugInfo == null) { - debugInfo = buildDebugString(); - } - - return debugInfo; - } - - private String buildDebugString() { try { return Joiner.on("\n").join(asList( "", @@ -82,19 +77,4 @@ public class DeviceInfo { } return ""; } - - private boolean checkForPlayStore() { - try { - PackageManager packageManager = context.getPackageManager(); - List packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES); - for (PackageInfo packageInfo : packages) { - if ("com.google.market".equals(packageInfo.packageName) || "com.android.vending".equals(packageInfo.packageName)) { - return true; - } - } - } catch(Exception e) { - Timber.e(e, e.getMessage()); - } - return false; - } } diff --git a/src/main/java/org/tasks/preferences/HelpAndFeedbackActivity.java b/src/main/java/org/tasks/preferences/HelpAndFeedbackActivity.java index 6842e47c4..aa02de07a 100644 --- a/src/main/java/org/tasks/preferences/HelpAndFeedbackActivity.java +++ b/src/main/java/org/tasks/preferences/HelpAndFeedbackActivity.java @@ -11,7 +11,7 @@ import javax.inject.Inject; public class HelpAndFeedbackActivity extends InjectingPreferenceActivity { - @Inject DeviceInfo deviceInfo; + @Inject Device device; @Inject Preferences preferences; @Override @@ -23,9 +23,9 @@ public class HelpAndFeedbackActivity extends InjectingPreferenceActivity { findPreference(getString(R.string.contact_developer)).setIntent( new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "Tasks Support ", null)) {{ putExtra(Intent.EXTRA_SUBJECT, "Tasks Feedback"); - putExtra(Intent.EXTRA_TEXT, deviceInfo.getDebugInfo()); + putExtra(Intent.EXTRA_TEXT, device.getDebugInfo()); }}); - if (!deviceInfo.isPlayStoreAvailable()) { + if (!device.isPlayStoreAvailable()) { remove(R.string.rate_tasks); } }