Android Studio inspections

pull/795/head
Alex Baker 6 years ago
parent c4ede5a0e9
commit bd968eb127

@ -1,19 +1,17 @@
package org.tasks.injection;
import org.junit.Before;
import static androidx.test.InstrumentationRegistry.getTargetContext;
import static org.tasks.TestUtilities.initializeMockito;
import org.junit.Before;
public abstract class InjectingTestCase {
private TestComponent component;
@Before
public void setUp() {
initializeMockito(getTargetContext());
component =
TestComponent component =
DaggerTestComponent.builder().testModule(new TestModule(getTargetContext())).build();
inject(component);
}

@ -1,56 +0,0 @@
package org.tasks.location;
import android.content.Context;
import android.os.Bundle;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.places.Places;
import javax.inject.Inject;
import org.tasks.injection.ForApplication;
import timber.log.Timber;
public class GoogleApi implements GoogleApiClient.ConnectionCallbacks {
private final GoogleApiClient.Builder builder;
private GoogleApiClient googleApiClient;
private GoogleApiClientConnectionHandler googleApiClientConnectionHandler;
@Inject
public GoogleApi(@ForApplication Context context) {
builder =
new GoogleApiClient.Builder(context)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this);
}
public void connect(final GoogleApiClientConnectionHandler googleApiClientConnectionHandler) {
connect(
googleApiClientConnectionHandler,
connectionResult -> Timber.e("onConnectionFailed(%s)", connectionResult));
}
private void connect(
final GoogleApiClientConnectionHandler googleApiClientConnectionHandler,
GoogleApiClient.OnConnectionFailedListener onConnectionFailedListener) {
this.googleApiClientConnectionHandler = googleApiClientConnectionHandler;
googleApiClient = builder.addOnConnectionFailedListener(onConnectionFailedListener).build();
googleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
Timber.i("onConnected(Bundle)");
googleApiClientConnectionHandler.onConnect(googleApiClient);
}
@Override
public void onConnectionSuspended(int i) {
Timber.i("onConnectionSuspended(%s)", i);
}
public interface GoogleApiClientConnectionHandler {
void onConnect(GoogleApiClient client);
}
}

@ -15,15 +15,11 @@ import android.util.DisplayMetrics;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import timber.log.Timber;
/**
@ -218,19 +214,6 @@ public class AndroidUtilities {
}
}
/** Returns the final word characters after the last '.' */
public static String getFileExtension(String file) {
int index = file.lastIndexOf('.');
String extension = "";
if (index > 0) {
extension = file.substring(index + 1);
if (!extension.matches("\\w+")) {
extension = "";
}
}
return extension;
}
interface SerializedPut<T> {
void put(T object, String key, char type, String value) throws NumberFormatException;

@ -115,7 +115,7 @@ public class BeastModePreferences extends ThemedInjectingAppCompatActivity
adapter.setItems(asList(prefsArray));
return true;
default:
return super.onOptionsItemSelected(item);
return onOptionsItemSelected(item);
}
}

@ -1,18 +1,15 @@
/** TODO: make this lightweight, don't extend the entire MainActivity */
package com.todoroo.astrid.activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskCreator;
import org.tasks.data.TaskAttachment;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.preferences.Preferences;
import java.util.ArrayList;
@ -31,8 +28,6 @@ import static org.tasks.intents.TaskIntents.getEditTaskStack;
public final class ShareLinkActivity extends InjectingAppCompatActivity {
@Inject TaskCreator taskCreator;
@Inject TaskDao taskDao;
@Inject Preferences preferences;
@Override
public void onCreate(Bundle savedInstanceState) {

@ -20,7 +20,6 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.FilesControlSet;
import com.todoroo.astrid.notes.CommentsController;
import com.todoroo.astrid.repeats.RepeatControlSet;
import com.todoroo.astrid.service.TaskDeleter;
@ -43,7 +42,6 @@ import org.tasks.preferences.Preferences;
import org.tasks.ui.MenuColorizer;
import org.tasks.ui.TaskEditControlFragment;
import java.io.IOException;
import java.util.List;
import javax.inject.Inject;
@ -54,7 +52,6 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import butterknife.BindView;
import butterknife.ButterKnife;
import timber.log.Timber;
import static org.tasks.date.DateTimeUtils.newDateTime;
import static org.tasks.files.FileHelper.copyToUri;
@ -246,10 +243,6 @@ public final class TaskEditFragment extends InjectingFragment
return getFragment(RepeatControlSet.TAG);
}
private FilesControlSet getFilesControlSet() {
return getFragment(FilesControlSet.TAG);
}
@SuppressWarnings("unchecked")
private <T extends TaskEditControlFragment> T getFragment(int tag) {
return (T) getChildFragmentManager().findFragmentByTag(getString(tag));

@ -263,7 +263,7 @@ public class TaskListFragment extends InjectingFragment
searchSubject = PublishSubject.create();
searchDisposable = searchSubject
.debounce(SEARCH_DEBOUNCE_TIMEOUT, TimeUnit.MILLISECONDS)
.subscribe(query -> searchByQuery(query));
.subscribe(this::searchByQuery);
actionView.setOnQueryTextListener(
new SearchView.OnQueryTextListener() {

@ -81,6 +81,6 @@ public class MultipleSelectCriterion extends CustomFilterCriterion implements Pa
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(entryTitles);
dest.writeStringArray(entryValues);
super.writeToParcel(dest);
writeToParcel(dest);
}
}

@ -76,6 +76,6 @@ public class TextInputCriterion extends CustomFilterCriterion implements Parcela
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(prompt);
dest.writeString(hint);
super.writeToParcel(dest);
writeToParcel(dest);
}
}

