forked from sendbird/sendbird-uikit-android
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
23 changed files
with
1,113 additions
and
4 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
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
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
63 changes: 63 additions & 0 deletions
63
.../src/main/java/com/sendbird/uikit/activities/viewholder/MyAudioFileMessageViewHolder.java
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,63 @@ | ||
package com.sendbird.uikit.activities.viewholder; | ||
|
||
import android.net.Uri; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.databinding.ViewDataBinding; | ||
|
||
import com.sendbird.android.BaseChannel; | ||
import com.sendbird.android.BaseMessage; | ||
import com.sendbird.android.FileMessage; | ||
import com.sendbird.android.Reaction; | ||
import com.sendbird.uikit.BR; | ||
import com.sendbird.uikit.consts.ClickableViewIdentifier; | ||
import com.sendbird.uikit.consts.MessageGroupType; | ||
import com.sendbird.uikit.interfaces.OnItemClickListener; | ||
import com.sendbird.uikit.interfaces.OnItemLongClickListener; | ||
import com.sendbird.uikit.widgets.EmojiReactionListView; | ||
import com.sendbird.uikit.widgets.MyAudioFileMessageView; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public final class MyAudioFileMessageViewHolder extends GroupChannelMessageViewHolder { | ||
private final EmojiReactionListView emojiReactionListView; | ||
|
||
MyAudioFileMessageViewHolder(@NonNull ViewDataBinding binding, boolean useMessageGroupUI) { | ||
super(binding, useMessageGroupUI); | ||
emojiReactionListView = ((MyAudioFileMessageView) binding.getRoot()).getBinding().rvEmojiReactionList; | ||
final MyAudioFileMessageView root = (MyAudioFileMessageView) binding.getRoot(); | ||
|
||
clickableViewMap.put(ClickableViewIdentifier.QuoteReply.name(), root.getBinding().quoteReplyPanel); | ||
} | ||
|
||
@Override | ||
public void bind(BaseChannel channel, @NonNull BaseMessage message, MessageGroupType messageGroupType) { | ||
binding.setVariable(BR.channel, channel); | ||
binding.setVariable(BR.message, message); | ||
binding.setVariable(BR.messageGroupType, messageGroupType); | ||
|
||
final MyAudioFileMessageView root = (MyAudioFileMessageView) binding.getRoot(); | ||
FileMessage fileMessage = (FileMessage) message; | ||
String url = fileMessage.getUrl(); | ||
root.bind(Uri.parse(url)); | ||
} | ||
|
||
@Override | ||
public void setEmojiReaction(List<Reaction> reactionList, | ||
OnItemClickListener<String> emojiReactionClickListener, | ||
OnItemLongClickListener<String> emojiReactionLongClickListener, | ||
View.OnClickListener moreButtonClickListener) { | ||
emojiReactionListView.setReactionList(reactionList); | ||
emojiReactionListView.setEmojiReactionClickListener(emojiReactionClickListener); | ||
emojiReactionListView.setEmojiReactionLongClickListener(emojiReactionLongClickListener); | ||
emojiReactionListView.setMoreButtonClickListener(moreButtonClickListener); | ||
} | ||
|
||
@Override | ||
public Map<String, View> getClickableViewMap() { | ||
return clickableViewMap; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...c/main/java/com/sendbird/uikit/activities/viewholder/OtherAudioFileMessageViewHolder.java
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,63 @@ | ||
package com.sendbird.uikit.activities.viewholder; | ||
|
||
import android.net.Uri; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.databinding.ViewDataBinding; | ||
|
||
import com.sendbird.android.BaseChannel; | ||
import com.sendbird.android.BaseMessage; | ||
import com.sendbird.android.FileMessage; | ||
import com.sendbird.android.Reaction; | ||
import com.sendbird.uikit.BR; | ||
import com.sendbird.uikit.consts.ClickableViewIdentifier; | ||
import com.sendbird.uikit.consts.MessageGroupType; | ||
import com.sendbird.uikit.interfaces.OnItemClickListener; | ||
import com.sendbird.uikit.interfaces.OnItemLongClickListener; | ||
import com.sendbird.uikit.widgets.EmojiReactionListView; | ||
import com.sendbird.uikit.widgets.OtherAudioFileMessageView; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public final class OtherAudioFileMessageViewHolder extends GroupChannelMessageViewHolder { | ||
private final EmojiReactionListView emojiReactionListView; | ||
|
||
OtherAudioFileMessageViewHolder(@NonNull ViewDataBinding binding, boolean useMessageGroupUI) { | ||
super(binding, useMessageGroupUI); | ||
emojiReactionListView = ((OtherAudioFileMessageView) binding.getRoot()).getBinding().rvEmojiReactionList; | ||
final OtherAudioFileMessageView root = (OtherAudioFileMessageView) binding.getRoot(); | ||
|
||
clickableViewMap.put(ClickableViewIdentifier.Chat.name(), root.getBinding().ivThumbnailOveray); | ||
clickableViewMap.put(ClickableViewIdentifier.QuoteReply.name(), root.getBinding().quoteReplyPanel); | ||
} | ||
|
||
@Override | ||
public void bind(BaseChannel channel, @NonNull BaseMessage message, MessageGroupType messageGroupType) { | ||
binding.setVariable(BR.channel, channel); | ||
binding.setVariable(BR.message, message); | ||
binding.setVariable(BR.messageGroupType, messageGroupType); | ||
|
||
final OtherAudioFileMessageView root = (OtherAudioFileMessageView) binding.getRoot(); | ||
FileMessage fileMessage = (FileMessage) message; | ||
String url = fileMessage.getUrl(); | ||
root.bind(Uri.parse(url)); | ||
} | ||
|
||
@Override | ||
public void setEmojiReaction(List<Reaction> reactionList, | ||
OnItemClickListener<String> emojiReactionClickListener, | ||
OnItemLongClickListener<String> emojiReactionLongClickListener, | ||
View.OnClickListener moreButtonClickListener) { | ||
emojiReactionListView.setReactionList(reactionList); | ||
emojiReactionListView.setEmojiReactionClickListener(emojiReactionClickListener); | ||
emojiReactionListView.setEmojiReactionLongClickListener(emojiReactionLongClickListener); | ||
emojiReactionListView.setMoreButtonClickListener(moreButtonClickListener); | ||
} | ||
|
||
@Override | ||
public Map<String, View> getClickableViewMap() { | ||
return clickableViewMap; | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
uikit/src/main/java/com/sendbird/uikit/widgets/AudioManager.java
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,114 @@ | ||
package com.sendbird.uikit.widgets; | ||
|
||
import android.net.Uri; | ||
|
||
import androidx.lifecycle.Lifecycle; | ||
import androidx.lifecycle.LifecycleObserver; | ||
import androidx.lifecycle.OnLifecycleEvent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AudioManager implements AudioPlayer.AudioPlayerListener, LifecycleObserver { | ||
|
||
public interface AudioChangeListener { | ||
void onAudioChanged(Uri uriPlaying, boolean isPlaying); | ||
void onStateEnded(Uri uriPlaying); | ||
void onIsPlayingChanged(Uri uriPlaying, boolean isPlaying); | ||
} | ||
|
||
private static AudioManager sInstance = null; | ||
private Uri uriPlaying; | ||
|
||
private final List<AudioChangeListener> listeners = new ArrayList<>(); | ||
private final AudioPlayer player = AudioPlayer.getInstance(); | ||
|
||
private AudioManager() { | ||
player.setListener(this); | ||
} | ||
|
||
public static AudioManager getInstance() { | ||
if (sInstance == null) { | ||
sInstance = new AudioManager(); | ||
} | ||
return sInstance; | ||
} | ||
|
||
public void attachLifecycle(Lifecycle lifecycle) { | ||
lifecycle.addObserver(this); | ||
} | ||
|
||
public void detachLifecycle(Lifecycle lifecycle) { | ||
stop(); | ||
lifecycle.removeObserver(this); | ||
} | ||
|
||
public void registerAudioChangeListener(AudioChangeListener listener) { | ||
this.listeners.add(listener); | ||
} | ||
|
||
public void unregisterAudioChangeListener(AudioChangeListener listener) { | ||
this.listeners.remove(listener); | ||
} | ||
|
||
private void notifyAudioChanged(boolean isPlaying) { | ||
for (AudioChangeListener listener: listeners) { | ||
listener.onAudioChanged(uriPlaying, isPlaying); | ||
} | ||
} | ||
|
||
public void togglePlay(Uri uri) { | ||
if (uriPlaying != uri) { | ||
uriPlaying = uri; | ||
player.stop(); | ||
player.start(uriPlaying); | ||
notifyAudioChanged(true); | ||
} else { | ||
player.toggle(); | ||
notifyAudioChanged(player.isPlaying()); | ||
} | ||
} | ||
|
||
private void stop() { | ||
uriPlaying = null; | ||
player.stop(); | ||
notifyAudioChanged(false); | ||
} | ||
|
||
public boolean isUriPlaying(Uri uri) { | ||
return uriPlaying != null && uri != null && uriPlaying.toString().equals(uri.toString()); | ||
} | ||
|
||
public boolean isPlaying() { | ||
return player.isPlaying(); | ||
} | ||
|
||
public int getProgress() { | ||
return (int) player.getCurrentProgress(); | ||
} | ||
|
||
@Override | ||
public void onStateEnded() { | ||
for (AudioChangeListener listener: listeners) { | ||
stop(); | ||
listener.onStateEnded(uriPlaying); | ||
} | ||
} | ||
|
||
@Override | ||
public void onIsPlayingChanged(boolean isPlaying) { | ||
for (AudioChangeListener listener: listeners) { | ||
listener.onIsPlayingChanged(uriPlaying, isPlaying); | ||
} | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) | ||
public void onPause() { | ||
player.pause(); | ||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) | ||
public void onResume() { | ||
player.resume(); | ||
} | ||
} |
Oops, something went wrong.