Skip to content

Commit

Permalink
修复部分细节
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjianxiandev committed Mar 7, 2020
1 parent 9f083bc commit a2bb2db
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 38 deletions.
87 changes: 85 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
# WanAndroidMVVM
打造一款MVVM+LiveData+ViewModel+RxJava+okHttp+Retrofit+Glide的Kotlin版本的WanAndroid客户端

# WanAndroid-Kotlin 项目
根据鸿神提供的[WanAndroid开放Api](https://www.wanandroid.com/)来制作的WanAndroidApp, 基本实现了所有的功能,使用kotlin语言开发,基于Material Design+AndroidX + MVVM + ViewModel + LiveData + RxJava + Retrofit等优秀的开源框架,实现的一个尽可能体验较佳的App,自己也是初学Kotlin,Kotlin语法不足之处也请大家批评指正

## 项目地址
[WanAndroid(github)](https://github.com/wangjianxiandev/WanAndroidMvvm)**欢迎大佬们star**)
## 下载体验
## 当前版本(1.0)

## 项目展示
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155603650.gif)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155729951.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155743511.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155752391.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/2020030615580032.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155806302.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155816230.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155824475.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200306155830660.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NDI0MTQz,size_16,color_FFFFFF,t_70)

## 项目功能
### 首页
- 首页文章列表
- 首页banner
- 搜索热词(包含在搜索界面)
- 置顶文章

### 知识体系
- 体系数据
- 知识体系下的文章

### 导航
- 导航数据

### 公众号
- 获取公众号列表

### 项目
- 项目分类
- 项目列表数据

### 登录与注册
- 登录、注册功能

### 收藏
- 收藏文章列表
- 取消收藏

### 搜索
- 首页文章搜索
- 关键词搜索
- 搜索历史记录


### ToDo
- 添加Todo
- 完成Todo
- 更新Todo
- 删除Todo

### 设置
- 清除缓存
- 版本信息
- 关于我们
- 退出登录


