Content warnings now show/hide on all timelines.
This commit is contained in:
		
					parent
					
						
							
								1429dfc7b5
							
						
					
				
			
			
				commit
				
					
						2b6bc8a5c7
					
				
			
		
					 5 changed files with 88 additions and 14 deletions
				
			
		|  | @ -15,8 +15,6 @@ | |||
| 
 | ||||
| package com.keylesspalace.tusky; | ||||
| 
 | ||||
| import android.os.Build; | ||||
| import android.text.Html; | ||||
| import android.text.Spanned; | ||||
| 
 | ||||
| import org.json.JSONArray; | ||||
|  | @ -52,10 +50,11 @@ public class Status { | |||
|     private boolean reblogged; | ||||
|     /** whether the authenticated user has favourited this status */ | ||||
|     private boolean favourited; | ||||
|     private boolean sensitive; | ||||
|     private String spoilerText; | ||||
|     private Visibility visibility; | ||||
|     private MediaAttachment[] attachments; | ||||
|     private Mention[] mentions; | ||||
|     private boolean sensitive; | ||||
| 
 | ||||
|     public static final int MAX_MEDIA_ATTACHMENTS = 4; | ||||
| 
 | ||||
|  | @ -71,6 +70,7 @@ public class Status { | |||
|         this.createdAt = createdAt; | ||||
|         this.reblogged = reblogged; | ||||
|         this.favourited = favourited; | ||||
|         this.spoilerText = ""; | ||||
|         this.visibility = Visibility.valueOf(visibility.toUpperCase()); | ||||
|         this.attachments = new MediaAttachment[0]; | ||||
|         this.mentions = new Mention[0]; | ||||
|  | @ -116,6 +116,14 @@ public class Status { | |||
|         return favourited; | ||||
|     } | ||||
| 
 | ||||
|     public boolean getSensitive() { | ||||
|         return sensitive; | ||||
|     } | ||||
| 
 | ||||
|     public String getSpoilerText() { | ||||
|         return spoilerText; | ||||
|     } | ||||
| 
 | ||||
|     public Visibility getVisibility() { | ||||
|         return visibility; | ||||
|     } | ||||
|  | @ -128,10 +136,6 @@ public class Status { | |||
|         return mentions; | ||||
|     } | ||||
| 
 | ||||
|     public boolean getSensitive() { | ||||
|         return sensitive; | ||||
|     } | ||||
| 
 | ||||
|     public void setRebloggedByUsername(String name) { | ||||
|         rebloggedByUsername = name; | ||||
|     } | ||||
|  | @ -144,6 +148,10 @@ public class Status { | |||
|         this.favourited = favourited; | ||||
|     } | ||||
| 
 | ||||
|     public void setSpoilerText(String spoilerText) { | ||||
|         this.spoilerText = spoilerText; | ||||
|     } | ||||
| 
 | ||||
|     public void setMentions(Mention[] mentions) { | ||||
|         this.mentions = mentions; | ||||
|     } | ||||
|  | @ -188,6 +196,7 @@ public class Status { | |||
|         Date createdAt = parseDate(object.getString("created_at")); | ||||
|         boolean reblogged = object.getBoolean("reblogged"); | ||||
|         boolean favourited = object.getBoolean("favourited"); | ||||
|         String spoilerText = object.getString("spoiler_text"); | ||||
|         boolean sensitive = object.optBoolean("sensitive"); | ||||
|         String visibility = object.getString("visibility"); | ||||
| 
 | ||||
|  | @ -260,6 +269,9 @@ public class Status { | |||
|             if (attachments != null) { | ||||
|                 status.setAttachments(attachments, sensitive); | ||||
|             } | ||||
|             if (!spoilerText.isEmpty()) { | ||||
|                 status.setSpoilerText(spoilerText); | ||||
|             } | ||||
|         } | ||||
|         return status; | ||||
|     } | ||||
|  |  | |||
|  | @ -21,23 +21,19 @@ import android.support.v7.widget.RecyclerView; | |||
| import android.text.SpannableStringBuilder; | ||||
| import android.text.Spanned; | ||||
| import android.text.method.LinkMovementMethod; | ||||
| import android.text.method.MovementMethod; | ||||
| import android.text.style.ClickableSpan; | ||||
| import android.text.style.URLSpan; | ||||
| import android.text.util.Linkify; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.CompoundButton; | ||||
| import android.widget.ImageButton; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.TextView; | ||||
| import android.widget.ToggleButton; | ||||
| 
 | ||||
| import com.android.volley.toolbox.ImageLoader; | ||||
| import com.android.volley.toolbox.NetworkImageView; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.Date; | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
| 
 | ||||
| public class StatusViewHolder extends RecyclerView.ViewHolder { | ||||
|     private View container; | ||||
|  | @ -59,6 +55,9 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { | |||
|     private NetworkImageView mediaPreview2; | ||||
|     private NetworkImageView mediaPreview3; | ||||
|     private View sensitiveMediaWarning; | ||||
|     private View contentWarningBar; | ||||
|     private TextView contentWarningDescription; | ||||
|     private ToggleButton contentWarningButton; | ||||
| 
 | ||||
|     public StatusViewHolder(View itemView) { | ||||
|         super(itemView); | ||||
|  | @ -87,6 +86,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { | |||
|         mediaPreview2.setDefaultImageResId(R.drawable.media_preview_unloaded); | ||||
|         mediaPreview3.setDefaultImageResId(R.drawable.media_preview_unloaded); | ||||
|         sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning); | ||||
|         contentWarningBar = itemView.findViewById(R.id.status_content_warning_bar); | ||||
|         contentWarningDescription = | ||||
|                 (TextView) itemView.findViewById(R.id.status_content_warning_description); | ||||
|         contentWarningButton = | ||||
|                 (ToggleButton) itemView.findViewById(R.id.status_content_warning_button); | ||||
|     } | ||||
| 
 | ||||
|     public void setDisplayName(String name) { | ||||
|  | @ -258,6 +262,23 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { | |||
|         sensitiveMediaWarning.setVisibility(View.GONE); | ||||
|     } | ||||
| 
 | ||||
|     public void setSpoilerText(String spoilerText) { | ||||
|         contentWarningDescription.setText(spoilerText); | ||||
|         contentWarningBar.setVisibility(View.VISIBLE); | ||||
|         content.setVisibility(View.GONE); | ||||
|         contentWarningButton.setOnCheckedChangeListener( | ||||
|                 new CompoundButton.OnCheckedChangeListener() { | ||||
|                     @Override | ||||
|                     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | ||||
|                         if (isChecked) { | ||||
|                             content.setVisibility(View.VISIBLE); | ||||
|                         } else { | ||||
|                             content.setVisibility(View.GONE); | ||||
|                         } | ||||
|                     } | ||||
|                 }); | ||||
|     } | ||||
| 
 | ||||
|     public void setupButtons(final StatusActionListener listener, final int position) { | ||||
|         avatar.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|  | @ -329,5 +350,8 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { | |||
|         if (status.getVisibility() == Status.Visibility.PRIVATE) { | ||||
|             disableReblogging(); | ||||
|         } | ||||
|         if (!status.getSpoilerText().isEmpty()) { | ||||
|             setSpoilerText(status.getSpoilerText()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										6
									
								
								app/src/main/res/drawable/toggle_small.xml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								app/src/main/res/drawable/toggle_small.xml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:shape="rectangle"> | ||||
|     <solid android:color="#ffafafaf" /> | ||||
|     <corners android:radius="2dp" /> | ||||
| </shape> | ||||
|  | @ -69,13 +69,43 @@ | |||
| 
 | ||||
|     </LinearLayout> | ||||
| 
 | ||||
|     <LinearLayout | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:orientation="horizontal" | ||||
|         android:id="@+id/status_content_warning_bar" | ||||
|         android:visibility="gone" | ||||
|         android:layout_toRightOf="@+id/status_avatar" | ||||
|         android:layout_toEndOf="@+id/status_avatar" | ||||
|         android:layout_below="@+id/status_name_bar" | ||||
|         android:layout_marginBottom="8dp"> | ||||
| 
 | ||||
|         <TextView | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:id="@+id/status_content_warning_description" /> | ||||
| 
 | ||||
|         <ToggleButton | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:minWidth="0dp" | ||||
|             android:minHeight="0dp" | ||||
|             android:id="@+id/status_content_warning_button" | ||||
|             android:textOn="@string/status_content_warning_show_less" | ||||
|             android:textOff="@string/status_content_warning_show_more" | ||||
|             android:background="@drawable/toggle_small" | ||||
|             android:padding="4dp" | ||||
|             android:layout_marginLeft="8dp"/> | ||||
| 
 | ||||
|     </LinearLayout> | ||||
| 
 | ||||
|     <TextView | ||||
|         android:id="@+id/status_content" | ||||
|         android:layout_width="wrap_content" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_toRightOf="@+id/status_avatar" | ||||
|         android:layout_toEndOf="@+id/status_avatar" | ||||
|         android:layout_below="@+id/status_name_bar" /> | ||||
|         android:layout_below="@+id/status_content_warning_bar" /> | ||||
| 
 | ||||
|     <LinearLayout | ||||
|         android:id="@+id/status_media_preview_container" | ||||
|  |  | |||
|  | @ -67,6 +67,8 @@ | |||
|     <string name="status_boosted_format">%s boosted</string> | ||||
|     <string name="status_sensitive_media_title">Sensitive Media</string> | ||||
|     <string name="status_sensitive_media_directions">Click to view.</string> | ||||
|     <string name="status_content_warning_show_more">Show More</string> | ||||
|     <string name="status_content_warning_show_less">Show Less</string> | ||||
| 
 | ||||
|     <string name="footer_retry_statuses">Could not load the rest of the statuses.</string> | ||||
|     <string name="footer_retry_notifications">Could not load the rest of the statuses.</string> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue