Use binding

This commit is contained in:
tzugen 2021-12-22 13:36:13 +01:00
parent 4a996f8edc
commit 5a02467ee8
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
4 changed files with 207 additions and 199 deletions

View File

@ -41,6 +41,7 @@ android {
buildFeatures {
buildConfig = false
viewBinding true
dataBinding true
}
}

View File

@ -61,6 +61,7 @@ android {
buildFeatures {
viewBinding true
dataBinding true
}
compileOptions {

View File

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
@ -12,6 +11,7 @@ import androidx.navigation.Navigation
import org.koin.core.component.KoinComponent
import org.moire.ultrasonic.R
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
import org.moire.ultrasonic.databinding.MainBinding
import org.moire.ultrasonic.util.Constants
import org.moire.ultrasonic.util.Settings
import org.moire.ultrasonic.util.Util
@ -21,7 +21,6 @@ import org.moire.ultrasonic.util.Util
*/
class MainFragment : Fragment(), KoinComponent {
private lateinit var list: ScrollView
private lateinit var musicTitle: TextView
private lateinit var artistsButton: TextView
private lateinit var albumsButton: TextView
@ -41,6 +40,8 @@ class MainFragment : Fragment(), KoinComponent {
private lateinit var albumsAlphaByArtistButton: TextView
private lateinit var videosButton: TextView
private var binding: MainBinding? = null
override fun onCreate(savedInstanceState: Bundle?) {
Util.applyTheme(this.context)
super.onCreate(savedInstanceState)
@ -50,13 +51,12 @@ class MainFragment : Fragment(), KoinComponent {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.main, container, false)
): View {
binding = MainBinding.inflate(inflater, container, false)
return binding!!.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
list = view.findViewById(R.id.main_list)
setupButtons()
setupClickListener()
setupItemVisibility()
@ -81,25 +81,30 @@ class MainFragment : Fragment(), KoinComponent {
}
}
override fun onDestroyView() {
super.onDestroyView()
binding = null
}
private fun setupButtons() {
musicTitle = list.findViewById(R.id.main_music)
artistsButton = list.findViewById(R.id.main_artists_button)
albumsButton = list.findViewById(R.id.main_albums_button)
genresButton = list.findViewById(R.id.main_genres_button)
videosTitle = list.findViewById(R.id.main_videos_title)
songsTitle = list.findViewById(R.id.main_songs)
randomSongsButton = list.findViewById(R.id.main_songs_button)
songsStarredButton = list.findViewById(R.id.main_songs_starred)
albumsTitle = list.findViewById(R.id.main_albums)
albumsNewestButton = list.findViewById(R.id.main_albums_newest)
albumsRandomButton = list.findViewById(R.id.main_albums_random)
albumsHighestButton = list.findViewById(R.id.main_albums_highest)
albumsStarredButton = list.findViewById(R.id.main_albums_starred)
albumsRecentButton = list.findViewById(R.id.main_albums_recent)
albumsFrequentButton = list.findViewById(R.id.main_albums_frequent)
albumsAlphaByNameButton = list.findViewById(R.id.main_albums_alphaByName)
albumsAlphaByArtistButton = list.findViewById(R.id.main_albums_alphaByArtist)
videosButton = list.findViewById(R.id.main_videos)
musicTitle = binding!!.mainMusic
artistsButton = binding!!.mainArtistsButton
albumsButton = binding!!.mainAlbumsButton
genresButton = binding!!.mainGenresButton
videosTitle = binding!!.mainVideosTitle
songsTitle = binding!!.mainSongs
randomSongsButton = binding!!.mainSongsButton
songsStarredButton = binding!!.mainSongsStarred
albumsTitle = binding!!.mainAlbums
albumsNewestButton = binding!!.mainAlbumsNewest
albumsRandomButton = binding!!.mainAlbumsRandom
albumsHighestButton = binding!!.mainAlbumsHighest
albumsStarredButton = binding!!.mainAlbumsStarred
albumsRecentButton = binding!!.mainAlbumsRecent
albumsFrequentButton = binding!!.mainAlbumsFrequent
albumsAlphaByNameButton = binding!!.mainAlbumsAlphaByName
albumsAlphaByArtistButton = binding!!.mainAlbumsAlphaByArtist
videosButton = binding!!.mainVideos
}
private fun setupItemVisibility() {

View File

@ -1,215 +1,216 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:id="@+id/main_list">
<layout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main_list">
<LinearLayout
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:orientation="vertical">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
a:id="@+id/main_music"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:paddingStart="6dp"
a:text="@string/main.music"
a:textAllCaps="true"
a:textAppearance="?android:attr/textAppearanceSmall"
a:textColor="@color/cyan"
a:textStyle="bold" />
android:id="@+id/main_music"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="6dp"
android:text="@string/main.music"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/cyan"
android:textStyle="bold" />
<TextView
a:id="@+id/main_artists_button"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.artists_title"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_artists_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.artists_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_button"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_title"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_genres_button"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.genres_title"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_genres_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.genres_title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_songs"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:paddingStart="6dp"
a:text="@string/main.songs_title"
a:textAllCaps="true"
a:textAppearance="?android:attr/textAppearanceSmall"
a:textColor="@color/cyan"
a:textStyle="bold" />
android:id="@+id/main_songs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="6dp"
android:text="@string/main.songs_title"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/cyan"
android:textStyle="bold" />
<TextView
a:id="@+id/main_songs_button"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.songs_random"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_songs_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.songs_random"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_songs_starred"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.songs_starred"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_songs_starred"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.songs_starred"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:paddingStart="6dp"
a:text="@string/main.albums_title"
a:textAllCaps="true"
a:textAppearance="?android:attr/textAppearanceSmall"
a:textColor="@color/cyan"
a:textStyle="bold" />
android:id="@+id/main_albums"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="6dp"
android:text="@string/main.albums_title"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/cyan"
android:textStyle="bold" />
<TextView
a:id="@+id/main_albums_newest"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_newest"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_newest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_newest"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_recent"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_recent"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_recent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_recent"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_frequent"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_frequent"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_frequent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_frequent"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_highest"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_highest"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_highest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_highest"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_random"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_random"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_random"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_random"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_starred"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_starred"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_starred"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_starred"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_alphaByName"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_alphaByName"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_alphaByName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_alphaByName"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_albums_alphaByArtist"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.albums_alphaByArtist"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_albums_alphaByArtist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.albums_alphaByArtist"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
a:id="@+id/main_videos_title"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:paddingStart="6dp"
a:text="@string/main.videos"
a:textAllCaps="true"
a:textAppearance="?android:attr/textAppearanceSmall"
a:textColor="@color/cyan"
a:textStyle="bold" />
android:id="@+id/main_videos_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="6dp"
android:text="@string/main.videos"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/cyan"
android:textStyle="bold" />
<TextView
a:id="@+id/main_videos"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:gravity="center_vertical"
a:minHeight="40dip"
a:paddingStart="6dip"
a:paddingEnd="6dip"
a:text="@string/main.videos"
a:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/main_videos"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="40dip"
android:paddingStart="6dip"
android:paddingEnd="6dip"
android:text="@string/main.videos"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</ScrollView>
</layout>