@@ -31,12 +31,14 @@ class LetterSoundsFragment : Fragment() {
31
31
32
32
private var textView: TextView ? = null
33
33
34
+ private val TAG = javaClass.name
35
+
34
36
override fun onCreateView (
35
37
inflater : LayoutInflater ,
36
38
container : ViewGroup ? ,
37
39
savedInstanceState : Bundle ?
38
40
): View ? {
39
- Log .i(javaClass.name , " onCreateView" )
41
+ Log .i(TAG , " onCreateView" )
40
42
41
43
letterSoundsViewModel = ViewModelProvider (this ).get(
42
44
LetterSoundsViewModel ::class .java
@@ -46,15 +48,15 @@ class LetterSoundsFragment : Fragment() {
46
48
textView = root.findViewById(R .id.text_letter_sounds) as ? TextView
47
49
letterSoundsViewModel!! .text.observe(viewLifecycleOwner, object : Observer <String ?> {
48
50
override fun onChanged (s : String? ) {
49
- Log .i(javaClass.name , " onChanged" )
51
+ Log .i(TAG , " onChanged" )
50
52
textView?.text = s
51
53
}
52
54
})
53
55
return root
54
56
}
55
57
56
58
override fun onStart () {
57
- Log .i(javaClass.name , " onStart" )
59
+ Log .i(TAG , " onStart" )
58
60
super .onStart()
59
61
60
62
// Download LetterSounds from REST API, and store them in the database
@@ -64,18 +66,18 @@ class LetterSoundsFragment : Fragment() {
64
66
LetterSoundsService ::class .java
65
67
)
66
68
val letterSoundGsonsCall = letterSoundsService.listLetterSounds()
67
- Log .i(javaClass.name , " letterSoundGsonsCall.request(): " + letterSoundGsonsCall.request())
69
+ Log .i(TAG , " letterSoundGsonsCall.request(): " + letterSoundGsonsCall.request())
68
70
letterSoundGsonsCall.enqueue(object : Callback <List <LetterSoundGson >> {
69
71
override fun onResponse (
70
72
call : Call <List <LetterSoundGson >>,
71
73
response : Response <List <LetterSoundGson >>
72
74
) {
73
- Log .i(javaClass.name , " onResponse" )
75
+ Log .i(TAG , " onResponse" )
74
76
75
- Log .i(javaClass.name , " response: $response " )
77
+ Log .i(TAG , " response: $response " )
76
78
if (response.isSuccessful) {
77
79
val letterSoundGsons = response.body()!!
78
- Log .i(javaClass.name , " letterSoundGsons.size(): " + letterSoundGsons.size)
80
+ Log .i(TAG , " letterSoundGsons.size(): " + letterSoundGsons.size)
79
81
80
82
if (letterSoundGsons.size > 0 ) {
81
83
processResponseBody(letterSoundGsons)
@@ -90,9 +92,9 @@ class LetterSoundsFragment : Fragment() {
90
92
}
91
93
92
94
override fun onFailure (call : Call <List <LetterSoundGson >>, t : Throwable ) {
93
- Log .e(javaClass.name , " onFailure" , t)
95
+ Log .e(TAG , " onFailure" , t)
94
96
95
- Log .e(javaClass.name , " t.getCause():" , t.cause)
97
+ Log .e(TAG , " t.getCause():" , t.cause)
96
98
97
99
// Handle error
98
100
Snackbar .make(textView!! , t.cause.toString(), Snackbar .LENGTH_LONG )
@@ -104,12 +106,12 @@ class LetterSoundsFragment : Fragment() {
104
106
}
105
107
106
108
private fun processResponseBody (letterSoundGsons : List <LetterSoundGson >) {
107
- Log .i(javaClass.name , " processResponseBody" )
109
+ Log .i(TAG , " processResponseBody" )
108
110
109
111
val executorService = Executors .newSingleThreadExecutor()
110
112
executorService.execute(object : Runnable {
111
113
override fun run () {
112
- Log .i(javaClass.name , " run" )
114
+ Log .i(TAG , " run" )
113
115
114
116
val roomDb = RoomDb .getDatabase(context)
115
117
val letterSoundDao = roomDb.letterSoundDao()
@@ -122,50 +124,50 @@ class LetterSoundsFragment : Fragment() {
122
124
letterSoundDao.deleteAll()
123
125
124
126
for (letterSoundGson in letterSoundGsons) {
125
- Log .i(javaClass.name , " letterSoundGson.getId(): " + letterSoundGson.id)
127
+ Log .i(TAG , " letterSoundGson.getId(): " + letterSoundGson.id)
126
128
127
129
// Store the LetterSound in the database
128
130
val letterSound = GsonToRoomConverter .getLetterSound(letterSoundGson)
129
131
letterSoundDao.insert(letterSound)
130
132
Log .i(
131
- javaClass.name ,
133
+ TAG ,
132
134
" Stored LetterSound in database with ID " + letterSound.id
133
135
)
134
136
135
137
// Store all the LetterSound's letters in the database
136
138
val letterGsons = letterSoundGson.letters
137
- Log .i(javaClass.name , " letterGsons.size(): " + letterGsons.size)
139
+ Log .i(TAG , " letterGsons.size(): " + letterGsons.size)
138
140
for (letterGson in letterGsons) {
139
- Log .i(javaClass.name , " letterGson.getId(): " + letterGson.id)
141
+ Log .i(TAG , " letterGson.getId(): " + letterGson.id)
140
142
val letterSound_Letter = LetterSound_Letter ()
141
143
letterSound_Letter.letterSound_id = letterSoundGson.id
142
144
letterSound_Letter.letters_id = letterGson.id
143
145
letterSound_LetterDao.insert(letterSound_Letter)
144
146
Log .i(
145
- javaClass.name ,
147
+ TAG ,
146
148
" Stored LetterSound_Letter in database. LetterSound_id: " + letterSound_Letter.letterSound_id + " , letters_id: " + letterSound_Letter.letters_id
147
149
)
148
150
}
149
151
150
152
// Store all the LetterSound's sounds in the database
151
153
val soundGsons = letterSoundGson.sounds
152
- Log .i(javaClass.name , " soundGsons.size():" + soundGsons.size)
154
+ Log .i(TAG , " soundGsons.size():" + soundGsons.size)
153
155
for (soundGson in soundGsons) {
154
- Log .i(javaClass.name , " soundGson.getId(): " + soundGson.id)
156
+ Log .i(TAG , " soundGson.getId(): " + soundGson.id)
155
157
val letterSound_Sound = LetterSound_Sound ()
156
158
letterSound_Sound.letterSound_id = letterSoundGson.id
157
159
letterSound_Sound.sounds_id = soundGson.id
158
160
letterSound_SoundDao.insert(letterSound_Sound)
159
161
Log .i(
160
- javaClass.name ,
162
+ TAG ,
161
163
" Stored LetterSound_Sound in database. LetterSound_id: " + letterSound_Sound.letterSound_id + " , sounds_id: " + letterSound_Sound.sounds_id
162
164
)
163
165
}
164
166
}
165
167
166
168
// Update the UI
167
169
val letterSounds = letterSoundDao.loadAll()
168
- Log .i(javaClass.name , " letterSounds.size(): " + letterSounds.size)
170
+ Log .i(TAG , " letterSounds.size(): " + letterSounds.size)
169
171
activity!! .runOnUiThread {
170
172
textView!! .text = " letterSounds.size(): " + letterSounds.size
171
173
Snackbar .make(
0 commit comments