cleanup code in ConversationsFragment, SearchFragment and Report*Fragments (#2027)

This commit is contained in:
Konrad Pozniak 2020-12-27 21:25:35 +01:00 committed by Alibek Omarov
parent 719dcb13fc
commit 08c8aee553
5 changed files with 13 additions and 51 deletions

View File

@ -30,7 +30,6 @@ import androidx.recyclerview.widget.SimpleItemAnimator
import com.keylesspalace.tusky.AccountActivity
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.ViewTagActivity
import com.keylesspalace.tusky.db.AppDatabase
import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.di.ViewModelFactory
import com.keylesspalace.tusky.fragment.SFragment
@ -45,8 +44,6 @@ class ConversationsFragment : SFragment(), StatusActionListener, Injectable, Res
@Inject
lateinit var viewModelFactory: ViewModelFactory
@Inject
lateinit var db: AppDatabase
private val viewModel: ConversationsViewModel by viewModels { viewModelFactory }

View File

@ -15,14 +15,11 @@
package com.keylesspalace.tusky.components.report.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.fragment.app.activityViewModels
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.components.report.ReportViewModel
import com.keylesspalace.tusky.components.report.Screen
@ -34,19 +31,12 @@ import com.keylesspalace.tusky.util.show
import kotlinx.android.synthetic.main.fragment_report_done.*
import javax.inject.Inject
class ReportDoneFragment : Fragment(), Injectable {
class ReportDoneFragment : Fragment(R.layout.fragment_report_done), Injectable {
@Inject
lateinit var viewModelFactory: ViewModelFactory
private val viewModel: ReportViewModel by viewModels({ requireActivity() }) { viewModelFactory }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_report_done, container, false)
}
private val viewModel: ReportViewModel by activityViewModels { viewModelFactory }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
textReported.text = getString(R.string.report_sent_success, viewModel.accountUserName)

View File

@ -16,13 +16,11 @@
package com.keylesspalace.tusky.components.report.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.fragment.app.activityViewModels
import com.google.android.material.snackbar.Snackbar
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.components.report.ReportViewModel
@ -34,18 +32,12 @@ import kotlinx.android.synthetic.main.fragment_report_note.*
import java.io.IOException
import javax.inject.Inject
class ReportNoteFragment : Fragment(), Injectable {
class ReportNoteFragment : Fragment(R.layout.fragment_report_note), Injectable {
@Inject
lateinit var viewModelFactory: ViewModelFactory
private val viewModel: ReportViewModel by viewModels({ requireActivity() }) { viewModelFactory }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_report_note, container, false)
}
private val viewModel: ReportViewModel by activityViewModels { viewModelFactory }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
fillViews()

View File

@ -16,15 +16,13 @@
package com.keylesspalace.tusky.components.report.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.app.ActivityOptionsCompat
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.paging.PagedList
import androidx.fragment.app.activityViewModels
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
@ -49,7 +47,7 @@ import com.keylesspalace.tusky.viewdata.AttachmentViewData
import kotlinx.android.synthetic.main.fragment_report_statuses.*
import javax.inject.Inject
class ReportStatusesFragment : Fragment(), Injectable, AdapterHandler {
class ReportStatusesFragment : Fragment(R.layout.fragment_report_statuses), Injectable, AdapterHandler {
@Inject
lateinit var viewModelFactory: ViewModelFactory
@ -57,10 +55,9 @@ class ReportStatusesFragment : Fragment(), Injectable, AdapterHandler {
@Inject
lateinit var accountManager: AccountManager
private val viewModel: ReportViewModel by viewModels({ requireActivity() }) { viewModelFactory }
private val viewModel: ReportViewModel by activityViewModels { viewModelFactory }
private lateinit var adapter: StatusesAdapter
private lateinit var layoutManager: LinearLayoutManager
private var snackbarErrorRetry: Snackbar? = null
@ -88,12 +85,6 @@ class ReportStatusesFragment : Fragment(), Injectable, AdapterHandler {
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_report_statuses, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
handleClicks()
initStatusesView()
@ -127,8 +118,7 @@ class ReportStatusesFragment : Fragment(), Injectable, AdapterHandler {
viewModel.statusViewState, this)
recyclerView.addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL))
layoutManager = LinearLayoutManager(requireContext())
recyclerView.layoutManager = layoutManager
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.adapter = adapter
(recyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false

View File

@ -1,11 +1,9 @@
package com.keylesspalace.tusky.components.search.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.PagedList
@ -27,13 +25,13 @@ import com.keylesspalace.tusky.util.*
import kotlinx.android.synthetic.main.fragment_search.*
import javax.inject.Inject
abstract class SearchFragment<T> : Fragment(),
abstract class SearchFragment<T> : Fragment(R.layout.fragment_search),
LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener {
@Inject
lateinit var viewModelFactory: ViewModelFactory
protected val viewModel: SearchViewModel by viewModels({ requireActivity() }) { viewModelFactory }
protected val viewModel: SearchViewModel by activityViewModels { viewModelFactory }
private var snackbarErrorRetry: Snackbar? = null
@ -44,12 +42,7 @@ abstract class SearchFragment<T> : Fragment(),
abstract val data: LiveData<PagedList<T>>
protected lateinit var adapter: PagedListAdapter<T, *>
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_search, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initAdapter()
setupSwipeRefreshLayout()
subscribeObservables()