-
Notifications
You must be signed in to change notification settings - Fork 0
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
37 changed files
with
1,555 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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,37 @@ | ||
package com.damon.app; | ||
|
||
import android.app.Application; | ||
|
||
import com.damon.di.component.AppComponent; | ||
import com.damon.di.component.DaggerAppComponent; | ||
import com.damon.di.module.AppModule; | ||
|
||
/** | ||
* @author: DamonJiang | ||
* @date: 2018/9/24 0024 | ||
* @description: | ||
*/ | ||
public class App extends Application{ | ||
private static App context; | ||
private AppComponent appComponent; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
context = (App) this.getApplicationContext(); | ||
appComponent = DaggerAppComponent.builder() | ||
.appModule(new AppModule(context)) | ||
.build(); | ||
} | ||
public AppComponent getAppComponent() { | ||
return appComponent; | ||
} | ||
/** | ||
* 获取全局的 context | ||
* | ||
* @return | ||
*/ | ||
public static synchronized App getContext() { | ||
return context; | ||
} | ||
} |
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,40 @@ | ||
package com.damon.base; | ||
|
||
|
||
import android.util.Log; | ||
|
||
|
||
import com.damon.base.view.IView; | ||
|
||
import io.reactivex.observers.ResourceObserver; | ||
|
||
/** | ||
* @author: DamonJiang | ||
* @date: 2018/9/25 0025 | ||
* @description: DisposableObserver 的封装 | ||
*/ | ||
public abstract class AYBaseObserver<T> extends ResourceObserver<T>{ | ||
private IView mView; | ||
private String mErrorMsg; | ||
|
||
|
||
protected AYBaseObserver(IView view, String errorMsg) { | ||
this.mView = view; | ||
this.mErrorMsg = errorMsg; | ||
} | ||
|
||
|
||
@Override | ||
public void onComplete() { | ||
Log.d("===========", "onComplete"); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
Log.d("===========", "onError"); | ||
if (mView == null) { | ||
return; | ||
} | ||
mView.onShowError(mErrorMsg); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
app/src/main/java/com/damon/base/activity/BaseActivity.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,103 @@ | ||
package com.damon.base.activity; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.damon.app.App; | ||
import com.damon.base.view.IView; | ||
import com.damon.di.component.ActivityComponent; | ||
import com.damon.di.component.DaggerActivityComponent; | ||
import com.damon.utils.CommonUtils; | ||
|
||
import butterknife.ButterKnife; | ||
import butterknife.Unbinder; | ||
|
||
/** | ||
* @author: DamonJiang | ||
* @date: 2018/9/21 0021 | ||
* @description: activity 超类 | ||
*/ | ||
public abstract class BaseActivity extends AppCompatActivity implements IView { | ||
|
||
private Unbinder unbinder; | ||
protected ActivityComponent activityComponent; | ||
|
||
protected abstract int getLayoutId(); // 初始化 UI | ||
|
||
protected abstract void onAttachView(); // 注入 view | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(getLayoutId()); | ||
// 依赖注入 | ||
activityComponent = DaggerActivityComponent.builder() | ||
.appComponent(App.getContext().getAppComponent()) | ||
.build(); | ||
|
||
onAttachView(); | ||
|
||
//绑定初始化 ButterKnife | ||
unbinder = ButterKnife.bind(this); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
if (unbinder != null && unbinder != Unbinder.EMPTY) { | ||
unbinder.unbind(); | ||
unbinder = null; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* 不带返回码的页面跳转, | ||
* 如果是不需要传参,则 bundle 传 null 即可 | ||
* | ||
* @param clazz | ||
* @param bundle | ||
*/ | ||
public void startActivity(Class<?> clazz, Bundle bundle) { | ||
try { | ||
Intent intent = new Intent(this, clazz); | ||
if (bundle != null) intent.putExtras(bundle); | ||
startActivity(intent); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* 带返回码的页面跳转, | ||
* 如果是不需要传参,则 bundle 传 null 即可 | ||
* | ||
* @param clazz | ||
* @param bundle | ||
*/ | ||
public void startActivityForResult(Class<?> clazz, Bundle bundle, int requestCode) { | ||
try { | ||
Intent intent = new Intent(this, clazz); | ||
if (bundle != null) intent.putExtras(bundle); | ||
startActivityForResult(intent, requestCode); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onShowError(String errorMsg) { | ||
CommonUtils.showToast(this, errorMsg); | ||
} | ||
|
||
@Override | ||
public void onShowLoading() {} | ||
|
||
@Override | ||
public void onDissLoading() { | ||
|
||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/com/damon/base/activity/MVPBaseActivity.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,50 @@ | ||
package com.damon.base.activity; | ||
|
||
|
||
import android.util.Log; | ||
|
||
import com.damon.base.presenter.IPresenter; | ||
import com.damon.base.view.IView; | ||
|
||
import javax.inject.Inject; | ||
|
||
/** | ||
* @author: DamonJiang | ||
* @date: 2018/9/21 0021 | ||
* @description: mvp 模式下的 Activity 超类 | ||
* <p> | ||
* 作用:沉淀 view 的公共回调函数,提供给子类使用。 | ||
* 约束:所有 mvp 下的 activity 都必须实现该类,并明确指定泛型 presenter, | ||
* 使用 dagger2 注解将 p 注入到 view 中,子类直接使用 mPresenter 即可。 | ||
* </P> | ||
*/ | ||
public abstract class MVPBaseActivity<T extends IPresenter> extends BaseActivity implements IView { | ||
private static final String TAG = "MVPBaseActivity"; | ||
@Inject | ||
protected T mPresenter; | ||
protected abstract void inject(); // Dageer 注入 | ||
|
||
/** | ||
* 将 view 注入到 presenter | ||
*/ | ||
@Override | ||
protected void onAttachView() { | ||
inject(); | ||
if (mPresenter != null) { | ||
mPresenter.onAttachView(this); | ||
} | ||
} | ||
|
||
/** | ||
* 销毁当前页面时清除 View 层持有的 Presenter层对象,防止内存泄露 | ||
*/ | ||
@Override | ||
protected void onDestroy() { | ||
if (mPresenter != null) { | ||
mPresenter.onDetachView(); | ||
mPresenter = null; | ||
System.gc(); | ||
} | ||
super.onDestroy(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/damon/base/presenter/BasePresenter.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,43 @@ | ||
package com.damon.base.presenter; | ||
|
||
|
||
import com.damon.base.view.IView; | ||
|
||
import io.reactivex.disposables.CompositeDisposable; | ||
import io.reactivex.disposables.Disposable; | ||
|
||
/** | ||
* @author: DamonJiang | ||
* @date: 2018/9/21 0021 | ||
* @description: presenter 超类 | ||
* <p> | ||
* 作用:给所有子类提供公共的回调函数,所有具体的 presenter 都要实现这个类, | ||
* </p> | ||
*/ | ||
public class BasePresenter<T extends IView> implements IPresenter<T> { | ||
private CompositeDisposable compositeDisposable; | ||
protected T mView; | ||
|
||
|
||
@Override | ||
public void onAttachView(T view) { | ||
this.mView = view; | ||
} | ||
|
||
@Override | ||
public void onDetachView() { | ||
this.mView = null; | ||
if (compositeDisposable != null) { | ||
compositeDisposable.clear(); | ||
System.gc(); | ||
} | ||
} | ||
|
||
protected void addSubscribe(Disposable disposable) { | ||
if (compositeDisposable == null) { | ||
compositeDisposable = new CompositeDisposable(); | ||
} | ||
compositeDisposable.add(disposable); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/damon/base/presenter/IPresenter.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,27 @@ | ||
package com.damon.base.presenter; | ||
|
||
import com.damon.base.view.IView; | ||
|
||
/** | ||
* @author: DamonJiang | ||
* @date: 2018/9/21 0021 | ||
* @description: mvp 模式下 p 层的抽象出来的接口类, | ||
* <p> | ||
* 作用:主要封装一些公共的回调函数,由 BasePresenter 实现该 | ||
* 接口类,BasePresenter 的子类可以根据自己的业务需求进行 | ||
* 继续扩展业务回调函数。 | ||
* </p> | ||
*/ | ||
public interface IPresenter<T extends IView> { | ||
/** | ||
* 注入 view | ||
* | ||
* @param view | ||
*/ | ||
void onAttachView(T view); | ||
|
||
/** | ||
* 回收View | ||
*/ | ||
void onDetachView(); | ||
} |
Oops, something went wrong.