Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Aldaoudieh committed Mar 3, 2021
1 parent 3f5ba89 commit 5df2f48
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import me.grishka.houseclub.api.model.Channel;

public class DataProvider {
class DataProvider {
private static Channel channelCache = null;

@Nullable
Expand All @@ -15,10 +15,6 @@ public static Channel getChannel(String id) {
return Objects.equals(channelCache.channel, id) ? channelCache : null;
}

public static Channel getCachedChannel(){
return channelCache;
}

public static void saveChannel(Channel channel) {
channelCache = channel;
}
Expand Down
106 changes: 32 additions & 74 deletions Houseclub/src/main/java/me/grishka/houseclub/VoiceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class VoiceService extends Service{
private RtcEngine engine;
private Channel channel;
private boolean muted=true;
private boolean isSpeakerMuted=false;
private Handler uiHandler=new Handler(Looper.getMainLooper());
private Runnable pinger=new Runnable(){
@Override
Expand Down Expand Up @@ -115,59 +114,37 @@ public int onStartCommand(Intent intent, int flags, int startId){
channel=DataProvider.getChannel(id);
updateChannel(channel);

Notification n=buildNotification();
startForeground(10, n);
Intent snoozeIntent = new Intent(this, NotificationHandlerBroadcastReceiver.class);
snoozeIntent.setAction(NotificationHandlerBroadcastReceiver.ACTION_LEAVE_ROOM);
PendingIntent leaveRoomPendingIntent = PendingIntent.getBroadcast(this, 0, snoozeIntent, 0);
Notification.Action leaveRoomAction = new Notification.Action.Builder(
Icon.createWithResource(this, R.drawable.ic_leave),
getString(R.string.leave_room),
leaveRoomPendingIntent
).build();

NotificationManager nm=getSystemService(NotificationManager.class);
Notification.Builder n=new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_phone_in_talk)
.setContentTitle(getString(R.string.ongoing_call))
.setContentText(intent.getStringExtra("topic"))
.setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, MainActivity.class).putExtra("openCurrentChannel", true), PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(leaveRoomAction);
if(Build.VERSION.SDK_INT>=26){
if(nm.getNotificationChannel("ongoing")==null){
NotificationChannel nc=new NotificationChannel("ongoing", "Ongoing calls", NotificationManager.IMPORTANCE_LOW);
nm.createNotificationChannel(nc);
}
n.setChannelId("ongoing");
}
startForeground(10, n.build());

doJoinChannel();
}
return START_NOT_STICKY;
}

private Notification buildNotification(){
Intent leaveRoomIntent = new Intent(this, NotificationHandlerBroadcastReceiver.class);
leaveRoomIntent.setAction(NotificationHandlerBroadcastReceiver.ACTION_LEAVE_ROOM);
PendingIntent leaveRoomPendingIntent = PendingIntent.getBroadcast(this, 0, leaveRoomIntent, 0);
Notification.Action leaveRoomAction = new Notification.Action.Builder(
Icon.createWithResource(this, R.drawable.ic_leave),
getString(R.string.leave_room),
leaveRoomPendingIntent
).build();

Intent muteSpeakerIntent = new Intent(this, NotificationHandlerBroadcastReceiver.class);
muteSpeakerIntent.setAction(NotificationHandlerBroadcastReceiver.ACTION_TOGGLE_MUTE_SPEAKER);
PendingIntent muteSpeakerPendingIntent = PendingIntent.getBroadcast(this, 0, muteSpeakerIntent, 0);
Notification.Action muteSpeakerAction = new Notification.Action.Builder(
Icon.createWithResource(this, isSpeakerMuted?R.drawable.ic_baseline_volume_off_24:R.drawable.ic_baseline_volume_up_24),
getString(isSpeakerMuted?R.string.unmute_speaker:R.string.mute_speaker),
muteSpeakerPendingIntent
).build();

NotificationManager nm=getSystemService(NotificationManager.class);
Notification.Builder n=new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_phone_in_talk)
.setContentTitle(getString(R.string.ongoing_call))
.setContentText(channel.topic)
.setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, MainActivity.class).putExtra("openCurrentChannel", true), PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(leaveRoomAction)
.addAction(muteSpeakerAction);
if(Build.VERSION.SDK_INT>=26){
if(nm.getNotificationChannel("ongoing")==null){
NotificationChannel nc=new NotificationChannel("ongoing", "Ongoing calls", NotificationManager.IMPORTANCE_LOW);
nm.createNotificationChannel(nc);
}
n.setChannelId("ongoing");
}
return n.build();
}

private void updateNotification(){
NotificationManager nm=getSystemService(NotificationManager.class);
Notification n= buildNotification();
nm.notify(10, n);
}

