Hello! I am writing a player for Android and I now have this picture:
Activity class It contains a list of music tracks, as well as the bottom panel. On the panel there are buttons "Back", "Play / Pause" and "Next", as well as the name of the track and its author.
List adapter class In the list, each element has a name and author of the track, as well as either the first letter of the track name in the circle (if this track is not playing), or
ProgressBar(if preparing to play), orMiniEqualizer(if music is playing), or thePlayicon (if music is paused). Clicking on the item (list item) starts playing the track, pressing it again pauses.Class player. It has
MediaPlayer, which is responsible for playing music, this class has methods for controlling playback, information about the track being played is also stored there, and there are methods getters returning this information.PlayBackinterface. This is actually the question. I created an interface (we will not complicate it, let it be onlyplayandpausemethods). By clicking on a pause from the bottom panel in the list item, the equalizer should change to thePlayicon. It is the same with stopping music from the list and changing the picture in the bottom panel. Ie, in simple, language, the bottom panel (activity) and the list (adapter) should be mutually connected, so I decided to resort to the interface. Initially, an instance of thePlayerclass is created in activity, then passed to the adapter. I call its methods, there they pull the methods of the interface, and thus realize the connection between the two classes.
What is the problem?
I pass 2 Playback to the class of the player: one for activity, the second for the adapter, and call their methods in two places. Is it possible to somehow call in one?
MediaPlayer. And he, in turn, when someone changes the state (no matter who), will notify all subscribers about this change. As soon as the activation receives this notification, it will update the list and update the panel. - Vladimir Parfenov