extract new call item to layout

This commit is contained in:
AndyScherzinger 2018-04-26 15:00:31 +02:00
parent deaa761736
commit 797755221c
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 80 additions and 127 deletions

View file

@ -1,101 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.adapters.items;
import android.view.View;
import android.widget.RelativeLayout;
import com.nextcloud.talk.R;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractHeaderItem;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.flexibleadapter.items.IHeader;
import eu.davidea.viewholders.FlexibleViewHolder;
public class NewCallHeaderItem extends AbstractHeaderItem<NewCallHeaderItem.HeaderViewHolder>
implements IHeader<NewCallHeaderItem.HeaderViewHolder> {
HeaderViewHolder headerViewHolder;
public NewCallHeaderItem() {
super();
setSelectable(true);
}
@Override
public boolean equals(Object o) {
return false;
}
@Override
public int getLayoutRes() {
return R.layout.rv_item_call_header;
}
@Override
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, HeaderViewHolder holder, int position, List<Object> payloads) {
headerViewHolder = holder;
if (holder.secondaryRelativeLayout.getVisibility() == View.GONE && adapter.isSelected(position)) {
togglePublicCall(true);
} else if (holder.initialRelativeLayout.getVisibility() == View.GONE && !adapter.isSelected(position)) {
togglePublicCall(false);
}
}
@Override
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
headerViewHolder = new HeaderViewHolder(view, adapter);
return headerViewHolder;
}
public void togglePublicCall(boolean showDescription) {
if (!showDescription) {
headerViewHolder.secondaryRelativeLayout.setVisibility(View.GONE);
headerViewHolder.initialRelativeLayout.setVisibility(View.VISIBLE);
} else {
headerViewHolder.initialRelativeLayout.setVisibility(View.GONE);
headerViewHolder.secondaryRelativeLayout.setVisibility(View.VISIBLE);
}
}
static class HeaderViewHolder extends FlexibleViewHolder {
@BindView(R.id.initial_relative_layout)
public RelativeLayout initialRelativeLayout;
@BindView(R.id.secondary_relative_layout)
public RelativeLayout secondaryRelativeLayout;
/**
* Default constructor.
*/
HeaderViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter, true);
ButterKnife.bind(this, view);
}
}
}

View file

@ -44,6 +44,7 @@ import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.RelativeLayout;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
@ -51,7 +52,6 @@ import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.kennyc.bottomsheet.BottomSheet;
import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.CallActivity;
import com.nextcloud.talk.adapters.items.NewCallHeaderItem;
import com.nextcloud.talk.adapters.items.UserHeaderItem;
import com.nextcloud.talk.adapters.items.UserItem;
import com.nextcloud.talk.api.NcApi;
@ -120,6 +120,15 @@ public class ContactsController extends BaseController implements SearchView.OnQ
@Inject
EventBus eventBus;
@BindView(R.id.call_header_layout)
public RelativeLayout callHeaderLayout;
@BindView(R.id.initial_relative_layout)
public RelativeLayout initialRelativeLayout;
@BindView(R.id.secondary_relative_layout)
public RelativeLayout secondaryRelativeLayout;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@ -153,7 +162,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
private boolean isNewConversationView;
private boolean isPublicCall;
private HashMap<String, UserHeaderItem> userHeaderItems = new HashMap<String, UserHeaderItem>();
private HashMap<String, UserHeaderItem> userHeaderItems = new HashMap<>();
public ContactsController() {
super();
@ -170,7 +179,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
@Override
protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
return inflater.inflate(R.layout.controller_generic_rv, container, false);
return inflater.inflate(R.layout.controller_contacts_rv, container, false);
}
@Override
@ -466,7 +475,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
});
if (isNewConversationView) {
contactItems.add(0, new NewCallHeaderItem());
callHeaderLayout.setVisibility(View.VISIBLE);
} else {
callHeaderLayout.setVisibility(View.GONE);
}
adapter.updateDataSet(contactItems, true);
@ -743,12 +754,21 @@ public class ContactsController extends BaseController implements SearchView.OnQ
checkAndHandleBottomButtons();
}
} else if (adapter.getItem(position) instanceof NewCallHeaderItem) {
adapter.toggleSelection(position);
isPublicCall = adapter.isSelected(position);
((NewCallHeaderItem) adapter.getItem(position)).togglePublicCall(isPublicCall);
checkAndHandleBottomButtons();
}
return true;
}
@OnClick(R.id.call_header_layout)
private void toggleCallHeader() {
adapter.toggleSelection(0);
isPublicCall = adapter.isSelected(0);
if (!isPublicCall) {
secondaryRelativeLayout.setVisibility(View.GONE);
initialRelativeLayout.setVisibility(View.VISIBLE);
} else {
initialRelativeLayout.setVisibility(View.GONE);
secondaryRelativeLayout.setVisibility(View.VISIBLE);
}
checkAndHandleBottomButtons();
}
}

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Andy Scherzinger
~ Copyright (C) 2018 Andy Scherzinger
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/rv_item_call_header"/>
<include layout="@layout/controller_generic_rv" />
</LinearLayout>

View file

@ -21,6 +21,7 @@
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/generic_rv_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/nc_white_color">

View file

@ -21,6 +21,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/call_header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -32,25 +33,28 @@
<ImageView
android:id="@+id/public_call_link"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:layout_marginStart="24dp"
android:src="@drawable/ic_group_black_24px"/>
android:layout_marginEnd="8dp"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:contentDescription="@null"
android:src="@drawable/ic_group_black_24px"
android:tint="@color/colorPrimary" />
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="24dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_toEndOf="@id/public_call_link"
android:ellipsize="middle"
android:singleLine="true"
android:text="@string/nc_public_call"
android:textAppearance="?android:attr/textAppearanceListItem"
tools:text="@string/nc_public_call"/>
tools:text="@string/nc_public_call" />
</RelativeLayout>
@ -72,7 +76,7 @@
android:text="@string/nc_public_call_explanation"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceListItem"
tools:text="@string/nc_public_call_explanation"/>
tools:text="@string/nc_public_call_explanation" />
</RelativeLayout>
</RelativeLayout>