質問編集履歴
1
コードを載せて欲しいとのことでしたので、載せました。よろしくお願いいたします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,309 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
このように出ました。nullではないので、remove出来てないという認識でいいのでしょうか?それともこれはデタッチはできているのでしょうか?
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
<コード>
|
20
|
+
|
21
|
+
locateEachCardメソッドにListenerRegistrationを設置しました。
|
22
|
+
|
23
|
+
フラグメントを閉じた時に呼び出されるOnGoBackOnGameSettingFragmentメソッドでlistenerRegistrationをデタッチしました。(はずだが、されていなかった?)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
Fragmentのコードもさらに下の方に載せました。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```ここに言語を入力
|
32
|
+
|
33
|
+
private fun locateEachCard() {
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
listeningWords = database.collection(dbCollection).document(keyword).collection("words").document(keyword)
|
38
|
+
|
39
|
+
.addSnapshotListener { it, e ->
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
if (e != null) return@addSnapshotListener
|
44
|
+
|
45
|
+
if (it == null || !it.exists()) return@addSnapshotListener
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
val wordsDataList = mutableListOf<WordsData>()
|
52
|
+
|
53
|
+
val hashmap = it["words"] as MutableList<HashMap<String, String>>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
for(i in 0 .. 24){
|
58
|
+
|
59
|
+
wordsDataList.add(WordsData(hashmap[i]["word"], hashmap[i]["color"]))
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
listeningSelectedCards = database.collection(dbCollection).document(keyword).collection("selectedCards").addSnapshotListener { query, e ->
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if(e != null) return@addSnapshotListener
|
70
|
+
|
71
|
+
val selectedCardList = mutableListOf<WordsData>()
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
supportFragmentManager.beginTransaction().remove(ResultFragment()).commit();
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
if(query == null || query.isEmpty){
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
remaining_red.setText("赤カードの残り枚数:")
|
84
|
+
|
85
|
+
remaining_blue.setText("青カードの残り枚数:")
|
86
|
+
|
87
|
+
red_number_of_remaining.setText("8")
|
88
|
+
|
89
|
+
blue_number_of_remaining.setText("7")
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
turn = Turn.RED_TEAM_TURN
|
94
|
+
|
95
|
+
text_which_team_turn.setText("赤チームのターンです")
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
} else{
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
willUpdate(query, selectedCardList)
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
newTurn()
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
val listItem = mutableListOf<String>()
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
val adapter = CardAdapter(wordsDataList, selectedCardList, object : CardAdapter.OnCardAdapterListener {
|
118
|
+
|
119
|
+
override fun OnClickCard(word: String, wordsData: WordsData, holder: CardAdapter.ViewHolder) {
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
showWhatYouClicked(listItem, word, wordsDataList)
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
})
|
128
|
+
|
129
|
+
recycler_view.layoutManager = GridLayoutManager(this, 5)
|
130
|
+
|
131
|
+
recycler_view.adapter = adapter
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
if(ifGameIsOver) showResultFragment()
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
.
|
144
|
+
|
145
|
+
.
|
146
|
+
|
147
|
+
.
|
148
|
+
|
149
|
+
.
|
150
|
+
|
151
|
+
.
|
152
|
+
|
153
|
+
.
|
154
|
+
|
155
|
+
.
|
156
|
+
|
157
|
+
.
|
158
|
+
|
159
|
+
override fun OnGoBackOnGameSettingFragment() {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
listeningWords?.remove()
|
164
|
+
|
165
|
+
listeningSelectedCards?.remove()
|
166
|
+
|
167
|
+
listeningMembers?.remove()
|
168
|
+
|
169
|
+
Log.d("listeningSelectedCards", "$listeningSelectedCards" //D/listeningSelectedCards: com.google.firebase.firestore.core.ListenerRegistrationImpl@c3b3b7bと出ました
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
teamToCollectAllCards = ""
|
174
|
+
|
175
|
+
teamGotGray = null
|
176
|
+
|
177
|
+
ifGameIsOver = false
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
//下ではfirebaseの”selectedCards"というコレクションにあるドキュメントを一つ一つ処理しています。(もっと効率な方法あったら教えてください)
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
database.collection(dbCollection).document(keyword).collection("selectedCards").get().addOnSuccessListener {
|
186
|
+
|
187
|
+
for( i in 0 until it.documents.size){
|
188
|
+
|
189
|
+
val documentId = it.documents[i].id
|
190
|
+
|
191
|
+
database.collection(dbCollection).document(keyword).collection("selectedCards").document(documentId).delete()
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
recycler_view.layoutManager = null
|
198
|
+
|
199
|
+
recycler_view.adapter = null
|
200
|
+
|
201
|
+
btn_explain.visibility = View.INVISIBLE
|
202
|
+
|
203
|
+
text_which_team_turn.setText("")
|
204
|
+
|
205
|
+
remaining_red.setText("")
|
206
|
+
|
207
|
+
remaining_blue.setText("")
|
208
|
+
|
209
|
+
blue_number_of_remaining.setText("")
|
210
|
+
|
211
|
+
red_number_of_remaining.setText("")
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
importWordsFromCSV()
|
216
|
+
|
217
|
+
supportFragmentManager.beginTransaction()
|
218
|
+
|
219
|
+
.replace(R.id.container_game, GameSettingFragment.newInstance(keyword, nickname))
|
220
|
+
|
221
|
+
.commit()
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
```
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
ゲーム終了時のResultフラグメントです。(ここからOnGoBackOnGameSettingFragmentメソッドを呼び出すので、載せておきます。)
|
232
|
+
|
233
|
+
```ここに言語を入力
|
234
|
+
|
235
|
+
class ResultFragment : Fragment() {
|
236
|
+
|
237
|
+
.
|
238
|
+
|
239
|
+
.
|
240
|
+
|
241
|
+
.
|
242
|
+
|
243
|
+
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
244
|
+
|
245
|
+
.
|
246
|
+
|
247
|
+
.
|
248
|
+
|
249
|
+
.
|
250
|
+
|
251
|
+
btn_another_game_start.setOnClickListener {
|
252
|
+
|
253
|
+
database.collection(dbCollection).document(keyword).update("readyForAnotherGame", true)
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
btn_back_game_setting.setOnClickListener {
|
262
|
+
|
263
|
+
database.collection(dbCollection).document(keyword).update("readyToEndGame", true)
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
listening = database.collection(dbCollection).document(keyword).addSnapshotListener { it, e ->
|
272
|
+
|
273
|
+
if (e != null) return@addSnapshotListener
|
274
|
+
|
275
|
+
if (it == null ) return@addSnapshotListener
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
val endGame = it.getBoolean("readyToEndGame")?: false
|
280
|
+
|
281
|
+
Log.d("endGame", "$endGame")
|
282
|
+
|
283
|
+
if(endGame){
|
284
|
+
|
285
|
+
listener?.OnGoBackOnGameSettingFragment()
|
286
|
+
|
287
|
+
getFragmentManager()?.beginTransaction()?.remove(this)?.commit()
|
288
|
+
|
289
|
+
return@addSnapshotListener
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
val tryAnotherGame = it.getBoolean("readyForAnotherGame")?: false
|
296
|
+
|
297
|
+
Log.d("tryAnotherGame", "$tryAnotherGame")
|
298
|
+
|
299
|
+
if(tryAnotherGame){
|
300
|
+
|
301
|
+
listener?.OnStartAnotherGame(turnCount)
|
302
|
+
|
303
|
+
getFragmentManager()?.beginTransaction()?.remove(this)?.commit()
|
304
|
+
|
305
|
+
return@addSnapshotListener
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
.
|
318
|
+
|
319
|
+
.
|
320
|
+
|
321
|
+
```
|