-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new Add Station dialog that opens when a user selects to open an M3U …
…or PLS file from storage
- Loading branch information
Showing
7 changed files
with
193 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
app/src/main/java/com/jamal2367/urlradio/dialogs/AddStationDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* AddStationDialog.kt | ||
* Implements the AddStationDialog class | ||
* A AddStationDialog shows a dialog with list of stations to import | ||
* | ||
* This file is part of | ||
* TRANSISTOR - Radio App for Android | ||
* | ||
* Copyright (c) 2015-23 - Y20K.org | ||
* Licensed under the MIT-License | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
package com.jamal2367.urlradio.dialogs | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.recyclerview.widget.DefaultItemAnimator | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import com.jamal2367.urlradio.R | ||
import com.jamal2367.urlradio.collection.CollectionAdapter | ||
import com.jamal2367.urlradio.core.Station | ||
import com.jamal2367.urlradio.search.SearchResultAdapter | ||
|
||
|
||
/* | ||
* AddStationDialog class | ||
*/ | ||
class AddStationDialog ( | ||
private val context: Context, | ||
private val stationList: List<Station>, | ||
private val listener: AddStationDialogListener) : | ||
SearchResultAdapter.SearchResultAdapterListener { | ||
|
||
|
||
/* Interface used to communicate back to activity */ | ||
interface AddStationDialogListener { | ||
fun onAddStationDialog(station: Station) | ||
} | ||
|
||
|
||
/* Define log tag */ | ||
private val TAG = AddStationDialog::class.java.simpleName | ||
|
||
|
||
/* Main class variables */ | ||
private lateinit var dialog: AlertDialog | ||
private lateinit var stationSearchResultList: RecyclerView | ||
private lateinit var searchResultAdapter: SearchResultAdapter | ||
private var station: Station = Station() | ||
|
||
|
||
/* Overrides onSearchResultTapped from SearchResultAdapterListener */ | ||
override fun onSearchResultTapped(result: Station) { | ||
station = result | ||
// make add button clickable | ||
activateAddButton() | ||
} | ||
|
||
|
||
/* Construct and show dialog */ | ||
fun show() { | ||
// prepare dialog builder | ||
val builder = MaterialAlertDialogBuilder(context) | ||
|
||
// set title | ||
builder.setTitle(R.string.dialog_add_station_title) | ||
|
||
// get views | ||
val inflater = LayoutInflater.from(context) | ||
val view = inflater.inflate(R.layout.dialog_add_station, null) | ||
stationSearchResultList = view.findViewById(R.id.station_list) | ||
|
||
// set up list of search results | ||
setupRecyclerView(context) | ||
|
||
// add okay ("Add") button | ||
builder.setPositiveButton(R.string.dialog_find_station_button_add) { _, _ -> | ||
// listen for click on add button | ||
listener.onAddStationDialog(station) | ||
searchResultAdapter.stopPrePlayback() | ||
} | ||
// add cancel button | ||
builder.setNegativeButton(R.string.dialog_generic_button_cancel) { _, _ -> | ||
searchResultAdapter.stopPrePlayback() | ||
} | ||
// handle outside-click as "no" | ||
builder.setOnCancelListener { | ||
searchResultAdapter.stopPrePlayback() | ||
} | ||
|
||
// set dialog view | ||
builder.setView(view) | ||
|
||
// create and display dialog | ||
dialog = builder.create() | ||
dialog.show() | ||
|
||
// initially disable "Add" button | ||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = false | ||
} | ||
|
||
|
||
/* Sets up list of results (RecyclerView) */ | ||
private fun setupRecyclerView(context: Context) { | ||
searchResultAdapter = SearchResultAdapter(this, stationList) | ||
stationSearchResultList.adapter = searchResultAdapter | ||
val layoutManager: LinearLayoutManager = object: LinearLayoutManager(context) { | ||
override fun supportsPredictiveItemAnimations(): Boolean { | ||
return true | ||
} | ||
} | ||
stationSearchResultList.layoutManager = layoutManager | ||
stationSearchResultList.itemAnimator = DefaultItemAnimator() | ||
} | ||
|
||
|
||
/* Implement activateAddButton to enable the "Add" button */ | ||
override fun activateAddButton() { | ||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = true | ||
} | ||
|
||
|
||
/* Implement deactivateAddButton to disable the "Add" button */ | ||
override fun deactivateAddButton() { | ||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = false | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?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" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/station_list" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginEnd="8dp" | ||
android:paddingTop="16dp" | ||
app:layout_constrainedHeight="true" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters