提交 61a04465 编写于 作者: 门心叼龙's avatar 门心叼龙

dagger2 add

上级 e1e31ec2
......@@ -17,6 +17,7 @@
<option value="$PROJECT_DIR$/module_main" />
<option value="$PROJECT_DIR$/module_me" />
<option value="$PROJECT_DIR$/module_news" />
<option value="$PROJECT_DIR$/module_test" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
......
......@@ -29,7 +29,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -12,6 +12,7 @@
<module fileurl="file://$PROJECT_DIR$/module_main/module_main.iml" filepath="$PROJECT_DIR$/module_main/module_main.iml" />
<module fileurl="file://$PROJECT_DIR$/module_me/module_me.iml" filepath="$PROJECT_DIR$/module_me/module_me.iml" />
<module fileurl="file://$PROJECT_DIR$/module_news/module_news.iml" filepath="$PROJECT_DIR$/module_news/module_news.iml" />
<module fileurl="file://$PROJECT_DIR$/module_test/module_test.iml" filepath="$PROJECT_DIR$/module_test/module_test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
因为 它太大了无法显示 source diff 。你可以改为 查看blob
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="FlyTour" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
......
......@@ -73,7 +73,7 @@ dependencies {
api deps.stetho
annotationProcessor deps.glide_compiler
annotationProcessor deps.arouter_compiler
annotationProcessor deps.glide_compiler
annotationProcessor deps.dagger_compiler
}
["arouter-compiler-1.2.2.jar (com.alibaba:arouter-compiler:1.2.2)","auto-service-1.0-rc2.jar (com.google.auto.service:auto-service:1.0-rc2)","compiler-4.8.0.jar (com.github.bumptech.glide:compiler:4.8.0)"]
\ No newline at end of file
["arouter-compiler-1.2.2.jar (com.alibaba:arouter-compiler:1.2.2)","dagger-compiler-2.13.jar (com.google.dagger:dagger-compiler:2.13)","auto-service-1.0-rc2.jar (com.google.auto.service:auto-service:1.0-rc2)","compiler-4.8.0.jar (com.github.bumptech.glide:compiler:4.8.0)"]
\ No newline at end of file
package com.fly.tour.common.base;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
......@@ -235,4 +236,9 @@ public abstract class BaseActivity extends RxAppCompatActivity implements BaseVi
@Subscribe(threadMode = ThreadMode.MAIN)
public <T> void onEvent(BaseActivityEvent<T> event) {
}
@Override
public Context getContext() {
return this;
}
}
package com.fly.tour.common.dagger.base;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.fly.tour.common.R;
import com.fly.tour.common.event.common.BaseActivityEvent;
import com.fly.tour.common.manager.ActivityManager;
import com.fly.tour.common.mvp.BaseView;
import com.fly.tour.common.util.NetUtil;
import com.fly.tour.common.view.LoadingInitView;
import com.fly.tour.common.view.LoadingTransView;
import com.fly.tour.common.view.NetErrorView;
import com.fly.tour.common.view.NoDataView;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
/**
* Description: <BaseActivity><br>
* Author: gxl<br>
* Date: 2018/1/16<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseActivity extends RxAppCompatActivity implements BaseView {
protected static final String TAG = BaseActivity.class.getSimpleName();
protected TextView mTxtTitle;
protected Toolbar mToolbar;
protected NetErrorView mNetErrorView;
protected NoDataView mNoDataView;
protected LoadingInitView mLoadingInitView;
protected LoadingTransView mLoadingTransView;
private ViewStub mViewStubToolbar;
private ViewStub mViewStubContent;
private ViewStub mViewStubInitLoading;
private ViewStub mViewStubTransLoading;
private ViewStub mViewStubNoData;
private ViewStub mViewStubError;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_root);
initCommonView();
ARouter.getInstance().inject(this);
initView();
initListener();
initData();
EventBus.getDefault().register(this);
ActivityManager.getInstance().addActivity(this);
}
protected void initCommonView() {
mViewStubToolbar = findViewById(R.id.view_stub_toolbar);
mViewStubContent = findViewById(R.id.view_stub_content);
mViewStubContent = findViewById(R.id.view_stub_content);
mViewStubInitLoading = findViewById(R.id.view_stub_init_loading);
mViewStubTransLoading = findViewById(R.id.view_stub_trans_loading);
mViewStubError = findViewById(R.id.view_stub_error);
mViewStubNoData = findViewById(R.id.view_stub_nodata);
if (enableToolbar()) {
mViewStubToolbar.setLayoutResource(onBindToolbarLayout());
View view = mViewStubToolbar.inflate();
initToolbar(view);
}
mViewStubContent.setLayoutResource(onBindLayout());
mViewStubContent.inflate();
}
protected void initToolbar(View view) {
mToolbar = view.findViewById(R.id.toolbar_root);
mTxtTitle = view.findViewById(R.id.toolbar_title);
if (mToolbar != null) {
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
if (mTxtTitle != null && !TextUtils.isEmpty(title)) {
mTxtTitle.setText(title);
}
//可以再次覆盖设置title
String tootBarTitle = getTootBarTitle();
if (mTxtTitle != null && !TextUtils.isEmpty(tootBarTitle)) {
mTxtTitle.setText(tootBarTitle);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
ActivityManager.getInstance().finishActivity(this);
}
public int onBindToolbarLayout() {
return R.layout.common_toolbar;
}
public abstract int onBindLayout();
public abstract void initView();
public abstract void initData();
public void initListener() {
}
@Override
public void finishActivity() {
finish();
}
public String getTootBarTitle() {
return "";
}
public boolean enableToolbar() {
return true;
}
public void showInitLoadView() {
showInitLoadView(true);
}
public void hideInitLoadView() {
showInitLoadView(false);
}
@Override
public void showTransLoadingView() {
showTransLoadingView(true);
}
@Override
public void hideTransLoadingView() {
showTransLoadingView(false);
}
public void showNoDataView() {
showNoDataView(true);
}
public void showNoDataView(int resid) {
showNoDataView(true, resid);
}
public void hideNoDataView() {
showNoDataView(false);
}
public void hideNetWorkErrView() {
showNetWorkErrView(false);
}
public void showNetWorkErrView() {
showNetWorkErrView(true);
}
private void showInitLoadView(boolean show) {
if (mLoadingInitView == null) {
View view = mViewStubInitLoading.inflate();
mLoadingInitView = view.findViewById(R.id.view_init_loading);
}
mLoadingInitView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoadingInitView.loading(show);
}
private void showNetWorkErrView(boolean show) {
if (mNetErrorView == null) {
View view = mViewStubError.inflate();
mNetErrorView = view.findViewById(R.id.view_net_error);
mNetErrorView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!NetUtil.checkNetToast()) {
return;
}
hideNetWorkErrView();
initData();
}
});
}
mNetErrorView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void showNoDataView(boolean show) {
if (mNoDataView == null) {
View view = mViewStubNoData.inflate();
mNoDataView = view.findViewById(R.id.view_no_data);
}
mNoDataView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void showNoDataView(boolean show, int resid) {
showNoDataView(show);
if (show) {
mNoDataView.setNoDataView(resid);
}
}
private void showTransLoadingView(boolean show) {
if (mLoadingTransView == null) {
View view = mViewStubTransLoading.inflate();
mLoadingTransView = view.findViewById(R.id.view_trans_loading);
}
mLoadingTransView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoadingTransView.loading(show);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public <T> void onEvent(BaseActivityEvent<T> event) {
}
@Override
public Context getContext() {
return this;
}
}
package com.fly.tour.common.dagger.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.fly.tour.common.dagger.mvp.BaseModel;
import com.fly.tour.common.dagger.mvp.BasePresenter;
import javax.inject.Inject;
/**
* Description: <BaseMvpActivity><br>
* Author: gxl<br>
* Date: 2018/1/16<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseMvpActivity<M extends BaseModel,V,P extends BasePresenter<M,V>> extends BaseActivity {
@Inject
public P mPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
injectPresenter();
if(mPresenter != null){
mPresenter.injectLifecycle(this);
}
super.onCreate(savedInstanceState);
}
public abstract void injectPresenter();
@Override
protected void onDestroy() {
super.onDestroy();
if(mPresenter != null){
mPresenter.detach();
}
}
}
package com.fly.tour.common.dagger.base;
import com.fly.tour.common.dagger.mvp.BaseModel;
import com.fly.tour.common.dagger.mvp.BaseRefreshPresenter;
import com.fly.tour.common.dagger.mvp.BaseRefreshView;
import com.refresh.lib.BaseRefreshLayout;
import com.refresh.lib.DaisyRefreshLayout;
/**
* Description: <下拉刷新、上拉加载更多的Activity><br>
* Author: gxl<br>
* Date: 2018/2/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseRefreshActivity<M extends BaseModel, V extends BaseRefreshView<T>, P extends BaseRefreshPresenter<M, V, T>, T> extends BaseMvpActivity<M, V, P> implements BaseRefreshView<T> {
protected DaisyRefreshLayout mRefreshLayout;
@Override
protected void initCommonView() {
super.initCommonView();
initRefreshView();
}
public void initRefreshView() {
mRefreshLayout = findViewById(onBindRreshLayout());
// 下拉刷新
mRefreshLayout.setOnRefreshListener(new BaseRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
onRefreshEvent();
}
});
// 上拉加载
mRefreshLayout.setOnLoadMoreListener(new BaseRefreshLayout.OnLoadMoreListener() {
@Override
public void onLoadMore() {
onLoadMoreEvent();
}
});
// 自动加载
mRefreshLayout.setOnAutoLoadListener(new BaseRefreshLayout.OnAutoLoadListener() {
@Override
public void onAutoLoad() {
onAutoLoadEvent();
}
});
}
protected abstract int onBindRreshLayout();
@Override
public void enableRefresh(boolean b) {
mRefreshLayout.setEnableRefresh(b);
}
@Override
public void enableLoadMore(boolean b) {
mRefreshLayout.setEnableLoadMore(b);
}
@Override
public void stopRefresh() {
mRefreshLayout.setRefreshing(false);
}
@Override
public void stopLoadMore() {
mRefreshLayout.setLoadMore(false);
}
@Override
public void autoLoadData() {
mRefreshLayout.autoRefresh();
}
}
package com.fly.tour.common.dagger.mvp;
import android.content.Context;
import com.trello.rxlifecycle2.LifecycleProvider;
import javax.inject.Inject;
/**
* Description: <BaseModel><br>
* Author: gxl<br>
* Date: 2018/3/18<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class BaseModel {
private Context mContext;
public BaseModel(Context context) {
mContext = context;
}
private LifecycleProvider lifecycle;
public void injectLifecycle(LifecycleProvider lifecycle) {
this.lifecycle = lifecycle;
}
public LifecycleProvider getLifecycle() {
return lifecycle;
}
public Context getContext() {
return mContext;
}
public void destory(){}
}
package com.fly.tour.common.dagger.mvp;
import android.content.Context;
import com.trello.rxlifecycle2.LifecycleProvider;
import javax.inject.Inject;
/**
* Description: <BasePresenter><br>
* Author: gxl<br>
* Date: 2018/1/15<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BasePresenter<M extends BaseModel, V> {
protected Context mContext;
protected V mView;
protected M mModel;
public BasePresenter(Context context,V view, M model) {
this.mContext = context;
mView = view;
mModel = model;
}
public BasePresenter(Context context) {
mContext = context;
}
public void detach() {
detachView();
detachModel();
}
public void detachView() {
mView = null;
}
public void detachModel() {
mModel.destory();
mModel = null;
}
public void injectLifecycle(LifecycleProvider lifecycle) {
if (mModel != null) {
mModel.injectLifecycle(lifecycle);
}
}
}
package com.fly.tour.common.dagger.mvp;
import com.fly.tour.common.mvp.BaseView;
/**
* Description: <基本的刷新数据协议><br>
* Author: gxl<br>
* Date: 2018/2/25<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface BaseRefreshContract {
interface Presenter {
/**
* 刷新数据
*/
void refreshData();
/**
* 加载更多
*/
void loadMoreData();
}
interface View extends BaseView{
/**
* 是否启用下拉刷新
* @param b
*/
void enableRefresh(boolean b);
/**
*是否启用上拉加载更多
*/
void enableLoadMore(boolean b);
/**
*刷新回调
*/
void onRefreshEvent();
/**
* 加载更多的回调
*/
void onLoadMoreEvent();
/**
* 自动加载的事件
*/
void onAutoLoadEvent();
/**
* 停止刷新
*/
void stopRefresh();
/**
* 停止加载更多
*/
void stopLoadMore();
/**
* 自动加载数据
*/
void autoLoadData();
}
}
package com.fly.tour.common.dagger.mvp;
import android.content.Context;
/**
* Description: <BaseRefreshPresenter><br>
* Author: gxl<br>
* Date: 2018/2/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseRefreshPresenter<M extends BaseModel,V extends BaseRefreshView<T>,T> extends BasePresenter<M,V> implements BaseRefreshContract.Presenter{
public BaseRefreshPresenter(Context context) {
super(context);
}
}
package com.fly.tour.common.dagger.mvp;
import com.fly.tour.common.mvp.BaseRefreshContract;
import java.util.List;
/**
* Description: <BaseRefreshView><br>
* Author: gxl<br>
* Date: 2018/2/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface BaseRefreshView<T> extends BaseRefreshContract.View {
//刷新数据
void refreshData(List<T> data);
//加载更多
void loadMoreData(List<T> data);
}
package com.fly.tour.common.mvp;
import android.content.Context;
/**
* Description: <BaseView><br>
* Author: gxl<br>
......@@ -12,4 +14,5 @@ public interface BaseView extends ILoadView,INoDataView,ITransView,INetErrView{
void initListener();
void initData();
void finishActivity();
Context getContext();
}
......@@ -31,4 +31,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
......@@ -31,4 +31,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api deps.dagger
annotationProcessor deps.dagger_compiler
}
......@@ -12,6 +12,8 @@ import com.fly.tour.db.entity.NewsDetail;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
/**
* Description: <NewsTypeDao><br>
* Author: gxl<br>
......@@ -22,6 +24,7 @@ import java.util.List;
public class NewsDetailDao {
private SQLiteDatabase mDatabase;
@Inject
public NewsDetailDao(Context context) {
mDatabase = NewsDBHelper.getInstance(context).getReadableDatabase();
}
......
......@@ -88,6 +88,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/apk_list" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-libraries" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/checkDebugClasspath" />
......
......@@ -49,4 +49,5 @@ dependencies {
annotationProcessor deps.arouter_compiler
annotationProcessor deps.glide_compiler
annotationProcessor deps.dagger_compiler
}
}
......@@ -2,18 +2,20 @@ package com.fly.tour.news;
import android.content.Context;
import android.content.Intent;
import android.support.test.espresso.DaggerBaseLayerComponent;
import android.widget.TextView;
import com.fly.tour.common.base.BaseMvpActivity;
import com.fly.tour.common.dagger.base.BaseMvpActivity;
import com.fly.tour.common.event.KeyCode;
import com.fly.tour.db.entity.NewsDetail;
import com.fly.tour.news.contract.NewsDetailContract;
import com.fly.tour.news.model.NewsDetailModel;
import com.fly.tour.news.presenter.NewsDetailPresenter;
import com.fly.tour.news.dagger.inject.component.DaggerNewsDetailComponent;
import com.fly.tour.news.dagger.inject.module.NewsDetailModule;
import com.fly.tour.news.dagger.model.NewsDetailModel;
import com.fly.tour.news.dagger.presenter.NewsDetailPresenter;
import com.fly.tour.trip.R;
public class NewsDetailActivity extends BaseMvpActivity<NewsDetailModel,NewsDetailContract.View,NewsDetailPresenter> implements NewsDetailContract.View{
public static void startNewsDetailActivity(Context context,int id){
Intent intent = new Intent(context, NewsDetailActivity.class);
intent.putExtra(KeyCode.News.NEWS_ID,id);
......@@ -39,14 +41,16 @@ public class NewsDetailActivity extends BaseMvpActivity<NewsDetailModel,NewsDeta
mPresenter.getNewsDetailById(newsid);
}
@Override
public NewsDetailPresenter initPresenter() {
return new NewsDetailPresenter(this);
}
@Override
public void showNewsDetail(NewsDetail newsDetail) {
mTxtNewsTitle.setText(newsDetail.getTitle());
mTxtNewsContent.setText(newsDetail.getContent());
}
@Override
public void injectPresenter() {
DaggerNewsDetailComponent.builder().newsDetailModule(new NewsDetailModule(this)).build().inject(this);
}
}
package com.fly.tour.news.dagger.inject.component;
import com.fly.tour.news.NewsDetailActivity;
import com.fly.tour.news.dagger.inject.module.NewsDetailModule;
import dagger.Component;
/**
* Description: <NewsDetailComponent><br>
* Author: gxl<br>
* Date: 2019/5/31<br>
* Version: V1.0.0<br>
* Update: <br>
*/
@Component(modules = {NewsDetailModule.class})
public interface NewsDetailComponent {
void inject(NewsDetailActivity activity);
}
package com.fly.tour.news.dagger.inject.module;
import android.content.Context;
import com.fly.tour.news.contract.NewsDetailContract;
import com.fly.tour.news.dagger.model.NewsDetailModel;
import dagger.Module;
import dagger.Provides;
/**
* Description: <NewsDetailModule><br>
* Author: gxl<br>
* Date: 2019/5/31<br>
* Version: V1.0.0<br>
* Update: <br>
*/
@Module
public class NewsDetailModule {
private NewsDetailContract.View mView;
public NewsDetailModule(NewsDetailContract.View view) {
this.mView = view;
}
@Provides
public Context providerContext(){
return mView.getContext();
}
@Provides
public NewsDetailContract.View providerNewsDetailView(){
return mView;
}
}
package com.fly.tour.news.dagger.model;
import android.content.Context;
import com.fly.tour.common.dagger.mvp.BaseModel;
import com.fly.tour.db.dao.NewsDetailDao;
import com.fly.tour.db.entity.NewsDetail;
import com.fly.tour.news.contract.NewsDetailContract;
import javax.inject.Inject;
/**
* Description: <NewsDetailModel><br>
* Author: gxl<br>
* Date: 2019/5/29<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class NewsDetailModel extends BaseModel implements NewsDetailContract.Model {
private NewsDetailDao mNewsDetailDao;
@Inject
public NewsDetailModel(Context context,NewsDetailDao detailDao) {
super(context);
mNewsDetailDao = detailDao;
}
@Override
public NewsDetail getNewsDetailById(int id) {
return mNewsDetailDao.getNewsDetailById(id);
}
}
package com.fly.tour.news.dagger.presenter;
import android.content.Context;
import android.util.Log;
import com.fly.tour.common.dagger.mvp.BasePresenter;
import com.fly.tour.common.util.NetUtil;
import com.fly.tour.common.util.log.KLog;
import com.fly.tour.db.entity.NewsDetail;
import com.fly.tour.news.contract.NewsDetailContract;
import com.fly.tour.news.dagger.model.NewsDetailModel;
import javax.inject.Inject;
/**
* Description: <NewsDetailPresenter><br>
* Author: gxl<br>
* Date: 2019/5/29<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class NewsDetailPresenter extends BasePresenter<NewsDetailModel,NewsDetailContract.View> implements NewsDetailContract.Presenter{
@Inject
public NewsDetailPresenter(Context context, NewsDetailContract.View view, NewsDetailModel model) {
super(context, view, model);
}
@Override
public void getNewsDetailById(final int id) {
KLog.v("MYTAG","context:"+mContext);
mView.showInitLoadView();
new android.os.Handler().postDelayed(new Runnable() {
@Override
public void run() {
if(!NetUtil.checkNetToast()){
mView.showNetWorkErrView();
return;
}
NewsDetail newsDetail = mModel.getNewsDetailById(id);
if(newsDetail != null){
mView.showNewsDetail(newsDetail);
}else{
mView.showNoDataView();
}
mView.hideInitLoadView();
}
},1000 * 2);
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.fly.tour.test"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api 'com.google.dagger:dagger:2.13'
annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.fly.tour.test;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.fly.tour.test", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fly.tour.test">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.fly.tour.test;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.fly.tour.test.inject.component.DaggerMainActivityComponent;
import com.fly.tour.test.presenter.MainPresenter;
import javax.inject.Inject;
public class MainActivity extends AppCompatActivity {
@Inject
public MainPresenter mMainPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DaggerMainActivityComponent.create().inject(this);
mMainPresenter.prinitHelloWorld();
}
}
package com.fly.tour.test.inject.component;
import com.fly.tour.test.MainActivity;
import dagger.Component;
/**
* Description: <MainActivityComponent><br>
* Author: gxl<br>
* Date: 2019/5/31<br>
* Version: V1.0.0<br>
* Update: <br>
*/
@Component
public interface MainActivityComponent {
void inject(MainActivity mainActivity);
}
package com.fly.tour.test.presenter;
import android.util.Log;
import javax.inject.Inject;
/**
* Description: <MainPresenter><br>
* Author: gxl<br>
* Date: 2019/5/31<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MainPresenter {
@Inject
public MainPresenter() {
}
public void prinitHelloWorld(){
Log.v("MYTAG","hello world");
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0"/>
<item
android:color="#00000000"
android:offset="1.0"/>
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z"/>
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
<resources>
<string name="app_name">module_test</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
package com.fly.tour.test;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
include ':module_app', ':lib_common', ':module_main', ':module_news', ':module_find', ':module_me', ':lib_refresh_layout', ':lib_fly_db', ':lib_fly_api'
include ':module_app', ':lib_common', ':module_main', ':module_news', ':module_find', ':module_me', ':lib_refresh_layout', ':lib_fly_db', ':lib_fly_api', ':module_test'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册