Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
LightSun committed Dec 18, 2019
1 parent 34d12b1 commit 0ebbbf1
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 111 deletions.
1 change: 1 addition & 0 deletions Android-components/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.iml
.gradle
.idea
/local.properties
/.idea/workspace.xml
/.idea/libraries
Expand Down
10 changes: 3 additions & 7 deletions Android-components/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
package com.heaven7.android.component;

import android.app.Activity;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.OnLifecycleEvent;
import android.content.Context;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;

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;
import com.heaven7.java.base.util.SmartReference;

import java.util.ArrayList;
import java.util.Iterator;

import static com.heaven7.android.component.lifecycle.LifeCycleComponent.ON_CREATE;
import static com.heaven7.android.component.lifecycle.LifeCycleComponent.ON_DESTROY;
import static com.heaven7.android.component.lifecycle.LifeCycleComponent.ON_PAUSE;
import static com.heaven7.android.component.lifecycle.LifeCycleComponent.ON_RESUME;
import static com.heaven7.android.component.lifecycle.LifeCycleComponent.ON_START;
import static com.heaven7.android.component.lifecycle.LifeCycleComponent.ON_STOP;

/**
* <p>for this class can only used for activity. we recommend you
* use {@linkplain AppComponentOwner2} instead.
* </p>
* the app component owner.
* Created by heaven7 on 2017/8/15 0015.
* @see AppImageComponent
Expand All @@ -39,6 +25,7 @@
*
* @since 1.0.5
*/
@Deprecated
public class AppComponentOwner extends AbstractLifeCycleComponentOwner<LifeCycleComponent>{
private final AppComponentFactory mFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.heaven7.android.component;

import android.app.Activity;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

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;

/**
* app fragment component owner
Expand All @@ -13,17 +22,85 @@
public class AppComponentOwner2 extends AbstractLifeCycleComponentOwner<LifeCycleComponent2> implements LifecycleObserver {

private static final String TAG = "AppComponentOwner";
private final AppComponentFactory mFactory;

private AppImageComponent mImageCpt;
private AppLoadingComponent mLoadingCpt;
private AppGuideComponent mGuideCpt;
private AppToastComponent mToastCpt;

/**
* create app-component context. this should be called before 'super.onCreate(saveInstanceState)'
*
* @param owner the owner
*/
public AppComponentOwner2(@NonNull LifecycleOwner owner) {
this(owner, null);
}
public AppComponentOwner2(@NonNull LifecycleOwner owner, AppComponentFactory factory) {
super(owner);
this.mFactory = factory;
// ReportFragment.injectIfNeededIn(activity);
}
/**
* get the activity or null if the owner is unknown.
* @param <T> the activity type
* @return the activity
*/
@SuppressWarnings("unchecked")
public <T extends FragmentActivity> T getActivity() {
LifecycleOwner owner = getLifecycleOwner();
if(owner instanceof FragmentActivity){
return (T) owner;
}else if(owner instanceof Fragment){
return (T) ((Fragment) owner).getActivity();
}else if (owner instanceof android.app.Fragment){
return (T) ((android.app.Fragment) owner).getActivity();
}
return null;
}

public @Nullable
AppImageComponent getAppImageComponent() {
if (mImageCpt == null) {
mImageCpt = mFactory.onCreateAppImageComponent(getActivity());
registerLifeCycleContextIfNeed(mImageCpt);
}
return mImageCpt;
}

public @Nullable
AppLoadingComponent getAppLoadingComponent() {
if (mLoadingCpt == null) {
mLoadingCpt = mFactory.onCreateAppLoadingComponent(getActivity());
registerLifeCycleContextIfNeed(mLoadingCpt);
}
return mLoadingCpt;
}

public @Nullable
AppGuideComponent getAppGuideComponent() {
if (mGuideCpt == null) {
mGuideCpt = mFactory.onCreateAppGuideComponent(getActivity());
registerLifeCycleContextIfNeed(mGuideCpt);
}
return mGuideCpt;
}

public @Nullable
AppToastComponent getAppToastComponent() {
if (mToastCpt == null) {
mToastCpt = mFactory.onCreateAppToastComponent(getActivity());
registerLifeCycleContextIfNeed(mToastCpt);
}
return mToastCpt;
}

private void registerLifeCycleContextIfNeed(Object component) {
if (component != null && component instanceof LifeCycleComponent2) {
mWeakLives.add(new SmartReference0<>((LifeCycleComponent2) component));
}
}
@Override
protected void onLifeCycle(LifecycleOwner owner, LifeCycleComponent2 t, int liftCycle) {
t.onLifeCycle(owner, liftCycle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.heaven7.android.component.gallery;

import android.os.Parcel;
import android.os.Parcelable;

/**
* the pick option
* @author heaven7
* @since 1.1.4
*/
public class PickOption {
public class PickOption implements Parcelable {

private int minCount;
private int maxCount;
Expand Down Expand Up @@ -113,4 +116,44 @@ public PickOption build() {
return new PickOption(this);
}
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.minCount);
dest.writeInt(this.maxCount);
dest.writeByte(this.crop ? (byte) 1 : (byte) 0);
dest.writeInt(this.aspectX);
dest.writeInt(this.aspectY);
dest.writeInt(this.outputX);
dest.writeInt(this.outputY);
dest.writeString(this.outputFormat);
}

protected PickOption(Parcel in) {
this.minCount = in.readInt();
this.maxCount = in.readInt();
this.crop = in.readByte() != 0;
this.aspectX = in.readInt();
this.aspectY = in.readInt();
this.outputX = in.readInt();
this.outputY = in.readInt();
this.outputFormat = in.readString();
}

public static final Creator<PickOption> CREATOR = new Creator<PickOption>() {
@Override
public PickOption createFromParcel(Parcel source) {
return new PickOption(source);
}

@Override
public PickOption[] newArray(int size) {
return new PickOption[size];
}
};
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 0ebbbf1

Please sign in to comment.