-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
3,113 additions
and
2,370 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
ComponentImpl/src/main/java/com/xiaojinzi/component/bean/ActivityResult.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.xiaojinzi.component.bean; | ||
|
||
import android.content.Intent; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.xiaojinzi.component.error.ignore.ActivityResultException; | ||
|
||
/** | ||
* activity result 的返回对象,{@link android.app.Activity#onActivityResult(int, int, Intent)} | ||
* time : 2018/12/04 | ||
* | ||
* @author : xiaojinzi 30212 | ||
*/ | ||
public class ActivityResult { | ||
|
||
public final int requestCode; | ||
|
||
public final int resultCode; | ||
|
||
@Nullable | ||
public final Intent data; | ||
|
||
public ActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
this.requestCode = requestCode; | ||
this.resultCode = resultCode; | ||
this.data = data; | ||
} | ||
|
||
public Intent intentCheckAndGet() throws ActivityResultException { | ||
if (data == null) { | ||
throw new ActivityResultException("the intent result data is null"); | ||
} | ||
return data; | ||
} | ||
|
||
public Intent intentWithResultCodeCheckAndGet(int expectedResultCode) { | ||
if (data == null) { | ||
throw new ActivityResultException("the intent result data is null"); | ||
} | ||
if (expectedResultCode != resultCode) { | ||
throw new ActivityResultException("the resultCode is not matching " + expectedResultCode); | ||
} | ||
return data; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ponent/error/ActivityResultException.java → ...error/ignore/ActivityResultException.java
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
84 changes: 84 additions & 0 deletions
84
ComponentImpl/src/main/java/com/xiaojinzi/component/impl/BiCallback.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.xiaojinzi.component.impl; | ||
|
||
import android.support.annotation.CallSuper; | ||
import android.support.annotation.MainThread; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.xiaojinzi.component.support.Function; | ||
import com.xiaojinzi.component.support.Utils; | ||
|
||
/** | ||
* 当整个流程完成的时候,回调这个接口 | ||
* <p> | ||
* 详细的请查看 {@link Callback} | ||
* | ||
* @author xiaojinzi 30212 | ||
*/ | ||
public interface BiCallback<T> extends OnRouterCancel, OnRouterError { | ||
|
||
/** | ||
* 当路由成功的时候,回调 | ||
* | ||
* @param result 路由成功的对象 | ||
* @param t 返回的对象 | ||
*/ | ||
@MainThread | ||
void onSuccess(@NonNull RouterResult result, @NonNull T t); | ||
|
||
/** | ||
* 做一个转化 | ||
* | ||
* @param <T> | ||
* @param <R> | ||
*/ | ||
abstract class Map<T, R> implements BiCallback<T>,Function<T, R> { | ||
|
||
@NonNull | ||
private BiCallback targetBiCallback; | ||
|
||
public Map(@NonNull BiCallback targetBiCallback) { | ||
this.targetBiCallback = targetBiCallback; | ||
} | ||
|
||
@Override | ||
public void onSuccess(@NonNull RouterResult result, @NonNull T t) { | ||
try { | ||
targetBiCallback.onSuccess(result, Utils.checkNullPointer(apply(t), "apply(t)")); | ||
} catch (Exception e) { | ||
targetBiCallback.onError(new RouterErrorResult(e)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCancel(@Nullable RouterRequest originalRequest) { | ||
targetBiCallback.onCancel(originalRequest); | ||
} | ||
|
||
@Override | ||
public void onError(@NonNull RouterErrorResult errorResult) { | ||
targetBiCallback.onError(errorResult); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* 空白实现类 | ||
*/ | ||
class BiCallbackAdapter<T> implements BiCallback<T> { | ||
|
||
@Override | ||
public void onSuccess(@NonNull RouterResult result, @NonNull T t) { | ||
} | ||
|
||
@Override | ||
public void onError(@NonNull RouterErrorResult errorResult) { | ||
} | ||
|
||
@Override | ||
public void onCancel(@NonNull RouterRequest originalRequest) { | ||
} | ||
|
||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
ComponentImpl/src/main/java/com/xiaojinzi/component/impl/BiCallbackWrap.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.xiaojinzi.component.impl; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
/** | ||
* 为了实现 {@link BiCallback} 用户的这个 Callback 的各个方法最多只能执行一次 | ||
* | ||
* @param <T> | ||
*/ | ||
public class BiCallbackWrap<T> implements BiCallback<T> { | ||
|
||
/** | ||
* 标记是否结束 | ||
*/ | ||
private boolean isEnd; | ||
|
||
@NonNull | ||
private BiCallback<T> targetBiCallback; | ||
|
||
public BiCallbackWrap(@NonNull BiCallback<T> targetBiCallback) { | ||
this.targetBiCallback = targetBiCallback; | ||
} | ||
|
||
@Override | ||
public synchronized void onSuccess(@NonNull RouterResult result, @NonNull T t) { | ||
if (!isEnd) { | ||
targetBiCallback.onSuccess(result, t); | ||
} | ||
isEnd = true; | ||
} | ||
|
||
@Override | ||
public synchronized void onCancel(@Nullable RouterRequest originalRequest) { | ||
if (!isEnd) { | ||
targetBiCallback.onCancel(originalRequest); | ||
} | ||
isEnd = true; | ||
} | ||
|
||
@Override | ||
public synchronized void onError(@NonNull RouterErrorResult errorResult) { | ||
if (!isEnd) { | ||
targetBiCallback.onError(errorResult); | ||
} | ||
isEnd = true; | ||
} | ||
|
||
} |
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
Oops, something went wrong.