Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 74ad646

Browse files
committed
Update File
1 parent 3da560d commit 74ad646

File tree

11 files changed

+85
-182
lines changed

11 files changed

+85
-182
lines changed

app/src/main/java/com/codekk/ext/Ext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fun Context.opTagBoolean(): Boolean = sharedPreferences().getBoolean("op_tag", t
6868
fun Context.opTagBoolean(value: Boolean) = sharedPreferences().edit().putBoolean("op_tag", value).apply()
6969

7070
fun Context.opUriWebBoolean(): Boolean = sharedPreferences().getBoolean("op_uri_web", true)
71-
fun Context.opUriWebBoolean(value: Boolean) = sharedPreferences().edit().putBoolean("op_uri_web", value).apply()
71+
fun Context.opUriWebBoolean(value: Boolean) = sharedPreferences().edit().putBoolean("op_uri_web", value).commit()
7272

7373
fun Context.opaTagBoolean(): Boolean = sharedPreferences().getBoolean("opa_tag", true)
7474
fun Context.opaTagBoolean(value: Boolean) = sharedPreferences().edit().putBoolean("opa_tag", value).apply()

app/src/main/java/com/codekk/ext/ExtEntity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ data class BlogListBean(@SerializedName("_id") var id: String,
4646
var authorName: String,
4747
var tagList: List<String>?)
4848

49-
data class RecommendListModel(@SerializedName("summaryArray") var recommendList: List<RecommendListBean>)
49+
data class RecommendListModel(@SerializedName("recommendArray") var recommendList: List<RecommendListBean>)
5050

5151
data class RecommendListBean(var url: String,
5252
var title: String,

app/src/main/java/com/codekk/ui/activity/MainActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.navigation.ui.setupActionBarWithNavController
1212
import androidx.navigation.ui.setupWithNavController
1313
import com.codekk.R
1414
import kotlinx.android.synthetic.main.activity_main.*
15+
import kotlinx.android.synthetic.main.layout_toolbar.*
1516
import org.jetbrains.anko.startActivity
1617

1718
class MainActivity : AppCompatActivity() {
@@ -21,9 +22,9 @@ class MainActivity : AppCompatActivity() {
2122
override fun onCreate(savedInstanceState: Bundle?) {
2223
super.onCreate(savedInstanceState)
2324
setContentView(R.layout.activity_main)
24-
setSupportActionBar(mToolbar)
25-
mToolbar.setNavigationIcon(R.drawable.ic_menu)
26-
mToolbar.setNavigationOnClickListener { drawerLayout.openDrawer(GravityCompat.START) }
25+
setSupportActionBar(toolbar)
26+
toolbar.setNavigationIcon(R.drawable.ic_menu)
27+
toolbar.setNavigationOnClickListener { drawerLayout.openDrawer(GravityCompat.START) }
2728
val navController = findNavController(R.id.hostFragment)
2829
appBarConfiguration = AppBarConfiguration(setOf(R.id.op, R.id.opa, R.id.job, R.id.blog, R.id.recommend), drawerLayout)
2930
setupActionBarWithNavController(navController, appBarConfiguration)
Lines changed: 14 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,36 @@
11
package com.codekk.ui.activity
22

33
import android.os.Bundle
4-
import android.text.TextUtils
5-
import android.text.util.Linkify
6-
import android.view.View
7-
import androidx.appcompat.widget.AppCompatTextView
8-
import androidx.core.text.parseAsHtml
9-
import androidx.recyclerview.widget.LinearLayoutManager
10-
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
11-
import com.codekk.Constant
4+
import android.view.MenuItem
5+
import androidx.appcompat.app.AppCompatActivity
126
import com.codekk.R
13-
import com.codekk.ext.*
14-
import com.codekk.mvp.presenter.impl.OpPresenterImpl
15-
import com.codekk.mvp.view.OpListView
16-
import com.codekk.ui.base.BaseActivity
17-
import com.codekk.ui.widget.LoadMoreRecyclerView
18-
import com.google.android.flexbox.FlexboxLayout
19-
import com.xadapter.*
20-
import com.xadapter.adapter.XAdapter
21-
import kotlinx.android.synthetic.main.activity_base.*
22-
import kotlinx.android.synthetic.main.layout_list.*
7+
import com.codekk.ui.fragment.OpListFragment
238
import kotlinx.android.synthetic.main.layout_toolbar.*
24-
import org.jetbrains.anko.startActivity
259

2610
/**
2711
* by y on 2017/5/17
2812
*/
29-
class OpSearchActivity : BaseActivity<OpPresenterImpl>(R.layout.layout_list), OpListView, LoadMoreRecyclerView.LoadMoreListener, SwipeRefreshLayout.OnRefreshListener {
30-
13+
class OpSearchActivity : AppCompatActivity() {
3114
companion object {
3215
const val TEXT_KEY = "text"
3316
}
3417

3518
private var text: String = ""
36-
private var page = 1
37-
private lateinit var mAdapter: XAdapter<OpListBean>
38-
39-
override fun initBundle(bundle: Bundle) {
40-
super.initBundle(bundle)
41-
text = bundle.getString(TEXT_KEY, "")
42-
}
4319

44-
override fun initCreate(savedInstanceState: Bundle?) {
20+
override fun onCreate(savedInstanceState: Bundle?) {
21+
super.onCreate(savedInstanceState)
22+
setContentView(R.layout.layout_fragment)
23+
text = intent?.extras?.getString(TEXT_KEY, "") ?: ""
4524
toolbar.title = text
4625
setSupportActionBar(toolbar)
47-
recyclerView.setHasFixedSize(true)
48-
recyclerView.layoutManager = LinearLayoutManager(this)
49-
recyclerView.setLoadingListener(this)
50-
mAdapter = XAdapter()
51-
52-
recyclerView.adapter = mAdapter
53-
.setItemLayoutId(R.layout.item_search)
54-
.setOnItemClickListener { _, _, info ->
55-
startActivity<ReadmeActivity>(
56-
ReadmeActivity.TYPE to arrayOf(info.id, info.projectName, info.projectUrl),
57-
ReadmeActivity.KEY to Constant.TYPE_OP
58-
)
59-
}
60-
.setOnBind { holder, _, entity ->
61-
holder.setText(R.id.tv_author_name, TextUtils.concat("添加者:", entity.authorName))
62-
holder.setText(R.id.tv_author_url, TextUtils.concat("个人主页:", entity.authorUrl))
63-
holder.setText(R.id.tv_project_name, TextUtils.concat("项目名称:", entity.projectName))
64-
val projectUrl = holder.findById<AppCompatTextView>(R.id.tv_project_url)
65-
projectUrl.autoLinkMask = if (opUriWebBoolean()) Linkify.WEB_URLS else 0
66-
projectUrl.text = entity.projectUrl
67-
68-
val textView = holder.findById<AppCompatTextView>(R.id.tv_desc)
69-
val descEmpty = TextUtils.isEmpty(entity.desc)
70-
textView.visibility = if (descEmpty) View.GONE else View.VISIBLE
71-
textView.text = if (descEmpty) "" else entity.desc.parseAsHtml()
72-
73-
val flexboxLayout = holder.findById<FlexboxLayout>(R.id.fl_box)
74-
if (opTagBoolean()) {
75-
flexboxLayout.visibility = View.VISIBLE
76-
flexboxLayout.tags(entity.tags()) {
77-
startActivity<OpSearchActivity>(TEXT_KEY to it)
78-
finish()
79-
}
80-
} else {
81-
flexboxLayout.visibility = View.GONE
82-
}
83-
}
84-
85-
refreshLayout.setOnRefreshListener(this)
86-
refreshLayout.post { this.onRefresh() }
87-
}
88-
89-
override fun clickNetWork() {
90-
super.clickNetWork()
91-
if (!refreshLayout.isRefreshing) {
92-
onRefresh()
93-
}
94-
}
95-
96-
override fun initPresenter(): OpPresenterImpl? {
97-
return OpPresenterImpl(this)
98-
}
99-
100-
override fun showProgress() {
101-
refreshLayout.isRefreshing = true
102-
}
103-
104-
override fun hideProgress() {
105-
refreshLayout.isRefreshing = false
106-
}
107-
108-
override fun onRefresh() {
109-
statusLayout.success()
110-
mPresenter?.netWorkRequestSearch(text, page = 1)
111-
}
112-
113-
override fun onLoadMore() {
114-
if (refreshLayout.isRefreshing) {
115-
return
116-
}
117-
mPresenter?.netWorkRequestSearch(text, page)
118-
}
119-
120-
override fun netWorkSuccess(entity: OpListModel) {
121-
if (page == 1) {
122-
mAdapter.removeAll()
123-
}
124-
++page
125-
mAdapter.addAll(entity.opList)
126-
}
127-
128-
override fun netWorkError(throwable: Throwable) {
129-
if (page == 1) {
130-
statusLayout.error()
131-
mAdapter.removeAll()
132-
} else {
133-
statusLayout.snackBar(R.string.net_error)
134-
}
26+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
27+
supportFragmentManager.beginTransaction().replace(R.id.fragment, OpListFragment.get(text)).commitAllowingStateLoss()
13528
}
13629

137-
override fun noMore() {
138-
if (page == 1) {
139-
statusLayout.empty()
140-
mAdapter.removeAll()
141-
} else {
142-
statusLayout.snackBar(R.string.data_empty)
30+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
31+
if (item.itemId == android.R.id.home) {
32+
finish()
14333
}
34+
return super.onOptionsItemSelected(item)
14435
}
14536
}

app/src/main/java/com/codekk/ui/activity/RecommendSearchActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.codekk.ui.activity
22

33
import android.os.Bundle
4-
import android.text.Html
54
import android.text.TextUtils
65
import android.view.View
76
import androidx.appcompat.widget.AppCompatTextView
7+
import androidx.core.text.parseAsHtml
88
import androidx.recyclerview.widget.LinearLayoutManager
99
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1010
import com.codekk.R
@@ -123,7 +123,7 @@ class RecommendSearchActivity : BaseActivity<RecommendPresenterImpl>(R.layout.la
123123
val descView = holder.findById<AppCompatTextView>(R.id.tv_recommend_desc)
124124
descView.visibility = if (TextUtils.isEmpty(recommendArrayBean.desc)) View.GONE else View.VISIBLE
125125
if (!TextUtils.isEmpty(recommendArrayBean.desc)) {
126-
descView.text = Html.fromHtml(recommendArrayBean.desc)
126+
descView.text = recommendArrayBean.desc.parseAsHtml()
127127
}
128128
}
129129

app/src/main/java/com/codekk/ui/activity/SettingActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.codekk.ext.*
1010
import com.xadapter.*
1111
import com.xadapter.adapter.XMultiAdapter
1212
import kotlinx.android.synthetic.main.activity_setting.*
13+
import kotlinx.android.synthetic.main.layout_toolbar.*
1314

1415
/**
1516
* by y on 2017/5/18
@@ -22,6 +23,7 @@ class SettingActivity : AppCompatActivity() {
2223
toolbar.setTitle(R.string.setting_title)
2324
setSupportActionBar(toolbar)
2425
supportActionBar?.setDisplayHomeAsUpEnabled(true)
26+
2527
recyclerView.setHasFixedSize(true)
2628
recyclerView.layoutManager = LinearLayoutManager(recyclerView.context)
2729

@@ -47,7 +49,7 @@ class SettingActivity : AppCompatActivity() {
4749
4 -> tagCheckBox.isChecked = holder.getContext().blogTagBoolean()
4850
}
4951
holder.itemView.setOnClickListener {
50-
it.settingItemClick(entity.itemMultiPosition, !tagCheckBox.isChecked)
52+
it.settingItemClick(entity.itemMultiPosition, tagCheckBox.isChecked)
5153
tagCheckBox.isChecked = !tagCheckBox.isChecked
5254
}
5355
}

app/src/main/java/com/codekk/ui/fragment/OpListFragment.kt

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.codekk.ui.fragment
22

3-
import android.text.Html
3+
import android.os.Bundle
44
import android.text.TextUtils
55
import android.text.util.Linkify
66
import android.view.Menu
77
import android.view.MenuInflater
88
import android.view.MenuItem
99
import android.view.View
1010
import androidx.appcompat.widget.AppCompatTextView
11+
import androidx.core.os.bundleOf
12+
import androidx.core.text.parseAsHtml
1113
import androidx.recyclerview.widget.LinearLayoutManager
1214
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1315
import com.codekk.Constant
@@ -31,7 +33,23 @@ import org.jetbrains.anko.support.v4.startActivity
3133
*/
3234
class OpListFragment : BaseFragment<OpPresenterImpl>(R.layout.layout_list), SwipeRefreshLayout.OnRefreshListener, OpListView, LoadMoreRecyclerView.LoadMoreListener {
3335

36+
companion object {
37+
fun get(text: String): OpListFragment {
38+
return OpListFragment().apply {
39+
arguments = bundleOf(
40+
OpSearchActivity.TEXT_KEY to text
41+
)
42+
}
43+
}
44+
}
45+
3446
private lateinit var mAdapter: XAdapter<OpListBean>
47+
private var searchText: String = ""
48+
49+
override fun onCreate(savedInstanceState: Bundle?) {
50+
super.onCreate(savedInstanceState)
51+
arguments?.let { searchText = it.getString(OpSearchActivity.TEXT_KEY, "") }
52+
}
3553

3654
override fun initActivityCreated() {
3755
setHasOptionsMenu(true)
@@ -43,16 +61,13 @@ class OpListFragment : BaseFragment<OpPresenterImpl>(R.layout.layout_list), Swip
4361
recyclerView.adapter = mAdapter
4462
.setItemLayoutId(R.layout.item_op_list)
4563
.setOnItemClickListener { _, _, info ->
46-
startActivity<ReadmeActivity>(
47-
ReadmeActivity.KEY to arrayOf(info.id, info.projectName, info.projectUrl),
48-
ReadmeActivity.TYPE to Constant.TYPE_OP
49-
)
64+
startActivity<ReadmeActivity>(ReadmeActivity.KEY to arrayOf(info.id, info.projectName, info.projectUrl), ReadmeActivity.TYPE to Constant.TYPE_OP)
5065
}
5166
.setOnBind { holder, _, entity -> onXBind(holder, entity) }
5267

5368
refreshLayout.setOnRefreshListener(this)
5469
refreshLayout.post { this.onRefresh() }
55-
activity?.findViewById<View>(R.id.mToolbar)?.setOnClickListener { recyclerView.smoothScrollToPosition(0) }
70+
activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener { recyclerView.smoothScrollToPosition(0) }
5671
}
5772

5873
override fun clickNetWork() {
@@ -63,7 +78,9 @@ class OpListFragment : BaseFragment<OpPresenterImpl>(R.layout.layout_list), Swip
6378
}
6479

6580
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
66-
inflater.inflate(R.menu.search_menu, menu)
81+
if (searchText.isEmpty()) {
82+
inflater.inflate(R.menu.search_menu, menu)
83+
}
6784
super.onCreateOptionsMenu(menu, inflater)
6885
}
6986

@@ -79,21 +96,27 @@ class OpListFragment : BaseFragment<OpPresenterImpl>(R.layout.layout_list), Swip
7996
} ?: return super.onOptionsItemSelected(item)
8097
}
8198

82-
override fun initPresenter(): OpPresenterImpl? {
83-
return OpPresenterImpl(this)
84-
}
99+
override fun initPresenter(): OpPresenterImpl? = OpPresenterImpl(this)
85100

86101
override fun onRefresh() {
87102
mStatusView.success()
88103
page = 1
89-
mPresenter?.netWorkRequestList(page)
104+
if (searchText.isEmpty()) {
105+
mPresenter?.netWorkRequestList(page)
106+
} else {
107+
mPresenter?.netWorkRequestSearch(searchText, page)
108+
}
90109
}
91110

92111
override fun onLoadMore() {
93112
if (refreshLayout.isRefreshing) {
94113
return
95114
}
96-
mPresenter?.netWorkRequestList(page)
115+
if (searchText.isEmpty()) {
116+
mPresenter?.netWorkRequestList(page)
117+
} else {
118+
mPresenter?.netWorkRequestSearch(searchText, page)
119+
}
97120
}
98121

99122
override fun showProgress() {
@@ -143,13 +166,13 @@ class OpListFragment : BaseFragment<OpPresenterImpl>(R.layout.layout_list), Swip
143166
val textView = holder.findById<AppCompatTextView>(R.id.tv_desc)
144167
val descEmpty = TextUtils.isEmpty(projectArrayBean.desc)
145168
textView.visibility = if (descEmpty) View.GONE else View.VISIBLE
146-
textView.text = if (descEmpty) "" else Html.fromHtml(projectArrayBean.desc)
147-
val flexboxLayout = holder.findById<FlexboxLayout>(R.id.fl_box)
169+
textView.text = if (descEmpty) "" else projectArrayBean.desc.parseAsHtml()
170+
val tagLayout = holder.findById<FlexboxLayout>(R.id.fl_box)
148171
if (holder.getContext().opTagBoolean()) {
149-
flexboxLayout.visibility = View.VISIBLE
150-
flexboxLayout.tags(projectArrayBean.tags()) { startActivity<OpSearchActivity>(OpSearchActivity.TEXT_KEY to it) }
172+
tagLayout.visibility = View.VISIBLE
173+
tagLayout.tags(projectArrayBean.tags()) { startActivity<OpSearchActivity>(OpSearchActivity.TEXT_KEY to it) }
151174
} else {
152-
flexboxLayout.visibility = View.GONE
175+
tagLayout.visibility = View.GONE
153176
}
154177
}
155178

app/src/main/java/com/codekk/ui/fragment/RecommendListFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.codekk.ui.fragment
22

3-
import android.text.Html
43
import android.text.TextUtils
54
import android.view.Menu
65
import android.view.MenuInflater
76
import android.view.MenuItem
87
import android.view.View
98
import androidx.appcompat.widget.AppCompatTextView
9+
import androidx.core.text.parseAsHtml
1010
import androidx.recyclerview.widget.LinearLayoutManager
1111
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1212
import com.codekk.Constant
@@ -139,7 +139,7 @@ class RecommendListFragment : BaseFragment<RecommendPresenterImpl>(R.layout.layo
139139
val descView = holder.findById<AppCompatTextView>(R.id.tv_recommend_desc)
140140
descView.visibility = if (TextUtils.isEmpty(recommendArrayBean.desc)) View.GONE else View.VISIBLE
141141
if (!TextUtils.isEmpty(recommendArrayBean.desc)) {
142-
descView.text = Html.fromHtml(recommendArrayBean.desc)
142+
descView.text = recommendArrayBean.desc.parseAsHtml()
143143
}
144144
}
145145

0 commit comments

Comments
 (0)