@ -193,15 +193,16 @@ public class TasksXmlImporter {
}
try {
if (tag.equals(BackupConstants.TASK_TAG)) {
// Parse <task ... >
parseTask();
} else if (tag.equals(BackupConstants.COMMENT_TAG)) {
// Process <comment ... >
parseComment();
} else if (tag.equals(BackupConstants.METADATA_TAG)) {
// Process <metadata ... >
parseMetadata(2);
switch (tag) {
case BackupConstants.TASK_TAG:
parseTask();
break;
case BackupConstants.COMMENT_TAG:
parseComment();
break;
case BackupConstants.METADATA_TAG:
parseMetadata(2);
break;
}
} catch (Exception e) {
errorCount++;

@ -321,7 +321,7 @@ public class CustomFilterActivity extends ThemedInjectingAppCompatActivity
saveAndView();
return true;
}
return super.onOptionsItemSelected(item);
return onOptionsItemSelected(item);
}
@Override

@ -50,6 +50,7 @@ public class DefaultsPreferences extends InjectingPreferenceActivity
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject SyncAdapters syncAdapters;
@Inject Locale locale;
@Inject Device device;
private Preference defaultCalendarPref;
private Preference defaultRadiusPref;
@ -97,7 +98,7 @@ public class DefaultsPreferences extends InjectingPreferenceActivity
updateRadius();
requires(syncAdapters.isSyncEnabled(), R.string.p_default_remote_list);
requires(Device.SupportsLocationServices(this), R.string.p_default_location_reminder_key);
requires(device.supportsLocationServices(), R.string.p_default_location_reminder_key);
}
private void startCalendarSelectionActivity() {

@ -1199,10 +1199,6 @@ public class Task implements Parcelable {
return caldav;
}
public boolean hasFiles() {
return hasFiles;
}
@Retention(SOURCE)
@IntDef({Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE})
public @interface Priority {

@ -5,43 +5,39 @@
*/
package com.todoroo.astrid.gtasks;
import static com.google.common.collect.Lists.newArrayList;
import static org.tasks.time.DateTimeUtils.printTimestamp;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.service.TaskDeleter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import timber.log.Timber;
import static com.google.common.collect.Lists.newArrayList;
import static org.tasks.time.DateTimeUtils.printTimestamp;
public class GtasksListService {
private final GoogleTaskListDao googleTaskListDao;
private final TaskDeleter taskDeleter;
private final LocalBroadcastManager localBroadcastManager;
private final GoogleTaskDao googleTaskDao;
private final TaskDao taskDao;
@Inject
public GtasksListService(
GoogleTaskListDao googleTaskListDao,
TaskDeleter taskDeleter,
LocalBroadcastManager localBroadcastManager,
GoogleTaskDao googleTaskDao,
TaskDao taskDao) {
LocalBroadcastManager localBroadcastManager) {
this.googleTaskListDao = googleTaskListDao;
this.taskDeleter = taskDeleter;
this.localBroadcastManager = localBroadcastManager;
this.googleTaskDao = googleTaskDao;
this.taskDao = taskDao;
}
public GoogleTaskList getList(long id) {

@ -29,7 +29,7 @@ class OrderedMetadataListFragmentHelper {
private final TaskDao taskDao;
private final Map<Long, ArrayList<Long>> chainedCompletions =
Collections.synchronizedMap(new HashMap<Long, ArrayList<Long>>());
Collections.synchronizedMap(new HashMap<>());
private DraggableTaskAdapter taskAdapter;
private TaskListFragment fragment;
private GoogleTaskList list;

@ -6,7 +6,6 @@
package com.todoroo.astrid.service;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import com.google.common.base.Strings;

@ -21,7 +21,7 @@ class AstridOrderedListFragmentHelper {
private final SubtasksFilterUpdater updater;
private final TaskDao taskDao;
private final Map<String, ArrayList<String>> chainedCompletions =
Collections.synchronizedMap(new HashMap<String, ArrayList<String>>());
Collections.synchronizedMap(new HashMap<>());
private DraggableTaskAdapter taskAdapter;
private TaskListFragment fragment;
private TaskListMetadata list;

@ -20,7 +20,6 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
@ -359,9 +358,7 @@ public final class TagsControlSet extends TaskEditControlFragment {
chipGroup.removeAllViews();
for (TagData tagData : orderByName.sortedCopy(selectedTags)) {
Chip chip = chipProvider.getChip(tagData);
chip.setOnClickListener(view -> {
onClickRow();
});
chip.setOnClickListener(view -> onClickRow());
chip.setOnCloseIconClickListener(
view -> {
setTagSelected(tagData, false);

@ -7,8 +7,6 @@ import android.media.MediaRecorder;
import android.net.Uri;
import android.os.SystemClock;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import org.tasks.files.FileHelper;
import org.tasks.preferences.Preferences;

@ -160,6 +160,6 @@ public class FilterSettingsActivity extends ThemedInjectingAppCompatActivity
deleteTag();
break;
}
return super.onOptionsItemSelected(item);
return onOptionsItemSelected(item);
}
}

@ -225,7 +225,7 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi
deleteTag();
break;
}
return super.onOptionsItemSelected(item);
return onOptionsItemSelected(item);
}
private void discard() {

@ -291,6 +291,6 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity
deleteTag();
break;
}
return super.onOptionsItemSelected(item);
return onOptionsItemSelected(item);
}
}

@ -16,7 +16,6 @@ public class Tracking {
WIDGET_ADD(R.string.tracking_category_widget, R.string.tracking_action_add),
TIMER_START(R.string.tracking_category_timer, R.string.tracking_action_start),
GTASK_ENABLED(R.string.tracking_category_google_tasks, R.string.tracking_action_on),
GTASK_DISABLED(R.string.tracking_category_google_tasks, R.string.tracking_action_off),
GTASK_NEW_LIST(R.string.tracking_category_google_tasks, R.string.tracking_action_new_list),
GTASK_RENAME_LIST(
R.string.tracking_category_google_tasks, R.string.tracking_action_rename_list),

@ -24,6 +24,7 @@ import org.tasks.analytics.Tracker;
import org.tasks.injection.ForApplication;
import timber.log.Timber;
@SuppressWarnings("all")
public class BillingClient implements PurchasesUpdatedListener {
private final Inventory inventory;

@ -22,6 +22,7 @@ import org.apache.commons.collections4.map.MultiKeyMap;
* Primitive cookie store that stores cookies in a (volatile) hash map. Will be sufficient for
* session cookies.
*/
@SuppressWarnings("all")
class MemoryCookieStore implements CookieJar {
/**

@ -45,7 +45,4 @@ public interface GoogleTaskDao {
@Query("SELECT DISTINCT list_id FROM google_tasks WHERE deleted = 0 AND task IN (:tasks)")
List<String> getLists(List<Long> tasks);
@Query("SELECT task FROM google_tasks WHERE deleted = 0 AND list_id = :listId")
List<Long> getActiveTasks(String listId);
}

@ -41,9 +41,6 @@ public abstract class GoogleTaskListDao {
@Insert
public abstract void insert(GoogleTaskAccount googleTaskAccount);
@Update
public abstract void update(GoogleTaskList googleTaskList);
@Update
public abstract void update(GoogleTaskAccount account);
}

@ -1,17 +1,20 @@
package org.tasks.dialogs;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import android.content.Context;
import android.content.DialogInterface;
import androidx.appcompat.app.AlertDialog;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ListAdapter;
import java.util.List;
import org.tasks.locale.Locale;
import org.tasks.themes.Theme;
import java.util.List;
import androidx.appcompat.app.AlertDialog;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
public class AlertDialogBuilder {
private final AlertDialog.Builder builder;
@ -37,11 +40,6 @@ public class AlertDialogBuilder {
return this;
}
public AlertDialogBuilder setMessage(CharSequence charSequence) {
builder.setMessage(charSequence);
return this;
}
public AlertDialogBuilder setPositiveButton(
int ok, DialogInterface.OnClickListener onClickListener) {
builder.setPositiveButton(ok, onClickListener);
@ -145,9 +143,4 @@ public class AlertDialogBuilder {
locale.applyDirectionality(dialog);
return dialog;
}
public AlertDialogBuilder setCancelable(boolean cancelable) {
builder.setCancelable(cancelable);
return this;
}
}

@ -2,7 +2,6 @@ package org.tasks.dialogs;
import static androidx.core.content.ContextCompat.getColor;
import static com.google.common.collect.Lists.transform;
import static org.tasks.preferences.ResourceResolver.getData;
import android.app.Activity;
import android.app.Dialog;

@ -40,7 +40,7 @@ public class SortDialog extends InjectingDialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onCreate(savedInstanceState);
if (savedInstanceState != null) {
manualEnabled = savedInstanceState.getBoolean(EXTRA_MANUAL_ENABLED);

@ -1,17 +1,21 @@
package org.tasks.gtasks;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.transform;
import static java.util.Arrays.asList;
import android.accounts.Account;
import android.content.Context;
import com.google.common.base.Strings;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.transform;
import static java.util.Arrays.asList;
public class GoogleAccountManager {
@ -30,10 +34,6 @@ public class GoogleAccountManager {
return transform(getAccountList(), account -> account.name);
}
public boolean hasAccount(final String name) {
return getAccount(name) != null;
}
private List<Account> getAccountList() {
return permissionChecker.canAccessAccounts()
? asList(accountManager.getAccountsByType("com.google"))

@ -1,16 +1,17 @@
package org.tasks.gtasks;
import android.app.Activity;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
public class GtaskSyncAdapterHelper {
private final GoogleAccountManager accountManager;
private final Preferences preferences;
private final PlayServices playServices;
private final GoogleTaskListDao googleTaskListDao;
@ -18,12 +19,10 @@ public class GtaskSyncAdapterHelper {
@Inject
public GtaskSyncAdapterHelper(
GoogleAccountManager accountManager,
Preferences preferences,
PlayServices playServices,
GoogleTaskListDao googleTaskListDao,
Tracker tracker) {
this.accountManager = accountManager;
this.preferences = preferences;
this.playServices = playServices;
this.googleTaskListDao = googleTaskListDao;

@ -4,7 +4,6 @@ import android.content.Context;
import android.net.Uri;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import org.tasks.R;
import org.tasks.backup.TasksJsonExporter;

@ -22,7 +22,6 @@ import org.tasks.analytics.Tracking.Events;
import org.tasks.billing.BillingClient;
import org.tasks.billing.Inventory;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.files.FileExplore;
import org.tasks.files.FileHelper;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
@ -38,7 +37,6 @@ import java.io.File;
import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastKitKat;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
import static org.tasks.dialogs.ExportTasksDialog.newExportTasksDialog;
import static org.tasks.dialogs.ImportTasksDialog.newImportTasksDialog;

@ -13,7 +13,6 @@ import com.todoroo.astrid.voice.VoiceOutputAssistant;
import java.io.File;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.files.FileExplore;
import org.tasks.files.FileHelper;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;

@ -15,12 +15,10 @@ public abstract class PermissionRequestor {
this.permissionChecker = permissionChecker;
}
public boolean requestMic() {
if (permissionChecker.canAccessMic()) {
return true;
public void requestMic() {
if (!permissionChecker.canAccessMic()) {
requestPermission(Manifest.permission.RECORD_AUDIO, REQUEST_MIC);
}
requestPermission(Manifest.permission.RECORD_AUDIO, REQUEST_MIC);
return false;
}
public boolean requestCalendarPermissions() {

@ -52,6 +52,7 @@ import me.leolin.shortcutbadger.impl.ZukHomeBadger;
/**
* @author Leo Lin
*/
@SuppressWarnings("all")
public final class ShortcutBadger {
private static final String LOG_TAG = "ShortcutBadger";

@ -24,7 +24,6 @@ import butterknife.OnLongClick;
import com.google.android.material.chip.Chip;
import com.google.android.material.chip.ChipGroup;
import com.google.common.collect.Lists;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;

@ -1,9 +1,8 @@
package org.tasks.time;
import static org.tasks.date.DateTimeUtils.newDateTime;
import org.tasks.BuildConfig;
import java.util.Date;
import org.tasks.BuildConfig;
public class DateTimeUtils {
@ -22,14 +21,6 @@ public class DateTimeUtils {
MILLIS_PROVIDER = SYSTEM_MILLIS_PROVIDER;
}
public static long nextMidnight() {
return nextMidnight(currentTimeMillis());
}
private static long nextMidnight(long timestamp) {
return newDateTime(timestamp).startOfDay().plusDays(1).getMillis();
}
public static String printTimestamp(long timestamp) {
return BuildConfig.DEBUG ? new Date(timestamp).toString() : Long.toString(timestamp);
}

@ -27,7 +27,6 @@ import butterknife.OnClick;
import com.google.common.base.Strings;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;

@ -2,7 +2,6 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

@ -94,7 +94,6 @@
<color name="white_50">#80ffffff</color>
<color name="white_12">#1fffffff</color>
<color name="overdue_100">@color/red_500</color>
<color name="overdue_87">#def44336</color>
<color name="overdue">@color/overdue_87</color>

Loading…
Cancel
Save