Add ViewPager
Add a ViewPager, currently it has no purpose but it will eventually.
This commit is contained in:
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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?,
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user