|
| 1 | +package at.blogc.android.adapters.viewholders; |
| 2 | + |
| 3 | +import android.support.v7.widget.RecyclerView; |
| 4 | +import android.view.View; |
| 5 | +import android.view.animation.OvershootInterpolator; |
| 6 | +import android.widget.Button; |
| 7 | + |
| 8 | +import at.blogc.android.views.ExpandableTextView; |
| 9 | +import at.blogc.android.views.R; |
| 10 | + |
| 11 | +/** |
| 12 | + * Copyright (C) 2017 Cliff Ophalvens (Blogc.at) |
| 13 | + * |
| 14 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 15 | + * you may not use this file except in compliance with the License. |
| 16 | + * You may obtain a copy of the License at |
| 17 | + * |
| 18 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | + * |
| 20 | + * Unless required by applicable law or agreed to in writing, software |
| 21 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 22 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | + * See the License for the specific language governing permissions and |
| 24 | + * limitations under the License. |
| 25 | + */ |
| 26 | +public class ExpandableTextViewHolder extends RecyclerView.ViewHolder |
| 27 | + implements View.OnClickListener |
| 28 | +{ |
| 29 | + private final ExpandableTextView expandableTextView; |
| 30 | + private final Button buttonToggle; |
| 31 | + |
| 32 | + public ExpandableTextViewHolder(final View itemView) |
| 33 | + { |
| 34 | + super(itemView); |
| 35 | + |
| 36 | + // find views |
| 37 | + this.expandableTextView = itemView.findViewById(R.id.expandableTextView); |
| 38 | + this.buttonToggle = itemView.findViewById(R.id.button_toggle); |
| 39 | + |
| 40 | + // set interpolators for both expanding and collapsing animations |
| 41 | + this.expandableTextView.setInterpolator(new OvershootInterpolator()); |
| 42 | + |
| 43 | + // toggle the ExpandableTextView |
| 44 | + this.buttonToggle.setOnClickListener(this); |
| 45 | + } |
| 46 | + |
| 47 | + public void bindPosition(final int position) |
| 48 | + { |
| 49 | + final String loremIpsum = position + ": " + this.itemView.getContext().getString(R.string.lorem_ipsum); |
| 50 | + this.expandableTextView.setText(loremIpsum); |
| 51 | + } |
| 52 | + |
| 53 | + //region View.OnClickListener interface |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onClick(final View v) |
| 57 | + { |
| 58 | + this.buttonToggle.setText(this.expandableTextView.isExpanded() ? R.string.expand : R.string.collapse); |
| 59 | + this.expandableTextView.toggle(); |
| 60 | + } |
| 61 | + |
| 62 | + //endregion |
| 63 | +} |
0 commit comments