soonmyeong2

Create topic subscription template

...@@ -13,6 +13,7 @@ import com.google.android.gms.tasks.OnCompleteListener ...@@ -13,6 +13,7 @@ import com.google.android.gms.tasks.OnCompleteListener
13 import com.google.firebase.auth.FirebaseAuth 13 import com.google.firebase.auth.FirebaseAuth
14 import com.google.firebase.database.FirebaseDatabase 14 import com.google.firebase.database.FirebaseDatabase
15 import com.google.firebase.iid.FirebaseInstanceId 15 import com.google.firebase.iid.FirebaseInstanceId
16 +import com.google.firebase.messaging.FirebaseMessaging
16 import com.marcinmoskala.math.combinations 17 import com.marcinmoskala.math.combinations
17 import kotlinx.android.synthetic.main.activity_input_profil_second_one.* 18 import kotlinx.android.synthetic.main.activity_input_profil_second_one.*
18 19
...@@ -67,7 +68,8 @@ class InputProfilSecondOneActivity : AppCompatActivity() { ...@@ -67,7 +68,8 @@ class InputProfilSecondOneActivity : AppCompatActivity() {
67 68
68 skipButton.setOnClickListener { 69 skipButton.setOnClickListener {
69 sendToken() 70 sendToken()
70 - val user=firebaseAuth?.currentUser 71 + val user=firebaseAuth?.currentUser!!.uid
72 + Log.d("test:", user.toString())
71 val cat_1=listOf("c1_1","c1_2","c1_3") 73 val cat_1=listOf("c1_1","c1_2","c1_3")
72 val cat_2=listOf("c2_1","c2_2","c2_3","c2_4","c2_5","c2_6","c2_7") 74 val cat_2=listOf("c2_1","c2_2","c2_3","c2_4","c2_5","c2_6","c2_7")
73 val cat_3=listOf("c3_1","c3_2","c3_3") 75 val cat_3=listOf("c3_1","c3_2","c3_3")
...@@ -85,25 +87,25 @@ class InputProfilSecondOneActivity : AppCompatActivity() { ...@@ -85,25 +87,25 @@ class InputProfilSecondOneActivity : AppCompatActivity() {
85 val cat_15=listOf("c15_1","c15_2","c15_3") 87 val cat_15=listOf("c15_1","c15_2","c15_3")
86 val cat_16=listOf("c16_1","c16_2","c16_3","c16_4","c16_5","c16_6","c16_7") 88 val cat_16=listOf("c16_1","c16_2","c16_3","c16_4","c16_5","c16_6","c16_7")
87 89
88 - val policy_string_list= listOf("c1_1c2_1c3_1c4_1c5_1c6_1c7_1c8_1c9_1c10_1c11_1c12_1c13_1c14_1c15_1c16_1") 90 + //val policy_string_list= listOf("c1_1c2_1c3_1c4_1c5_1c6_1c7_1c8_1c9_1c10_1c11_1c12_1c13_1c14_1c15_1c16_1")
89 - var policy_string="" 91 + //var policy_string=""
90 - 92 +
91 - var user_cat_1= mutableListOf<String>() 93 + var user_cat_1 = mutableListOf("c1_1")
92 - var user_cat_2= mutableListOf<String>() 94 + var user_cat_2 = mutableListOf("c2_1")
93 - var user_cat_3= mutableListOf<String>() 95 + var user_cat_3 = mutableListOf("c3_1")
94 - var user_cat_4= mutableListOf<String>() 96 + var user_cat_4 = mutableListOf("c4_1")
95 - var user_cat_5= mutableListOf<String>() 97 + var user_cat_5 = mutableListOf("c5_1")
96 - var user_cat_6= mutableListOf<String>() 98 + var user_cat_6 = mutableListOf("c6_1")
97 - var user_cat_7= mutableListOf<String>() 99 + var user_cat_7 = mutableListOf("c7_1")
98 - var user_cat_8= mutableListOf<String>() 100 + var user_cat_8 = mutableListOf("c8_1")
99 - var user_cat_9= mutableListOf<String>() 101 + var user_cat_9 = mutableListOf("c9_1")
100 - var user_cat_10=mutableListOf<String>() 102 + var user_cat_10 = mutableListOf("c10_1")
101 - var user_cat_11=mutableListOf<String>() 103 + var user_cat_11 = mutableListOf("c11_1")
102 - var user_cat_12=mutableListOf<String>() 104 + var user_cat_12 = mutableListOf("c12_1")
103 - var user_cat_13=mutableListOf<String>() 105 + var user_cat_13 = mutableListOf("c13_1")
104 - var user_cat_14=mutableListOf<String>() 106 + var user_cat_14 = mutableListOf("c14_1")
105 - var user_cat_15=mutableListOf<String>() 107 + var user_cat_15 = mutableListOf("c15_1")
106 - var user_cat_16=mutableListOf<String>() 108 + var user_cat_16 = mutableListOf("c16_1")
107 109
108 for(item in cat_1){if(prof.getInt(item,3)==1){user_cat_1.add(item)}} 110 for(item in cat_1){if(prof.getInt(item,3)==1){user_cat_1.add(item)}}
109 for(item in cat_2){if(prof.getInt(item,3)==1){user_cat_2.add(item)}} 111 for(item in cat_2){if(prof.getInt(item,3)==1){user_cat_2.add(item)}}
...@@ -122,10 +124,105 @@ class InputProfilSecondOneActivity : AppCompatActivity() { ...@@ -122,10 +124,105 @@ class InputProfilSecondOneActivity : AppCompatActivity() {
122 for(item in cat_15){if(prof.getInt(item,3)==1){user_cat_15.add(item)}} 124 for(item in cat_15){if(prof.getInt(item,3)==1){user_cat_15.add(item)}}
123 for(item in cat_16){if(prof.getInt(item,3)==1){user_cat_16.add(item)}} 125 for(item in cat_16){if(prof.getInt(item,3)==1){user_cat_16.add(item)}}
124 126
127 + var topic = ""
128 + var user_topic = ""
129 +
130 + Log.d("hell gate1 : ", user_cat_1.toString())
131 + Log.d("hell gate2 : ", user_cat_2.toString())
132 + Log.d("hell gate3 : ", user_cat_3.toString())
133 + Log.d("hell gate4 : ", user_cat_4.toString())
134 + Log.d("hell gate5 : ", user_cat_5.toString())
135 + Log.d("hell gate6 : ", user_cat_6.toString())
136 + Log.d("hell gate7 : ", user_cat_7.toString())
137 + Log.d("hell gate8 : ", user_cat_8.toString())
138 + Log.d("hell gate9 : ", user_cat_9.toString())
139 + Log.d("hell gate10 : ", user_cat_10.toString())
140 + Log.d("hell gate11 : ", user_cat_11.toString())
141 + Log.d("hell gate12 : ", user_cat_12.toString())
142 + Log.d("hell gate13 : ", user_cat_13.toString())
143 + Log.d("hell gate14 : ", user_cat_14.toString())
144 + Log.d("hell gate15 : ", user_cat_15.toString())
145 + Log.d("hell gate16 : ", user_cat_16.toString())
146 +
147 +
148 + for(c1 in user_cat_1) {
149 + topic += c1
150 + for (c2 in user_cat_2) {
151 + topic += c2
152 + for (c3 in user_cat_3) {
153 + topic += c3
154 + for (c4 in user_cat_4) {
155 + topic += c4
156 + for (c5 in user_cat_5) {
157 + topic += c5
158 + for (c6 in user_cat_6) {
159 + topic += c6
160 + for (c7 in user_cat_7) {
161 + topic += c7
162 + for (c8 in user_cat_8) {
163 + topic += c8
164 + for (c9 in user_cat_9) {
165 + topic += c9
166 + for (c10 in user_cat_10) {
167 + topic += c10
168 + for (c11 in user_cat_11) {
169 + topic += c11
170 + for (c12 in user_cat_12) {
171 + topic += c12
172 + for (c13 in user_cat_13) {
173 + topic += c13
174 + for (c14 in user_cat_14) {
175 + topic += c14
176 + for (c15 in user_cat_15) {
177 + topic += c15
178 + for (c16 in user_cat_16) {
179 + topic += c16
180 + user_topic += (topic + "/")
181 + // debug
182 + // Log.d("topic : ", topic)
183 +
184 + /* topic 구독 코드
185 + FirebaseMessaging.getInstance().subscribeToTopic(topic).addOnCompleteListener { task ->
186 + if (!task.isSuccessful) { } // 성공
187 + }
188 + */
189 +
190 + topic = topic.substring(0, topic.length - c16.length)
191 + }
192 + topic = topic.substring(0, topic.length - c15.length)
193 + }
194 + topic = topic.substring(0, topic.length - c14.length)
195 + }
196 + topic = topic.substring(0, topic.length - c13.length)
197 + }
198 + topic = topic.substring(0, topic.length - c12.length)
199 + }
200 + topic = topic.substring(0, topic.length - c11.length)
201 + }
202 + topic = topic.substring(0, topic.length - c10.length)
203 + }
204 + topic = topic.substring(0, topic.length - c9.length)
205 + }
206 + topic = topic.substring(0, topic.length - c8.length)
207 + }
208 + topic = topic.substring(0, topic.length - c7.length)
209 + }
210 + topic = topic.substring(0, topic.length - c6.length)
211 + }
212 + topic = topic.substring(0, topic.length - c5.length)
213 + }
214 + topic = topic.substring(0, topic.length - c4.length)
215 + }
216 + topic = topic.substring(0, topic.length - c3.length)
217 + }
218 + topic = topic.substring(0, topic.length - c2.length)
219 + }
220 + topic = topic.substring(0, topic.length-c1.length)
221 + }
125 222
126 -user_cat_1.toSet().combinations(2) 223 + //Log.d("re:", user_topic)
224 + writeNewUser(user, "null", user_topic) // db에 쓰기
127 225
128 - writeNewUser(user!!.uid,"$tkn",policy_string)
129 226
130 var intent = Intent(this, SignInActivity::class.java) 227 var intent = Intent(this, SignInActivity::class.java)
131 startActivity(intent) 228 startActivity(intent)
...@@ -151,9 +248,7 @@ user_cat_1.toSet().combinations(2) ...@@ -151,9 +248,7 @@ user_cat_1.toSet().combinations(2)
151 /* 취소일 때 아무 액션이 없으므로 빈칸 */ 248 /* 취소일 때 아무 액션이 없으므로 빈칸 */
152 } 249 }
153 */ 250 */
154 -
155 .show() 251 .show()
156 -
157 } 252 }
158 253
159 previousButton.setOnClickListener { 254 previousButton.setOnClickListener {
......