Skip to content

Commit

Permalink
Stop using deprecated method for Dagger injection
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Feb 24, 2020
1 parent 44f5dd7 commit 75b3576
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.odk.collect.android.preferences;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.FragmentActivity;
Expand Down Expand Up @@ -35,9 +35,9 @@ public class FormMetadataFragment extends PreferenceFragmentCompat {
PermissionUtils permissionUtils;

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
DaggerUtils.getComponent(activity).inject(this);
public void onAttach(Context context) {
super.onAttach(context);
DaggerUtils.getComponent(context).inject(this);
}

@Override
Expand All @@ -55,7 +55,9 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initNormalPrefs();

if (savedInstanceState == null) {
if (permissionUtils.isReadPhoneStatePermissionGranted(getActivity())) {
initDangerousPrefs();
} else if (savedInstanceState == null) {
permissionUtils.requestReadPhoneStatePermission(getActivity(), true, new PermissionListener() {
@Override
public void granted() {
Expand All @@ -66,8 +68,6 @@ public void granted() {
public void denied() {
}
});
} else if (permissionUtils.isReadPhoneStatePermissionGranted(getActivity())) {
initDangerousPrefs();
}
}

Expand Down
6 changes: 3 additions & 3 deletions docs/CODE-GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ For Fragment objects you should hook into the `onAttach` lifecycle method instea

```java
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
DaggerUtils.getComponent(activity).inject(this);
public void onAttach(Context context) {
super.onAttach(context);
DaggerUtils.getComponent(context).inject(this);
}
```

Expand Down

0 comments on commit 75b3576

Please sign in to comment.