Skip to content

Commit d7734f3

Browse files
Use fragment's viewLifecycleOwner
1 parent f92ce08 commit d7734f3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

app/src/main/java/com/dp/logcatapp/fragments/savedlogsviewer/SavedLogsViewerFragment.kt

+15-14
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,6 @@ class SavedLogsViewerFragment : BaseFragment() {
163163
viewModel = ViewModelProviders.of(this)
164164
.get(SavedLogsViewerViewModel::class.java)
165165
viewModel.init(Uri.parse(arguments!!.getString(KEY_FILE_URI)))
166-
viewModel.getLogs().observe(this, Observer {
167-
progressBar.visibility = View.GONE
168-
if (it != null) {
169-
if (it.isEmpty()) {
170-
textViewEmpty.visibility = View.VISIBLE
171-
} else {
172-
textViewEmpty.visibility = View.GONE
173-
setLogs(it)
174-
scrollRecyclerView()
175-
}
176-
} else {
177-
textViewEmpty.visibility = View.VISIBLE
178-
}
179-
})
180166
}
181167

182168
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
@@ -228,6 +214,21 @@ class SavedLogsViewerFragment : BaseFragment() {
228214
.show(fragmentManager, CopyToClipboardDialogFragment.TAG)
229215
}
230216
}
217+
218+
viewModel.getLogs().observe(viewLifecycleOwner, Observer {
219+
progressBar.visibility = View.GONE
220+
if (it != null) {
221+
if (it.isEmpty()) {
222+
textViewEmpty.visibility = View.VISIBLE
223+
} else {
224+
textViewEmpty.visibility = View.GONE
225+
setLogs(it)
226+
scrollRecyclerView()
227+
}
228+
} else {
229+
textViewEmpty.visibility = View.VISIBLE
230+
}
231+
})
231232
}
232233

233234
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {

0 commit comments

Comments
 (0)