Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
c18a8b73
Commit
c18a8b73
authored
Jul 27, 2022
by
霍志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:历史和定位城市添加
parent
84b8fa54
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
13 deletions
+40
-13
RegionRecyclerViewAdapter.kt
m-consultant/src/main/java/com/yidianling/consultant/adapter/RegionRecyclerViewAdapter.kt
+2
-1
AreaPopupWindow.kt
m-consultant/src/main/java/com/yidianling/consultant/ui/view/AreaPopupWindow.kt
+38
-12
No files found.
m-consultant/src/main/java/com/yidianling/consultant/adapter/RegionRecyclerViewAdapter.kt
View file @
c18a8b73
...
...
@@ -16,7 +16,8 @@ import kotlinx.android.synthetic.main.consultant_item_region.view.*
* 省份列表适配器
* Created by zqk on 17-7-21.
*/
class
RegionRecyclerViewAdapter
(
val
context
:
Context
,
val
regionList
:
ArrayList
<
RegionItem
>,
var
selectedRegion
:
RegionItem
class
RegionRecyclerViewAdapter
(
val
context
:
Context
,
var
regionList
:
ArrayList
<
RegionItem
>,
var
selectedRegion
:
RegionItem
)
:
RecyclerView
.
Adapter
<
RegionRecyclerViewAdapter
.
ViewHolder
>()
{
var
onItemClickListener
:
MyBaseAdapter
.
OnItemClickListener
<
RegionItem
>?
=
null
...
...
m-consultant/src/main/java/com/yidianling/consultant/ui/view/AreaPopupWindow.kt
View file @
c18a8b73
...
...
@@ -41,6 +41,8 @@ class AreaPopupWindow(
private
var
recentCityBean
:
ConsultantRecentCity
?
=
ConsultantRecentCity
(
arrayListOf
())
var
onRegionSelectedListener
:
OnRegionSelectedListener
?
=
null
private
var
subLocationItem
:
SubItem
?
=
SubItem
()
private
var
locationHistoryList
:
ArrayList
<
RegionItem
>?
=
arrayListOf
()
init
{
val
view
=
...
...
@@ -52,12 +54,34 @@ class AreaPopupWindow(
this
.
isOutsideTouchable
=
true
this
.
height
=
((
RxDeviceTool
.
getScreenHeight
(
context
)
-
RxImageTool
.
dp2px
(
90f
))
*
0.618
).
toInt
()
//设置高度为屏幕的80%
//根据IP获取当前城市
getRegionByIp
()
recentCityBean
=
MMKV
.
defaultMMKV
().
decodeParcelable
(
RECENT_CITY
,
ConsultantRecentCity
::
class
.
java
)
if
(
recentCityBean
==
null
)
recentCityBean
=
ConsultantRecentCity
(
arrayListOf
())
var
locationList
:
ArrayList
<
SubItem
>?
=
arrayListOf
()
locationHistoryList
?.
add
(
RegionItem
(
recentCityBean
!!
.
recentCity
,
value
=
"历史"
,
key
=
"0"
,
code
=
"0"
)
)
subLocationItem
?.
let
{
locationList
?.
add
(
it
)
}
locationList
?.
let
{
RegionItem
(
it
,
value
=
"定位"
,
key
=
"-1"
,
code
=
"-1"
)
}
?.
let
{
locationHistoryList
?.
add
(
0
,
it
)
}
locationHistoryList
?.
addAll
(
regionList
)
regionAdapter
.
regionList
=
locationHistoryList
!!
if
(
selectedRegion
.
sub
.
isNotEmpty
())
{
subList
.
addAll
(
selectedRegion
.
sub
)
}
else
{
subList
.
addAll
(
regionList
[
0
].
sub
)
}
subAdapter
=
SubRecyclerViewAdapter
(
context
,
subList
,
selectedSub
)
view
.
rvRegion
.
layoutManager
=
...
...
@@ -74,7 +98,7 @@ class AreaPopupWindow(
view
.
rvSub
.
scrollToPosition
(
0
)
}
view
.
rvRegion
.
adapter
=
regionAdapter
val
i
=
regionList
val
i
=
locationHistoryList
!!
.
takeWhile
{
it
.
key
!=
selectedRegion
.
key
}
.
count
()
view
.
rvRegion
.
scrollToPosition
(
i
)
...
...
@@ -87,10 +111,16 @@ class AreaPopupWindow(
false
)
subAdapter
.
onItemClickListener
=
MyBaseAdapter
.
OnItemClickListener
{
_
,
_
,
data
->
//保留最近五次的搜索历史记录
recentCityBean
=
MMKV
.
defaultMMKV
().
decodeParcelable
(
RECENT_CITY
,
ConsultantRecentCity
::
class
.
java
)
if
(
recentCityBean
==
null
)
recentCityBean
=
ConsultantRecentCity
(
arrayListOf
())
//倒序保留最近五次的搜索历史记录并去重
saveCitySearchRecord
(
data
)
selectedSub
=
data
onRegionSelectedListener
?.
onRegionSelected
(
selectedRegion
,
selectedSub
)
}
view
.
rvSub
.
adapter
=
subAdapter
view
.
rvSub
.
scrollToPosition
(
subList
.
indexOf
(
selectedSub
)
+
1
)
}
private
fun
saveCitySearchRecord
(
data
:
SubItem
)
{
recentCityBean
?.
let
{
if
(
it
.
recentCity
.
size
<
5
)
{
it
.
recentCity
.
add
(
0
,
data
)
...
...
@@ -103,12 +133,6 @@ class AreaPopupWindow(
MMKV
.
defaultMMKV
().
encode
(
RECENT_CITY
,
recentCityBean
)
}
}
selectedSub
=
data
onRegionSelectedListener
?.
onRegionSelected
(
selectedRegion
,
selectedSub
)
}
view
.
rvSub
.
adapter
=
subAdapter
view
.
rvSub
.
scrollToPosition
(
subList
.
indexOf
(
selectedSub
)
+
1
)
getRegionByIp
()
}
@SuppressLint
(
"CheckResult"
)
...
...
@@ -118,7 +142,9 @@ class AreaPopupWindow(
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
({
if
(
it
.
code
==
"200"
)
{
subLocationItem
?.
code
=
it
.
data
.
city_code
subLocationItem
?.
key
=
it
.
data
.
city_code
subLocationItem
?.
value
=
it
.
data
.
city_name
}
},
{})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment