Add ViewPager
Add a ViewPager, currently it has no purpose but it will eventually.
This commit is contained in:
parent
d9dda08731
commit
c109c3f359
11 changed files with 75 additions and 13 deletions
|
@ -56,6 +56,9 @@ dependencies {
|
||||||
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
|
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
|
||||||
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
|
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
|
||||||
|
|
||||||
|
// Viewpager
|
||||||
|
implementation 'androidx.viewpager2:viewpager2:1.0.0'
|
||||||
|
|
||||||
// Image loading
|
// Image loading
|
||||||
implementation("io.coil-kt:coil:0.12.0")
|
implementation("io.coil-kt:coil:0.12.0")
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.oxycblt.auxio
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
@ -10,7 +11,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
|
|
||||||
Log.d(this::class.simpleName, "Activity Created.")
|
Log.d(this::class.simpleName, "Activity Created.")
|
||||||
}
|
}
|
||||||
|
|
42
app/src/main/java/org/oxycblt/auxio/MainFragment.kt
Normal file
42
app/src/main/java/org/oxycblt/auxio/MainFragment.kt
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package org.oxycblt.auxio
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
|
import org.oxycblt.auxio.databinding.FragmentMainBinding
|
||||||
|
import org.oxycblt.auxio.library.LibraryFragment
|
||||||
|
|
||||||
|
// TODO: Placeholder, page count will be dynamic
|
||||||
|
private const val PAGES = 1
|
||||||
|
|
||||||
|
class MainFragment : Fragment() {
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val binding = DataBindingUtil.inflate<FragmentMainBinding>(
|
||||||
|
inflater, R.layout.fragment_main, container, false
|
||||||
|
)
|
||||||
|
|
||||||
|
val adapter = FragmentAdapter(requireActivity())
|
||||||
|
binding.viewPager.adapter = adapter
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FragmentAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) {
|
||||||
|
override fun getItemCount(): Int = PAGES
|
||||||
|
|
||||||
|
override fun createFragment(position: Int): Fragment {
|
||||||
|
// TODO: Also placeholder, remove when there are other fragments than just library
|
||||||
|
return LibraryFragment()
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ class LoadingFragment : Fragment() {
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
binding = DataBindingUtil.inflate<FragmentLoadingBinding>(
|
binding = DataBindingUtil.inflate(
|
||||||
inflater, R.layout.fragment_loading, container, false
|
inflater, R.layout.fragment_loading, container, false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class LoadingFragment : Fragment() {
|
||||||
repoResponse?.let { response ->
|
repoResponse?.let { response ->
|
||||||
if (response == MusicLoaderResponse.DONE) {
|
if (response == MusicLoaderResponse.DONE) {
|
||||||
this.findNavController().navigate(
|
this.findNavController().navigate(
|
||||||
LoadingFragmentDirections.actionToLibrary()
|
LoadingFragmentDirections.actionToMain()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// If the response wasn't a success, then show the specific error message
|
// If the response wasn't a success, then show the specific error message
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.oxycblt.auxio.recycler
|
package org.oxycblt.auxio.recycler
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import coil.load
|
import coil.load
|
||||||
import org.oxycblt.auxio.databinding.AlbumItemBinding
|
import org.oxycblt.auxio.databinding.AlbumItemBinding
|
||||||
|
|
|
@ -29,21 +29,21 @@ fun RecyclerView.applyDivider() {
|
||||||
|
|
||||||
div.setDrawable(
|
div.setDrawable(
|
||||||
ColorDrawable(
|
ColorDrawable(
|
||||||
getDividerColor(this)
|
getDividerDrawable(this)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
addItemDecoration(div)
|
addItemDecoration(div)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDividerColor(recycler: RecyclerView): Int {
|
private fun getDividerDrawable(recycler: RecyclerView): Int {
|
||||||
val isDark = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES
|
val isDark = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES
|
||||||
|
|
||||||
// Depending on the theme use a different opacity for the divider
|
// Depending on the theme use a different opacity for the divider
|
||||||
val alpha = if (isDark) 45 else 85
|
val alpha = if (isDark) 45 else 85
|
||||||
|
|
||||||
return ColorUtils.setAlphaComponent(
|
return ColorUtils.setAlphaComponent(
|
||||||
ContextCompat.getColor(recycler.context, R.color.blue),
|
ContextCompat.getColor(recycler.context, R.color.divider_color),
|
||||||
alpha
|
alpha
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toolbar"
|
app:layout_constraintTop_toBottomOf="@+id/toolbar"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
tools:listitem="@layout/album_item" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</layout>
|
</layout>
|
14
app/src/main/res/layout/fragment_main.xml
Normal file
14
app/src/main/res/layout/fragment_main.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
|
android:id="@+id/viewPager"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
</layout>
|
|
@ -11,14 +11,14 @@
|
||||||
android:label="LoadingFragment"
|
android:label="LoadingFragment"
|
||||||
tools:layout="@layout/fragment_loading">
|
tools:layout="@layout/fragment_loading">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_to_library"
|
android:id="@+id/action_to_main"
|
||||||
app:destination="@id/libraryFragment"
|
app:destination="@id/mainFragment"
|
||||||
app:popUpTo="@id/loadingFragment"
|
app:popUpTo="@id/loadingFragment"
|
||||||
app:popUpToInclusive="true" />
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/libraryFragment"
|
android:id="@+id/mainFragment"
|
||||||
android:name="org.oxycblt.auxio.library.LibraryFragment"
|
android:name="org.oxycblt.auxio.MainFragment"
|
||||||
android:label="LibraryFragment"
|
android:label="LibraryFragment"
|
||||||
tools:layout="@layout/fragment_library" />
|
tools:layout="@layout/fragment_main" />
|
||||||
</navigation>
|
</navigation>
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="background">#151515</color>
|
<color name="background">#151515</color>
|
||||||
|
<color name="divider_color">#6d6d6d</color>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Base color set derived from Music Player GO.
|
Base color set derived from Music Player GO.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="background">#fafafa</color>
|
<color name="background">#fafafa</color>
|
||||||
|
<color name="divider_color">#6d6d6d</color>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Base color set derived from Music Player GO.
|
Base color set derived from Music Player GO.
|
||||||
|
|
Loading…
Reference in a new issue