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