Created
December 25, 2016 07:51
-
-
Save janishar/bde18926209f8c0f920ed668b180a8b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Inject | |
DataManager mDataManager; | |
private ActivityComponent activityComponent; | |
private TextView mTvUserInfo; | |
private TextView mTvAccessToken; | |
public ActivityComponent getActivityComponent() { | |
if (activityComponent == null) { | |
activityComponent = DaggerActivityComponent.builder() | |
.activityModule(new ActivityModule(this)) | |
.applicationComponent(DemoApplication.get(this).getComponent()) | |
.build(); | |
} | |
return activityComponent; | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
getActivityComponent().inject(this); | |
mTvUserInfo = (TextView) findViewById(R.id.tv_user_info); | |
mTvAccessToken = (TextView) findViewById(R.id.tv_access_token); | |
} | |
@Override | |
protected void onPostCreate(@Nullable Bundle savedInstanceState) { | |
super.onPostCreate(savedInstanceState); | |
createUser(); | |
getUser(); | |
mDataManager.saveAccessToken("ASDR12443JFDJF43543J543H3K543"); | |
String token = mDataManager.getAccessToken(); | |
if(token != null){ | |
mTvAccessToken.setText(token); | |
} | |
} | |
private void createUser(){ | |
try { | |
mDataManager.createUser(new User("Ali", "1367, Gurgaon, Haryana, India")); | |
}catch (Exception e){e.printStackTrace();} | |
} | |
private void getUser(){ | |
try { | |
User user = mDataManager.getUser(1L); | |
mTvUserInfo.setText(user.toString()); | |
}catch (Exception e){e.printStackTrace();} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DaggerActivityComponent ?error: Error:(69, 1) error: class, interface, or enum expected