Skip to content

Commit

Permalink
Hardened null pointer cases
Browse files Browse the repository at this point in the history
Removed comments
  • Loading branch information
Faltenreich committed Jun 26, 2018
1 parent 5518183 commit 5732fb5
Show file tree
Hide file tree
Showing 22 changed files with 16 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class Activity extends Measurement {

@SuppressWarnings("WeakerAccess")
public class Column extends Measurement.Column {
public static final String MINUTES = "minutes";
public static final String TYPE = "type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

import org.joda.time.DateTime;

import java.util.Objects;

/**
* Created by Filip on 13.08.2014.
*/
public abstract class BaseEntity {

public class Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import com.j256.ormlite.field.DatabaseField;

/**
* Created by Faltenreich on 11.09.2016.
*/
public class BaseServerEntity extends BaseEntity {

public class Column extends BaseEntity.Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 09.08.2014.
*/
@DatabaseTable
public class BloodSugar extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import java.util.ArrayList;
import java.util.List;

/**
* Created by Filip on 09.08.2014.
*/
@DatabaseTable
public class Entry extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
import static com.faltenreich.diaguard.data.entity.Food.Column.PROTEINS;
import static com.faltenreich.diaguard.data.entity.Food.Column.SUGAR;

/**
* Created by Faltenreich on 11.09.2016.
*/
public class Food extends BaseServerEntity {

private static final String IMAGE_SUFFIX = ".jpg";
private static final String KEYWORD_FULL_RESOLUTION = "full";

@SuppressWarnings("WeakerAccess")
public class Column extends BaseServerEntity.Column {
public static final String NAME = "name";
public static final String IMAGE_URL = "imageUrl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

import org.joda.time.format.DateTimeFormat;

/**
* Created by Faltenreich on 11.09.2016.
*/
public class FoodEaten extends BaseEntity {

public class Column extends BaseEntity.Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class HbA1c extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class Insulin extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faltenreich.diaguard.data.entity;

import com.faltenreich.diaguard.data.PreferenceHelper;
import com.google.gson.annotations.SerializedName;
import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
Expand All @@ -10,9 +9,6 @@
import java.util.ArrayList;
import java.util.List;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class Meal extends Measurement {

Expand Down Expand Up @@ -44,7 +40,7 @@ public void setFoodEaten(ForeignCollection<FoodEaten> foodEaten) {
this.foodEaten = foodEaten;
}

public float getTotalCarbohydrates() {
private float getTotalCarbohydrates() {
float carbohydrates = getCarbohydrates();
if (foodEaten != null) {
for (FoodEaten eaten : foodEaten) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import java.util.ArrayList;
import java.util.List;

/**
* Created by Filip on 11.05.2015.
*/
public abstract class Measurement extends BaseEntity {

private static final String TAG = Measurement.class.getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class OxygenSaturation extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class Pressure extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class Pulse extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
* Created by Filip on 11.05.2015.
*/
@DatabaseTable
public class Weight extends Measurement {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

import butterknife.BindView;

/**
* Created by Faltenreich on 28.10.2016.
*/

public class FoodDetailFragment extends BaseFoodFragment {

@BindView(R.id.food_brand) TextView brand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void initPreferences() {
}

private void setSummary(Preference preference) {
if (isAdded()) {
if (isAdded() && preference != null) {
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
preference.setSummary(listPreference.getEntry());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import com.faltenreich.diaguard.data.entity.Measurement;
import com.faltenreich.diaguard.util.ViewUtils;

/**
* Created by Filip on 04.11.13.
*/
public class CategoryPreference extends DialogPreference {

public final static String ACTIVE = "_active";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

import butterknife.BindView;

/**
* Created by Faltenreich on 17.10.2015.
*/
public class CategoryImageViewHolder extends BaseViewHolder<ListItemCategoryImage> implements View.OnClickListener {

@BindView(R.id.category_image) ImageView imageView;
Expand All @@ -27,7 +24,10 @@ public CategoryImageViewHolder(View view) {
public void bindData() {
int categoryImageResourceId = PreferenceHelper.getInstance().getCategoryImageResourceId(getListItem().getCategory());
if (categoryImageResourceId > 0) {
Picasso.with(getContext()).load(categoryImageResourceId).into(imageView);
Picasso picasso = Picasso.with(getContext());
if (picasso != null) {
picasso.load(categoryImageResourceId).into(imageView);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

import butterknife.BindView;

/**
* Created by Faltenreich on 17.10.2015.
*/
public class CategoryValueViewHolder extends BaseViewHolder<ListItemCategoryValue> implements View.OnClickListener {

@BindView(R.id.category_value_container) ViewGroup container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public void bindData() {
month.setText(dateTime.toString("MMMM YYYY"));
int resourceId = PreferenceHelper.getInstance().getMonthResourceId(dateTime);
int smallResourceId = PreferenceHelper.getInstance().getMonthSmallResourceId(dateTime);
Picasso.with(getContext()).load(resourceId).placeholder(smallResourceId).config(Bitmap.Config.RGB_565).into(background);
Picasso picasso = Picasso.with(getContext());
if (picasso != null) {
picasso.load(resourceId).placeholder(smallResourceId).config(Bitmap.Config.RGB_565).into(background);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@

import java.math.BigDecimal;

/**
* Created by Filip on 10.12.13.
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class ViewUtils {

Expand Down Expand Up @@ -69,8 +66,10 @@ public static int getDefaultTextColor(Context context) {

public static void requestFocusShowKeyboard(View view) {
view.requestFocus();
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
InputMethodManager inputMethodManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}

public static void showNumberPicker(AppCompatActivity activity, @StringRes int labelResId, int initialValue, int minValue, int maxValue, NumberPickerDialogFragment.NumberPickerDialogHandlerV2 listener) {
Expand Down

0 comments on commit 5732fb5

Please sign in to comment.