Toggle navigation
Toggle navigation
This project
Loading...
Sign in
장연우
/
WELLO
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
soonmyeong2
2019-11-16 03:13:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4d7735eda5f60d7f326204cdb0ce68e83e3943f4
4d7735ed
1 parent
e1cc2899
complete perpect search in NoSQL
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
4 deletions
vip/app/src/main/java/com/example/vip/AccountSettingActivity.kt
vip/app/src/main/java/com/example/vip/SearchActivity.kt
vip/app/src/main/res/layout/activity_account_settings.xml
vip/app/src/main/java/com/example/vip/AccountSettingActivity.kt
View file @
4d7735e
package
com.example.vip
import
android.content.Context
import
android.content.SharedPreferences
import
android.os.Bundle
import
androidx.appcompat.app.AppCompatActivity
import
kotlinx.android.synthetic.main.activity_account_settings.*
class
AccountSettingActivity
:
AppCompatActivity
()
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_account_settings
)
val
prof
:
SharedPreferences
=
getSharedPreferences
(
"policy_key"
,
Context
.
MODE_PRIVATE
)
val
editor
:
SharedPreferences
.
Editor
=
prof
.
edit
()
input_db
.
setOnClickListener
{
editor
.
putString
(
"0"
,
"[신한금융그룹] 신한 희망사회프로젝트 위기가정 재기지원사업 2년차 사업(2019년 5월~2020년 4월)"
)
editor
.
putString
(
"1"
,
"2020년 동계 아름드리 대학생 해외봉사단원 모집"
)
editor
.
putString
(
"2"
,
"초록우산 어린이재단 인재양성사업 - 2020 아이리더 모집공고"
)
editor
.
putString
(
"3"
,
"(열매나눔복지재단, 처갓집양념치킨)2019 저소득가구 창업지원사업 처갓집양념치킨 창업자 모집공고(5.31-)"
)
editor
.
putString
(
"4"
,
"[2017년도] 예비부부교실 / 신혼부부교실 : 연간일정"
)
editor
.
putString
(
"5"
,
"신생아지원"
)
editor
.
putString
(
"6"
,
"성폭력피해아동청소년 전용쉼터운영지원"
)
editor
.
putString
(
"7"
,
"국가유공자등취업지원"
)
editor
.
putString
(
"8"
,
"결혼이민자 통번역 서비스"
)
editor
.
putString
(
"9"
,
"한부모가족자녀 교육비 지원"
)
editor
.
commit
()
}
}
}
\ No newline at end of file
...
...
vip/app/src/main/java/com/example/vip/SearchActivity.kt
View file @
4d7735e
...
...
@@ -9,6 +9,7 @@ import androidx.core.content.ContextCompat.getSystemService
import
android.icu.lang.UCharacter.GraphemeClusterBreak.T
import
android.view.View
import
android.content.Intent
import
android.content.SharedPreferences
import
android.util.Log
import
android.view.inputmethod.InputMethodManager
import
android.widget.*
...
...
@@ -17,7 +18,10 @@ import com.google.firebase.database.*
import
com.google.firebase.database.DatabaseReference
import
com.google.firebase.database.FirebaseDatabase
import
kotlinx.android.synthetic.main.search.*
import
com.google.firebase.database.DatabaseError
import
com.google.firebase.database.DataSnapshot
import
com.google.firebase.database.ValueEventListener
import
androidx.fragment.app.FragmentActivity
data class
MemoItem
(
...
...
@@ -34,6 +38,9 @@ class SearchActivity : AppCompatActivity() {
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
search
)
val
prof
:
SharedPreferences
=
getSharedPreferences
(
"policy_key"
,
Context
.
MODE_PRIVATE
)
val
editor
:
SharedPreferences
.
Editor
=
prof
.
edit
()
val
searchList
=
ArrayList
<
SearchItem
>()
val
no_search
:
ImageView
=
findViewById
(
R
.
id
.
no_matching
)
// 노서치이미지
...
...
@@ -55,14 +62,66 @@ class SearchActivity : AppCompatActivity() {
searchView
.
setOnQueryTextListener
(
object
:
SearchView
.
OnQueryTextListener
{
override
fun
onQueryTextSubmit
(
query
:
String
):
Boolean
{
searchList
.
clear
()
// 검색 버튼이 눌러졌을 때 이벤트 처리
val
layout
:
LinearLayout
=
findViewById
(
R
.
id
.
hashtag_linear
)
layout
.
setVisibility
(
View
.
GONE
)
CloseKeyboard
()
// DB 내 목록에서 맞는거 찾는 부분
val
arr
=
arrayOf
(
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
)
val
key
=
arrayListOf
<
String
>()
for
(
i
in
arr
)
{
val
temp
=
prof
.
getString
(
"$i"
,
"fail"
)
val
regex
=
"$query"
.
toRegex
()
val
matchResult
:
MatchResult
?
=
regex
.
find
(
temp
.
toString
())
if
(
matchResult
!=
null
)
{
key
.
add
(
temp
.
toString
())
}
}
for
(
i
in
key
)
{
val
key_query
=
database
.
orderByChild
(
"Policy"
).
equalTo
(
"$i"
)
key_query
.
addListenerForSingleValueEvent
(
object
:
ValueEventListener
{
override
fun
onDataChange
(
dataSnapshot
:
DataSnapshot
)
{
//Toast.makeText(getBaseContext(), dataSnapshot.getValue().toString(), Toast.LENGTH_SHORT).show()
no_search
.
setVisibility
(
View
.
GONE
)
policy_scroll_view
.
setVisibility
(
View
.
VISIBLE
)
for
(
memoSnapshot
in
dataSnapshot
.
children
){
val
memo
=
memoSnapshot
.
getValue
(
MemoItem
::
class
.
java
)
searchList
.
add
(
SearchItem
(
ContextCompat
.
getDrawable
(
this
@SearchActivity
,
R
.
drawable
.
image01
)
!!
,
memo
!!
.
Policy
)
)
}
val
adapter
=
SearchAdapter
(
searchList
)
searchRecyclerView
.
adapter
=
adapter
}
override
fun
onCancelled
(
p0
:
DatabaseError
)
{
}
})
}
if
(
key
.
size
==
0
)
{
policy_scroll_view
.
setVisibility
(
View
.
GONE
)
no_search
.
setVisibility
(
View
.
VISIBLE
)
}
//////////
/*
database.orderByChild("Policy").startAt("$query").endAt("$query"+"\uf8ff").addListenerForSingleValueEvent(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
Toast
.
makeText
(
this
@SearchActivity
,
"실패
부분
: $query"
,
Toast
.
LENGTH_SHORT
).
show
()
Toast.makeText(this@SearchActivity, "실패 : $query", Toast.LENGTH_SHORT).show()
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists() == false){ // 값 없을 때
...
...
@@ -86,14 +145,15 @@ class SearchActivity : AppCompatActivity() {
val adapter=SearchAdapter(searchList)
searchRecyclerView.adapter=adapter
}
})
searchList
.
clear
()
})*/
return
true
}
override
fun
onQueryTextChange
(
newText
:
String
):
Boolean
{
// 검색어가 변경되었을 때 이벤트 처리
return
false
...
...
vip/app/src/main/res/layout/activity_account_settings.xml
View file @
4d7735e
...
...
@@ -78,6 +78,12 @@
android:text=
"회원 탈퇴 (준비중)"
android:textSize=
"17dp"
/>
<Button
android:id=
"@+id/input_db"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"디비에 넣기"
/>
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
...
...
Please
register
or
login
to post a comment