A bit of code cleanup, mostly getting rid of warnings.

This commit is contained in:
Vavassor 2017-02-22 14:13:51 -05:00
parent c4114b6be2
commit 46fe328967
32 changed files with 207 additions and 177 deletions

View File

@ -24,17 +24,17 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Account { class Account {
public String id; String id;
public String username; String username;
public String displayName; String displayName;
public Spanned note; Spanned note;
public String url; String url;
public String avatar; String avatar;
public String header; String header;
public String followersCount; String followersCount;
public String followingCount; String followingCount;
public String statusesCount; String statusesCount;
public static Account parse(JSONObject object) throws JSONException { public static Account parse(JSONObject object) throws JSONException {
Account account = new Account(); Account account = new Account();

View File

@ -15,7 +15,7 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
public interface AccountActionListener { interface AccountActionListener {
void onViewAccount(String id); void onViewAccount(String id);
void onBlock(final boolean block, final String id, final int position); void onBlock(final boolean block, final String id, final int position);
} }

View File

@ -31,6 +31,7 @@ import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.android.volley.AuthFailureError; import com.android.volley.AuthFailureError;
@ -96,8 +97,8 @@ public class AccountActivity extends BaseActivity {
} }
// Setup the tabs and timeline pager. // Setup the tabs and timeline pager.
AccountPagerAdapter adapter = new AccountPagerAdapter( AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this,
getSupportFragmentManager(), this, accountId); accountId);
String[] pageTitles = { String[] pageTitles = {
getString(R.string.title_statuses), getString(R.string.title_statuses),
getString(R.string.title_follows), getString(R.string.title_follows),
@ -115,7 +116,7 @@ public class AccountActivity extends BaseActivity {
for (int i = 0; i < tabLayout.getTabCount(); i++) { for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i); TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) { if (tab != null) {
tab.setCustomView(adapter.getTabView(i)); tab.setCustomView(adapter.getTabView(i, tabLayout));
} }
} }
} }

View File

@ -21,20 +21,21 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
public class AccountPagerAdapter extends FragmentPagerAdapter { class AccountPagerAdapter extends FragmentPagerAdapter {
private Context context; private Context context;
private String accountId; private String accountId;
private String[] pageTitles; private String[] pageTitles;
public AccountPagerAdapter(FragmentManager manager, Context context, String accountId) { AccountPagerAdapter(FragmentManager manager, Context context, String accountId) {
super(manager); super(manager);
this.context = context; this.context = context;
this.accountId = accountId; this.accountId = accountId;
} }
public void setPageTitles(String[] titles) { void setPageTitles(String[] titles) {
pageTitles = titles; pageTitles = titles;
} }
@ -66,8 +67,8 @@ public class AccountPagerAdapter extends FragmentPagerAdapter {
return pageTitles[position]; return pageTitles[position];
} }
public View getTabView(int position) { View getTabView(int position, ViewGroup root) {
View view = LayoutInflater.from(context).inflate(R.layout.tab_account, null); View view = LayoutInflater.from(context).inflate(R.layout.tab_account, root, false);
TextView title = (TextView) view.findViewById(R.id.title); TextView title = (TextView) view.findViewById(R.id.title);
title.setText(pageTitles[position]); title.setText(pageTitles[position]);
return view; return view;

View File

@ -15,6 +15,6 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
public interface AdapterItemRemover { interface AdapterItemRemover {
void removeItem(int position); void removeItem(int position);
} }

View File

@ -0,0 +1,27 @@
/* Copyright 2017 Andrew Dawson
*
* This file is part of Tusky.
*
* Tusky 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.
*
* Tusky 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 Tusky. If not, see
* <http://www.gnu.org/licenses/>. */
package com.keylesspalace.tusky;
/** Android Studio complains about built-in assertions so here's this is an alternative. */
class Assert {
private static boolean ENABLED = BuildConfig.DEBUG;
static void expect(boolean expression) {
if (ENABLED && !expression) {
throw new AssertionError();
}
}
}

View File

@ -81,7 +81,7 @@ class BlocksAdapter extends AccountAdapter {
} }
} }
public void setBlocked(boolean blocked, int position) { void setBlocked(boolean blocked, int position) {
if (blocked) { if (blocked) {
unblockedAccountPositions.remove(position); unblockedAccountPositions.remove(position);
} else { } else {

View File

@ -39,6 +39,7 @@ import android.os.Parcelable;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -174,14 +175,15 @@ public class ComposeActivity extends BaseActivity {
}; };
} }
private void doErrorDialog(int descriptionId, int actionId, View.OnClickListener listener) { private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
View.OnClickListener listener) {
Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), getString(descriptionId), Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), getString(descriptionId),
Snackbar.LENGTH_SHORT); Snackbar.LENGTH_SHORT);
bar.setAction(actionId, listener); bar.setAction(actionId, listener);
bar.show(); bar.show();
} }
private void displayTransientError(int stringId) { private void displayTransientError(@StringRes int stringId) {
Snackbar.make(findViewById(R.id.activity_compose), stringId, Snackbar.LENGTH_LONG).show(); Snackbar.make(findViewById(R.id.activity_compose), stringId, Snackbar.LENGTH_LONG).show();
} }

