This commit is contained in:
wangcongtao
2019-12-30 16:35:51 +08:00
parent 9b93caefda
commit 5752829cf3
128 changed files with 7092 additions and 491 deletions

View File

@@ -4,16 +4,26 @@ package com.mogo.commons.debug;
* @author congtaowang
* @since 2019-12-23
* <p>
* 各个莫快递调试信息控制接口
* 各个模块递调试信息控制接口
*/
public class DebugConfig {
private static boolean sDebug = true;
/**
* 是否为调试模式
*
* @return true - 调试模式 false - 非调试模式
*/
public static boolean isDebug() {
return sDebug;
}
/**
* 设置调试模式
*
* @param sDebug true - 调试模式 false - 非调试模式
*/
public static void setDebug( boolean sDebug ) {
DebugConfig.sDebug = sDebug;
}

View File

@@ -10,5 +10,10 @@ import android.content.Context;
*/
public interface IView {
/**
* 获取上下文
*
* @return
*/
Context getContext();
}

View File

@@ -30,7 +30,7 @@ public abstract class MvpActivity< V extends IView, P extends Presenter< V > >
/**
* 布局资源
*
* @return
* @return 布局资源 id
*/
protected abstract int getLayoutId();

View File

@@ -1,6 +1,14 @@
package com.mogo.commons.mvp;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.widget.PopupWindow;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
@@ -14,7 +22,8 @@ import androidx.lifecycle.OnLifecycleEvent;
*/
public abstract class Presenter< V extends IView > implements LifecycleObserver {
private V mView;
protected V mView;
private Context mContext;
public Presenter( V view ) {
this.mView = view;
@@ -49,4 +58,35 @@ public abstract class Presenter< V extends IView > implements LifecycleObserver
@NonNull LifecycleOwner owner,
@NonNull Lifecycle.Event event ) {
}
protected Context getContext() {
if ( mContext != null ) {
return mContext;
}
if ( mView instanceof Activity ) {
mContext = ( ( Activity ) mView );
}
if ( mView instanceof Fragment ) {
mContext = ( ( Fragment ) mView ).getContext();
}
if ( mView instanceof android.app.Fragment ) {
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) {
mContext = ( ( android.app.Fragment ) mView ).getContext();
} else {
mContext = ( ( android.app.Fragment ) mView ).getActivity();
}
}
if ( mView instanceof Dialog ) {
mContext = ( ( Dialog ) mView ).getContext();
}
if ( mView instanceof PopupWindow ) {
if ( ( ( PopupWindow ) mView ).getContentView() != null ) {
mContext = ( ( PopupWindow ) mView ).getContentView().getContext();
}
}
if ( mView instanceof View ) {
mContext = ( ( View ) mView ).getContext();
}
return mContext;
}
}