Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
LightSun committed Jan 5, 2020
1 parent 8ca59c3 commit 0748e60
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.heaven7.android.component;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;

import com.heaven7.android.component.guide.AppGuideComponent;
import com.heaven7.android.component.image.AppImageComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.heaven7.android.component;

import android.app.Activity;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.support.annotation.NonNull;
Expand All @@ -10,7 +9,6 @@

import com.heaven7.android.component.guide.AppGuideComponent;
import com.heaven7.android.component.image.AppImageComponent;
import com.heaven7.android.component.lifecycle.LifeCycleComponent;
import com.heaven7.android.component.lifecycle.LifeCycleComponent2;
import com.heaven7.android.component.loading.AppLoadingComponent;
import com.heaven7.android.component.toast.AppToastComponent;
Expand All @@ -37,6 +35,12 @@ public class AppComponentOwner2 extends AbstractLifeCycleComponentOwner<LifeCycl
public AppComponentOwner2(@NonNull LifecycleOwner owner) {
this(owner, null);
}
/**
* create app-component context. this should be called before 'super.onCreate(saveInstanceState)'
*
* @param owner the owner
* @param factory the factory
*/
public AppComponentOwner2(@NonNull LifecycleOwner owner, AppComponentFactory factory) {
super(owner);
this.mFactory = factory;
Expand All @@ -62,7 +66,7 @@ public <T extends FragmentActivity> T getActivity() {

public @Nullable
AppImageComponent getAppImageComponent() {
if (mImageCpt == null) {
if (mImageCpt == null && mFactory != null) {
mImageCpt = mFactory.onCreateAppImageComponent(getActivity());
registerLifeCycleContextIfNeed(mImageCpt);
}
Expand All @@ -71,7 +75,7 @@ AppImageComponent getAppImageComponent() {

public @Nullable
AppLoadingComponent getAppLoadingComponent() {
if (mLoadingCpt == null) {
if (mLoadingCpt == null && mFactory != null) {
mLoadingCpt = mFactory.onCreateAppLoadingComponent(getActivity());
registerLifeCycleContextIfNeed(mLoadingCpt);
}
Expand All @@ -80,7 +84,7 @@ AppLoadingComponent getAppLoadingComponent() {

public @Nullable
AppGuideComponent getAppGuideComponent() {
if (mGuideCpt == null) {
if (mGuideCpt == null && mFactory != null) {
mGuideCpt = mFactory.onCreateAppGuideComponent(getActivity());
registerLifeCycleContextIfNeed(mGuideCpt);
}
Expand All @@ -89,7 +93,7 @@ AppGuideComponent getAppGuideComponent() {

public @Nullable
AppToastComponent getAppToastComponent() {
if (mToastCpt == null) {
if (mToastCpt == null && mFactory != null) {
mToastCpt = mFactory.onCreateAppToastComponent(getActivity());
registerLifeCycleContextIfNeed(mToastCpt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/
public interface Repository {

Object getResource(RepositoryContext context, Key key);
Object get(RepositoryContext context, Key key);

void getResourceAsync(RepositoryContext context, Key key, Callback callback);
void getAsync(RepositoryContext context, Key key, Callback callback);

interface Callback{

void onSuccess(RepositoryContext context, Key key, Object data);

void onFailed(RepositoryContext context, Key key, Cause cause);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.heaven7.android.components.demo;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

Expand Down Expand Up @@ -28,15 +29,15 @@ public abstract class BaseActivity extends AppCompatActivity implements AppConte
public void onCreate(Bundle savedInstanceState) {
mAppComponentOwner = new AppComponentOwner(this, new AppComponentFactory() {
@Override
public AppImageComponent onCreateAppImageComponent(AppCompatActivity activity) {
public AppImageComponent onCreateAppImageComponent(Activity activity) {
return new GlideAppImageComponent();
}
@Override
public AppLoadingComponent onCreateAppLoadingComponent(AppCompatActivity activity) {
public AppLoadingComponent onCreateAppLoadingComponent(Activity activity) {
return BaseActivity.this.onCreateAppLoadingComponent();
}
@Override
public AppGuideComponent onCreateAppGuideComponent(AppCompatActivity activity) {
public AppGuideComponent onCreateAppGuideComponent(Activity activity) {
final GuideHelper helper = new GuideHelper(activity, getLayoutId());
//register back key listener of guide.
helper.setOnKeyListener(new BackKeyListener() {
Expand All @@ -48,7 +49,7 @@ protected void onBackPressed() {
return helper;
}
@Override
public AppToastComponent onCreateAppToastComponent(AppCompatActivity activity) {
public AppToastComponent onCreateAppToastComponent(Activity activity) {
return AppToastComponentImpl.create(activity);
}
});
Expand Down

0 comments on commit 0748e60

Please sign in to comment.