View File

@ -15,24 +15,24 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
public class CountUpDownLatch { class CountUpDownLatch {
private int count; private int count;
public CountUpDownLatch() { CountUpDownLatch() {
this.count = 0; this.count = 0;
} }
public synchronized void countDown() { synchronized void countDown() {
count--; count--;
notifyAll(); notifyAll();
} }
public synchronized void countUp() { synchronized void countUp() {
count++; count++;
notifyAll(); notifyAll();
} }
public synchronized void await() throws InterruptedException { synchronized void await() throws InterruptedException {
while (count != 0) { while (count != 0) {
wait(); wait();
} }

View File

@ -15,10 +15,10 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
public class DateUtils { class DateUtils {
/* This is a rough duplicate of android.text.format.DateUtils.getRelativeTimeSpanString, /* This is a rough duplicate of android.text.format.DateUtils.getRelativeTimeSpanString,
* but even with the FORMAT_ABBREV_RELATIVE flag it wasn't abbreviating enough. */ * but even with the FORMAT_ABBREV_RELATIVE flag it wasn't abbreviating enough. */
public static String getRelativeTimeSpanString(long then, long now) { static String getRelativeTimeSpanString(long then, long now) {
final long MINUTE = 60; final long MINUTE = 60;
final long HOUR = 60 * MINUTE; final long HOUR = 60 * MINUTE;
final long DAY = 24 * HOUR; final long DAY = 24 * HOUR;

View File

@ -22,17 +22,17 @@ import java.io.ByteArrayOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DownsizeImageTask extends AsyncTask<Bitmap, Void, Boolean> { class DownsizeImageTask extends AsyncTask<Bitmap, Void, Boolean> {
private Listener listener; private Listener listener;
private int sizeLimit; private int sizeLimit;
private List<byte[]> resultList; private List<byte[]> resultList;
public DownsizeImageTask(int sizeLimit, Listener listener) { DownsizeImageTask(int sizeLimit, Listener listener) {
this.listener = listener; this.listener = listener;
this.sizeLimit = sizeLimit; this.sizeLimit = sizeLimit;
} }
public static Bitmap scaleDown(Bitmap source, float maxImageSize, boolean filter) { private static Bitmap scaleDown(Bitmap source, float maxImageSize, boolean filter) {
float ratio = Math.min(maxImageSize / source.getWidth(), maxImageSize / source.getHeight()); float ratio = Math.min(maxImageSize / source.getWidth(), maxImageSize / source.getHeight());
int width = Math.round(ratio * source.getWidth()); int width = Math.round(ratio * source.getWidth());
int height = Math.round(ratio * source.getHeight()); int height = Math.round(ratio * source.getHeight());
@ -67,7 +67,7 @@ public class DownsizeImageTask extends AsyncTask<Bitmap, Void, Boolean> {
scaledImageSize /= 2; scaledImageSize /= 2;
iterations++; iterations++;
} while (stream.size() > sizeLimit); } while (stream.size() > sizeLimit);
assert(iterations < 3); Assert.expect(iterations < 3);
resultList.add(stream.toByteArray()); resultList.add(stream.toByteArray());
if (isCancelled()) { if (isCancelled()) {
return false; return false;

View File

@ -18,16 +18,20 @@ package com.keylesspalace.tusky;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
public abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListener { abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListener {
private int visibleThreshold = 15; private static final int VISIBLE_THRESHOLD = 15;
private int currentPage = 0; private int currentPage;
private int previousTotalItemCount = 0; private int previousTotalItemCount;
private boolean loading = true; private boolean loading;
private int startingPageIndex = 0; private int startingPageIndex;
private LinearLayoutManager layoutManager; private LinearLayoutManager layoutManager;
public EndlessOnScrollListener(LinearLayoutManager layoutManager) { EndlessOnScrollListener(LinearLayoutManager layoutManager) {
this.layoutManager = layoutManager; this.layoutManager = layoutManager;
currentPage = 0;
previousTotalItemCount = 0;
loading = true;
startingPageIndex = 0;
} }
@Override @Override
@ -45,14 +49,14 @@ public abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListe
loading = false; loading = false;
previousTotalItemCount = totalItemCount; previousTotalItemCount = totalItemCount;
} }
if (!loading && lastVisibleItemPosition + visibleThreshold > totalItemCount) { if (!loading && lastVisibleItemPosition + VISIBLE_THRESHOLD > totalItemCount) {
currentPage++; currentPage++;
onLoadMore(currentPage, totalItemCount, view); onLoadMore(currentPage, totalItemCount, view);
loading = true; loading = true;
} }
} }
public void reset() { void reset() {
currentPage = startingPageIndex; currentPage = startingPageIndex;
previousTotalItemCount = 0; previousTotalItemCount = 0;
loading = true; loading = true;

View File

@ -45,7 +45,7 @@ public class FlowLayout extends ViewGroup {
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
assert (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED); Assert.expect(MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED);
int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight();
int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom(); int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom();
int count = getChildCount(); int count = getChildCount();

View File

@ -21,7 +21,7 @@ import android.widget.Button;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
public class FooterViewHolder extends RecyclerView.ViewHolder { class FooterViewHolder extends RecyclerView.ViewHolder {
private View retryBar; private View retryBar;
private TextView retryMessage; private TextView retryMessage;
private Button retry; private Button retry;
@ -34,7 +34,7 @@ public class FooterViewHolder extends RecyclerView.ViewHolder {
END_OF_TIMELINE, END_OF_TIMELINE,
} }
public FooterViewHolder(View itemView) { FooterViewHolder(View itemView) {
super(itemView); super(itemView);
retryBar = itemView.findViewById(R.id.footer_retry_bar); retryBar = itemView.findViewById(R.id.footer_retry_bar);
retryMessage = (TextView) itemView.findViewById(R.id.footer_retry_message); retryMessage = (TextView) itemView.findViewById(R.id.footer_retry_message);
@ -44,7 +44,7 @@ public class FooterViewHolder extends RecyclerView.ViewHolder {
endOfTimelineMessage = (TextView) itemView.findViewById(R.id.footer_end_of_timeline_text); endOfTimelineMessage = (TextView) itemView.findViewById(R.id.footer_end_of_timeline_text);
} }
public void setupButton(final FooterActionListener listener) { void setupButton(final FooterActionListener listener) {
retry.setOnClickListener(new View.OnClickListener() { retry.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -53,15 +53,15 @@ public class FooterViewHolder extends RecyclerView.ViewHolder {
}); });
} }
public void setRetryMessage(int messageId) { void setRetryMessage(int messageId) {
retryMessage.setText(messageId); retryMessage.setText(messageId);
} }
public void setEndOfTimelineMessage(int messageId) { void setEndOfTimelineMessage(int messageId) {
endOfTimelineMessage.setText(messageId); endOfTimelineMessage.setText(messageId);
} }
public void setState(State state) { void setState(State state) {
switch (state) { switch (state) {
case LOADING: { case LOADING: {
retryBar.setVisibility(View.GONE); retryBar.setVisibility(View.GONE);

View File

@ -19,7 +19,7 @@ import android.os.Build;
import android.text.Html; import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
public class HtmlUtils { class HtmlUtils {
private static CharSequence trimTrailingWhitespace(CharSequence s) { private static CharSequence trimTrailingWhitespace(CharSequence s) {
int i = s.length(); int i = s.length();
do { do {
@ -28,7 +28,7 @@ public class HtmlUtils {
return s.subSequence(0, i + 1); return s.subSequence(0, i + 1);
} }
public static Spanned fromHtml(String html) { static Spanned fromHtml(String html) {
Spanned result; Spanned result;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY); result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);

View File

@ -20,8 +20,8 @@ import android.support.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class IOUtils { class IOUtils {
public static void closeQuietly(@Nullable InputStream stream) { static void closeQuietly(@Nullable InputStream stream) {
try { try {
if (stream != null) { if (stream != null) {
stream.close(); stream.close();

View File

@ -63,7 +63,7 @@ public class MainActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
// Setup the tabs and timeline pager. // Setup the tabs and timeline pager.
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager(), this); TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
String[] pageTitles = { String[] pageTitles = {
getString(R.string.title_home), getString(R.string.title_home),
getString(R.string.title_notifications), getString(R.string.title_notifications),

View File

@ -29,14 +29,14 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
public class MultipartRequest extends Request<JSONObject> { class MultipartRequest extends Request<JSONObject> {
private static final String CHARSET = "utf-8"; private static final String CHARSET = "utf-8";
private final String boundary = "something-" + System.currentTimeMillis(); private final String boundary = "something-" + System.currentTimeMillis();
private JSONObject parameters; private JSONObject parameters;
private Response.Listener<JSONObject> listener; private Response.Listener<JSONObject> listener;
public MultipartRequest(int method, String url, JSONObject parameters, MultipartRequest(int method, String url, JSONObject parameters,
Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) { Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
super(method, url, errorListener); super(method, url, errorListener);
this.parameters = parameters; this.parameters = parameters;
@ -108,10 +108,10 @@ public class MultipartRequest extends Request<JSONObject> {
return null; return null;
} }
public static class DataItem { static class DataItem {
public String name; String name;
public String filename; String filename;
public String mimeType; String mimeType;
public byte[] content; byte[] content;
} }
} }

View File

@ -24,8 +24,8 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Notification { class Notification {
public enum Type { enum Type {
MENTION, MENTION,
REBLOG, REBLOG,
FAVOURITE, FAVOURITE,
@ -37,39 +37,39 @@ public class Notification {
/** Which of the user's statuses has been mentioned, reblogged, or favourited. */ /** Which of the user's statuses has been mentioned, reblogged, or favourited. */
private Status status; private Status status;
public Notification(Type type, String id, String displayName) { private Notification(Type type, String id, String displayName) {
this.type = type; this.type = type;
this.id = id; this.id = id;
this.displayName = displayName; this.displayName = displayName;
} }
public Type getType() { Type getType() {
return type; return type;
} }
public String getId() { String getId() {
return id; return id;
} }
public String getDisplayName() { String getDisplayName() {
return displayName; return displayName;
} }
public @Nullable Status getStatus() { @Nullable Status getStatus() {
return status; return status;
} }
public void setStatus(Status status) { void setStatus(Status status) {
this.status = status; this.status = status;
} }
public boolean hasStatusType() { private boolean hasStatusType() {
return type == Type.MENTION return type == Type.MENTION
|| type == Type.FAVOURITE || type == Type.FAVOURITE
|| type == Type.REBLOG; || type == Type.REBLOG;
} }
public static List<Notification> parse(JSONArray array) throws JSONException { static List<Notification> parse(JSONArray array) throws JSONException {
List<Notification> notifications = new ArrayList<>(); List<Notification> notifications = new ArrayList<>();
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i); JSONObject object = array.getJSONObject(i);

View File

@ -28,7 +28,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
public class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRemover { class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRemover {
private static final int VIEW_TYPE_MENTION = 0; private static final int VIEW_TYPE_MENTION = 0;
private static final int VIEW_TYPE_FOOTER = 1; private static final int VIEW_TYPE_FOOTER = 1;
private static final int VIEW_TYPE_STATUS_NOTIFICATION = 2; private static final int VIEW_TYPE_STATUS_NOTIFICATION = 2;
@ -39,7 +39,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
private FooterActionListener footerListener; private FooterActionListener footerListener;
private FooterViewHolder.State footerState; private FooterViewHolder.State footerState;
public NotificationsAdapter(StatusActionListener statusListener, NotificationsAdapter(StatusActionListener statusListener,
FooterActionListener footerListener) { FooterActionListener footerListener) {
super(); super();
notifications = new ArrayList<>(); notifications = new ArrayList<>();
@ -143,7 +143,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
return null; return null;
} }
public int update(List<Notification> new_notifications) { int update(List<Notification> new_notifications) {
int scrollToPosition; int scrollToPosition;
if (notifications == null || notifications.isEmpty()) { if (notifications == null || notifications.isEmpty()) {
notifications = new_notifications; notifications = new_notifications;
@ -162,7 +162,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
return scrollToPosition; return scrollToPosition;
} }
public void addItems(List<Notification> new_notifications) { void addItems(List<Notification> new_notifications) {
int end = notifications.size(); int end = notifications.size();
notifications.addAll(new_notifications); notifications.addAll(new_notifications);
notifyItemRangeInserted(end, new_notifications.size()); notifyItemRangeInserted(end, new_notifications.size());
@ -173,19 +173,19 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
notifyItemChanged(position); notifyItemChanged(position);
} }
public void setFooterState(FooterViewHolder.State state) { void setFooterState(FooterViewHolder.State state) {
footerState = state; footerState = state;
} }
public static class FollowViewHolder extends RecyclerView.ViewHolder { private static class FollowViewHolder extends RecyclerView.ViewHolder {
private TextView message; private TextView message;
public FollowViewHolder(View itemView) { FollowViewHolder(View itemView) {
super(itemView); super(itemView);
message = (TextView) itemView.findViewById(R.id.notification_text); message = (TextView) itemView.findViewById(R.id.notification_text);
} }
public void setMessage(String displayName) { void setMessage(String displayName) {
Context context = message.getContext(); Context context = message.getContext();
String format = context.getString(R.string.notification_follow_format); String format = context.getString(R.string.notification_follow_format);
String wholeMessage = String.format(format, displayName); String wholeMessage = String.format(format, displayName);
@ -193,19 +193,19 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte
} }
} }
public static class StatusNotificationViewHolder extends RecyclerView.ViewHolder { private static class StatusNotificationViewHolder extends RecyclerView.ViewHolder {
private TextView message; private TextView message;
private ImageView icon; private ImageView icon;
private TextView statusContent; private TextView statusContent;
public StatusNotificationViewHolder(View itemView) { StatusNotificationViewHolder(View itemView) {
super(itemView); super(itemView);
message = (TextView) itemView.findViewById(R.id.notification_text); message = (TextView) itemView.findViewById(R.id.notification_text);
icon = (ImageView) itemView.findViewById(R.id.notification_icon); icon = (ImageView) itemView.findViewById(R.id.notification_icon);
statusContent = (TextView) itemView.findViewById(R.id.notification_content); statusContent = (TextView) itemView.findViewById(R.id.notification_content);
} }
public void setMessage(Notification.Type type, String displayName, Status status) { void setMessage(Notification.Type type, String displayName, Status status) {
Context context = message.getContext(); Context context = message.getContext();
String format; String format;
switch (type) { switch (type) {

View File

@ -33,11 +33,7 @@ public class PreferencesActivity extends AppCompatActivity
themeSwitched = savedInstanceState.getBoolean("themeSwitched"); themeSwitched = savedInstanceState.getBoolean("themeSwitched");
} else { } else {
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { themeSwitched = extras != null && extras.getBoolean("themeSwitched");
themeSwitched = extras.getBoolean("themeSwitched");
} else {
themeSwitched = false;
}
} }
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

View File

@ -140,9 +140,9 @@ public class PullNotificationService extends IntentService {
} }
private static class MentionResult { private static class MentionResult {
public String displayName; String displayName;
public String content; String content;
public String avatarUrl; String avatarUrl;
} }
private String truncateWithEllipses(String string, int limit) { private String truncateWithEllipses(String string, int limit) {

View File

@ -56,7 +56,7 @@ public class Status {
private MediaAttachment[] attachments; private MediaAttachment[] attachments;
private Mention[] mentions; private Mention[] mentions;
public static final int MAX_MEDIA_ATTACHMENTS = 4; static final int MAX_MEDIA_ATTACHMENTS = 4;
public Status(String id, String accountId, String displayName, String username, Spanned content, public Status(String id, String accountId, String displayName, String username, Spanned content,
String avatar, Date createdAt, boolean reblogged, boolean favourited, String avatar, Date createdAt, boolean reblogged, boolean favourited,
@ -76,87 +76,87 @@ public class Status {
this.mentions = new Mention[0]; this.mentions = new Mention[0];
} }
public String getId() { String getId() {
return id; return id;
} }
public String getAccountId() { String getAccountId() {
return accountId; return accountId;
} }
public String getDisplayName() { String getDisplayName() {
return displayName; return displayName;
} }
public String getUsername() { String getUsername() {
return username; return username;
} }
public Spanned getContent() { Spanned getContent() {
return content; return content;
} }
public String getAvatar() { String getAvatar() {
return avatar; return avatar;
} }
public Date getCreatedAt() { Date getCreatedAt() {
return createdAt; return createdAt;
} }
public String getRebloggedByDisplayName() { String getRebloggedByDisplayName() {
return rebloggedByDisplayName; return rebloggedByDisplayName;
} }
public boolean getReblogged() { boolean getReblogged() {
return reblogged; return reblogged;
} }
public boolean getFavourited() { boolean getFavourited() {
return favourited; return favourited;
} }
public boolean getSensitive() { boolean getSensitive() {
return sensitive; return sensitive;
} }
public String getSpoilerText() { String getSpoilerText() {
return spoilerText; return spoilerText;
} }
public Visibility getVisibility() { Visibility getVisibility() {
return visibility; return visibility;
} }
public MediaAttachment[] getAttachments() { MediaAttachment[] getAttachments() {
return attachments; return attachments;
} }
public Mention[] getMentions() { Mention[] getMentions() {
return mentions; return mentions;
} }
public void setRebloggedByDisplayName(String name) { private void setRebloggedByDisplayName(String name) {
rebloggedByDisplayName = name; rebloggedByDisplayName = name;
} }
public void setReblogged(boolean reblogged) { void setReblogged(boolean reblogged) {
this.reblogged = reblogged; this.reblogged = reblogged;
} }
public void setFavourited(boolean favourited) { void setFavourited(boolean favourited) {
this.favourited = favourited; this.favourited = favourited;
} }
public void setSpoilerText(String spoilerText) { private void setSpoilerText(String spoilerText) {
this.spoilerText = spoilerText; this.spoilerText = spoilerText;
} }
public void setMentions(Mention[] mentions) { private void setMentions(Mention[] mentions) {
this.mentions = mentions; this.mentions = mentions;
} }
public void setAttachments(MediaAttachment[] attachments, boolean sensitive) { private void setAttachments(MediaAttachment[] attachments, boolean sensitive) {
this.attachments = attachments; this.attachments = attachments;
this.sensitive = sensitive; this.sensitive = sensitive;
} }
@ -285,7 +285,7 @@ public class Status {
return statuses; return statuses;
} }
public static class MediaAttachment { static class MediaAttachment {
enum Type { enum Type {
IMAGE, IMAGE,
VIDEO, VIDEO,
@ -295,45 +295,45 @@ public class Status {
private String previewUrl; private String previewUrl;
private Type type; private Type type;
public MediaAttachment(String url, String previewUrl, Type type) { MediaAttachment(String url, String previewUrl, Type type) {
this.url = url; this.url = url;
this.previewUrl = previewUrl; this.previewUrl = previewUrl;
this.type = type; this.type = type;
} }
public String getUrl() { String getUrl() {
return url; return url;
} }
public String getPreviewUrl() { String getPreviewUrl() {
return previewUrl; return previewUrl;
} }
public Type getType() { Type getType() {
return type; return type;
} }
} }
public static class Mention { static class Mention {
private String url; private String url;
private String username; private String username;
private String id; private String id;
public Mention(String url, String username, String id) { Mention(String url, String username, String id) {
this.url = url; this.url = url;
this.username = username; this.username = username;
this.id = id; this.id = id;
} }
public String getUrl() { String getUrl() {
return url; return url;
} }
public String getUsername() { String getUsername() {
return username; return username;
} }
public String getId() { String getId() {
return id; return id;
} }
} }

View File

@ -17,7 +17,7 @@ package com.keylesspalace.tusky;
import android.view.View; import android.view.View;
public interface StatusActionListener { interface StatusActionListener {
void onReply(int position); void onReply(int position);
void onReblog(final boolean reblog, final int position); void onReblog(final boolean reblog, final int position);
void onFavourite(final boolean favourite, final int position); void onFavourite(final boolean favourite, final int position);

View File

@ -34,7 +34,7 @@ import com.android.volley.toolbox.NetworkImageView;
import java.util.Date; import java.util.Date;
public class StatusViewHolder extends RecyclerView.ViewHolder { class StatusViewHolder extends RecyclerView.ViewHolder {
private View container; private View container;
private TextView displayName; private TextView displayName;
private TextView username; private TextView username;
@ -58,7 +58,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
private TextView contentWarningDescription; private TextView contentWarningDescription;
private ToggleButton contentWarningButton; private ToggleButton contentWarningButton;
public StatusViewHolder(View itemView) { StatusViewHolder(View itemView) {
super(itemView); super(itemView);
container = itemView.findViewById(R.id.status_container); container = itemView.findViewById(R.id.status_container);
displayName = (TextView) itemView.findViewById(R.id.status_display_name); displayName = (TextView) itemView.findViewById(R.id.status_display_name);
@ -94,18 +94,18 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
(ToggleButton) itemView.findViewById(R.id.status_content_warning_button); (ToggleButton) itemView.findViewById(R.id.status_content_warning_button);
} }
public void setDisplayName(String name) { private void setDisplayName(String name) {
displayName.setText(name); displayName.setText(name);
} }
public void setUsername(String name) { void setUsername(String name) {
Context context = username.getContext(); Context context = username.getContext();
String format = context.getString(R.string.status_username_format); String format = context.getString(R.string.status_username_format);
String usernameText = String.format(format, name); String usernameText = String.format(format, name);
username.setText(usernameText); username.setText(usernameText);
} }
public void setContent(Spanned content, Status.Mention[] mentions, private void setContent(Spanned content, Status.Mention[] mentions,
final StatusActionListener listener) { final StatusActionListener listener) {
/* Redirect URLSpan's in the status content to the listener for viewing tag pages and /* Redirect URLSpan's in the status content to the listener for viewing tag pages and
* account pages. */ * account pages. */
@ -154,7 +154,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
this.content.setMovementMethod(LinkMovementMethod.getInstance()); this.content.setMovementMethod(LinkMovementMethod.getInstance());
} }
public void setAvatar(String url) { private void setAvatar(String url) {
if (url.isEmpty()) { if (url.isEmpty()) {
return; return;
} }
@ -163,7 +163,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
avatar.setImageUrl(url, imageLoader); avatar.setImageUrl(url, imageLoader);
} }
public void setCreatedAt(@Nullable Date createdAt) { private void setCreatedAt(@Nullable Date createdAt) {
String readout; String readout;
if (createdAt != null) { if (createdAt != null) {
long then = createdAt.getTime(); long then = createdAt.getTime();
@ -175,7 +175,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
sinceCreated.setText(readout); sinceCreated.setText(readout);
} }
public void setRebloggedByDisplayName(String name) { private void setRebloggedByDisplayName(String name) {
Context context = rebloggedByDisplayName.getContext(); Context context = rebloggedByDisplayName.getContext();
String format = context.getString(R.string.status_boosted_format); String format = context.getString(R.string.status_boosted_format);
String boostedText = String.format(format, name); String boostedText = String.format(format, name);
@ -183,11 +183,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
rebloggedBar.setVisibility(View.VISIBLE); rebloggedBar.setVisibility(View.VISIBLE);
} }
public void hideRebloggedByDisplayName() { private void hideRebloggedByDisplayName() {
rebloggedBar.setVisibility(View.GONE); rebloggedBar.setVisibility(View.GONE);
} }
public void setReblogged(boolean reblogged) { private void setReblogged(boolean reblogged) {
this.reblogged = reblogged; this.reblogged = reblogged;
int attribute; int attribute;
if (reblogged) { if (reblogged) {
@ -199,7 +199,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
} }
/** This should only be called after setReblogged, in order to override the tint correctly. */ /** This should only be called after setReblogged, in order to override the tint correctly. */
public void setRebloggingEnabled(boolean enabled) { private void setRebloggingEnabled(boolean enabled) {
reblogButton.setEnabled(enabled); reblogButton.setEnabled(enabled);
if (enabled) { if (enabled) {
reblogButton.setImageResource(R.drawable.ic_reblog); reblogButton.setImageResource(R.drawable.ic_reblog);
@ -209,7 +209,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
} }
} }
public void setFavourited(boolean favourited) { private void setFavourited(boolean favourited) {
this.favourited = favourited; this.favourited = favourited;
int attribute; int attribute;
if (favourited) { if (favourited) {
@ -220,7 +220,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
ThemeUtils.setImageViewTint(favouriteButton, attribute); ThemeUtils.setImageViewTint(favouriteButton, attribute);
} }
public void setMediaPreviews(final Status.MediaAttachment[] attachments, private void setMediaPreviews(final Status.MediaAttachment[] attachments,
boolean sensitive, final StatusActionListener listener) { boolean sensitive, final StatusActionListener listener) {
final NetworkImageView[] previews = { final NetworkImageView[] previews = {
mediaPreview0, mediaPreview0,
@ -268,11 +268,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
} }
} }
public void hideSensitiveMediaWarning() { private void hideSensitiveMediaWarning() {
sensitiveMediaWarning.setVisibility(View.GONE); sensitiveMediaWarning.setVisibility(View.GONE);
} }
public void setSpoilerText(String spoilerText) { private void setSpoilerText(String spoilerText) {
contentWarningDescription.setText(spoilerText); contentWarningDescription.setText(spoilerText);
contentWarningBar.setVisibility(View.VISIBLE); contentWarningBar.setVisibility(View.VISIBLE);
content.setVisibility(View.GONE); content.setVisibility(View.GONE);
@ -289,12 +289,12 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
}); });
} }
public void hideSpoilerText() { private void hideSpoilerText() {
contentWarningBar.setVisibility(View.GONE); contentWarningBar.setVisibility(View.GONE);
content.setVisibility(View.VISIBLE); content.setVisibility(View.VISIBLE);
} }
public void setupButtons(final StatusActionListener listener, final int position) { private void setupButtons(final StatusActionListener listener, final int position) {
avatar.setOnClickListener(new View.OnClickListener() { avatar.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -339,7 +339,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
container.setOnClickListener(viewThreadListener); container.setOnClickListener(viewThreadListener);
} }
public void setupWithStatus(Status status, StatusActionListener listener, int position) { void setupWithStatus(Status status, StatusActionListener listener, int position) {
setDisplayName(status.getDisplayName()); setDisplayName(status.getDisplayName());
setUsername(status.getUsername()); setUsername(status.getUsername());
setCreatedAt(status.getCreatedAt()); setCreatedAt(status.getCreatedAt());

View File

@ -22,8 +22,8 @@ import android.support.v4.content.ContextCompat;
import android.util.TypedValue; import android.util.TypedValue;
import android.widget.ImageView; import android.widget.ImageView;
public class ThemeUtils { class ThemeUtils {
public static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) { static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) {
TypedValue value = new TypedValue(); TypedValue value = new TypedValue();
int resourceId; int resourceId;
if (context.getTheme().resolveAttribute(attribute, value, true)) { if (context.getTheme().resolveAttribute(attribute, value, true)) {
@ -34,7 +34,7 @@ public class ThemeUtils {
return ContextCompat.getDrawable(context, resourceId); return ContextCompat.getDrawable(context, resourceId);
} }
public static int getDrawableId(Context context, int attribute, int fallbackDrawableId) { static int getDrawableId(Context context, int attribute, int fallbackDrawableId) {
TypedValue value = new TypedValue(); TypedValue value = new TypedValue();
if (context.getTheme().resolveAttribute(attribute, value, true)) { if (context.getTheme().resolveAttribute(attribute, value, true)) {
return value.resourceId; return value.resourceId;
@ -43,7 +43,7 @@ public class ThemeUtils {
} }
} }
public static int getColor(Context context, int attribute) { static int getColor(Context context, int attribute) {
TypedValue value = new TypedValue(); TypedValue value = new TypedValue();
if (context.getTheme().resolveAttribute(attribute, value, true)) { if (context.getTheme().resolveAttribute(attribute, value, true)) {
return value.data; return value.data;
@ -52,7 +52,7 @@ public class ThemeUtils {
} }
} }
public static void setImageViewTint(ImageView view, int attribute) { static void setImageViewTint(ImageView view, int attribute) {
view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN); view.setColorFilter(getColor(view.getContext(), attribute), PorterDuff.Mode.SRC_IN);
} }
} }

View File

@ -23,12 +23,12 @@ import android.view.ViewGroup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover { class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover {
private List<Status> statuses; private List<Status> statuses;
private StatusActionListener statusActionListener; private StatusActionListener statusActionListener;
private int statusIndex; private int statusIndex;
public ThreadAdapter(StatusActionListener listener) { ThreadAdapter(StatusActionListener listener) {
this.statusActionListener = listener; this.statusActionListener = listener;
this.statuses = new ArrayList<>(); this.statuses = new ArrayList<>();
this.statusIndex = 0; this.statusIndex = 0;
@ -53,7 +53,7 @@ public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRe
return statuses.size(); return statuses.size();
} }
public Status getItem(int position) { Status getItem(int position) {
return statuses.get(position); return statuses.get(position);
} }
@ -62,20 +62,20 @@ public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRe
notifyItemRemoved(position); notifyItemRemoved(position);
} }
public int insertStatus(Status status) { int insertStatus(Status status) {
int i = statusIndex; int i = statusIndex;
statuses.add(i, status); statuses.add(i, status);
notifyItemInserted(i); notifyItemInserted(i);
return i; return i;
} }
public void addAncestors(List<Status> ancestors) { void addAncestors(List<Status> ancestors) {
statusIndex = ancestors.size(); statusIndex = ancestors.size();
statuses.addAll(0, ancestors); statuses.addAll(0, ancestors);
notifyItemRangeInserted(0, statusIndex); notifyItemRangeInserted(0, statusIndex);
} }
public void addDescendants(List<Status> descendants) { void addDescendants(List<Status> descendants) {
int end = statuses.size(); int end = statuses.size();
statuses.addAll(descendants); statuses.addAll(descendants);
notifyItemRangeInserted(end, descendants.size()); notifyItemRangeInserted(end, descendants.size());

View File

@ -24,7 +24,7 @@ import android.view.ViewGroup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover { class TimelineAdapter extends RecyclerView.Adapter implements AdapterItemRemover {
private static final int VIEW_TYPE_STATUS = 0; private static final int VIEW_TYPE_STATUS = 0;
private static final int VIEW_TYPE_FOOTER = 1; private static final int VIEW_TYPE_FOOTER = 1;
@ -33,7 +33,7 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem
private FooterActionListener footerListener; private FooterActionListener footerListener;
private FooterViewHolder.State footerState; private FooterViewHolder.State footerState;
public TimelineAdapter(StatusActionListener statusListener, TimelineAdapter(StatusActionListener statusListener,
FooterActionListener footerListener) { FooterActionListener footerListener) {
super(); super();
statuses = new ArrayList<>(); statuses = new ArrayList<>();
@ -88,7 +88,7 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem
} }
} }
public int update(List<Status> newStatuses) { int update(List<Status> newStatuses) {
int scrollToPosition; int scrollToPosition;
if (statuses == null || statuses.isEmpty()) { if (statuses == null || statuses.isEmpty()) {
statuses = newStatuses; statuses = newStatuses;
@ -107,7 +107,7 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem
return scrollToPosition; return scrollToPosition;
} }
public void addItems(List<Status> newStatuses) { void addItems(List<Status> newStatuses) {
int end = statuses.size(); int end = statuses.size();
statuses.addAll(newStatuses); statuses.addAll(newStatuses);
notifyItemRangeInserted(end, newStatuses.size()); notifyItemRangeInserted(end, newStatuses.size());
@ -118,14 +118,14 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem
notifyItemRemoved(position); notifyItemRemoved(position);
} }
public @Nullable Status getItem(int position) { @Nullable Status getItem(int position) {
if (position >= 0 && position < statuses.size()) { if (position >= 0 && position < statuses.size()) {
return statuses.get(position); return statuses.get(position);
} }
return null; return null;
} }
public void setFooterState(FooterViewHolder.State state) { void setFooterState(FooterViewHolder.State state) {
footerState = state; footerState = state;
} }
} }

View File

@ -314,8 +314,11 @@ public class TimelineFragment extends SFragment implements
public void onViewAccount(int position) { public void onViewAccount(int position) {
Status status = adapter.getItem(position); Status status = adapter.getItem(position);
String id = status.getAccountId(); Assert.expect(status != null);
String username = status.getUsername(); if (status != null) {
super.viewAccount(id, username); String id = status.getAccountId();
String username = status.getUsername();
super.viewAccount(id, username);
}
} }
} }

View File

@ -15,24 +15,18 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.content.Context;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
public class TimelinePagerAdapter extends FragmentPagerAdapter { class TimelinePagerAdapter extends FragmentPagerAdapter {
private String[] pageTitles; private String[] pageTitles;
private Context context;
public TimelinePagerAdapter(FragmentManager manager, Context context) { TimelinePagerAdapter(FragmentManager manager) {
super(manager); super(manager);
this.context = context;
} }
public void setPageTitles(String[] titles) { void setPageTitles(String[] titles) {
pageTitles = titles; pageTitles = titles;
} }

View File

@ -36,6 +36,8 @@ import org.json.JSONObject;
import java.util.List; import java.util.List;
public class ViewThreadFragment extends SFragment implements StatusActionListener { public class ViewThreadFragment extends SFragment implements StatusActionListener {
private static final String TAG = "ViewThread"; // logging tag
private RecyclerView recyclerView; private RecyclerView recyclerView;
private ThreadAdapter adapter; private ThreadAdapter adapter;
@ -113,8 +115,8 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene
} }
private void onThreadRequestFailure() { private void onThreadRequestFailure() {
Log.e(TAG, "The request to fetch the thread has failed.");
//TODO: no //TODO: no
assert(false);
} }
public void onReply(int position) { public void onReply(int position) {

View File

@ -56,7 +56,7 @@ public class VolleySingleton {
return instance; return instance;
} }
public RequestQueue getRequestQueue() { private RequestQueue getRequestQueue() {
if (requestQueue == null) { if (requestQueue == null) {
/* getApplicationContext() is key, it keeps you from leaking the /* getApplicationContext() is key, it keeps you from leaking the
* Activity or BroadcastReceiver if someone passes one in. */ * Activity or BroadcastReceiver if someone passes one in. */
@ -65,15 +65,15 @@ public class VolleySingleton {
return requestQueue; return requestQueue;
} }
public <T> void addToRequestQueue(Request<T> request) { <T> void addToRequestQueue(Request<T> request) {
getRequestQueue().add(request); getRequestQueue().add(request);
} }
public void cancelAll(String tag) { void cancelAll(String tag) {
getRequestQueue().cancelAll(tag); getRequestQueue().cancelAll(tag);
} }
public ImageLoader getImageLoader() { ImageLoader getImageLoader() {
return imageLoader; return imageLoader;
} }
} }