Fixed garbage shown on older devices when the ellipsized value had line breaks in them
This commit is contained in:
parent
cc4c16e970
commit
5ea317c295
@ -1,3 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Haruki Hasegawa
|
||||||
|
* Copyright 2016 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package ch.dissem.apps.abit.adapter;
|
package ch.dissem.apps.abit.adapter;
|
||||||
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
@ -26,12 +43,18 @@ import ch.dissem.apps.abit.R;
|
|||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
|
|
||||||
|
import static ch.dissem.apps.abit.util.Strings.normalizeWhitespaces;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Adapted from the basic swipeable example by Haruki Hasegawa. See
|
||||||
|
*
|
||||||
* @author Christian Basler
|
* @author Christian Basler
|
||||||
|
* @see <a href="https://github.com/h6ah4i/android-advancedrecyclerview">
|
||||||
|
* https://github.com/h6ah4i/android-advancedrecyclerview</a>
|
||||||
*/
|
*/
|
||||||
public class SwipeableMessageAdapter
|
public class SwipeableMessageAdapter
|
||||||
extends RecyclerView.Adapter<SwipeableMessageAdapter.MyViewHolder>
|
extends RecyclerView.Adapter<SwipeableMessageAdapter.ViewHolder>
|
||||||
implements SwipeableItemAdapter<SwipeableMessageAdapter.MyViewHolder>, SwipeableItemConstants {
|
implements SwipeableItemAdapter<SwipeableMessageAdapter.ViewHolder>, SwipeableItemConstants {
|
||||||
|
|
||||||
private List<Plaintext> data = Collections.emptyList();
|
private List<Plaintext> data = Collections.emptyList();
|
||||||
private EventListener eventListener;
|
private EventListener eventListener;
|
||||||
@ -48,14 +71,14 @@ public class SwipeableMessageAdapter
|
|||||||
void onItemViewClicked(View v, boolean pinned);
|
void onItemViewClicked(View v, boolean pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MyViewHolder extends AbstractSwipeableItemViewHolder {
|
public static class ViewHolder extends AbstractSwipeableItemViewHolder {
|
||||||
public FrameLayout container;
|
public FrameLayout container;
|
||||||
public final ImageView avatar;
|
public final ImageView avatar;
|
||||||
public final TextView sender;
|
public final TextView sender;
|
||||||
public final TextView subject;
|
public final TextView subject;
|
||||||
public final TextView extract;
|
public final TextView extract;
|
||||||
|
|
||||||
public MyViewHolder(View v) {
|
public ViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
container = (FrameLayout) v.findViewById(R.id.container);
|
container = (FrameLayout) v.findViewById(R.id.container);
|
||||||
avatar = (ImageView) v.findViewById(R.id.avatar);
|
avatar = (ImageView) v.findViewById(R.id.avatar);
|
||||||
@ -117,14 +140,14 @@ public class SwipeableMessageAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||||
final View v = inflater.inflate(R.layout.message_row, parent, false);
|
final View v = inflater.inflate(R.layout.message_row, parent, false);
|
||||||
return new MyViewHolder(v);
|
return new ViewHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(MyViewHolder holder, int position) {
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
final Plaintext item = data.get(position);
|
final Plaintext item = data.get(position);
|
||||||
|
|
||||||
// set listeners
|
// set listeners
|
||||||
@ -136,8 +159,8 @@ public class SwipeableMessageAdapter
|
|||||||
// set data
|
// set data
|
||||||
holder.avatar.setImageDrawable(new Identicon(item.getFrom()));
|
holder.avatar.setImageDrawable(new Identicon(item.getFrom()));
|
||||||
holder.sender.setText(item.getFrom().toString());
|
holder.sender.setText(item.getFrom().toString());
|
||||||
holder.subject.setText(item.getSubject());
|
holder.subject.setText(normalizeWhitespaces(item.getSubject()));
|
||||||
holder.extract.setText(item.getText());
|
holder.extract.setText(normalizeWhitespaces(item.getText()));
|
||||||
if (item.isUnread()) {
|
if (item.isUnread()) {
|
||||||
holder.sender.setTypeface(Typeface.DEFAULT_BOLD);
|
holder.sender.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
holder.subject.setTypeface(Typeface.DEFAULT_BOLD);
|
holder.subject.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
@ -153,43 +176,36 @@ public class SwipeableMessageAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onGetSwipeReactionType(MyViewHolder holder, int position, int x, int y) {
|
public int onGetSwipeReactionType(ViewHolder holder, int position, int x, int y) {
|
||||||
if (label == null) {
|
if (label == null || label.getType() == Label.Type.TRASH) {
|
||||||
return REACTION_CAN_NOT_SWIPE_BOTH_H_WITH_RUBBER_BAND_EFFECT;
|
|
||||||
}
|
|
||||||
if (label.getType() == Label.Type.TRASH) {
|
|
||||||
return REACTION_CAN_SWIPE_LEFT | REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT;
|
return REACTION_CAN_SWIPE_LEFT | REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT;
|
||||||
}
|
}
|
||||||
return REACTION_CAN_SWIPE_BOTH_H;
|
return REACTION_CAN_SWIPE_BOTH_H;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetSwipeBackground(MyViewHolder holder, int position, int type) {
|
public void onSetSwipeBackground(ViewHolder holder, int position, int type) {
|
||||||
int bgRes = 0;
|
int bgRes = 0;
|
||||||
if (label == null) {
|
switch (type) {
|
||||||
bgRes = R.drawable.bg_swipe_item_neutral;
|
case DRAWABLE_SWIPE_NEUTRAL_BACKGROUND:
|
||||||
} else {
|
bgRes = R.drawable.bg_swipe_item_neutral;
|
||||||
switch (type) {
|
break;
|
||||||
case DRAWABLE_SWIPE_NEUTRAL_BACKGROUND:
|
case DRAWABLE_SWIPE_LEFT_BACKGROUND:
|
||||||
|
bgRes = R.drawable.bg_swipe_item_left;
|
||||||
|
break;
|
||||||
|
case DRAWABLE_SWIPE_RIGHT_BACKGROUND:
|
||||||
|
if (label == null || label.getType() == Label.Type.TRASH) {
|
||||||
bgRes = R.drawable.bg_swipe_item_neutral;
|
bgRes = R.drawable.bg_swipe_item_neutral;
|
||||||
break;
|
} else {
|
||||||
case DRAWABLE_SWIPE_LEFT_BACKGROUND:
|
bgRes = R.drawable.bg_swipe_item_right;
|
||||||
bgRes = R.drawable.bg_swipe_item_left;
|
}
|
||||||
break;
|
break;
|
||||||
case DRAWABLE_SWIPE_RIGHT_BACKGROUND:
|
|
||||||
if (label.getType() == Label.Type.TRASH) {
|
|
||||||
bgRes = R.drawable.bg_swipe_item_neutral;
|
|
||||||
} else {
|
|
||||||
bgRes = R.drawable.bg_swipe_item_right;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
holder.itemView.setBackgroundResource(bgRes);
|
holder.itemView.setBackgroundResource(bgRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SwipeResultAction onSwipeItem(MyViewHolder holder, final int position, int result) {
|
public SwipeResultAction onSwipeItem(ViewHolder holder, final int position, int result) {
|
||||||
switch (result) {
|
switch (result) {
|
||||||
// swipe right
|
// swipe right
|
||||||
case RESULT_SWIPED_RIGHT:
|
case RESULT_SWIPED_RIGHT:
|
||||||
|
31
app/src/main/java/ch/dissem/apps/abit/util/Strings.java
Normal file
31
app/src/main/java/ch/dissem/apps/abit/util/Strings.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 Christian Basler
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.dissem.apps.abit.util;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christian Basler
|
||||||
|
*/
|
||||||
|
public class Strings {
|
||||||
|
private final static Pattern WHITESPACES = Pattern.compile("\\s+");
|
||||||
|
|
||||||
|
public static String normalizeWhitespaces(CharSequence string) {
|
||||||
|
string = string.subSequence(0, Math.min(string.length(), 200));
|
||||||
|
return WHITESPACES.matcher(string).replaceAll(" ");
|
||||||
|
}
|
||||||
|
}
|
@ -26,15 +26,16 @@
|
|||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/bg_item_normal_state"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:foreground="?attr/selectableItemBackground"
|
android:foreground="?attr/selectableItemBackground"
|
||||||
android:background="@drawable/bg_item_normal_state"
|
|
||||||
tools:ignore="UselessParent">
|
tools:ignore="UselessParent">
|
||||||
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/avatar"
|
android:id="@+id/avatar"
|
||||||
@ -48,8 +49,9 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/sender"
|
android:id="@+id/sender"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignTop="@+id/avatar"
|
android:layout_alignTop="@+id/avatar"
|
||||||
android:layout_marginTop="-5dp"
|
android:layout_marginTop="-5dp"
|
||||||
android:layout_toEndOf="@+id/avatar"
|
android:layout_toEndOf="@+id/avatar"
|
||||||
@ -66,8 +68,9 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subject"
|
android:id="@+id/subject"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_below="@+id/sender"
|
android:layout_below="@+id/sender"
|
||||||
android:layout_toEndOf="@+id/avatar"
|
android:layout_toEndOf="@+id/avatar"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
@ -79,8 +82,9 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text"
|
android:id="@+id/text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_below="@+id/subject"
|
android:layout_below="@+id/subject"
|
||||||
android:layout_toEndOf="@+id/avatar"
|
android:layout_toEndOf="@+id/avatar"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
|
Loading…
Reference in New Issue
Block a user