mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-22 19:25:11 +00:00
HomeFragment view binding
This commit is contained in:
parent
4d14ddf1c6
commit
cdd5228447
2 changed files with 71 additions and 89 deletions
|
@ -22,37 +22,43 @@ import com.vanced.manager.R
|
|||
import com.vanced.manager.adapter.AppListAdapter
|
||||
import com.vanced.manager.adapter.LinkAdapter
|
||||
import com.vanced.manager.adapter.SponsorAdapter
|
||||
import com.vanced.manager.databinding.FragmentGrantRootBinding
|
||||
import com.vanced.manager.databinding.FragmentHomeBinding
|
||||
import com.vanced.manager.ui.core.BindingFragment
|
||||
import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModelFactory
|
||||
|
||||
open class HomeFragment : Fragment() {
|
||||
open class HomeFragment : BindingFragment<FragmentHomeBinding>() {
|
||||
|
||||
companion object {
|
||||
const val INSTALL_FAILED = "install_failed"
|
||||
const val REFRESH_HOME = "refresh_home"
|
||||
}
|
||||
|
||||
private lateinit var binding: FragmentHomeBinding
|
||||
private val viewModel: HomeViewModel by viewModels {
|
||||
HomeViewModelFactory(requireActivity())
|
||||
}
|
||||
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(requireActivity()) }
|
||||
private val prefs by lazy { PreferenceManager.getDefaultSharedPreferences(requireActivity()) }
|
||||
private lateinit var tooltip: ViewTooltip
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
requireActivity().title = getString(R.string.title_home)
|
||||
setHasOptionsMenu(true)
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
|
||||
return binding.root
|
||||
) = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun otherSetups() {
|
||||
bindData()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
private fun bindData() {
|
||||
requireActivity().title = getString(R.string.title_home)
|
||||
setHasOptionsMenu(true)
|
||||
with(binding) {
|
||||
viewModel = this@HomeFragment.viewModel
|
||||
|
||||
homeRefresh.setOnRefreshListener { viewModel.fetchData() }
|
||||
tooltip = ViewTooltip
|
||||
.on(recyclerAppList)
|
||||
.position(ViewTooltip.Position.TOP)
|
||||
|
@ -91,9 +97,13 @@ open class HomeFragment : Fragment() {
|
|||
adapter = LinkAdapter(requireActivity(), this@HomeFragment.viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflateWithCrowdin(R.menu.toolbar_menu, menu, resources)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
localBroadcastManager.unregisterReceiver(broadcastReceiver)
|
||||
|
@ -122,15 +132,5 @@ open class HomeFragment : Fragment() {
|
|||
intentFilter.addAction(REFRESH_HOME)
|
||||
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflateWithCrowdin(R.menu.toolbar_menu, menu, resources)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val INSTALL_FAILED = "install_failed"
|
||||
const val REFRESH_HOME = "refresh_home"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,75 +1,57 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:bind="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/home_refresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/home_refresh"
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
bind:onRefreshListener="@{()-> viewModel.fetchData()}">
|
||||
android:fillViewport="true"
|
||||
android:scrollbars="none">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:scrollbars="none">
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_app_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
tools:itemCount="3"
|
||||
tools:listitem="@layout/view_app"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_app_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
tools:itemCount="3"
|
||||
tools:listitem="@layout/view_app" />
|
||||
<TextView
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/useful_links"
|
||||
style="@style/CardTextHeader"/>
|
||||
|
||||
<TextView
|
||||
style="@style/CardTextHeader"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/useful_links" />
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_sponsors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
tools:itemCount="2"
|
||||
tools:listitem="@layout/view_sponsor"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_sponsors"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
tools:itemCount="2"
|
||||
tools:listitem="@layout/view_sponsor" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_links"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:paddingBottom="8dp"
|
||||
tools:itemCount="6"
|
||||
tools:listitem="@layout/view_social_link" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
</layout>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_links"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:paddingBottom="8dp"
|
||||
tools:itemCount="6"
|
||||
tools:listitem="@layout/view_social_link"/>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
|
Loading…
Reference in a new issue