a
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,89 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
apply plugin: 'com.google.dagger.hilt.android'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
versionCode rootProject.ext.android.versionCode
|
||||
versionName rootProject.ext.android.versionName
|
||||
multiDexEnabled true
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments += [
|
||||
"room.schemaLocation":"$projectDir/schemas".toString(),
|
||||
"room.incremental":"true",
|
||||
"room.expandProjection":"true",
|
||||
AROUTER_MODULE_NAME: project.getName()
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
kapt {
|
||||
arguments {
|
||||
arg("AROUTER_MODULE_NAME", project.getName())
|
||||
}
|
||||
generateStubs = true
|
||||
useBuildCache = true
|
||||
javacOptions {
|
||||
option("-Xmaxerrs", 500)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:common-base"))
|
||||
compileOnly(project(":common:common-service"))
|
||||
kapt rootProject.ext.compiler["arouterCompiler"]
|
||||
|
||||
compileOnly(rootProject.ext.jetpack["hilt"])
|
||||
kapt rootProject.ext.compiler["hiltAndroidCompiler"]
|
||||
}
|
||||
|
||||
// 发布module到maven仓库
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.17.0'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
plugins.withId("com.vanniktech.maven.publish") {
|
||||
mavenPublish {
|
||||
sonatypeHost = "S01"
|
||||
}
|
||||
}
|
||||
}
|
||||
apply plugin: "com.vanniktech.maven.publish"
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
-keep class com.bbgo.module_collect.bean.** {*;}
|
||||
@@ -0,0 +1,23 @@
|
||||
# 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
|
||||
|
||||
-keep class com.bbgo.module_collect.bean.** {*;}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.bbgo.module_collect
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.bbgo.module_collect.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.bbgo.module_collect">
|
||||
|
||||
</manifest>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.bbgo.module_collect.bean
|
||||
|
||||
import androidx.annotation.Keep
|
||||
|
||||
/**
|
||||
* author: wangyb
|
||||
* date: 2021/5/27 7:10 下午
|
||||
* description: todo
|
||||
*/
|
||||
@Keep
|
||||
data class CollectBean(val data: Any, var positon: Int, var type: String)
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.bbgo.module_collect.net.api
|
||||
|
||||
import com.bbgo.common_base.bean.HttpResult
|
||||
import com.bbgo.module_collect.bean.CollectBean
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Path
|
||||
|
||||
/**
|
||||
* author: wangyb
|
||||
* date: 4/7/21 9:24 PM
|
||||
* description: http api
|
||||
*/
|
||||
interface HttpApiService {
|
||||
|
||||
/**
|
||||
* 收藏站内文章
|
||||
* http://www.wanandroid.com/lg/collect/1165/json
|
||||
* @param id article id
|
||||
*/
|
||||
@POST("lg/collect/{id}/json")
|
||||
fun addCollectArticle(@Path("id") id: Int): Flow<HttpResult<CollectBean>>
|
||||
|
||||
/**
|
||||
* 文章列表中取消收藏文章
|
||||
* http://www.wanandroid.com/lg/uncollect_originId/2333/json
|
||||
* @param id
|
||||
*/
|
||||
@POST("lg/uncollect_originId/{id}/json")
|
||||
fun cancelCollectArticle(@Path("id") id: Int): Flow<HttpResult<CollectBean>>
|
||||
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.bbgo.module_collect.repository
|
||||
|
||||
import com.bbgo.common_base.bean.HttpResult
|
||||
import com.bbgo.common_base.net.ServiceCreators
|
||||
import com.bbgo.module_collect.bean.CollectBean
|
||||
import com.bbgo.module_collect.net.api.HttpApiService
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* author: wangyb
|
||||
* date: 3/29/21 9:32 PM
|
||||
* description: todo
|
||||
*/
|
||||
class CollectRepository private constructor() {
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var repository: CollectRepository? = null
|
||||
|
||||
fun getInstance(): CollectRepository {
|
||||
if (repository == null) {
|
||||
synchronized(CollectRepository::class.java) {
|
||||
if (repository == null) {
|
||||
repository = CollectRepository()
|
||||
}
|
||||
}
|
||||
}
|
||||
return repository!!
|
||||
}
|
||||
}
|
||||
|
||||
private val service = ServiceCreators.create(HttpApiService::class.java)
|
||||
|
||||
fun collectArticle(id: Int) : Flow<HttpResult<CollectBean>> {
|
||||
return service.addCollectArticle(id)
|
||||
}
|
||||
|
||||
fun unCollectArticle(id: Int) : Flow<HttpResult<CollectBean>> {
|
||||
return service.cancelCollectArticle(id)
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.bbgo.module_collect.service
|
||||
|
||||
import android.content.Context
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.bbgo.common_base.constants.RouterPath
|
||||
import com.bbgo.common_service.collect.CollectService
|
||||
import com.bbgo.module_collect.repository.CollectRepository
|
||||
import com.bbgo.module_collect.viewmodel.CollectViewModel
|
||||
|
||||
/**
|
||||
* author: wangyb
|
||||
* date: 2021/5/27 7:31 下午
|
||||
* description: todo
|
||||
*/
|
||||
@Route(path = RouterPath.Collect.SERVICE_COLLECT)
|
||||
class CollectServiceImpl : CollectService{
|
||||
|
||||
private val viewModel = CollectViewModel(CollectRepository.getInstance())
|
||||
|
||||
override fun collect(indexPage: Int, position: Int,pageId: Int) {
|
||||
viewModel.collectArticle(indexPage, position, pageId)
|
||||
}
|
||||
|
||||
override fun unCollect(indexPage: Int, position: Int,pageId: Int) {
|
||||
viewModel.unCollectArticle(indexPage, position, pageId)
|
||||
// viewModelScope.launch {
|
||||
// CollectRepository.getInstance().unCollectArticle(pageId)
|
||||
// .catch {
|
||||
//
|
||||
// }
|
||||
// .collectLatest {
|
||||
// if (it.errorCode != 0) {
|
||||
// context?.showToast("取消收藏失败")
|
||||
// return@collectLatest
|
||||
// }
|
||||
// context?.getString(R.string.cancel_collect_success)?.let { context?.showToast(it) }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
override fun init(context: Context?) {
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.bbgo.module_collect.viewmodel
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.bbgo.common_base.bus.BusKey
|
||||
import com.bbgo.common_base.bus.LiveDataBus
|
||||
import com.bbgo.common_base.constants.Constants.CollectType.COLLECT
|
||||
import com.bbgo.common_base.constants.Constants.CollectType.UNCOLLECT
|
||||
import com.bbgo.common_base.constants.Constants.CollectType.UNKNOWN
|
||||
import com.bbgo.common_base.event.MessageEvent
|
||||
import com.bbgo.common_base.ext.USER_NOT_LOGIN
|
||||
import com.bbgo.common_base.util.log.Logs
|
||||
import com.bbgo.module_collect.repository.CollectRepository
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* author: wangyb
|
||||
* date: 3/29/21 9:31 PM
|
||||
* description: todo
|
||||
*/
|
||||
class CollectViewModel(private val repository: CollectRepository) : ViewModel() {
|
||||
|
||||
fun collectArticle(indexPage: Int, position: Int, id: Int) = viewModelScope.launch {
|
||||
repository.collectArticle(id)
|
||||
.catch {
|
||||
Logs.e(TAG, it.message, it)
|
||||
}
|
||||
.collectLatest {
|
||||
val event = if (it.errorCode == USER_NOT_LOGIN) {
|
||||
MessageEvent(indexPage, UNKNOWN, position, id)
|
||||
} else {
|
||||
MessageEvent(indexPage, COLLECT, position, id)
|
||||
}
|
||||
LiveDataBus.get().with(BusKey.COLLECT).value = event
|
||||
}
|
||||
}
|
||||
|
||||
fun unCollectArticle(indexPage: Int, position: Int, id: Int) = viewModelScope.launch {
|
||||
repository.unCollectArticle(id)
|
||||
.catch {
|
||||
Logs.e(TAG, it.message, it)
|
||||
}
|
||||
.collectLatest {
|
||||
val event = if (it.errorCode == USER_NOT_LOGIN) {
|
||||
MessageEvent(indexPage, UNKNOWN, position, id)
|
||||
} else {
|
||||
MessageEvent(indexPage, UNCOLLECT, position, id)
|
||||
}
|
||||
LiveDataBus.get().with(BusKey.COLLECT).value = event
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "CollectViewModel"
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.bbgo.module_collect
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user