Skip to content

Commit

Permalink
移除view第三方库
Browse files Browse the repository at this point in the history
  • Loading branch information
haife committed Jan 12, 2023
1 parent c4cbfc1 commit 94f6e2c
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 271 deletions.
9 changes: 8 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation project(path: ':mcas')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/java/com/haife/mcas/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ package com.haife.mcas

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.haife.mcas.base.BaseSupportActivity
import com.haife.mcas.base.BaseSwipeBackActivity
import com.haife.mcas.di.component.AppComponent
import com.haife.mcas.mvp.IPresenter
import com.haife.mcas.mvp.presenter.MainPresenter

class MainActivity : BaseSwipeBackActivity<MainPresenter>() {


override fun setupActivityComponent(appComponent: AppComponent) {

}

override fun initView(savedInstanceState: Bundle?): Int = R.layout.activity_main

override fun initData(savedInstanceState: Bundle?) {

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/haife/mcas/di/component/MainComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.haife.mcas.di.component

import com.haife.mcas.MainActivity
import com.haife.mcas.di.module.MainModule
import com.haife.mcas.mvp.ui.fragment.MainFragment
import dagger.Component


@Component(modules = [MainModule::class], dependencies = [AppComponent::class])
interface MainComponent {
fun inject(fragment: MainActivity)
fun inject(fragment: MainFragment)

}
23 changes: 23 additions & 0 deletions app/src/main/java/com/haife/mcas/di/module/MainModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.haife.mcas.di.module

import com.haife.mcas.di.scope.ActivityScope
import com.haife.mcas.mvp.contract.MainContract
import com.haife.mcas.mvp.model.MainModel
import dagger.Module
import dagger.Provides

@Module
//构建MainModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
class MainModule(private val view: MainContract.View) {
@ActivityScope
@Provides
fun provideMainView(): MainContract.View {
return this.view
}

@ActivityScope
@Provides
fun provideMainModel(model: MainModel): MainContract.Model {
return model
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/haife/mcas/mvp/contract/MainContract.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.haife.mcas.mvp.contract

import androidx.fragment.app.Fragment
import com.haife.mcas.mvp.IModel
import com.haife.mcas.mvp.IView

interface MainContract {
interface View : IView {

fun getFragment(): Fragment

}

interface Model : IModel
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/haife/mcas/mvp/model/MainModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.haife.mcas.mvp.model

import android.app.Application
import com.google.gson.Gson
import com.haife.mcas.di.scope.ActivityScope
import com.haife.mcas.integration.IRepositoryManager
import com.haife.mcas.mvp.BaseModel
import com.haife.mcas.mvp.contract.MainContract
import javax.inject.Inject

@ActivityScope
class MainModel
@Inject
constructor(repositoryManager: IRepositoryManager) : BaseModel(repositoryManager), MainContract.Model {
@Inject
lateinit var mGson: Gson

@Inject
lateinit var mApplication: Application

override fun onDestroy() {
super.onDestroy()
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/haife/mcas/mvp/presenter/MainPresenter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.haife.mcas.mvp.presenter

import android.app.Application
import com.haife.mcas.di.scope.ActivityScope
import com.haife.mcas.di.scope.FragmentScope
import com.haife.mcas.http.imageloader.ImageLoader
import com.haife.mcas.integration.AppManager
import com.haife.mcas.mvp.BasePresenter
import com.haife.mcas.mvp.contract.MainContract

import me.jessyan.rxerrorhandler.core.RxErrorHandler
import javax.inject.Inject


@ActivityScope
class MainPresenter
@Inject
constructor(model: MainContract.Model, rootView: MainContract.View) :
BasePresenter<MainContract.Model, MainContract.View>(model, rootView) {
@Inject
lateinit var mErrorHandler: RxErrorHandler

@Inject
lateinit var mApplication: Application

@Inject
lateinit var mImageLoader: ImageLoader

@Inject
lateinit var mAppManager: AppManager

}
47 changes: 47 additions & 0 deletions app/src/main/java/com/haife/mcas/mvp/ui/fragment/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.haife.mcas.mvp.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.haife.mcas.R
import com.haife.mcas.base.BaseSupportFragment
import com.haife.mcas.di.component.AppComponent
import com.haife.mcas.di.module.MainModule
import com.haife.mcas.mvp.contract.MainContract
import com.haife.mcas.mvp.presenter.MainPresenter


class MainFragment : BaseSupportFragment<MainPresenter>(), MainContract.View {
companion object {
fun newInstance(): MainFragment {
val fragment = MainFragment()
return fragment
}
}

override fun setupFragmentComponent(appComponent: AppComponent) {

}

override fun initView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return inflater.inflate(R.layout.fragment_main, container, false)
}

/**
* 在 onActivityCreate()时调用
*/
override fun initData(savedInstanceState: Bundle?) {
initListener()
}

private fun initListener() {

}

override fun getFragment(): Fragment = this
override fun showMessage(message: String) {

}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

</LinearLayout>
2 changes: 1 addition & 1 deletion config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ext {
retrofitSdkVersion : "2.4.0",
dagger2SdkVersion : "2.19",
glideSdkVersion : "4.11.0",
fragmentationVersion : "1.0.2",
fragmentationVersion : "1.0.1",
butterknifeSdkVersion : "10.0.0",
rxlifecycleSdkVersion : "1.0",
rxlifecycle2SdkVersion : "2.2.2",
Expand Down
1 change: 1 addition & 0 deletions mcas/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ dependencies {
compileOnly rootProject.ext.dependencies["eventbus"]
api rootProject.ext.dependencies["gson"]
//view
api rootProject.ext.dependencies["qmui"]
api rootProject.ext.dependencies["fragmentation"]
api rootProject.ext.dependencies["fragmentation-code"]
api rootProject.ext.dependencies["fragmentation-swipeback"]
Expand Down
22 changes: 10 additions & 12 deletions mcas/src/main/java/com/haife/mcas/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,23 @@
import static com.haife.mcas.utils.ThirdViewUtil.convertAutoView;


/**
* Copyright © KaiWu Technology Company
*
* @author Haife
* @job Android Development
* @company KW | 开物科技
* @time 2019/7/1
* @desc 因为 Java 只能单继承, 所以如果要用到需要继承特定 {@link Activity} 的三方库, 那你就需要自己自定义 {@link Activity}
* 继承于这个特定的 {@link Activity}, 然后再按照 {@link BaseActivity} 的格式, 将代码复制过去, 记住一定要实现{@link IActivity}
*/
/**
* @company Copyright © Beijing Technology Company
* @since 2023/1/12
* @author Android Development
* @des:
*/
public abstract class BaseActivity<P extends IPresenter> extends AppCompatActivity implements IActivity, ActivityLifecycleable {
protected final String TAG = this.getClass().getSimpleName();
private final BehaviorSubject<ActivityEvent> mLifecycleSubject = BehaviorSubject.create();
private Cache<String, Object> mCache;
private Unbinder mUnbinder;
/**
* 如果当前页面逻辑简单, Presenter 可以为 null
*/
@Inject
@Nullable
protected P mPresenter;//如果当前页面逻辑简单, Presenter 可以为 null
protected P mPresenter;

@NonNull
@Override
Expand Down Expand Up @@ -80,7 +79,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
//如果initView返回0,框架则不会调用setContentView(),当然也不会 Bind ButterKnife
if (layoutResID != 0) {
setContentView(layoutResID);
//绑定到butterknife
mUnbinder = ButterKnife.bind(this);
}
} catch (Exception e) {
Expand Down
Loading

0 comments on commit 94f6e2c

Please sign in to comment.