Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 56d01e4

Browse files
committed
Add Tag Search.
1 parent 9fd24b0 commit 56d01e4

File tree

7 files changed

+92
-32
lines changed

7 files changed

+92
-32
lines changed

Diff for: .idea/modules.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: app/src/main/java/site/ddiu/tourval/MainActivity.kt

+37-22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import java.text.DecimalFormat
2929
class MainActivity : AppCompatActivity() {
3030

3131
data class LocItem(val objectId: String, val name: String, val desc: String, val location: AVGeoPoint, val distance: String)
32+
val likeList:MutableList<LocItem> = ArrayList ()
3233

3334
override fun onCreate(savedInstanceState: Bundle?) {
3435
super.onCreate(savedInstanceState)
@@ -44,19 +45,36 @@ class MainActivity : AppCompatActivity() {
4445
Log.i("kPermission", "permission---$it")
4546
})
4647

48+
initTags() // 初始化 热门标签 栏目
49+
50+
search_bar.setOnClickListener {
51+
switchSearch(0)
52+
}
53+
54+
55+
}
56+
57+
override fun onStart() {
58+
super.onStart()
59+
60+
like_list.layoutManager = LinearLayoutManager(act,LinearLayoutManager.HORIZONTAL,false)
61+
like_list.adapter = MainAdapter(likeList) {
62+
val intent = Intent(act, PlaceInfoActivity::class.java)
63+
intent.putExtra("objectId",it.objectId)
64+
startActivity(intent) //启动地图界面
65+
}
66+
67+
// 初始化高德定位
68+
GdLocation.init(this)
4769
GdLocation.getCurrentLocation {
4870
Log.d("GaodeLocation",it.address)
4971
val myLoc = it
5072
initLike(myLoc) // 初始化 猜你喜欢 栏目
5173
// textView_myLoc.text = "当前位置:" + it.address
5274
}
53-
54-
initTags() // 初始化 热门标签 栏目
55-
56-
5775
}
5876

