Twelve: Album file types
Change-Id: Iecb01cfd3266949a7088354a98201c5101a1a59e
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt
index fe8d007..f242671 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt
@@ -26,6 +26,7 @@
import androidx.recyclerview.widget.RecyclerView
import coil3.load
import com.google.android.material.appbar.MaterialToolbar
+import com.google.android.material.card.MaterialCardView
import com.google.android.material.progressindicator.LinearProgressIndicator
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.collectLatest
@@ -54,6 +55,8 @@
// Views
private val albumTitleTextView by getViewProperty<TextView>(R.id.albumTitleTextView)
private val artistNameTextView by getViewProperty<TextView>(R.id.artistNameTextView)
+ private val fileTypeMaterialCardView by getViewProperty<MaterialCardView>(R.id.fileTypeMaterialCardView)
+ private val fileTypeTextView by getViewProperty<TextView>(R.id.fileTypeTextView)
private val infoNestedScrollView by getViewProperty<NestedScrollView?>(R.id.infoNestedScrollView)
private val linearProgressIndicator by getViewProperty<LinearProgressIndicator>(R.id.linearProgressIndicator)
private val noElementsNestedScrollView by getViewProperty<NestedScrollView>(R.id.noElementsNestedScrollView)
@@ -317,6 +320,13 @@
noElementsNestedScrollView.isVisible = isEmpty
}
}
+
+ launch {
+ viewModel.albumFileTypes.collectLatest {
+ fileTypeMaterialCardView.isVisible = it.isNotEmpty()
+ fileTypeTextView.text = it.joinToString(" / ")
+ }
+ }
}
}
diff --git a/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt b/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt
index 7e28fbc..18010e6 100644
--- a/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt
+++ b/app/src/main/java/org/lineageos/twelve/viewmodels/AlbumViewModel.kt
@@ -20,6 +20,7 @@
import org.lineageos.twelve.models.Audio
import org.lineageos.twelve.models.RequestStatus
import org.lineageos.twelve.models.UniqueItem
+import org.lineageos.twelve.utils.MimeUtils
import kotlin.reflect.safeCast
class AlbumViewModel(application: Application) : TwelveViewModel(application) {
@@ -108,6 +109,33 @@
listOf()
)
+ @OptIn(ExperimentalCoroutinesApi::class)
+ val albumFileTypes = album
+ .filterNotNull()
+ .mapLatest {
+ when (it) {
+ is RequestStatus.Loading -> null
+
+ is RequestStatus.Success -> {
+ it.data.second
+ .map { audio -> audio.mimeType }
+ .distinct()
+ .takeIf { mimeTypes -> mimeTypes.size <= 2 }
+ ?.mapNotNull { mimeType -> MimeUtils.mimeTypeToDisplayName(mimeType) }
+ .orEmpty()
+ }
+
+ is RequestStatus.Error -> listOf()
+ }
+ }
+ .filterNotNull()
+ .flowOn(Dispatchers.IO)
+ .stateIn(
+ viewModelScope,
+ SharingStarted.WhileSubscribed(),
+ listOf()
+ )
+
fun loadAlbum(albumUri: Uri) {
this.albumUri.value = albumUri
}
diff --git a/app/src/main/res/layout/album_labels.xml b/app/src/main/res/layout/album_labels.xml
index 18aa3de..d588575 100644
--- a/app/src/main/res/layout/album_labels.xml
+++ b/app/src/main/res/layout/album_labels.xml
@@ -18,38 +18,79 @@
android:textAppearance="?attr/textAppearanceHeadlineMedium"
tools:text="Sweet Revenge" />
- <TextView
- android:id="@+id/artistNameTextView"
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:drawablePadding="8dp"
android:gravity="center_vertical"
- android:paddingVertical="4dp"
- android:paddingStart="0dp"
- android:paddingEnd="4dp"
- android:textAppearance="?attr/textAppearanceLabelLarge"
- android:textColor="@color/textview_pressed"
- app:backgroundTint="@android:color/transparent"
- app:drawableStartCompat="@drawable/ic_person"
- app:drawableTint="@color/textview_pressed"
- tools:text="Ryuichi Sakamoto" />
+ android:orientation="horizontal">
- <TextView
- android:id="@+id/yearTextView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?attr/textAppearanceLabelLarge"
- android:textColor="?attr/colorOnSurfaceVariant"
- android:visibility="gone"
- tools:text="1994"
- tools:visibility="visible" />
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:orientation="vertical">
- <TextView
- android:id="@+id/tracksInfoTextView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?attr/textAppearanceLabelLarge"
- android:textColor="?attr/colorOnSurfaceVariant"
- tools:text="7 tracks, 51 minutes" />
+ <TextView
+ android:id="@+id/artistNameTextView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:drawablePadding="8dp"
+ android:gravity="center_vertical"
+ android:paddingVertical="4dp"
+ android:paddingStart="0dp"
+ android:paddingEnd="4dp"
+ android:textAppearance="?attr/textAppearanceLabelLarge"
+ android:textColor="@color/textview_pressed"
+ app:backgroundTint="@android:color/transparent"
+ app:drawableStartCompat="@drawable/ic_person"
+ app:drawableTint="@color/textview_pressed"
+ tools:text="Ryuichi Sakamoto" />
+
+ <TextView
+ android:id="@+id/yearTextView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?attr/textAppearanceLabelLarge"
+ android:textColor="?attr/colorOnSurfaceVariant"
+ android:visibility="gone"
+ tools:text="1994"
+ tools:visibility="visible" />
+
+ <TextView
+ android:id="@+id/tracksInfoTextView"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?attr/textAppearanceLabelLarge"
+ android:textColor="?attr/colorOnSurfaceVariant"
+ tools:text="7 tracks, 51 minutes" />
+
+ </LinearLayout>
+
+ <com.google.android.material.card.MaterialCardView
+ android:id="@+id/fileTypeMaterialCardView"
+ style="@style/Widget.Material3.CardView.Filled"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:visibility="gone"
+ app:cardBackgroundColor="?attr/colorPrimaryContainer"
+ app:cardCornerRadius="4dp"
+ app:contentPaddingLeft="4dp"
+ app:contentPaddingRight="4dp"
+ tools:visibility="visible">
+
+ <TextView
+ android:id="@+id/fileTypeTextView"
+ android:layout_width="wrap_content"
+ android:layout_height="24dp"
+ android:gravity="center"
+ android:textAlignment="gravity"
+ android:textAppearance="?attr/textAppearanceLabelMedium"
+ android:textColor="?attr/colorOnPrimaryContainer"
+ tools:text="FLAC / MPEG" />
+
+ </com.google.android.material.card.MaterialCardView>
+
+ </LinearLayout>
</LinearLayout>