Showing
3 changed files
with
225 additions
and
1 deletions
1 | package com.example.vip | 1 | package com.example.vip |
2 | 2 | ||
3 | +import android.content.Intent | ||
3 | import androidx.appcompat.app.AppCompatActivity | 4 | import androidx.appcompat.app.AppCompatActivity |
4 | import android.os.Bundle | 5 | import android.os.Bundle |
6 | +import android.view.Menu | ||
7 | +import android.view.MenuItem | ||
8 | +import android.widget.Toast | ||
9 | +import androidx.appcompat.app.ActionBar | ||
10 | +import androidx.core.content.ContextCompat | ||
11 | +import com.google.android.material.bottomnavigation.BottomNavigationView | ||
12 | +import com.google.android.material.snackbar.Snackbar | ||
13 | +import com.google.firebase.database.DataSnapshot | ||
14 | +import com.google.firebase.database.DatabaseError | ||
15 | +import com.google.firebase.database.FirebaseDatabase | ||
16 | +import com.google.firebase.database.ValueEventListener | ||
17 | +import kotlinx.android.synthetic.main.activity_recommend.* | ||
18 | +import kotlinx.android.synthetic.main.activity_recommend.toolbar | ||
19 | +import kotlinx.android.synthetic.main.activity_signin.* | ||
20 | + | ||
21 | +data class MemoItemFavor( | ||
22 | + val Target : String = "", | ||
23 | + val Policy : String = "", | ||
24 | + val Content : String = "", | ||
25 | + val Link : String = "" | ||
26 | +) | ||
5 | 27 | ||
6 | class FavoritesActivity : AppCompatActivity() { | 28 | class FavoritesActivity : AppCompatActivity() { |
7 | 29 | ||
30 | + ////bottom navigation view operation start 1 | ||
31 | + lateinit var bottomBar: ActionBar | ||
32 | + ////bottom navigation view operation end 1 | ||
8 | override fun onCreate(savedInstanceState: Bundle?) { | 33 | override fun onCreate(savedInstanceState: Bundle?) { |
9 | super.onCreate(savedInstanceState) | 34 | super.onCreate(savedInstanceState) |
10 | setContentView(R.layout.activity_favorites) | 35 | setContentView(R.layout.activity_favorites) |
36 | + | ||
37 | + val policyList = ArrayList<PolicyItem>() | ||
38 | + var favordatabase = FirebaseDatabase.getInstance().reference | ||
39 | + | ||
40 | + if (intent.hasExtra("key")) { | ||
41 | + //textView.text = intent.getStringExtra("key") 텍뷰추가하면 인텐트로 값넘기는거 보임 | ||
42 | + | ||
43 | + favordatabase.orderByChild("Policy").startAt(intent.getStringExtra("key")).endAt(intent.getStringExtra("key")+"\uf8ff").addListenerForSingleValueEvent(object : | ||
44 | + ValueEventListener { | ||
45 | + override fun onCancelled(p0: DatabaseError) { | ||
46 | + Toast.makeText(this@FavoritesActivity, "실패부분", Toast.LENGTH_SHORT).show() | ||
47 | + } | ||
48 | + override fun onDataChange(dataSnapshot: DataSnapshot) { | ||
49 | + for (memoSnapshot in dataSnapshot.children){ | ||
50 | + val memo = memoSnapshot.getValue(MemoItemFavor::class.java) | ||
51 | + | ||
52 | + policyList.add( | ||
53 | + PolicyItem( | ||
54 | + ContextCompat.getDrawable(this@FavoritesActivity, R.drawable.image01)!!, | ||
55 | + memo!!.Policy, | ||
56 | + memo!!.Policy, | ||
57 | + memo!!.Policy, | ||
58 | + 4.toFloat(), | ||
59 | + "" | ||
60 | + | ||
61 | + ) | ||
62 | + ) | ||
63 | + } | ||
64 | + | ||
65 | + val adapter = PolicyAdapter(policyList) | ||
66 | + policyRecyclerView.adapter = adapter | ||
67 | + | ||
68 | + } | ||
69 | + | ||
70 | + }) | ||
71 | + | ||
72 | + | ||
73 | + } else { | ||
74 | + Toast.makeText(this, "putExtra value not found", Toast.LENGTH_SHORT).show() | ||
75 | + | ||
76 | + favordatabase.orderByChild("Policy").startAt(intent.getStringExtra("\uf8ff")).addListenerForSingleValueEvent(object : | ||
77 | + ValueEventListener { | ||
78 | + override fun onCancelled(p0: DatabaseError) { | ||
79 | + Toast.makeText(this@FavoritesActivity, "실패부분", Toast.LENGTH_SHORT).show() | ||
80 | + } | ||
81 | + override fun onDataChange(dataSnapshot: DataSnapshot) { | ||
82 | + for (memoSnapshot in dataSnapshot.children){ | ||
83 | + val memo = memoSnapshot.getValue(MemoItemFavor::class.java) | ||
84 | + | ||
85 | + policyList.add( | ||
86 | + PolicyItem( | ||
87 | + ContextCompat.getDrawable(this@FavoritesActivity, R.drawable.image01)!!, | ||
88 | + memo!!.Policy, | ||
89 | + memo!!.Policy, | ||
90 | + memo!!.Policy, | ||
91 | + 4.toFloat(), | ||
92 | + "" | ||
93 | + | ||
94 | + ) | ||
95 | + ) | ||
96 | + } | ||
97 | + | ||
98 | + val adapter = PolicyAdapter(policyList) | ||
99 | + policyRecyclerView.adapter = adapter | ||
100 | + | ||
101 | + } | ||
102 | + | ||
103 | + }) | ||
104 | + | ||
105 | + | ||
11 | } | 106 | } |
107 | + | ||
108 | + | ||
109 | + | ||
110 | + // 1. 툴바 사용 설정 | ||
111 | + setSupportActionBar(toolbar) | ||
112 | + | ||
113 | + // 2. 툴바 왼쪽 버튼 설정 | ||
114 | + supportActionBar!!.setDisplayHomeAsUpEnabled(true) // 왼쪽 버튼 사용 여부 true | ||
115 | + supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정 | ||
116 | + supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기 | ||
117 | + | ||
118 | + ////bottom navigation view operation start 2 | ||
119 | + bottomBar=supportActionBar!! | ||
120 | + val bottomNavigation: BottomNavigationView =findViewById(R.id.bottomNavigation) | ||
121 | + bottomNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener) | ||
122 | + ////bottom navigation view operation end 2 | ||
123 | + | ||
124 | + } | ||
125 | + // 3.툴바 메뉴 버튼을 설정 | ||
126 | + override fun onCreateOptionsMenu(menu: Menu?): Boolean { | ||
127 | + menuInflater.inflate(R.menu.main_menu, menu) // main_menu 메뉴를 toolbar 메뉴 버튼으로 설정 | ||
128 | + return true | ||
129 | + } | ||
130 | + | ||
131 | + // 4.툴바 메뉴 버튼이 클릭 됐을 때 콜백 | ||
132 | + override fun onOptionsItemSelected(item: MenuItem?): Boolean { | ||
133 | + // 클릭된 메뉴 아이템의 아이디 마다 when 구절로 클릭시 동작을 설정한다. | ||
134 | + when(item!!.itemId){ | ||
135 | + android.R.id.home->{ // 메뉴 버튼 | ||
136 | + Snackbar.make(toolbar,"Menu pressed", Snackbar.LENGTH_SHORT).show() | ||
137 | + } | ||
138 | + R.id.menu_search->{ // 검색 버튼 | ||
139 | + val search_Intent = Intent(this, SearchActivity::class.java) | ||
140 | + startActivity(search_Intent) | ||
141 | + //Snackbar.make(toolbar,"Search menu pressed",Snackbar.LENGTH_SHORT).show() | ||
142 | + } | ||
143 | + } | ||
144 | + return super.onOptionsItemSelected(item) | ||
145 | + } | ||
146 | + | ||
147 | + //bottom navigation view operation start 3 | ||
148 | + private val mOnNavigationItemSelectedListener= | ||
149 | + BottomNavigationView.OnNavigationItemSelectedListener{ item-> | ||
150 | + when (item.itemId){ | ||
151 | + | ||
152 | + R.id.bottomHome ->{ | ||
153 | + val intent = Intent(this, SignInActivity::class.java) | ||
154 | + startActivity(intent) | ||
155 | + return@OnNavigationItemSelectedListener true | ||
156 | + } | ||
157 | + R.id.bottomRecommend ->{ | ||
158 | + val intent = Intent(this, RecommendActivity::class.java) | ||
159 | + startActivity(intent) | ||
160 | + return@OnNavigationItemSelectedListener true | ||
161 | + } | ||
162 | + R.id.bottomFavorites ->{ | ||
163 | + val intent = Intent(this, FavoritesActivity::class.java) | ||
164 | + startActivity(intent) | ||
165 | + return@OnNavigationItemSelectedListener true | ||
166 | + } | ||
167 | + R.id.bottomInfo ->{ | ||
168 | + val intent = Intent(this, InfoActivity::class.java) | ||
169 | + startActivity(intent) | ||
170 | + return@OnNavigationItemSelectedListener true | ||
171 | + } | ||
172 | + | ||
173 | + | ||
174 | + } | ||
175 | + false | ||
176 | + } | ||
177 | +//bottom navigation view operation end 3 | ||
178 | + | ||
12 | } | 179 | } | ... | ... |
... | @@ -37,7 +37,8 @@ class SearchAdapter(private val items: ArrayList<SearchItem>) : | ... | @@ -37,7 +37,8 @@ class SearchAdapter(private val items: ArrayList<SearchItem>) : |
37 | view.searchIconText.text = item.searchItemText | 37 | view.searchIconText.text = item.searchItemText |
38 | view.setOnClickListener{ | 38 | view.setOnClickListener{ |
39 | 39 | ||
40 | - val intent=Intent(view.context, WelcomeActivity::class.java) | 40 | + val intent=Intent(view.context, DetailActivity::class.java) |
41 | + intent.putExtra("key",item.searchItemText) | ||
41 | view.context.startActivity(intent) | 42 | view.context.startActivity(intent) |
42 | } | 43 | } |
43 | } | 44 | } | ... | ... |
... | @@ -6,4 +6,60 @@ | ... | @@ -6,4 +6,60 @@ |
6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
7 | tools:context=".FavoritesActivity"> | 7 | tools:context=".FavoritesActivity"> |
8 | 8 | ||
9 | + <LinearLayout | ||
10 | + android:id="@+id/linearLayout" | ||
11 | + android:layout_width="match_parent" | ||
12 | + android:layout_height="match_parent" | ||
13 | + android:orientation="vertical" | ||
14 | + app:layout_constraintBottom_toBottomOf="parent" | ||
15 | + app:layout_constraintEnd_toEndOf="parent" | ||
16 | + app:layout_constraintStart_toStartOf="parent" | ||
17 | + app:layout_constraintTop_toTopOf="parent"> | ||
18 | + | ||
19 | + <androidx.appcompat.widget.Toolbar | ||
20 | + android:id="@+id/toolbar" | ||
21 | + android:layout_width="fill_parent" | ||
22 | + android:layout_height="wrap_content" | ||
23 | + android:layout_marginBottom="11dp" | ||
24 | + android:background="#FFF" | ||
25 | + android:elevation="5dp" | ||
26 | + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" | ||
27 | + app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> | ||
28 | + | ||
29 | + <ImageView | ||
30 | + android:layout_width="77dp" | ||
31 | + android:layout_height="44dp" | ||
32 | + android:layout_gravity="center" | ||
33 | + android:src="@drawable/toolbar_logo" /> | ||
34 | + </androidx.appcompat.widget.Toolbar> | ||
35 | + | ||
36 | + | ||
37 | + <androidx.recyclerview.widget.RecyclerView | ||
38 | + android:id="@+id/policyRecyclerView" | ||
39 | + android:layout_width="match_parent" | ||
40 | + android:layout_height="500dp" | ||
41 | + android:layout_weight="1" | ||
42 | + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" | ||
43 | + tools:listitem="@layout/item_policy" /> | ||
44 | + | ||
45 | + <FrameLayout | ||
46 | + android:layout_width="match_parent" | ||
47 | + android:layout_height="wrap_content" | ||
48 | + android:id="@+id/fragmentContainer" | ||
49 | + app:layout_constraintBottom_toBottomOf="parent" | ||
50 | + > | ||
51 | + | ||
52 | + <com.google.android.material.bottomnavigation.BottomNavigationView | ||
53 | + android:id="@+id/bottomNavigation" | ||
54 | + android:layout_width="match_parent" | ||
55 | + android:layout_height="wrap_content" | ||
56 | + android:layout_gravity="bottom" | ||
57 | + android:background="#FFF" | ||
58 | + app:itemIconTint="#29ABE2" | ||
59 | + app:itemTextColor="#29ABE2" | ||
60 | + app:labelVisibilityMode="labeled" | ||
61 | + app:menu="@menu/bottom_nav_menu" /> | ||
62 | + </FrameLayout> | ||
63 | + | ||
64 | + </LinearLayout> | ||
9 | </androidx.constraintlayout.widget.ConstraintLayout> | 65 | </androidx.constraintlayout.widget.ConstraintLayout> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment