Rename DeviceInfo to Device

pull/384/head
Alex Baker 9 years ago
parent 6364269406
commit f431aeaa56

@ -15,7 +15,7 @@ import com.todoroo.astrid.activity.TaskEditFragment;
import org.tasks.R; import org.tasks.R;
import org.tasks.activities.CameraActivity; import org.tasks.activities.CameraActivity;
import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.DeviceInfo; import org.tasks.preferences.Device;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -25,7 +25,7 @@ import javax.inject.Inject;
public class ActFmCameraModule { public class ActFmCameraModule {
private final Fragment fragment; private final Fragment fragment;
private DeviceInfo deviceInfo; private Device device;
private DialogBuilder dialogBuilder; private DialogBuilder dialogBuilder;
public interface ClearImageCallback { public interface ClearImageCallback {
@ -33,9 +33,9 @@ public class ActFmCameraModule {
} }
@Inject @Inject
public ActFmCameraModule(Fragment fragment, DeviceInfo deviceInfo, DialogBuilder dialogBuilder) { public ActFmCameraModule(Fragment fragment, Device device, DialogBuilder dialogBuilder) {
this.fragment = fragment; this.fragment = fragment;
this.deviceInfo = deviceInfo; this.device = device;
this.dialogBuilder = dialogBuilder; this.dialogBuilder = dialogBuilder;
} }
@ -43,7 +43,7 @@ public class ActFmCameraModule {
final List<Runnable> runnables = new ArrayList<>(); final List<Runnable> runnables = new ArrayList<>();
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();
final boolean cameraAvailable = deviceInfo.hasCamera(); final boolean cameraAvailable = device.hasCamera();
if (cameraAvailable) { if (cameraAvailable) {
runnables.add(new Runnable() { runnables.add(new Runnable() {
@Override @Override

@ -77,7 +77,7 @@ import org.tasks.location.GeofenceService;
import org.tasks.location.PlacePicker; import org.tasks.location.PlacePicker;
import org.tasks.notifications.NotificationManager; import org.tasks.notifications.NotificationManager;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import org.tasks.preferences.DeviceInfo; import org.tasks.preferences.Device;
import org.tasks.preferences.PermissionRequestor; import org.tasks.preferences.PermissionRequestor;
import org.tasks.ui.DeadlineControlSet; import org.tasks.ui.DeadlineControlSet;
import org.tasks.ui.MenuColorizer; import org.tasks.ui.MenuColorizer;
@ -168,7 +168,7 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot
@Inject GeofenceService geofenceService; @Inject GeofenceService geofenceService;
@Inject DialogBuilder dialogBuilder; @Inject DialogBuilder dialogBuilder;
@Inject PermissionRequestor permissionRequestor; @Inject PermissionRequestor permissionRequestor;
@Inject DeviceInfo deviceInfo; @Inject Device device;
// --- UI components // --- UI components
@ -313,7 +313,7 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot
controlSetMap.put(getString(R.string.TEA_ctrl_notes_pref), controlSetMap.put(getString(R.string.TEA_ctrl_notes_pref),
notesControlSet); notesControlSet);
reminderControlSet = new ReminderControlSet(alarmService, geofenceService, this, permissionRequestor, deviceInfo); reminderControlSet = new ReminderControlSet(alarmService, geofenceService, this, permissionRequestor, device);
controls.add(reminderControlSet); controls.add(reminderControlSet);
controlSetMap.put(getString(R.string.TEA_ctrl_reminders_pref), reminderControlSet); controlSetMap.put(getString(R.string.TEA_ctrl_reminders_pref), reminderControlSet);

@ -18,7 +18,7 @@ import android.preference.PreferenceManager;
import org.tasks.R; import org.tasks.R;
import org.tasks.activities.TimePickerActivity; import org.tasks.activities.TimePickerActivity;
import org.tasks.injection.InjectingPreferenceActivity; import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.preferences.DeviceInfo; import org.tasks.preferences.Device;
import org.tasks.preferences.PermissionChecker; import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.PermissionRequestor; import org.tasks.preferences.PermissionRequestor;
import org.tasks.scheduling.GeofenceSchedulingIntentService; 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_QUIET_END = 10002;
private static final int REQUEST_DEFAULT_REMIND = 10003; private static final int REQUEST_DEFAULT_REMIND = 10003;
@Inject DeviceInfo deviceInfo; @Inject Device device;
@Inject PermissionRequestor permissionRequestor; @Inject PermissionRequestor permissionRequestor;
@Inject PermissionChecker permissionChecker; @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(atLeastJellybean(), R.string.p_rmd_notif_actions_enabled, R.string.p_notification_priority);
requires(atLeastMarshmallow(), R.string.p_doze_notifications); 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) { private void rescheduleNotificationsOnChange(int... resIds) {

@ -29,7 +29,7 @@ import org.tasks.activities.DateAndTimePickerActivity;
import org.tasks.location.Geofence; import org.tasks.location.Geofence;
import org.tasks.location.GeofenceService; import org.tasks.location.GeofenceService;
import org.tasks.location.PlacePicker; import org.tasks.location.PlacePicker;
import org.tasks.preferences.DeviceInfo; import org.tasks.preferences.Device;
import org.tasks.preferences.PermissionRequestor; import org.tasks.preferences.PermissionRequestor;
import org.tasks.ui.HiddenTopArrayAdapter; import org.tasks.ui.HiddenTopArrayAdapter;
@ -66,20 +66,20 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte
private GeofenceService geofenceService; private GeofenceService geofenceService;
private TaskEditFragment taskEditFragment; private TaskEditFragment taskEditFragment;
private PermissionRequestor permissionRequestor; private PermissionRequestor permissionRequestor;
private DeviceInfo deviceInfo; private Device device;
private List<String> spinnerOptions = new ArrayList<>(); private List<String> spinnerOptions = new ArrayList<>();
private ArrayAdapter<String> remindAdapter; private ArrayAdapter<String> remindAdapter;
public ReminderControlSet(AlarmService alarmService, GeofenceService geofenceService, public ReminderControlSet(AlarmService alarmService, GeofenceService geofenceService,
TaskEditFragment taskEditFragment, PermissionRequestor permissionRequestor, TaskEditFragment taskEditFragment, PermissionRequestor permissionRequestor,
DeviceInfo deviceInfo) { Device device) {
super(taskEditFragment.getActivity(), R.layout.control_set_reminders); super(taskEditFragment.getActivity(), R.layout.control_set_reminders);
this.alarmService = alarmService; this.alarmService = alarmService;
this.geofenceService = geofenceService; this.geofenceService = geofenceService;
this.taskEditFragment = taskEditFragment; this.taskEditFragment = taskEditFragment;
this.permissionRequestor = permissionRequestor; this.permissionRequestor = permissionRequestor;
this.deviceInfo = deviceInfo; this.device = device;
} }
public int getValue() { public int getValue() {
@ -170,7 +170,7 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte
if (randomControlSet == null) { if (randomControlSet == null) {
spinnerOptions.add(taskEditFragment.getString(R.string.randomly)); 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_location));
} }
spinnerOptions.add(taskEditFragment.getString(R.string.pick_a_date_and_time)); spinnerOptions.add(taskEditFragment.getString(R.string.pick_a_date_and_time));

@ -6,7 +6,7 @@ import android.os.Bundle;
import org.tasks.R; import org.tasks.R;
import org.tasks.injection.InjectingDialogFragment; import org.tasks.injection.InjectingDialogFragment;
import org.tasks.preferences.DeviceInfo; import org.tasks.preferences.Device;
import java.util.List; import java.util.List;
@ -25,7 +25,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment {
} }
@Inject DialogBuilder dialogBuilder; @Inject DialogBuilder dialogBuilder;
@Inject DeviceInfo deviceInfo; @Inject Device device;
private AddAttachmentCallback callback; private AddAttachmentCallback callback;
private DialogInterface.OnCancelListener onCancelListener; private DialogInterface.OnCancelListener onCancelListener;
@ -34,7 +34,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
List<String> entries = newArrayList(); List<String> entries = newArrayList();
final List<Runnable> actions = newArrayList(); final List<Runnable> actions = newArrayList();
if (deviceInfo.hasCamera()) { if (device.hasCamera()) {
entries.add(getString(R.string.take_a_picture)); entries.add(getString(R.string.take_a_picture));
actions.add(new Runnable() { actions.add(new Runnable() {
@Override @Override
@ -43,7 +43,7 @@ public class AddAttachmentDialog extends InjectingDialogFragment {
} }
}); });
} }
if (deviceInfo.hasGallery()) { if (device.hasGallery()) {
entries.add(getString(R.string.pick_from_gallery)); entries.add(getString(R.string.pick_from_gallery));
actions.add(new Runnable() { actions.add(new Runnable() {
@Override @Override

@ -16,30 +16,33 @@ import org.tasks.injection.ForApplication;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
import timber.log.Timber; import timber.log.Timber;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
@Singleton public class Device {
public class DeviceInfo {
private Context context; private Context context;
private Boolean isPlayStoreAvailable;
private String debugInfo;
@Inject @Inject
public DeviceInfo(@ForApplication Context context) { public Device(@ForApplication Context context) {
this.context = context; this.context = context;
} }
public boolean isPlayStoreAvailable() { public boolean isPlayStoreAvailable() {
if (isPlayStoreAvailable == null) { try {
isPlayStoreAvailable = checkForPlayStore(); PackageManager packageManager = context.getPackageManager();
List<PackageInfo> 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;
return isPlayStoreAvailable;
} }
public boolean hasCamera() { public boolean hasCamera() {
@ -57,14 +60,6 @@ public class DeviceInfo {
} }
public String getDebugInfo() { public String getDebugInfo() {
if (debugInfo == null) {
debugInfo = buildDebugString();
}
return debugInfo;
}
private String buildDebugString() {
try { try {
return Joiner.on("\n").join(asList( return Joiner.on("\n").join(asList(
"", "",
@ -82,19 +77,4 @@ public class DeviceInfo {
} }
return ""; return "";
} }
private boolean checkForPlayStore() {
try {
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> 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;
}
} }

@ -11,7 +11,7 @@ import javax.inject.Inject;
public class HelpAndFeedbackActivity extends InjectingPreferenceActivity { public class HelpAndFeedbackActivity extends InjectingPreferenceActivity {
@Inject DeviceInfo deviceInfo; @Inject Device device;
@Inject Preferences preferences; @Inject Preferences preferences;
@Override @Override
@ -23,9 +23,9 @@ public class HelpAndFeedbackActivity extends InjectingPreferenceActivity {
findPreference(getString(R.string.contact_developer)).setIntent( findPreference(getString(R.string.contact_developer)).setIntent(
new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "Tasks Support <support@tasks.org>", null)) {{ new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "Tasks Support <support@tasks.org>", null)) {{
putExtra(Intent.EXTRA_SUBJECT, "Tasks Feedback"); 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); remove(R.string.rate_tasks);
} }
} }

Loading…
Cancel
Save