BFragment.kt
7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.wello.vip
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import kotlinx.android.synthetic.main.fragment_a.*
class BFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_a, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val prof: SharedPreferences = view!!.context.getSharedPreferences("profdata", Context.MODE_PRIVATE)
////// DB 긁어오는 곳 /////////
val policyList = ArrayList<PolicyItem>()
var recomdatabase = FirebaseDatabase.getInstance().reference
recomdatabase.orderByChild("View").addListenerForSingleValueEvent(object :
ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
//Toast.makeText(this@RecommendActivity, "실패부분", Toast.LENGTH_SHORT).show()
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
//if (policyList0.size == 0) {
for (memoSnapshot in dataSnapshot.children) {
val memo = memoSnapshot.getValue(MemoItemRecom::class.java)
var all_flag = arrayListOf<String>()
var check_flag = arrayListOf<String>()
var user_category = arrayListOf<String>()
var user_topic = prof.getString("existing_topic","none")
//Toast.makeText(this@RecommendActivity, user_topic, Toast.LENGTH_SHORT).show()
val regex = "c[0-9]+[_][0-9]+".toRegex()
val matchResult : Sequence<MatchResult> = regex.findAll(user_topic.toString())
for(i in matchResult) {
if (i.value.split("_")[1] != "1") {
user_category.add(i.value)
}
}
for(i in user_category) {
if (i.split("_")[0] == "c1") { all_flag.add("c1"); if ((i.split("_")[1] in memo!!.Category1.split(" ")) || (memo!!.Category1.split(" ")[0] == "1")) { check_flag.add("c1") } }
if (i.split("_")[0] == "c2") { all_flag.add("c2"); if ((i.split("_")[1] in memo!!.Category2.split(" ")) || (memo!!.Category2.split(" ")[0] == "1")) { check_flag.add("c2") } }
if (i.split("_")[0] == "c3") { all_flag.add("c3"); if ((i.split("_")[1] in memo!!.Category3.split(" ")) || (memo!!.Category3.split(" ")[0] == "1")) { check_flag.add("c3") } }
if (i.split("_")[0] == "c4") { all_flag.add("c4"); if ((i.split("_")[1] in memo!!.Category4.split(" ")) || (memo!!.Category4.split(" ")[0] == "1")) { check_flag.add("c4") } }
if (i.split("_")[0] == "c5") { all_flag.add("c5"); if ((i.split("_")[1] in memo!!.Category5.split(" ")) || (memo!!.Category5.split(" ")[0] == "1")) { check_flag.add("c5") } }
if (i.split("_")[0] == "c6") { all_flag.add("c6"); if ((i.split("_")[1] in memo!!.Category6.split(" ")) || (memo!!.Category6.split(" ")[0] == "1")) { check_flag.add("c6") } }
if (i.split("_")[0] == "c7") { all_flag.add("c7"); if ((i.split("_")[1] in memo!!.Category7.split(" ")) || (memo!!.Category7.split(" ")[0] == "1")) { check_flag.add("c7") } }
if (i.split("_")[0] == "c8") { all_flag.add("c8"); if ((i.split("_")[1] in memo!!.Category8.split(" ")) || (memo!!.Category8.split(" ")[0] == "1")) { check_flag.add("c8") } }
if (i.split("_")[0] == "c9") { all_flag.add("c9"); if ((i.split("_")[1] in memo!!.Category9.split(" ")) || (memo!!.Category9.split(" ")[0] == "1")) { check_flag.add("c9") } }
if (i.split("_")[0] == "c10") { all_flag.add("c10"); if ((i.split("_")[1] in memo!!.Category10.split(" ")) || (memo!!.Category10.split(" ")[0] == "1")) { check_flag.add("c10") } }
if (i.split("_")[0] == "c11") { all_flag.add("c11"); if ((i.split("_")[1] in memo!!.Category11.split(" ")) || (memo!!.Category11.split(" ")[0] == "1")) { check_flag.add("c11") } }
if (i.split("_")[0] == "c12") { all_flag.add("c12"); if ((i.split("_")[1] in memo!!.Category12.split(" ")) || (memo!!.Category12.split(" ")[0] == "1")) { check_flag.add("c12") } }
if (i.split("_")[0] == "c13") { all_flag.add("c13"); if ((i.split("_")[1] in memo!!.Category13.split(" ")) || (memo!!.Category13.split(" ")[0] == "1")) { check_flag.add("c13") } }
if (i.split("_")[0] == "c14") { all_flag.add("c14"); if ((i.split("_")[1] in memo!!.Category14.split(" ")) || (memo!!.Category14.split(" ")[0] == "1")) { check_flag.add("c14") } }
if (i.split("_")[0] == "c15") { all_flag.add("c15"); if ((i.split("_")[1] in memo!!.Category15.split(" ")) || (memo!!.Category15.split(" ")[0] == "1")) { check_flag.add("c15") } }
if (i.split("_")[0] == "c16") { all_flag.add("c16"); if ((i.split("_")[1] in memo!!.Category16.split(" ")) || (memo!!.Category16.split(" ")[0] == "1")) { check_flag.add("c16") } }
}
var set_all = all_flag.distinct()
var set_check = check_flag.distinct()
if (set_all.size == set_check.size) {
if ("2" in memo!!.Category5.split(" ") ||
"3" in memo!!.Category5.split(" ") ||
"4" in memo!!.Category5.split(" ") ||
"5" in memo!!.Category5.split(" ") ||
"2" in memo!!.Category6.split(" ") ||
"3" in memo!!.Category6.split(" ") ||
"4" in memo!!.Category6.split(" ") ||
"5" in memo!!.Category6.split(" ") ||
"6" in memo!!.Category6.split(" ") ||
"7" in memo!!.Category6.split(" ") ||
"17" in memo!!.Category8.split(" ")) {
policyList.add(
PolicyItem(
ContextCompat.getDrawable(context!!.applicationContext, R.drawable.recommend_default_blue)!!, memo!!.Policy, memo!!.Content, memo!!.Link, memo!!.View, memo!!.Keyword, memo!!.Date, memo!!.Review, memo!!.Score, memo!!.Category1, memo!!.Category2, memo!!.Category3, memo!!.Category4, memo!!.Category5, memo!!.Category6, memo!!.Category7, memo!!.Category8, memo!!.Category9, memo!!.Category10, memo!!.Category11, memo!!.Category12, memo!!.Category13, memo!!.Category14, memo!!.Category15, memo!!.Category16, memo!!.Value, memo!!.D_day
)
)
val adapter = PolicyAdapter(policyList)
policyRecyclerView.adapter = adapter
policyRecyclerView.setItemViewCacheSize((200000000))
}
}
}
//Toast.makeText(context!!.applicationContext, "총 "+policyList.size.toString()+"개의 추천 정책을 찾았습니다.", Toast.LENGTH_SHORT).show()
}
})
}
}