### 特别感谢
- 感谢鸿洋大神的[WanAndroid网站提供开放Api](https://www.wanandroid.com/)

### 开源
- [异步事件处理-RxJava2](https://github.com/ReactiveX/RxJava)
- [网络请求的框架-Okhttp](https://github.com/square/okhttp)
- [网络加载框架-Retrofit](https://github.com/square/retrofit)
- [转换json数据的官方框架-Gson](https://github.com/google/gson)
- [事件发布-Eventbus](https://github.com/greenrobot/EventBus)
- [可扩展的对话框-Material-dialogs](https://github.com/afollestad/material-dialogs)
- [WebView的一个强大的库-Agentweb](https://github.com/Justson/AgentWeb)
- [Android流式布局-FlowLayout](https://github.com/hongyangAndroid/FlowLayout)
- [图片加载-Glide4](https://github.com/bumptech/glide)
- [下拉刷新-SmartRefreshLayout](https://github.com/scwang90/SmartRefreshLayout)
- [轮播图-banner](https://github.com/youth5201314/banner)
- [控件绑定-butterknife](https://github.com/JakeWharton/butterknife)
- [纵向导航-verticalTabLayout](https://note.youdao.com/)

1 change: 1 addition & 0 deletions app/release/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<activity
android:name=".ui.activity.SplashActivity"
android:configChanges="orientation|keyboardHidden|navigation|locale"
android:launchMode="singleTask"
android:theme="@style/App.Theme.Launch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CustomUserAvatar : ImageView {
private var mCircleName: String? = null
private var mColor = 0
private var mCount = 0
private var mStyle = 0
private var mShadowRadius= 0f
private var mIsShowBlurMask: Boolean = false

constructor(context: Context?) : super(context) {
Expand Down Expand Up @@ -61,7 +63,7 @@ class CustomUserAvatar : ImageView {
super.onDraw(canvas)
// 绘制发光效果
mPaintBackground!!.color = mColor
mPaintBackground!!.style = Paint.Style.STROKE
mPaintBackground!!.style = if (mStyle == 0) Paint.Style.STROKE else Paint.Style.FILL
mPaintBackground!!.strokeWidth = 5f
if (mIsShowBlurMask) {
mPaintBackground!!.maskFilter = BlurMaskFilter(10.0f, BlurMaskFilter.Blur.SOLID)
Expand All @@ -75,11 +77,11 @@ class CustomUserAvatar : ImageView {
// 设置文本大小
mPaintText!!.textSize = width / 3.toFloat()
// 设置文本颜色跟随应用主题颜色
mPaintText!!.color = mColor
mPaintText!!.color = if (mStyle == 0) mColor else context.getColor(R.color.always_white_text)
// 设置画笔粗细
mPaintText!!.strokeWidth = 5f
// 设置阴影半径
mPaintText!!.setShadowLayer(5f, 5f, 5f, Color.BLACK)
mPaintText!!.setShadowLayer(mShadowRadius, mShadowRadius, mShadowRadius, Color.BLACK)
// 绘制文字的最小矩形
mPaintText!!.getTextBounds(mCircleName, 0, 1, mRect)
val fontMetricsInt = mPaintText!!.fontMetricsInt
Expand Down Expand Up @@ -153,4 +155,12 @@ class CustomUserAvatar : ImageView {
fun setColor(color: Int) {
mColor = color
}

fun setStyle(style : Int) {
mStyle = style
}

fun setShadowRadius(radius : Float) {
mShadowRadius = radius
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ object Constant {
const val KEY_TODO_TYPE = "todo_type"

const val KEY_TODO_HANDLE_TYPE = "todo_handle"

const val PAINT_STYLE_STROKE_FULL = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MainActivity : BaseActivity(), LoginSuccessListener {
headView = navigation_draw.getHeaderView(0)
headView.circle_image_name.text = mUsername
headView.circle_image.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
headView.circle_image.setIsShowBlurMask(true)
headView.circle_image.setIsShowBlurMask(false)
headView.circle_image.setShowNameCount(1)
headView.circle_image.setCircleName(mUsername)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.wjx.android.wanandroidmvvm.Custom.interpolator.CustomScaleInterpolator
import com.wjx.android.wanandroidmvvm.R
import com.wjx.android.wanandroidmvvm.ui.navigation.data.NavigationTabNameResponse
import com.wjx.android.wanandroidmvvm.base.utils.Constant
import kotlinx.android.synthetic.main.navigation_item.view.*

/**
Expand All @@ -28,6 +28,7 @@ class NavigationTabAdapter (layoutId : Int, listData : MutableList<String>?)
addOnClickListener(R.id.circle_imageView)
setText(R.id.nav_tab_name, item)
itemView.circle_imageView.setColor(ContextCompat.getColor(mContext, R.color.colorPrimary))
itemView.circle_imageView.setStyle(Constant.PAINT_STYLE_STROKE_FULL)
itemView.circle_imageView.setCircleName(item.toString())
if (adapterPosition == selectedPosition) {
val animatorX =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.wjx.android.wanandroidmvvm.ui.search.viewmodel.SearchViewModel
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import kotlinx.android.synthetic.main.activity_search.*
import kotlinx.android.synthetic.main.activity_search.mSrlRefresh
import kotlinx.android.synthetic.main.custom_search.*
import kotlinx.android.synthetic.main.custom_search.view.*
import kotlinx.android.synthetic.main.history_foot.view.*
Expand Down Expand Up @@ -60,8 +61,8 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {

override fun initDataObserver() {
super.initDataObserver()
mViewModel.mHotKeyData.observe(this, Observer { resonse ->
resonse?.let {
mViewModel.mHotKeyData.observe(this, Observer { response ->
response?.let {
showHotKeyTags(it.data)
}
})
Expand Down Expand Up @@ -122,15 +123,19 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {
}
}
mSearchHistoryAdapter.setOnItemClickListener { _, _, position ->
initSearchKey(mSearchHistoryAdapter.data[position])
loadSearchResultByHistory(mSearchHistoryAdapter.data[position])
}
}

override fun onLoadMoreData() {
mViewModel.loadSearchResult(++mCurrentPageNum, search_input.text.toString())
}

override fun onRefreshData() {}
override fun onRefreshData() {
if (mSrlRefresh.isRefreshing) {
mSrlRefresh.isRefreshing = false
}
}

private fun initSearch() {
search_back.setOnClickListener { finish() }
Expand All @@ -140,18 +145,18 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {
hideKeyboard()
}
search_button.setOnClickListener { view ->
initSearchKey(search_input.text.toString())
loadSearchResultByHistory(search_input.text.toString())
}
search_input.setOnEditorActionListener(TextView.OnEditorActionListener { view, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
initSearchKey(search_input.text.toString())
loadSearchResultByHistory(search_input.text.toString())
return@OnEditorActionListener true
}
false
})
}

private fun initSearchKey(key: String) {
private fun loadSearchResultByHistory(key: String) {
if (key.isEmpty()) {
displaySearchView()
toast("请输入关键词")
Expand All @@ -163,6 +168,9 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {
mViewModel.loadSearchResult(mCurrentPageNum, key)
}

/**
* 展示热门搜索等搜索记录也的view
*/
private fun displaySearchView() {
if (isShow) {
return
Expand All @@ -175,6 +183,9 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {
isShow = true
}

/**
* 隐藏热门搜索等搜索记录也的view
*/
private fun hideSearchView() {
if (!isShow) return
search_text_top.visibility = View.GONE
Expand All @@ -199,7 +210,7 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {
}
}
search_flowlayout.setOnTagClickListener { view, position, _ ->
initSearchKey(tags[position])
loadSearchResultByHistory(tags[position])
true
}
}
Expand All @@ -210,25 +221,21 @@ class SearchActivity : BaseArticleListActivity<SearchViewModel>() {
}

private fun updateRecordPosition(name: String) {

val records = mSearchHistoryAdapter.data

// 判断是否存在一个同样的搜索记录
val index = records.indexOf(name)
if (index == -1) {

// 不存在相同记录但是记录条数为10条,删除最后一条
if (records.size >= mMaxHistory) {
// 删除最后一条
mSearchHistoryAdapter.remove(mMaxHistory - 1)
}

// 不存在就添加
// 如果不存在,直接把数据添加到列表首
mSearchHistoryAdapter.addData(0, name)
return
}

// 如果存在相同数据
if (index != 0) {
// 存在就调整该记录到第一条。
// 删除原来记录中的数据,并把当前数据放到列表首
mSearchHistoryAdapter.remove(index)
mSearchHistoryAdapter.addData(0, name)
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/drawable/flow_selector.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="false">
<shape>
<solid android:color="@color/windowBackground" />
Expand All @@ -13,5 +12,4 @@
<corners android:radius="@dimen/card_corner_radius"/>
</shape>
</item>

</selector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_collect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="1024.0"
android:viewportWidth="1024.0">
<path
android:strokeColor="#e6e6e6"
android:strokeWidth="80"
android:pathData="M761.4,136.9C588.3,90.9 512,238.2 512,238.2 512,238.2 435.7,90.9 262.6,136.9 89.6,183 -5.3,414.9 208.7,623 422.7,831.1 512,910.2 512,910.2 512,910.2 601.3,831.1 815.3,623 1029.3,414.9 934.4,183 761.4,136.9"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/search_edit_background.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp"/>
<corners android:radius="20dp"/>
<solid android:color="@color/white"/>
</shape>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/text_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape>
<corners android:radius="20dp" />
<solid android:color="@color/white" />
</shape>
</item>
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp" />
<solid android:color="@color/textTipColor" />
</shape>
</item>
</selector>
15 changes: 10 additions & 5 deletions app/src/main/res/layout/custom_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="@dimen/dp_10"
android:paddingTop="10dp"
android:paddingBottom="10dp">

Expand All @@ -46,11 +47,15 @@
android:src="@drawable/ic_close" />
</RelativeLayout>

<Button
<TextView
android:id="@+id/search_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:layout_width="50dp"
android:layout_height="30dp"
android:gravity="center"
android:layout_marginEnd="@dimen/dp_10"
android:text="@string/search"
android:textColor="@color/white" />
android:background="@drawable/text_selector"
android:clickable="true"
android:textSize="14sp"
android:textColor="@color/black" />
</LinearLayout>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/project_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
android:textColor="@color/holo_red_light"
android:textSize="10dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/item_home_author"
app:layout_constraintStart_toEndOf="@+id/item_home_top_article"
app:layout_constraintTop_toTopOf="@+id/item_home_author" />
app:layout_constraintBottom_toBottomOf="@+id/item_project_author"
app:layout_constraintStart_toEndOf="@+id/item_project_top_article"
app:layout_constraintTop_toTopOf="@+id/item_project_author" />

<TextView
android:id="@+id/item_project_question"
Expand Down
Loading

0 comments on commit a2bb2db

Please sign in to comment.