59-
private fun addItemToFloatLayout(floatLayout:QMUIFloatLayout, itemText:String) {
77+
private fun addItemToFloatLayout(floatLayout:QMUIFloatLayout, itemId:Int, itemText:String) {
6078
val currentChildCount = floatLayout.childCount
6179

6280
//自定义textview样式
@@ -69,36 +87,31 @@ class MainActivity : AppCompatActivity() {
6987
val layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
7088
floatLayout.addView(textView, layoutParams)//将textview添加到floatLayout布局中
7189
textView.setOnClickListener {
72-
toast(textView.text)
90+
switchSearch(itemId)
7391
}
7492
}
7593

7694
private fun initTags () {
7795
qmuidemo_floatlayout.gravity = Gravity.LEFT //floatLayout中子节点左对齐
7896
qmuidemo_floatlayout.maxNumber = Int.MAX_VALUE
7997
qmuidemo_floatlayout.maxLines = Integer.MAX_VALUE
80-
addItemToFloatLayout(qmuidemo_floatlayout,"地铁沿线")
81-
addItemToFloatLayout(qmuidemo_floatlayout,"山水")
82-
addItemToFloatLayout(qmuidemo_floatlayout,"自然")
83-
addItemToFloatLayout(qmuidemo_floatlayout,"人文")
84-
addItemToFloatLayout(qmuidemo_floatlayout,"历史")
85-
addItemToFloatLayout(qmuidemo_floatlayout,"春游景点")
98+
99+
// 查询
100+
val query: AVQuery<AVObject> = AVQuery("TagInfo")
101+
query.findInBackground(object : FindCallback<AVObject>() {
102+
override fun done(list:List<AVObject>, e: AVException?) {
103+
for (avObject in list) {
104+
addItemToFloatLayout(qmuidemo_floatlayout,avObject.getInt("tagId"),avObject.getString("tagName"))
105+
}
106+
}
107+
})
86108
}
87109

88110
private fun initLike (myLoc: AMapLocation) {
89-
val likeList:MutableList<LocItem> = ArrayList ()
90111
var isNear = false
91112

92-
like_list.layoutManager = LinearLayoutManager(act,LinearLayoutManager.HORIZONTAL,false)
93-
like_list.adapter = MainAdapter(likeList) {
94-
val intent = Intent(act, PlaceInfoActivity::class.java)
95-
intent.putExtra("objectId",it.objectId)
96-
startActivity(intent) //启动地图界面
97-
}
98-
99113
// 查询
100114
val query: AVQuery<AVObject> = AVQuery("PlaceInfo")
101-
query.whereNotEqualTo("name", "111")
102115
query.findInBackground(object : FindCallback<AVObject>() {
103116
override fun done(list:List<AVObject>, e: AVException?) {
104117
for (avObject in list) {
@@ -110,6 +123,7 @@ class MainActivity : AppCompatActivity() {
110123
val distance_f = AMapUtils.calculateLineDistance(LatLng(myLoc.latitude,myLoc.longitude), LatLng(poi.latitude,poi.longitude))
111124

112125
if (distance_f < 1500) {
126+
nearPlace_layout.visibility = View.VISIBLE
113127
textView_myLoc.text = "当前位置:" + name
114128
isNear = true
115129
textView_myLoc.setOnClickListener {
@@ -145,8 +159,9 @@ class MainActivity : AppCompatActivity() {
145159

146160
}
147161

148-
fun switchSearch(view: View) {
162+
private fun switchSearch(tagId: Int) {
149163
val intent = Intent(this, SearchActivity::class.java)
164+
intent.putExtra("tagId", tagId)
150165
startActivity(intent) //启动地图界面
151166
}
152167

Diff for: app/src/main/java/site/ddiu/tourval/MapActivity.kt

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class MapActivity : AppCompatActivity() {
3434
QMUIStatusBarHelper.translucent(this) //沉浸化状态栏
3535
QMUIStatusBarHelper.setStatusBarLightMode(act) //设置状态栏黑色字体图标
3636

37-
val intent = intent
3837
val objectId = intent.getStringExtra("objectId")
3938

4039

Diff for: app/src/main/java/site/ddiu/tourval/MyApplication.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public void onCreate() {
2828
// 放在 SDK 初始化语句 AVOSCloud.initialize() 后面,只需要调用一次即可
2929
AVOSCloud.setDebugLogEnabled(true);
3030

31-
// 初始化高德定位
32-
GdLocation.init(this);
31+
3332

3433
}
3534

Diff for: app/src/main/java/site/ddiu/tourval/SearchActivity.kt

+53-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class SearchActivity : AppCompatActivity() {
4141
QMUIStatusBarHelper.translucent(this) //沉浸化状态栏
4242
QMUIStatusBarHelper.setStatusBarLightMode(act) //设置状态栏黑色字体图标
4343

44+
val tagId = intent.getIntExtra("tagId",0)
45+
4446
history_search.gravity = Gravity.LEFT //floatLayout中子节点左对齐
4547
history_search.maxNumber = Int.MAX_VALUE
4648
history_search.maxLines = Integer.MAX_VALUE
@@ -55,10 +57,14 @@ class SearchActivity : AppCompatActivity() {
5557
search(searchText)
5658
}
5759

58-
editText_search.isFocusable = true;
59-
editText_search.isFocusableInTouchMode = true;
60-
editText_search.requestFocus()
61-
60+
if (tagId > 0) {
61+
searchTag(tagId)
62+
}
63+
else {
64+
editText_search.isFocusable = true
65+
editText_search.isFocusableInTouchMode = true
66+
editText_search.requestFocus()
67+
}
6268

6369
}
6470

@@ -171,4 +177,47 @@ class SearchActivity : AppCompatActivity() {
171177
}
172178
})
173179
}
180+
181+
fun searchTag(tagId: Int) {
182+
val searchQueryList:MutableList<MainActivity.LocItem> = ArrayList ()
183+
184+
val query = AVQuery<AVObject>("PlaceInfo")
185+
query.whereEqualTo("tags", tagId)
186+
query.findInBackground(object : FindCallback<AVObject>() {
187+
override fun done(list:List<AVObject> , e: AVException?) {
188+
for (avObject in list) {
189+
val objectId = avObject.objectId
190+
val name = avObject.getString("name")
191+
val desc = avObject.getString("desc")
192+
val poi = avObject.getAVGeoPoint("location")
193+
val distance = ""
194+
195+
Log.d("OBJECTID",objectId)
196+
Log.d("NAME",name)
197+
Log.d("DESC",desc)
198+
199+
searchQueryList.add(MainActivity.LocItem(objectId, name, desc, poi, distance))
200+
}
201+
if (list.isEmpty()) {
202+
toast("没有结果")
203+
historySearch_view.visibility = View.VISIBLE
204+
searchResult_view.visibility = View.GONE
205+
206+
initSearchHistory()
207+
}
208+
else {
209+
toast("搜索到" + list.size + "条结果")
210+
historySearch_view.visibility = View.GONE
211+
searchResult_view.visibility = View.VISIBLE
212+
}
213+
searchResult_list.layoutManager = LinearLayoutManager(act, LinearLayoutManager.VERTICAL,false)
214+
searchResult_list.adapter = SearchResultAdapter(searchQueryList) {
215+
val intent = Intent(act, PlaceInfoActivity::class.java)
216+
intent.putExtra("objectId",it.objectId)
217+
startActivity(intent) //启动地图界面
218+
}
219+
searchResult_list.addItemDecoration(DividerItemDecoration(act, DividerItemDecoration.VERTICAL))
220+
}
221+
})
222+
}
174223
}

Diff for: app/src/main/res/layout/activity_main.xml

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
android:layout_height="50dp"
4949
android:alpha="1.0"
5050
android:background="@color/qmui_config_color_white"
51-
android:onClick="switchSearch"
5251
android:orientation="horizontal"
5352
app:layout_constraintEnd_toEndOf="parent"
5453
app:layout_constraintHorizontal_bias="0.0"

Diff for: build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
buildscript {
44
ext.support_version = '23.1.1'
55
ext.kotlin_version = '1.2.40'
6-
ext.anko_version = '0.8.2'
6+
ext.anko_version = '0.10.4'
77
repositories {
88
google()
99
jcenter()

0 commit comments

Comments
 (0)