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;
|
||||
|
||||
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.valueobject.Label;
|
||||
|
||||
import static ch.dissem.apps.abit.util.Strings.normalizeWhitespaces;
|
||||
|
||||
/**
|
||||
* Adapted from the basic swipeable example by Haruki Hasegawa. See
|
||||
*
|
||||
* @author Christian Basler
|
||||
* @see <a href="https://github.com/h6ah4i/android-advancedrecyclerview">
|
||||
* https://github.com/h6ah4i/android-advancedrecyclerview</a>
|
||||
*/
|
||||
public class SwipeableMessageAdapter
|
||||
extends RecyclerView.Adapter<SwipeableMessageAdapter.MyViewHolder>
|
||||
implements SwipeableItemAdapter<SwipeableMessageAdapter.MyViewHolder>, SwipeableItemConstants {
|
||||
extends RecyclerView.Adapter<SwipeableMessageAdapter.ViewHolder>
|
||||
implements SwipeableItemAdapter<SwipeableMessageAdapter.ViewHolder>, SwipeableItemConstants {
|
||||
|
||||
private List<Plaintext> data = Collections.emptyList();
|
||||
private EventListener eventListener;
|
||||
@ -48,14 +71,14 @@ public class SwipeableMessageAdapter
|
||||
void onItemViewClicked(View v, boolean pinned);
|
||||
}
|
||||
|
||||
public static class MyViewHolder extends AbstractSwipeableItemViewHolder {
|
||||
public static class ViewHolder extends AbstractSwipeableItemViewHolder {
|
||||
public FrameLayout container;
|
||||
public final ImageView avatar;
|
||||
public final TextView sender;
|
||||
public final TextView subject;
|
||||
public final TextView extract;
|
||||
|
||||
public MyViewHolder(View v) {
|
||||
public ViewHolder(View v) {
|
||||
super(v);
|
||||
container = (FrameLayout) v.findViewById(R.id.container);
|
||||
avatar = (ImageView) v.findViewById(R.id.avatar);
|
||||
@ -117,14 +140,14 @@ public class SwipeableMessageAdapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
final View v = inflater.inflate(R.layout.message_row, parent, false);
|
||||
return new MyViewHolder(v);
|
||||
return new ViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MyViewHolder holder, int position) {
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
final Plaintext item = data.get(position);
|
||||
|
||||
// set listeners
|
||||
@ -136,8 +159,8 @@ public class SwipeableMessageAdapter
|
||||
// set data
|
||||
holder.avatar.setImageDrawable(new Identicon(item.getFrom()));
|
||||
holder.sender.setText(item.getFrom().toString());
|
||||
holder.subject.setText(item.getSubject());
|
||||
holder.extract.setText(item.getText());
|
||||
holder.subject.setText(normalizeWhitespaces(item.getSubject()));
|
||||
holder.extract.setText(normalizeWhitespaces(item.getText()));
|
||||
if (item.isUnread()) {
|
||||
holder.sender.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
holder.subject.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
@ -153,22 +176,16 @@ public class SwipeableMessageAdapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(MyViewHolder holder, int position, int x, int y) {
|
||||
if (label == null) {
|
||||
return REACTION_CAN_NOT_SWIPE_BOTH_H_WITH_RUBBER_BAND_EFFECT;
|
||||
}
|
||||
if (label.getType() == Label.Type.TRASH) {
|
||||
public int onGetSwipeReactionType(ViewHolder holder, int position, int x, int y) {
|
||||
if (label == null || label.getType() == Label.Type.TRASH) {
|
||||
return REACTION_CAN_SWIPE_LEFT | REACTION_CAN_NOT_SWIPE_RIGHT_WITH_RUBBER_BAND_EFFECT;
|
||||
}
|
||||
return REACTION_CAN_SWIPE_BOTH_H;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(MyViewHolder holder, int position, int type) {
|
||||
public void onSetSwipeBackground(ViewHolder holder, int position, int type) {
|
||||
int bgRes = 0;
|
||||
if (label == null) {
|
||||
bgRes = R.drawable.bg_swipe_item_neutral;
|
||||
} else {
|
||||
switch (type) {
|
||||
case DRAWABLE_SWIPE_NEUTRAL_BACKGROUND:
|
||||
bgRes = R.drawable.bg_swipe_item_neutral;
|
||||
@ -177,19 +194,18 @@ public class SwipeableMessageAdapter
|
||||
bgRes = R.drawable.bg_swipe_item_left;
|
||||
break;
|
||||
case DRAWABLE_SWIPE_RIGHT_BACKGROUND:
|
||||
if (label.getType() == Label.Type.TRASH) {
|
||||
if (label == null || 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwipeResultAction onSwipeItem(MyViewHolder holder, final int position, int result) {
|
||||
public SwipeResultAction onSwipeItem(ViewHolder holder, final int position, int result) {
|
||||
switch (result) {
|
||||
// swipe 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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_item_normal_state"
|
||||
android:clickable="true"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:background="@drawable/bg_item_normal_state"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<RelativeLayout 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_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/avatar"
|
||||
@ -48,8 +49,9 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sender"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignTop="@+id/avatar"
|
||||
android:layout_marginTop="-5dp"
|
||||
android:layout_toEndOf="@+id/avatar"
|
||||
@ -66,8 +68,9 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subject"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@+id/sender"
|
||||
android:layout_toEndOf="@+id/avatar"
|
||||
android:ellipsize="end"
|
||||
@ -79,8 +82,9 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@+id/subject"
|
||||
android:layout_toEndOf="@+id/avatar"
|
||||
android:ellipsize="end"
|
||||
|
Loading…
Reference in New Issue
Block a user