Folder color fix
This commit is contained in:
parent
ac0babeb80
commit
ee6af2a6d6
5 changed files with 155 additions and 141 deletions
|
@ -1,11 +1,15 @@
|
|||
package code.name.monkey.retromusic.adapter
|
||||
|
||||
import android.graphics.PorterDuff
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.base.*
|
||||
import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
|
||||
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
|
||||
import code.name.monkey.retromusic.glide.audiocover.AudioFileCover
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.util.RetroUtil
|
||||
|
@ -16,164 +20,161 @@ import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
|||
import java.io.File
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import kotlin.math.*
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
class SongFileAdapter(
|
||||
private val activity: AppCompatActivity,
|
||||
private var dataSet: List<File>?,
|
||||
private val itemLayoutRes: Int,
|
||||
private val callbacks: Callbacks?,
|
||||
cabHolder: CabHolder?
|
||||
private val activity: AppCompatActivity,
|
||||
private var dataSet: List<File>?,
|
||||
private val itemLayoutRes: Int,
|
||||
private val callbacks: Callbacks?,
|
||||
cabHolder: CabHolder?
|
||||
) : AbsMultiSelectAdapter<SongFileAdapter.ViewHolder, File>(
|
||||
activity, cabHolder, R.menu.menu_media_selection
|
||||
activity, cabHolder, R.menu.menu_media_selection
|
||||
), FastScrollRecyclerView.SectionedAdapter {
|
||||
|
||||
init {
|
||||
this.setHasStableIds(true)
|
||||
}
|
||||
init {
|
||||
this.setHasStableIds(true)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (dataSet!![position].isDirectory) FOLDER else FILE
|
||||
}
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (dataSet!![position].isDirectory) FOLDER else FILE
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return dataSet!![position].hashCode().toLong()
|
||||
}
|
||||
override fun getItemId(position: Int): Long {
|
||||
return dataSet!![position].hashCode().toLong()
|
||||
}
|
||||
|
||||
fun swapDataSet(songFiles: List<File>) {
|
||||
this.dataSet = songFiles
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
fun swapDataSet(songFiles: List<File>) {
|
||||
this.dataSet = songFiles
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false))
|
||||
}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, index: Int) {
|
||||
val file = dataSet!![index]
|
||||
holder.itemView.isActivated = isChecked(file)
|
||||
holder.title?.text = getFileTitle(file)
|
||||
if (holder.text != null) {
|
||||
if (holder.itemViewType == FILE) {
|
||||
holder.text?.text = getFileText(file)
|
||||
} else {
|
||||
holder.text?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
override fun onBindViewHolder(holder: ViewHolder, index: Int) {
|
||||
val file = dataSet!![index]
|
||||
holder.itemView.isActivated = isChecked(file)
|
||||
holder.title?.text = getFileTitle(file)
|
||||
if (holder.text != null) {
|
||||
if (holder.itemViewType == FILE) {
|
||||
holder.text?.text = getFileText(file)
|
||||
} else {
|
||||
holder.text?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
if (holder.image != null) {
|
||||
loadFileImage(file, holder)
|
||||
}
|
||||
}
|
||||
if (holder.image != null) {
|
||||
loadFileImage(file, holder)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFileTitle(file: File): String {
|
||||
return file.name
|
||||
}
|
||||
private fun getFileTitle(file: File): String {
|
||||
return file.name
|
||||
}
|
||||
|
||||
private fun getFileText(file: File): String? {
|
||||
return if (file.isDirectory) null else readableFileSize(file.length())
|
||||
}
|
||||
private fun getFileText(file: File): String? {
|
||||
return if (file.isDirectory) null else readableFileSize(file.length())
|
||||
}
|
||||
|
||||
private fun loadFileImage(file: File, holder: ViewHolder) {
|
||||
val iconColor = ATHUtil.resolveColor(activity, R.attr.iconColor)
|
||||
if (file.isDirectory) {
|
||||
holder.image?.let {
|
||||
it.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN)
|
||||
it.setImageResource(R.drawable.ic_folder_white_24dp)
|
||||
}
|
||||
holder.imageTextContainer?.setCardBackgroundColor(
|
||||
ATHUtil.resolveColor(
|
||||
activity, R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
private fun loadFileImage(file: File, holder: ViewHolder) {
|
||||
val iconColor = ATHUtil.resolveColor(activity, R.attr.colorControlNormal)
|
||||
if (file.isDirectory) {
|
||||
holder.image?.let {
|
||||
it.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN)
|
||||
it.setImageResource(R.drawable.ic_folder_white_24dp)
|
||||
}
|
||||
holder.imageTextContainer?.setCardBackgroundColor(ATHUtil.resolveColor(activity, R.attr.colorSurface))
|
||||
|
||||
} else {
|
||||
val error = RetroUtil.getTintedVectorDrawable(
|
||||
activity, R.drawable.ic_file_music_white_24dp, iconColor
|
||||
)
|
||||
Glide.with(activity).load(AudioFileCover(file.path))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE).error(error).placeholder(error)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.signature(MediaStoreSignature("", file.lastModified(), 0)).into(holder.image)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val error = RetroUtil.getTintedVectorDrawable(
|
||||
activity, R.drawable.ic_file_music_white_24dp, iconColor
|
||||
)
|
||||
Glide.with(activity).load(AudioFileCover(file.path))
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE).error(error).placeholder(error)
|
||||
.animate(android.R.anim.fade_in)
|
||||
.signature(MediaStoreSignature("", file.lastModified(), 0)).into(holder.image)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet!!.size
|
||||
}
|
||||
override fun getItemCount(): Int {
|
||||
return dataSet!!.size
|
||||
}
|
||||
|
||||
override fun getIdentifier(position: Int): File? {
|
||||
return dataSet!![position]
|
||||
}
|
||||
override fun getIdentifier(position: Int): File? {
|
||||
return dataSet!![position]
|
||||
}
|
||||
|
||||
override fun getName(`object`: File): String {
|
||||
return getFileTitle(`object`)
|
||||
}
|
||||
override fun getName(`object`: File): String {
|
||||
return getFileTitle(`object`)
|
||||
}
|
||||
|
||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: ArrayList<File>) {
|
||||
if (callbacks == null) return
|
||||
callbacks.onMultipleItemAction(menuItem, selection)
|
||||
}
|
||||
override fun onMultipleItemAction(menuItem: MenuItem, selection: ArrayList<File>) {
|
||||
if (callbacks == null) return
|
||||
callbacks.onMultipleItemAction(menuItem, selection)
|
||||
}
|
||||
|
||||
override fun getSectionName(position: Int): String {
|
||||
return dataSet!![position].name[0].toString().toUpperCase()
|
||||
}
|
||||
override fun getSectionName(position: Int): String {
|
||||
return dataSet!![position].name[0].toString().toUpperCase()
|
||||
}
|
||||
|
||||
interface Callbacks {
|
||||
fun onFileSelected(file: File)
|
||||
interface Callbacks {
|
||||
fun onFileSelected(file: File)
|
||||
|
||||
fun onFileMenuClicked(file: File, view: View)
|
||||
fun onFileMenuClicked(file: File, view: View)
|
||||
|
||||
fun onMultipleItemAction(item: MenuItem, files: ArrayList<File>)
|
||||
}
|
||||
fun onMultipleItemAction(item: MenuItem, files: ArrayList<File>)
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
|
||||
inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
|
||||
|
||||
init {
|
||||
if (menu != null && callbacks != null) {
|
||||
menu!!.setOnClickListener { v ->
|
||||
val position = adapterPosition
|
||||
if (isPositionInRange(position)) {
|
||||
callbacks.onFileMenuClicked(dataSet!![position], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (imageTextContainer != null) {
|
||||
imageTextContainer?.cardElevation = 0f
|
||||
}
|
||||
}
|
||||
init {
|
||||
if (menu != null && callbacks != null) {
|
||||
menu?.setOnClickListener { v ->
|
||||
val position = adapterPosition
|
||||
if (isPositionInRange(position)) {
|
||||
callbacks.onFileMenuClicked(dataSet!![position], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (imageTextContainer != null) {
|
||||
imageTextContainer?.cardElevation = 0f
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
val position = adapterPosition
|
||||
if (isPositionInRange(position)) {
|
||||
if (isInQuickSelectMode) {
|
||||
toggleChecked(position)
|
||||
} else {
|
||||
callbacks?.onFileSelected(dataSet!![position])
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onClick(v: View?) {
|
||||
val position = adapterPosition
|
||||
if (isPositionInRange(position)) {
|
||||
if (isInQuickSelectMode) {
|
||||
toggleChecked(position)
|
||||
} else {
|
||||
callbacks?.onFileSelected(dataSet!![position])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View?): Boolean {
|
||||
val position = adapterPosition
|
||||
return isPositionInRange(position) && toggleChecked(position)
|
||||
}
|
||||
override fun onLongClick(v: View?): Boolean {
|
||||
val position = adapterPosition
|
||||
return isPositionInRange(position) && toggleChecked(position)
|
||||
}
|
||||
|
||||
private fun isPositionInRange(position: Int): Boolean {
|
||||
return position >= 0 && position < dataSet!!.size
|
||||
}
|
||||
}
|
||||
private fun isPositionInRange(position: Int): Boolean {
|
||||
return position >= 0 && position < dataSet!!.size
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
companion object {
|
||||
|
||||
private const val FILE = 0
|
||||
private const val FOLDER = 1
|
||||
private const val FILE = 0
|
||||
private const val FOLDER = 1
|
||||
|
||||
fun readableFileSize(size: Long): String {
|
||||
if (size <= 0) return "$size B"
|
||||
val units = arrayOf("B", "KB", "MB", "GB", "TB")
|
||||
val digitGroups = (log10(size.toDouble()) / log10(1024.0)).toInt()
|
||||
return DecimalFormat("#,##0.##").format(size / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups]
|
||||
}
|
||||
}
|
||||
fun readableFileSize(size: Long): String {
|
||||
if (size <= 0) return "$size B"
|
||||
val units = arrayOf("B", "KB", "MB", "GB", "TB")
|
||||
val digitGroups = (log10(size.toDouble()) / log10(1024.0)).toInt()
|
||||
return DecimalFormat("#,##0.##").format(size / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -229,9 +229,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
|
||||
private void setUpAppbarColor() {
|
||||
int primaryColor = ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorPrimary);
|
||||
int primaryColor = ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface);
|
||||
getMainActivity().setSupportActionBar(toolbar);
|
||||
appBarLayout.setBackgroundColor(primaryColor);
|
||||
toolbar.setBackgroundColor(RetroColorUtil.toolbarColor(getMainActivity()));
|
||||
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
|
||||
toolbar.setNavigationOnClickListener(v -> {
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?rectSelector"
|
||||
android:background="?attr/colorSurface"
|
||||
android:foreground="?rectSelector"
|
||||
android:gravity="center_vertical|start"
|
||||
android:minHeight="@dimen/tab_height"
|
||||
android:orientation="horizontal"
|
||||
|
|
|
@ -31,17 +31,22 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/bannerContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/imageContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="228dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:cardCornerRadius="24dp"
|
||||
app:cardUseCompatPadding="true">
|
||||
app:cardUseCompatPadding="true"
|
||||
app:layout_constraintDimensionRatio="16:9"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -134,7 +139,13 @@
|
|||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<include layout="@layout/home_content" />
|
||||
</LinearLayout>
|
||||
<include
|
||||
layout="@layout/home_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageContainer" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</LinearLayout>
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/coordinatorLayout"
|
||||
android:background="?attr/colorSurface"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
@ -25,6 +26,7 @@
|
|||
android:id="@+id/appBarLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:elevation="0dp"
|
||||
app:elevation="0dp">
|
||||
|
||||
|
@ -73,9 +75,9 @@
|
|||
android:id="@+id/breadCrumbs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/tab_height"
|
||||
app:cardBackgroundColor="?colorSurface"
|
||||
android:paddingStart="60dp"
|
||||
android:paddingEnd="8dp"
|
||||
app:cardBackgroundColor="?colorSurface"
|
||||
app:layout_collapseMode="pin" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
Loading…
Reference in a new issue