private void doJoinChannel(){
engine.setAudioProfile(Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO, Constants.AUDIO_SCENARIO_GAME_STREAMING);
engine.setChannelProfile(isSelfSpeaker ? Constants.CHANNEL_PROFILE_COMMUNICATION : Constants.CHANNEL_PROFILE_LIVE_BROADCASTING);
engine.joinChannel(channel.token, channel.channel, "", Integer.parseInt(ClubhouseSession.userID));
uiHandler.postDelayed(pinger, 30000);
Expand Down Expand Up @@ -262,10 +239,6 @@ public void leaveChannel(){
uiHandler.removeCallbacks(pinger);
pubnub.unsubscribeAll();
pubnub.destroy();
uiHandler.post(() -> {
for(ChannelEventListener l:listeners)
l.onSelfLeft();
});
}

public void leaveCurrentChannel(){
Expand Down Expand Up @@ -332,23 +305,10 @@ public void setMuted(boolean muted){
engine.muteLocalAudioStream(muted);
}

public void setSpeakerMuted(boolean muted){
this.isSpeakerMuted=muted;
engine.adjustPlaybackSignalVolume(muted?0:100);
engine.adjustAudioMixingPlayoutVolume(muted?0:100);
updateNotification();
for(ChannelEventListener l:listeners)
l.onSpeakerMuted(muted);
}

public boolean isMuted(){
return muted;
}

public boolean isSpeakerMuted(){
return isSpeakerMuted;
}

public Channel getChannel(){
return channel;
}
Expand Down Expand Up @@ -456,14 +416,12 @@ public void run(){

public interface ChannelEventListener{
void onUserMuteChanged(int id, boolean muted);
void onSpeakerMuted(boolean muted);
void onUserJoined(ChannelUser user);
void onUserLeft(int id);
void onCanSpeak(String inviterName, int inviterID);
void onChannelUpdated(Channel channel);
void onSpeakingUsersChanged(List<Integer> ids);
void onChannelEnded();
void onSelfLeft();
}

private class RtcEngineEventHandler extends IRtcEngineEventHandler{
Expand Down Expand Up @@ -497,14 +455,14 @@ public void onUserMuteAudio(int uid, boolean muted){
uiHandler.post(new Runnable(){
@Override
public void run(){
for(ChannelUser u:channel.users){
if(u.userId==uid){
u.isMuted=muted;
break;
}
}
for(ChannelEventListener l:listeners)
l.onUserMuteChanged(uid, muted);
for(ChannelUser u:channel.users){
if(u.userId==uid){
u.isMuted=muted;
break;
}
}
for(ChannelEventListener l:listeners)
l.onUserMuteChanged(uid, muted);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.grishka.houseclub.fragments;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Outline;
Expand All @@ -18,6 +20,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -30,20 +33,16 @@
import me.grishka.appkit.imageloader.ImageLoaderViewHolder;
import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.utils.V;
import me.grishka.houseclub.DataProvider;
import me.grishka.houseclub.MainActivity;
import me.grishka.houseclub.R;
import me.grishka.houseclub.VoiceService;
import me.grishka.houseclub.api.ClubhouseSession;
import me.grishka.houseclub.api.methods.GetChannels;
import me.grishka.houseclub.api.model.Channel;
import me.grishka.houseclub.api.model.ChannelUser;

public class HomeFragment extends BaseRecyclerFragment<Channel>{

private ChannelAdapter adapter;
private View returnView;

private ViewOutlineProvider roundedCornersOutline=new ViewOutlineProvider(){
@Override
public void getOutline(View view, Outline outline){
Expand Down Expand Up @@ -85,90 +84,8 @@ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull R
}
});
getToolbar().setElevation(0);

// add Return to "channel" bar to bottom of toolbar
LayoutInflater inflater = LayoutInflater.from(getActivity());
View returnBar = inflater.inflate(R.layout.return_row_bar, null);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

((ViewGroup) getView()).addView(returnBar, 1, layoutParams);
returnBar.setOnClickListener((it) -> {
Channel channel = DataProvider.getCachedChannel();
if (channel != null)
((MainActivity) getActivity()).joinChannel(channel);
});
returnView = getView().findViewById(R.id.return_container);
VoiceService.addListener(channelEventListener);
}

private final VoiceService.ChannelEventListener channelEventListener = new VoiceService.ChannelEventListener() {
@Override
public void onUserMuteChanged(int id, boolean muted) {
}

@Override
public void onUserJoined(ChannelUser user) {
}

@Override
public void onUserLeft(int id) {
}

@Override
public void onCanSpeak(String inviterName, int inviterID) {
}

@Override
public void onChannelUpdated(Channel channel) {
checkReturnBar();
}

@Override
public void onSpeakingUsersChanged(List<Integer> ids) {
}

@Override
public void onChannelEnded() {
hideReturnBar();
}

@Override
public void onSelfLeft() {
hideReturnBar();
}

};

private void hideReturnBar() {
if (returnView != null) {
returnView.setVisibility(View.GONE);
}
}

private void checkReturnBar() {
try {
Channel channel = DataProvider.getCachedChannel();
if (returnView != null) {
if (channel != null) {
TextView title = returnView.findViewById(R.id.return_title);
if (title != null) {
String channelNameShortened;
if (channel.topic == null) channelNameShortened = "the channel";
else {
channelNameShortened = channel.topic.substring(0, Math.min(channel.topic.length(), 16));
if (channelNameShortened.length() < channel.topic.length())
channelNameShortened += "...";
}
title.setText(getString(R.string.return_to_channel, channelNameShortened));
}
returnView.setVisibility(View.VISIBLE);
} else returnView.setVisibility(View.GONE);
}
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
Expand All @@ -183,6 +100,7 @@ protected RecyclerView.Adapter getAdapter(){
}
return adapter;
}

@Override
public boolean wantsLightNavigationBar(){
return true;
Expand Down Expand Up @@ -277,6 +195,7 @@ public ChannelViewHolder(){

itemView.setOutlineProvider(roundedCornersOutline);
itemView.setClipToOutline(true);
itemView.setElevation(V.dp(2));
itemView.setOnClickListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class InChannelFragment extends BaseRecyclerFragment<ChannelUser> impleme
private MergeRecyclerAdapter adapter;
private UserListAdapter speakersAdapter, followedAdapter, othersAdapter;
private ImageButton muteBtn;
private ImageButton muteSpeakerBtn;
private Button raiseBtn;
private Channel channel;
private ArrayList<ChannelUser> speakers=new ArrayList<>(), followedBySpeakers=new ArrayList<>(), otherUsers=new ArrayList<>();
Expand All @@ -71,11 +70,9 @@ public void onViewCreated(View view, Bundle savedInstanceState){

raiseBtn=view.findViewById(R.id.raise);
muteBtn=view.findViewById(R.id.mute);
muteSpeakerBtn=view.findViewById(R.id.mute_speaker);

raiseBtn.setOnClickListener(this::onRaiseClick);
muteBtn.setOnClickListener(this::onMuteClick);
muteSpeakerBtn.setOnClickListener(this::onMuteSpeakerClick);

GridLayoutManager lm=new GridLayoutManager(getActivity(), 12);
lm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup(){
Expand All @@ -100,7 +97,6 @@ public int getSpanSize(int position){
VoiceService svc=VoiceService.getInstance();
if(svc!=null){
muteBtn.setImageResource(svc.isMuted() ? R.drawable.ic_mic_off : R.drawable.ic_mic);
muteSpeakerBtn.setImageResource(svc.isSpeakerMuted() ? R.drawable.ic_baseline_volume_off_24 : R.drawable.ic_baseline_volume_up_24);
onUserMuteChanged(Integer.parseInt(ClubhouseSession.userID), svc.isMuted());
}
}
Expand Down Expand Up @@ -172,11 +168,6 @@ private void onMuteClick(View v){
onUserMuteChanged(Integer.parseInt(ClubhouseSession.userID), svc.isMuted());
}

private void onMuteSpeakerClick(View v){
VoiceService svc=VoiceService.getInstance();
svc.setSpeakerMuted(!svc.isSpeakerMuted());
}

@Override
public void onUserMuteChanged(int id, boolean muted){
int i=0;
Expand All @@ -198,11 +189,6 @@ public void onUserMuteChanged(int id, boolean muted){
}
}

@Override
public void onSpeakerMuted(boolean muted) {
muteSpeakerBtn.setImageResource(muted ? R.drawable.ic_baseline_volume_off_24 : R.drawable.ic_baseline_volume_up_24);
}

@Override
public void onUserJoined(ChannelUser user){
if(user.isSpeaker){
Expand Down Expand Up @@ -323,9 +309,6 @@ public void onChannelEnded(){
Nav.finish(this);
}

@Override
public void onSelfLeft() { }

private class UserListAdapter extends RecyclerView.Adapter<UserViewHolder> implements ImageLoaderRecyclerAdapter{

private List<ChannelUser> users;
Expand Down
Loading

1 comment on commit 5df2f48

@avary
Copy link

@avary avary commented on 5df2f48 Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you revert this?

Please sign in to comment.