Add ViewPager

Add a ViewPager, currently it has no purpose but it will eventually.
This commit is contained in:
OxygenCobalt 2020-08-26 16:16:01 -06:00
parent d9dda08731
commit c109c3f359
11 changed files with 75 additions and 13 deletions

View file

@ -56,6 +56,9 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
// Viewpager
implementation 'androidx.viewpager2:viewpager2:1.0.0'
// Image loading
implementation("io.coil-kt:coil:0.12.0")

View file

@ -3,6 +3,7 @@ package org.oxycblt.auxio
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
class MainActivity : AppCompatActivity() {
@ -10,7 +11,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
Log.d(this::class.simpleName, "Activity Created.")
}

View 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()
}
}

View file

@ -32,7 +32,7 @@ class LoadingFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate<FragmentLoadingBinding>(
binding = DataBindingUtil.inflate(
inflater, R.layout.fragment_loading, container, false
)
@ -65,7 +65,7 @@ class LoadingFragment : Fragment() {
repoResponse?.let { response ->
if (response == MusicLoaderResponse.DONE) {
this.findNavController().navigate(
LoadingFragmentDirections.actionToLibrary()
LoadingFragmentDirections.actionToMain()
)
} else {
// If the response wasn't a success, then show the specific error message

View file

@ -1,6 +1,5 @@
package org.oxycblt.auxio.recycler
import android.net.Uri
import androidx.recyclerview.widget.RecyclerView
import coil.load
import org.oxycblt.auxio.databinding.AlbumItemBinding

View file

@ -29,21 +29,21 @@ fun RecyclerView.applyDivider() {
div.setDrawable(
ColorDrawable(
getDividerColor(this)
getDividerDrawable(this)
)
)
addItemDecoration(div)
}
private fun getDividerColor(recycler: RecyclerView): Int {
private fun getDividerDrawable(recycler: RecyclerView): Int {
val isDark = AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES
// Depending on the theme use a different opacity for the divider
val alpha = if (isDark) 45 else 85
return ColorUtils.setAlphaComponent(
ContextCompat.getColor(recycler.context, R.color.blue),
ContextCompat.getColor(recycler.context, R.color.divider_color),
alpha
)
}

View file

@ -25,7 +25,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
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>
</layout>

View 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>

View file

@ -11,14 +11,14 @@
android:label="LoadingFragment"
tools:layout="@layout/fragment_loading">
<action
android:id="@+id/action_to_library"
app:destination="@id/libraryFragment"
android:id="@+id/action_to_main"
app:destination="@id/mainFragment"
app:popUpTo="@id/loadingFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/libraryFragment"
android:name="org.oxycblt.auxio.library.LibraryFragment"
android:id="@+id/mainFragment"
android:name="org.oxycblt.auxio.MainFragment"
android:label="LibraryFragment"
tools:layout="@layout/fragment_library" />
tools:layout="@layout/fragment_main" />
</navigation>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#151515</color>
<color name="divider_color">#6d6d6d</color>
<!--
Base color set derived from Music Player GO.

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#fafafa</color>
<color name="divider_color">#6d6d6d</color>
<!--
Base color set derived from Music Player GO.