-
Notifications
You must be signed in to change notification settings - Fork 32
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
jiewang41
committed
Jan 22, 2021
1 parent
45b8bb5
commit aa949f2
Showing
26 changed files
with
321 additions
and
193 deletions.
There are no files selected for viewing
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
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
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
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
22 changes: 0 additions & 22 deletions
22
app/src/main/kotlin/com/wj/sampleproject/interfaces/ArticleListInterface.kt
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
app/src/main/kotlin/com/wj/sampleproject/interfaces/ArticleListItemInterface.kt
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,19 @@ | ||
package com.wj.sampleproject.interfaces | ||
|
||
import com.wj.sampleproject.entity.ArticleEntity | ||
|
||
/** | ||
* 文章列表点击事件接口 | ||
* | ||
* - 创建时间:2021/1/22 | ||
* | ||
* @author 王杰 | ||
*/ | ||
interface ArticleListItemInterface { | ||
|
||
/** 文章列表条目点击 */ | ||
val onArticleItemClick: (ArticleEntity) -> Unit | ||
|
||
/** 文章收藏点击 */ | ||
val onArticleCollectClick: (ArticleEntity) -> Unit | ||
} |
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
49 changes: 0 additions & 49 deletions
49
app/src/main/kotlin/com/wj/sampleproject/interfaces/impl/ArticleListInterfaceImpl.kt
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
app/src/main/kotlin/com/wj/sampleproject/interfaces/impl/ArticleListItemInterfaceImpl.kt
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,45 @@ | ||
package com.wj.sampleproject.interfaces.impl | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.viewModelScope | ||
import cn.wj.common.ext.condition | ||
import com.wj.sampleproject.activity.WebViewActivity | ||
import com.wj.sampleproject.base.viewmodel.BaseViewModel | ||
import com.wj.sampleproject.entity.ArticleEntity | ||
import com.wj.sampleproject.interfaces.ArticleCollectionInterface | ||
import com.wj.sampleproject.interfaces.ArticleListItemInterface | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* 文章列表点击事件接口实现类 | ||
* | ||
* - 创建时间:2021/1/22 | ||
* | ||
* @author 王杰 | ||
*/ | ||
class ArticleListItemInterfaceImpl( | ||
private val viewModel: BaseViewModel, | ||
private val jumpToWebViewData: MutableLiveData<WebViewActivity.ActionModel> | ||
) : ArticleListItemInterface { | ||
|
||
/** 文章列表条目点击 */ | ||
override val onArticleItemClick: (ArticleEntity) -> Unit = { item -> | ||
jumpToWebViewData.value = WebViewActivity.ActionModel(item.id.orEmpty(), item.title.orEmpty(), item.link.orEmpty()) | ||
} | ||
|
||
/** 文章收藏点击 */ | ||
override val onArticleCollectClick: (ArticleEntity) -> Unit = fun(item) { | ||
val impl = viewModel as? ArticleCollectionInterface ?: return | ||
viewModel.viewModelScope.launch { | ||
if (item.collected.get().condition) { | ||
// 已收藏,取消收藏 | ||
item.collected.set(false) | ||
impl.unCollect(item, viewModel.snackbarData) | ||
} else { | ||
// 未收藏,收藏 | ||
item.collected.set(true) | ||
impl.collect(item, viewModel.snackbarData) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.