Skip to content

Commit

Permalink
Adds library stats dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Dec 21, 2020
1 parent 322eda4 commit 3067fa2
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.view.isGone
import androidx.viewpager2.widget.ViewPager2
import butterknife.BindView
import butterknife.ButterKnife
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.progressindicator.ProgressIndicator
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout
Expand Down Expand Up @@ -135,10 +136,28 @@ class LibraryActivity : BaseActivity(),
searchClear?.isVisible = false
return true
}
R.id.library_sync_state -> {
presenter.showStats()
return true
}
}
return super.onOptionsItemSelected(item)
}

override fun showStats(stats: LibraryStats) {
val dialog = MaterialAlertDialogBuilder(this)
.setTitle(R.string.library_stats__title)
.setView(R.layout.library_stats__layout)
.setPositiveButton(android.R.string.ok) { md, _ -> md.dismiss() }
.show()

dialog.findViewById<TextView>(R.id.library_stats__genre_value)?.text = "${stats.genres}"
dialog.findViewById<TextView>(R.id.library_stats__artist_value)?.text = "${stats.artists}"
dialog.findViewById<TextView>(R.id.library_stats__album_value)?.text = "${stats.albums}"
dialog.findViewById<TextView>(R.id.library_stats__track_value)?.text = "${stats.tracks}"
dialog.findViewById<TextView>(R.id.library_stats__playlist_value)?.text = "${stats.playlists}"
}

override fun syncComplete(stats: LibraryStats) {
val message = getString(
R.string.library__sync_complete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ interface LibraryView : BaseView {
fun hideSyncProgress()
fun updateArtistOnlyPreference(albumArtistOnly: Boolean?)
fun syncComplete(stats: LibraryStats)
fun showStats(stats: LibraryStats)
}

interface LibraryPresenter : Presenter<LibraryView> {
fun refresh()
fun loadArtistPreference()
fun setArtistPreference(albumArtistOnly: Boolean)
fun search(keyword: String)
fun showStats()
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ constructor(
}
}

override fun showStats() {
scope.launch {
view?.showStats(librarySyncInteractor.syncStats())
}
}

override fun loadArtistPreference() {
scope.launch {
val shouldDisplay = settingsManager.shouldDisplayOnlyAlbumArtists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface LibrarySyncInteractor {

fun setOnCompleteListener(onCompleteListener: OnCompleteListener?)
fun setOnStartListener(onStartListener: OnStartListener?)
suspend fun syncStats(): LibraryStats

interface OnCompleteListener {
fun onTermination()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ class LibrarySyncInteractorImpl
}
}

override suspend fun syncStats(): LibraryStats {
return LibraryStats(
genres = genreRepository.count(),
artists = artistRepository.count(),
albums = albumRepository.count(),
tracks = trackRepository.count(),
playlists = playlistRepository.count()
)
}

private suspend fun checkIfShouldSync(auto: Boolean): Boolean {
return if (auto) isEmpty() else true
}
Expand Down
139 changes: 139 additions & 0 deletions app/src/main/res/layout/library_stats__layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
style="@style/TextAppearance.MaterialComponents.Caption"
android:id="@+id/library_stats__description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/library_stats__description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/library_stats__genre_label"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif-medium"
android:text="@string/media__genres"
android:textColor="@color/primary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_stats__description" />

<TextView
android:id="@+id/library_stats__artist_label"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-medium"
android:text="@string/media__artists"
android:textColor="@color/primary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_stats__genre_label" />

<TextView
android:id="@+id/library_stats__album_label"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-medium"
android:text="@string/media__albums"
android:textColor="@color/primary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_stats__artist_label" />

<TextView
android:id="@+id/library_stats__track_label"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-medium"
android:text="@string/media__tracks"
android:textColor="@color/primary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_stats__album_label" />

<TextView
android:id="@+id/library_stats__playlist_label"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-medium"
android:text="@string/media__playlists"
android:textColor="@color/primary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/library_stats__track_label" />

<TextView
android:id="@+id/library_stats__genre_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/library_stats__genre_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/library_stats__genre_label"
app:layout_constraintTop_toTopOf="@id/library_stats__genre_label"
tools:text="1" />

<TextView
android:id="@+id/library_stats__artist_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/library_stats__artist_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/library_stats__artist_label"
app:layout_constraintTop_toTopOf="@id/library_stats__artist_label"
tools:text="1" />

<TextView
android:id="@+id/library_stats__album_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/library_stats__album_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/library_stats__album_label"
app:layout_constraintTop_toBottomOf="@id/library_stats__album_label"
app:layout_constraintTop_toTopOf="@id/library_stats__album_label"
tools:text="1" />

<TextView
android:id="@+id/library_stats__track_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/library_stats__track_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/library_stats__track_label"
app:layout_constraintTop_toBottomOf="@id/library_stats__track_label"
app:layout_constraintTop_toTopOf="@id/library_stats__track_label"
tools:text="1" />

<TextView
android:id="@+id/library_stats__playlist_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/library_stats__playlist_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/library_stats__playlist_label"
app:layout_constraintTop_toBottomOf="@id/library_stats__playlist_label"
app:layout_constraintTop_toTopOf="@id/library_stats__playlist_label"
tools:text="1" />

</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/menu/library_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
android:title="@string/library_album_artists_only"
app:showAsAction="never"/>

<item
android:id="@+id/library_sync_state"
android:title="@string/library_menu__sync_state"
app:showAsAction="never"/>

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<version
version="1.4.0"
release="Dec x,2020">
<feature>Adds statistics dialog when you can check how many tracks, etc are currently synced.</feature>
<feature>Improves visual feedback when performing a library metadata sync.</feature>
<feature>Adds a feedback message when queueing tracks/albums/genres/artists.</feature>
<feature>Adds the ability to queue the album or artist when browsing the track list.</feature>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,12 @@
<string name="menu_play_album">Play Now (Album)</string>
<string name="library__sync_complete">"Sync completed successfully. %1$d genres(s), %2$d artist(s) %3$d album(s), %4$d tracks and %5$d playlist(s) are available."</string>
<string name="refresh_failed">Refresh was unsuccessful.</string>
<string name="library_menu__sync_state">Library Sync State</string>
<string name="library_stats__title">Library Sync Information</string>
<string name="media__albums">Albums</string>
<string name="media__genres">Genres</string>
<string name="media__artists">Artists</string>
<string name="media__tracks">Tracks</string>
<string name="media__playlists">Playlists</string>
<string name="library_stats__description">The following metadata entries are currently available to MusicBee Remote:</string>
</resources>

0 comments on commit 3067fa2

Please sign in to comment.