Skip to content

Commit

Permalink
Merge branch 'feature-ui-improvements' of github.com:dievskiy/Houseclub
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosUvaSilva committed Mar 1, 2021
2 parents e507c4f + bea3197 commit 173a14f
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

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

@Nullable
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -422,6 +426,7 @@ public interface ChannelEventListener{
void onChannelUpdated(Channel channel);
void onSpeakingUsersChanged(List<Integer> ids);
void onChannelEnded();
void onSelfLeft();
}

private class RtcEngineEventHandler extends IRtcEngineEventHandler{
Expand Down
115 changes: 105 additions & 10 deletions Houseclub/src/main/java/me/grishka/houseclub/fragments/HomeFragment.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
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;
import android.graphics.Rect;
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;
import android.view.MenuItem;
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;

Expand All @@ -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<Channel>{

private ChannelAdapter adapter;
private View returnView;
private boolean hasLeft = false;

private ViewOutlineProvider roundedCornersOutline=new ViewOutlineProvider(){
@Override
public void getOutline(View view, Outline outline){
Expand Down Expand Up @@ -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<Integer> 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){
Expand All @@ -100,7 +197,6 @@ protected RecyclerView.Adapter getAdapter(){
}
return adapter;
}

@Override
public boolean wantsLightNavigationBar(){
return true;
Expand Down Expand Up @@ -195,7 +291,6 @@ 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 @@ -309,6 +309,9 @@ 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
Original file line number Diff line number Diff line change
@@ -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;
}

}
32 changes: 32 additions & 0 deletions Houseclub/src/main/res/drawable/background_channel_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<item>
<shape android:id="@android:id/mask">
<solid android:color="#fff" />

<padding
android:bottom="0dp"
android:left="8dp"
android:right="8dp"
android:top="0dp" />
<corners
android:radius="25dp" />
</shape>
</item>
</ripple>
</item>
<item>
<shape android:id="@android:id/mask">
<solid android:color="#aaa" />
<padding
android:bottom="0dp"
android:left="8dp"
android:right="8dp"
android:top="0dp" />
<corners android:radius="25dp" />
</shape>
</item>

</transition>
32 changes: 32 additions & 0 deletions Houseclub/src/main/res/drawable/button_blue_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<item>
<shape android:id="@android:id/mask">
<solid android:color="@color/blue" />

<padding
android:bottom="0dp"
android:left="8dp"
android:right="8dp"
android:top="0dp" />
<corners
android:radius="28dp" />
</shape>
</item>
</ripple>
</item>
<item>
<shape android:id="@android:id/mask">
<solid android:color="#494E57" />
<padding
android:bottom="0dp"
android:left="8dp"
android:right="8dp"
android:top="0dp" />
<corners android:radius="28dp" />
</shape>
</item>

</transition>
6 changes: 6 additions & 0 deletions Houseclub/src/main/res/drawable/shadow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#10000000"
android:endColor="@android:color/transparent"
android:angle="90" />
</shape>
3 changes: 1 addition & 2 deletions Houseclub/src/main/res/layout/channel_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<TextView
android:id="@+id/topic"
Expand Down
42 changes: 42 additions & 0 deletions Houseclub/src/main/res/layout/return_row_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"
android:visibility="invisible"
tools:visibility="visible">

<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@drawable/shadow" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/return_container"
android:layout_gravity="bottom"
android:background="#fff"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:paddingTop="10dp"
android:paddingBottom="10dp">

<TextView
android:id="@+id/return_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="Return to channel"
android:textColor="@color/text_gray" />

</LinearLayout>
</LinearLayout>
1 change: 1 addition & 0 deletions Houseclub/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@
<string name="event_expired">This event has already ended</string>
<string name="log_in_to_activate">Please log in again to activate your account.</string>
<string name="ok">OK</string>
<string name="return_to_channel">Return to %1$s</string>
</resources>
Loading

0 comments on commit 173a14f

Please sign in to comment.