From b2de7bd534dcd3064ba35049edc521d7ff5e2c76 Mon Sep 17 00:00:00 2001 From: Michatec <121869403+Michatec@users.noreply.github.com> Date: Sun, 25 Jan 2026 16:33:17 +0100 Subject: [PATCH] - Progress Bar added - CollectionAdapter.kt updated - File download optimized - Housekeeping updated --- .../java/com/michatec/radio/MainActivity.kt | 12 ----- .../radio/collection/CollectionAdapter.kt | 48 ++++++++++++------- .../java/com/michatec/radio/core/Station.kt | 14 +++++- .../radio/helpers/CollectionHelper.kt | 3 +- .../com/michatec/radio/helpers/FileHelper.kt | 6 +-- app/src/main/res/layout/card_station.xml | 30 ++++++++++++ 6 files changed, 75 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/michatec/radio/MainActivity.kt b/app/src/main/java/com/michatec/radio/MainActivity.kt index d5ce898..4574ce6 100644 --- a/app/src/main/java/com/michatec/radio/MainActivity.kt +++ b/app/src/main/java/com/michatec/radio/MainActivity.kt @@ -41,18 +41,6 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - // house-keeping: determine if edit stations is enabled by default todo: remove in 2023 - if (PreferencesHelper.isHouseKeepingNecessary()) { - // house-keeping 1: remove hard coded default image - ImportHelper.removeDefaultStationImageUris(this) - // house-keeping 2: if existing user detected, enable Edit Stations by default - if (PreferencesHelper.loadCollectionSize() != -1) { - // existing user detected - enable Edit Stations by default - PreferencesHelper.saveEditStationsEnabled(true) - } - PreferencesHelper.saveHouseKeepingNecessaryState() - } - // set up views setContentView(R.layout.activity_main) diff --git a/app/src/main/java/com/michatec/radio/collection/CollectionAdapter.kt b/app/src/main/java/com/michatec/radio/collection/CollectionAdapter.kt index 78b0be7..c59c6e3 100644 --- a/app/src/main/java/com/michatec/radio/collection/CollectionAdapter.kt +++ b/app/src/main/java/com/michatec/radio/collection/CollectionAdapter.kt @@ -24,6 +24,7 @@ import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo import android.widget.ImageView +import android.widget.ProgressBar import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.cardview.widget.CardView @@ -193,6 +194,8 @@ class CollectionAdapter( setStationImage(stationViewHolder, station) setStationButtons(stationViewHolder, station) setEditViews(stationViewHolder, station) + setPlaybackProgress(stationViewHolder, station) + setDownloadProgress(stationViewHolder, station) // show / hide edit views when (expandedStationPosition) { @@ -248,6 +251,28 @@ class CollectionAdapter( } + /* Sets the playback progress view */ + private fun setPlaybackProgress(stationViewHolder: StationViewHolder, station: Station) { + if (station.bufferingProgress > 0) { + stationViewHolder.bufferingProgress.progress = station.bufferingProgress + stationViewHolder.bufferingProgress.isVisible = true + } else { + stationViewHolder.bufferingProgress.isGone = true + } + } + + + /* Sets the download progress view */ + private fun setDownloadProgress(stationViewHolder: StationViewHolder, station: Station) { + if (station.downloadProgress > 0) { + stationViewHolder.downloadProgress.progress = station.downloadProgress + stationViewHolder.downloadProgress.isVisible = true + } else { + stationViewHolder.downloadProgress.isGone = true + } + } + + /* Sets the edit views */ private fun setEditViews(stationViewHolder: StationViewHolder, station: Station) { stationViewHolder.stationNameEditView.setText(station.name, TextView.BufferType.EDITABLE) @@ -486,10 +511,10 @@ class CollectionAdapter( setStationButtons(holder, station) } Keys.HOLDER_UPDATE_PLAYBACK_PROGRESS -> { - // todo implement + setPlaybackProgress(holder, station) } Keys.HOLDER_UPDATE_DOWNLOAD_STATE -> { - // todo implement + setDownloadProgress(holder, station) } } } @@ -576,21 +601,6 @@ class CollectionAdapter( } -// /* Initiates update of a station's information */ // todo move to CollectionHelper -// private fun updateStation(context: Context, station: Station) { -// if (station.radioBrowserStationUuid.isNotEmpty()) { -// // get updated station from radio browser - results are handled by onRadioBrowserSearchResults -// val radioBrowserSearch: RadioBrowserSearch = RadioBrowserSearch(context, this) -// radioBrowserSearch.searchStation(context, station.radioBrowserStationUuid, Keys.SEARCH_TYPE_BY_UUID) -// } else if (station.remoteStationLocation.isNotEmpty()) { -// // download playlist // todo check content type detection is necessary here -// DownloadHelper.downloadPlaylists(context, arrayOf(station.remoteStationLocation)) -// } else { -// Log.w(TAG, "Unable to update station: ${station.name}.") -// } -// } - - /* Determines if position is last */ private fun isPositionFooter(position: Int): Boolean { return position == collection.stations.size @@ -601,7 +611,7 @@ class CollectionAdapter( @SuppressLint("NotifyDataSetChanged") private fun updateRecyclerView(oldCollection: Collection, newCollection: Collection) { collection = newCollection - if (oldCollection.stations.size == 0 && newCollection.stations.size > 0) { + if (oldCollection.stations.isEmpty() && newCollection.stations.isNotEmpty()) { // data set has been initialized - redraw the whole list notifyDataSetChanged() } else { @@ -673,6 +683,8 @@ class CollectionAdapter( val stationImageView: ImageView = stationCardLayout.findViewById(R.id.station_icon) val stationNameView: TextView = stationCardLayout.findViewById(R.id.station_name) val stationStarredView: ImageView = stationCardLayout.findViewById(R.id.starred_icon) + val bufferingProgress: ProgressBar = stationCardLayout.findViewById(R.id.buffering_progress) + val downloadProgress: ProgressBar = stationCardLayout.findViewById(R.id.download_progress) // val menuButtonView: ImageView = stationCardLayout.findViewById(R.id.menu_button) val playButtonView: ImageView = stationCardLayout.findViewById(R.id.playback_button) diff --git a/app/src/main/java/com/michatec/radio/core/Station.kt b/app/src/main/java/com/michatec/radio/core/Station.kt index 34e1221..eb1ce18 100644 --- a/app/src/main/java/com/michatec/radio/core/Station.kt +++ b/app/src/main/java/com/michatec/radio/core/Station.kt @@ -48,7 +48,9 @@ data class Station( @Expose var radioBrowserStationUuid: String = String(), @Expose var radioBrowserChangeUuid: String = String(), @Expose var bitrate: Int = 0, - @Expose var codec: String = String() + @Expose var codec: String = String(), + @Expose var bufferingProgress: Int = 0, + @Expose var downloadProgress: Int = 0 ) : Parcelable { @@ -79,6 +81,12 @@ data class Station( } + /* Getter for media type */ + fun getMediaType(): String { + return streamContent + } + + /* Creates a deep copy of a Station */ fun deepCopy(): Station { return Station( @@ -101,7 +109,9 @@ data class Station( radioBrowserStationUuid = radioBrowserStationUuid, radioBrowserChangeUuid = radioBrowserChangeUuid, bitrate = bitrate, - codec = codec + codec = codec, + bufferingProgress = bufferingProgress, + downloadProgress = downloadProgress ) } } diff --git a/app/src/main/java/com/michatec/radio/helpers/CollectionHelper.kt b/app/src/main/java/com/michatec/radio/helpers/CollectionHelper.kt index 785a1c2..e340c22 100644 --- a/app/src/main/java/com/michatec/radio/helpers/CollectionHelper.kt +++ b/app/src/main/java/com/michatec/radio/helpers/CollectionHelper.kt @@ -688,7 +688,6 @@ object CollectionHelper { /* Creates a MediaItem with MediaMetadata for a single radio station - used to prepare player */ fun buildMediaItem(context: Context, station: Station): MediaItem { - // todo implement HLS MediaItems // put uri in RequestMetadata - credit: https://stackoverflow.com/a/70103460 val requestMetadata = MediaItem.RequestMetadata.Builder().apply { setMediaUri(station.getStreamUri().toUri()) @@ -713,7 +712,7 @@ object CollectionHelper { setMediaId(station.uuid) setRequestMetadata(requestMetadata) setMediaMetadata(mediaMetadata) - //setMimeType(station.getMediaType()) + setMimeType(station.getMediaType()) setUri(station.getStreamUri().toUri()) }.build() } diff --git a/app/src/main/java/com/michatec/radio/helpers/FileHelper.kt b/app/src/main/java/com/michatec/radio/helpers/FileHelper.kt index 979617d..1ac69e3 100644 --- a/app/src/main/java/com/michatec/radio/helpers/FileHelper.kt +++ b/app/src/main/java/com/michatec/radio/helpers/FileHelper.kt @@ -417,16 +417,14 @@ object FileHelper { /* Reads InputStream from file uri and returns it as String */ private fun readTextFileFromFile(context: Context): String { - // todo read https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html - // https://developer.android.com/training/secure-file-sharing/retrieve-info - // check if file exists val file = File(context.getExternalFilesDir(Keys.FOLDER_COLLECTION), Keys.COLLECTION_FILE) if (!file.exists() || !file.canRead()) { return String() } // read until last line reached - val stream: InputStream = file.inputStream() + val uri = Uri.fromFile(file) + val stream: InputStream = context.contentResolver.openInputStream(uri) ?: return String() val reader = BufferedReader(InputStreamReader(stream)) val builder: StringBuilder = StringBuilder() reader.forEachLine { diff --git a/app/src/main/res/layout/card_station.xml b/app/src/main/res/layout/card_station.xml index 209f619..b15c571 100644 --- a/app/src/main/res/layout/card_station.xml +++ b/app/src/main/res/layout/card_station.xml @@ -31,6 +31,21 @@ app:shapeAppearanceOverlay="@style/RoundedCorners" app:srcCompat="@drawable/ic_default_station_image_72dp" /> + + + +