diff --git a/Houseclub/src/main/java/me/grishka/houseclub/DataProvider.java b/Houseclub/src/main/java/me/grishka/houseclub/DataProvider.java index a4bf9b74..0db97f20 100644 --- a/Houseclub/src/main/java/me/grishka/houseclub/DataProvider.java +++ b/Houseclub/src/main/java/me/grishka/houseclub/DataProvider.java @@ -6,7 +6,7 @@ import me.grishka.houseclub.api.model.Channel; -class DataProvider { +public class DataProvider { private static Channel channelCache = null; @Nullable @@ -15,6 +15,10 @@ 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; } diff --git a/Houseclub/src/main/java/me/grishka/houseclub/VoiceService.java b/Houseclub/src/main/java/me/grishka/houseclub/VoiceService.java index cf547b3b..17610312 100644 --- a/Houseclub/src/main/java/me/grishka/houseclub/VoiceService.java +++ b/Houseclub/src/main/java/me/grishka/houseclub/VoiceService.java @@ -239,6 +239,10 @@ public void leaveChannel(){ uiHandler.removeCallbacks(pinger); pubnub.unsubscribeAll(); pubnub.destroy(); + uiHandler.post(() -> { + for(ChannelEventListener l:listeners) + l.onSelfLeft(); + }); } public void leaveCurrentChannel(){ @@ -422,6 +426,7 @@ public interface ChannelEventListener{ void onChannelUpdated(Channel channel); void onSpeakingUsersChanged(List ids); void onChannelEnded(); + void onSelfLeft(); } private class RtcEngineEventHandler extends IRtcEngineEventHandler{ diff --git a/Houseclub/src/main/java/me/grishka/houseclub/fragments/HomeFragment.java b/Houseclub/src/main/java/me/grishka/houseclub/fragments/HomeFragment.java index c402653f..d7a30977 100644 --- a/Houseclub/src/main/java/me/grishka/houseclub/fragments/HomeFragment.java +++ b/Houseclub/src/main/java/me/grishka/houseclub/fragments/HomeFragment.java @@ -1,8 +1,6 @@ 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; @@ -10,6 +8,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -17,10 +16,11 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewOutlineProvider; +import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -33,16 +33,22 @@ 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; +import me.grishka.houseclub.utils.AndroidUtils; public class HomeFragment extends BaseRecyclerFragment{ private ChannelAdapter adapter; + private View returnView; + private boolean hasLeft = false; + private ViewOutlineProvider roundedCornersOutline=new ViewOutlineProvider(){ @Override public void getOutline(View view, Outline outline){ @@ -84,14 +90,105 @@ 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()); + returnView = inflater.inflate(R.layout.return_row_bar, null); + final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); + ViewGroup parent = ((ViewGroup) getView().getParent()); + parent.addView(returnView, params); + returnView.post(() -> { + final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) returnView.getLayoutParams(); + layoutParams.gravity = Gravity.BOTTOM; + if (AndroidUtils.hasNavigationBar(getActivity())) { + layoutParams.bottomMargin = AndroidUtils.getNavigationBarSize(getContext()); + } + }); - @Override - public void onConfigurationChanged(Configuration newConfig){ - super.onConfigurationChanged(newConfig); - getToolbar().setElevation(0); + returnView.findViewById(R.id.return_container).setOnClickListener((it) -> { + Channel channel = DataProvider.getCachedChannel(); + if (channel != null) + ((MainActivity) getActivity()).joinChannel(channel); + }); + 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) { + hasLeft = false; + checkReturnBar(); + } + + @Override + public void onSpeakingUsersChanged(List ids) { + } + + @Override + public void onChannelEnded() { + hideReturnBar(); + } + + @Override + public void onSelfLeft() { + hasLeft = true; + hideReturnBar(); + } + + }; + + private void hideReturnBar() { + if (returnView != null) { + returnView.setVisibility(View.INVISIBLE); + } + list.setPadding(list.getPaddingLeft(), list.getPaddingTop(), list.getPaddingRight(), 0); + } + + 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 channelName = (channel.topic == null) ? "the channel" : channel.topic; + title.setText(getString(R.string.return_to_channel, channelName)); + } + returnView.setVisibility(View.VISIBLE); + list.setPadding(list.getPaddingLeft(), list.getPaddingTop(), list.getPaddingRight(), returnView.getHeight()); + } else hideReturnBar(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + getToolbar().setElevation(0); + // return bar with navigation bar will look ugly + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE + && AndroidUtils.hasNavigationBar(getActivity())) + hideReturnBar(); + else if (returnView.getVisibility() == View.INVISIBLE && !hasLeft) checkReturnBar(); + } + @Override protected RecyclerView.Adapter getAdapter(){ if(adapter==null){ @@ -100,7 +197,6 @@ protected RecyclerView.Adapter getAdapter(){ } return adapter; } - @Override public boolean wantsLightNavigationBar(){ return true; @@ -195,7 +291,6 @@ public ChannelViewHolder(){ itemView.setOutlineProvider(roundedCornersOutline); itemView.setClipToOutline(true); - itemView.setElevation(V.dp(2)); itemView.setOnClickListener(this); } diff --git a/Houseclub/src/main/java/me/grishka/houseclub/fragments/InChannelFragment.java b/Houseclub/src/main/java/me/grishka/houseclub/fragments/InChannelFragment.java index 518776ec..158a134b 100644 --- a/Houseclub/src/main/java/me/grishka/houseclub/fragments/InChannelFragment.java +++ b/Houseclub/src/main/java/me/grishka/houseclub/fragments/InChannelFragment.java @@ -309,6 +309,9 @@ public void onChannelEnded(){ Nav.finish(this); } + @Override + public void onSelfLeft() { } + private class UserListAdapter extends RecyclerView.Adapter implements ImageLoaderRecyclerAdapter{ private List users; diff --git a/Houseclub/src/main/java/me/grishka/houseclub/utils/AndroidUtils.java b/Houseclub/src/main/java/me/grishka/houseclub/utils/AndroidUtils.java new file mode 100644 index 00000000..4a4c60f3 --- /dev/null +++ b/Houseclub/src/main/java/me/grishka/houseclub/utils/AndroidUtils.java @@ -0,0 +1,28 @@ +package me.grishka.houseclub.utils; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Rect; +import android.util.DisplayMetrics; + +public class AndroidUtils { + + public static boolean hasNavigationBar(Activity activity) { + Rect rectangle = new Rect(); + DisplayMetrics displayMetrics = new DisplayMetrics(); + activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle); + activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics); + return displayMetrics.heightPixels != (rectangle.top + rectangle.height()); + } + + public static int getNavigationBarSize(Context context){ + Resources resources = context.getResources(); + int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); + if (resourceId > 0) { + return resources.getDimensionPixelSize(resourceId); + } + return 0; + } + +} diff --git a/Houseclub/src/main/res/drawable/background_channel_item.xml b/Houseclub/src/main/res/drawable/background_channel_item.xml new file mode 100644 index 00000000..ce9d91ed --- /dev/null +++ b/Houseclub/src/main/res/drawable/background_channel_item.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Houseclub/src/main/res/drawable/button_blue_background.xml b/Houseclub/src/main/res/drawable/button_blue_background.xml new file mode 100644 index 00000000..5e5c45dc --- /dev/null +++ b/Houseclub/src/main/res/drawable/button_blue_background.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Houseclub/src/main/res/drawable/shadow.xml b/Houseclub/src/main/res/drawable/shadow.xml new file mode 100644 index 00000000..87a40d63 --- /dev/null +++ b/Houseclub/src/main/res/drawable/shadow.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/Houseclub/src/main/res/layout/channel_row.xml b/Houseclub/src/main/res/layout/channel_row.xml index f1d3eb5c..a956c069 100644 --- a/Houseclub/src/main/res/layout/channel_row.xml +++ b/Houseclub/src/main/res/layout/channel_row.xml @@ -4,8 +4,7 @@ android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" android:padding="16dp" - android:background="#FFF" - android:foreground="?android:selectableItemBackground"> + android:background="@drawable/background_channel_item"> + + + + + + + + + + diff --git a/Houseclub/src/main/res/values/strings.xml b/Houseclub/src/main/res/values/strings.xml index 5d4b63ce..69afcf5c 100644 --- a/Houseclub/src/main/res/values/strings.xml +++ b/Houseclub/src/main/res/values/strings.xml @@ -58,4 +58,5 @@ This event has already ended Please log in again to activate your account. OK + Return to %1$s diff --git a/Houseclub/src/main/res/values/styles.xml b/Houseclub/src/main/res/values/styles.xml index 2efade17..58c72c37 100644 --- a/Houseclub/src/main/res/values/styles.xml +++ b/Houseclub/src/main/res/values/styles.xml @@ -27,6 +27,8 @@ @color/blue @null false + 38dp + @drawable/button_blue_background