From 46fe328967f1fb5030cf5ee0c29ab131f10496d6 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Wed, 22 Feb 2017 14:13:51 -0500 Subject: [PATCH] A bit of code cleanup, mostly getting rid of warnings. --- .../java/com/keylesspalace/tusky/Account.java | 22 +++---- .../tusky/AccountActionListener.java | 2 +- .../keylesspalace/tusky/AccountActivity.java | 7 +- .../tusky/AccountPagerAdapter.java | 11 ++-- .../tusky/AdapterItemRemover.java | 2 +- .../java/com/keylesspalace/tusky/Assert.java | 27 ++++++++ .../keylesspalace/tusky/BlocksAdapter.java | 2 +- .../keylesspalace/tusky/ComposeActivity.java | 6 +- .../keylesspalace/tusky/CountUpDownLatch.java | 10 +-- .../com/keylesspalace/tusky/DateUtils.java | 4 +- .../tusky/DownsizeImageTask.java | 8 +-- .../tusky/EndlessOnScrollListener.java | 22 ++++--- .../com/keylesspalace/tusky/FlowLayout.java | 2 +- .../keylesspalace/tusky/FooterViewHolder.java | 12 ++-- .../com/keylesspalace/tusky/HtmlUtils.java | 4 +- .../java/com/keylesspalace/tusky/IOUtils.java | 4 +- .../com/keylesspalace/tusky/MainActivity.java | 2 +- .../keylesspalace/tusky/MultipartRequest.java | 14 ++-- .../com/keylesspalace/tusky/Notification.java | 20 +++--- .../tusky/NotificationsAdapter.java | 22 +++---- .../tusky/PreferencesActivity.java | 6 +- .../tusky/PullNotificationService.java | 6 +- .../java/com/keylesspalace/tusky/Status.java | 64 +++++++++---------- .../tusky/StatusActionListener.java | 2 +- .../keylesspalace/tusky/StatusViewHolder.java | 36 +++++------ .../com/keylesspalace/tusky/ThemeUtils.java | 10 +-- .../keylesspalace/tusky/ThreadAdapter.java | 12 ++-- .../keylesspalace/tusky/TimelineAdapter.java | 12 ++-- .../keylesspalace/tusky/TimelineFragment.java | 9 ++- .../tusky/TimelinePagerAdapter.java | 12 +--- .../tusky/ViewThreadFragment.java | 4 +- .../keylesspalace/tusky/VolleySingleton.java | 8 +-- 32 files changed, 207 insertions(+), 177 deletions(-) create mode 100644 app/src/main/java/com/keylesspalace/tusky/Assert.java diff --git a/app/src/main/java/com/keylesspalace/tusky/Account.java b/app/src/main/java/com/keylesspalace/tusky/Account.java index c22eab6f..3b9ca997 100644 --- a/app/src/main/java/com/keylesspalace/tusky/Account.java +++ b/app/src/main/java/com/keylesspalace/tusky/Account.java @@ -24,17 +24,17 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.List; -public class Account { - public String id; - public String username; - public String displayName; - public Spanned note; - public String url; - public String avatar; - public String header; - public String followersCount; - public String followingCount; - public String statusesCount; +class Account { + String id; + String username; + String displayName; + Spanned note; + String url; + String avatar; + String header; + String followersCount; + String followingCount; + String statusesCount; public static Account parse(JSONObject object) throws JSONException { Account account = new Account(); diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActionListener.java b/app/src/main/java/com/keylesspalace/tusky/AccountActionListener.java index e45cbc93..eb63175b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActionListener.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActionListener.java @@ -15,7 +15,7 @@ package com.keylesspalace.tusky; -public interface AccountActionListener { +interface AccountActionListener { void onViewAccount(String id); void onBlock(final boolean block, final String id, final int position); } diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java index 822f765d..83959bde 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.java @@ -31,6 +31,7 @@ import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; import com.android.volley.AuthFailureError; @@ -96,8 +97,8 @@ public class AccountActivity extends BaseActivity { } // Setup the tabs and timeline pager. - AccountPagerAdapter adapter = new AccountPagerAdapter( - getSupportFragmentManager(), this, accountId); + AccountPagerAdapter adapter = new AccountPagerAdapter(getSupportFragmentManager(), this, + accountId); String[] pageTitles = { getString(R.string.title_statuses), getString(R.string.title_follows), @@ -115,7 +116,7 @@ public class AccountActivity extends BaseActivity { for (int i = 0; i < tabLayout.getTabCount(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i); if (tab != null) { - tab.setCustomView(adapter.getTabView(i)); + tab.setCustomView(adapter.getTabView(i, tabLayout)); } } } diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountPagerAdapter.java b/app/src/main/java/com/keylesspalace/tusky/AccountPagerAdapter.java index fade04ec..46f39ffd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountPagerAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/AccountPagerAdapter.java @@ -21,20 +21,21 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; -public class AccountPagerAdapter extends FragmentPagerAdapter { +class AccountPagerAdapter extends FragmentPagerAdapter { private Context context; private String accountId; private String[] pageTitles; - public AccountPagerAdapter(FragmentManager manager, Context context, String accountId) { + AccountPagerAdapter(FragmentManager manager, Context context, String accountId) { super(manager); this.context = context; this.accountId = accountId; } - public void setPageTitles(String[] titles) { + void setPageTitles(String[] titles) { pageTitles = titles; } @@ -66,8 +67,8 @@ public class AccountPagerAdapter extends FragmentPagerAdapter { return pageTitles[position]; } - public View getTabView(int position) { - View view = LayoutInflater.from(context).inflate(R.layout.tab_account, null); + View getTabView(int position, ViewGroup root) { + View view = LayoutInflater.from(context).inflate(R.layout.tab_account, root, false); TextView title = (TextView) view.findViewById(R.id.title); title.setText(pageTitles[position]); return view; diff --git a/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java b/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java index 3791d7c5..e35a1d2a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java +++ b/app/src/main/java/com/keylesspalace/tusky/AdapterItemRemover.java @@ -15,6 +15,6 @@ package com.keylesspalace.tusky; -public interface AdapterItemRemover { +interface AdapterItemRemover { void removeItem(int position); } diff --git a/app/src/main/java/com/keylesspalace/tusky/Assert.java b/app/src/main/java/com/keylesspalace/tusky/Assert.java new file mode 100644 index 00000000..11b6af3e --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/Assert.java @@ -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 + * . */ + +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(); + } + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java b/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java index c3d23394..c37ae1ba 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/BlocksAdapter.java @@ -81,7 +81,7 @@ class BlocksAdapter extends AccountAdapter { } } - public void setBlocked(boolean blocked, int position) { + void setBlocked(boolean blocked, int position) { if (blocked) { unblockedAccountPositions.remove(position); } else { diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index b222c91c..4019389d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -39,6 +39,7 @@ import android.os.Parcelable; import android.provider.OpenableColumns; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; 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.LENGTH_SHORT); bar.setAction(actionId, listener); 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(); } diff --git a/app/src/main/java/com/keylesspalace/tusky/CountUpDownLatch.java b/app/src/main/java/com/keylesspalace/tusky/CountUpDownLatch.java index 3e32a141..d23c400b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/CountUpDownLatch.java +++ b/app/src/main/java/com/keylesspalace/tusky/CountUpDownLatch.java @@ -15,24 +15,24 @@ package com.keylesspalace.tusky; -public class CountUpDownLatch { +class CountUpDownLatch { private int count; - public CountUpDownLatch() { + CountUpDownLatch() { this.count = 0; } - public synchronized void countDown() { + synchronized void countDown() { count--; notifyAll(); } - public synchronized void countUp() { + synchronized void countUp() { count++; notifyAll(); } - public synchronized void await() throws InterruptedException { + synchronized void await() throws InterruptedException { while (count != 0) { wait(); } diff --git a/app/src/main/java/com/keylesspalace/tusky/DateUtils.java b/app/src/main/java/com/keylesspalace/tusky/DateUtils.java index 202cf353..96a43e02 100644 --- a/app/src/main/java/com/keylesspalace/tusky/DateUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/DateUtils.java @@ -15,10 +15,10 @@ package com.keylesspalace.tusky; -public class DateUtils { +class DateUtils { /* This is a rough duplicate of android.text.format.DateUtils.getRelativeTimeSpanString, * 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 HOUR = 60 * MINUTE; final long DAY = 24 * HOUR; diff --git a/app/src/main/java/com/keylesspalace/tusky/DownsizeImageTask.java b/app/src/main/java/com/keylesspalace/tusky/DownsizeImageTask.java index 1fb49f01..4ad52a65 100644 --- a/app/src/main/java/com/keylesspalace/tusky/DownsizeImageTask.java +++ b/app/src/main/java/com/keylesspalace/tusky/DownsizeImageTask.java @@ -22,17 +22,17 @@ import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; -public class DownsizeImageTask extends AsyncTask { +class DownsizeImageTask extends AsyncTask { private Listener listener; private int sizeLimit; private List resultList; - public DownsizeImageTask(int sizeLimit, Listener listener) { + DownsizeImageTask(int sizeLimit, Listener listener) { this.listener = listener; 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()); int width = Math.round(ratio * source.getWidth()); int height = Math.round(ratio * source.getHeight()); @@ -67,7 +67,7 @@ public class DownsizeImageTask extends AsyncTask { scaledImageSize /= 2; iterations++; } while (stream.size() > sizeLimit); - assert(iterations < 3); + Assert.expect(iterations < 3); resultList.add(stream.toByteArray()); if (isCancelled()) { return false; diff --git a/app/src/main/java/com/keylesspalace/tusky/EndlessOnScrollListener.java b/app/src/main/java/com/keylesspalace/tusky/EndlessOnScrollListener.java index e79e92b8..6b4b7e56 100644 --- a/app/src/main/java/com/keylesspalace/tusky/EndlessOnScrollListener.java +++ b/app/src/main/java/com/keylesspalace/tusky/EndlessOnScrollListener.java @@ -18,16 +18,20 @@ package com.keylesspalace.tusky; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -public abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListener { - private int visibleThreshold = 15; - private int currentPage = 0; - private int previousTotalItemCount = 0; - private boolean loading = true; - private int startingPageIndex = 0; +abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListener { + private static final int VISIBLE_THRESHOLD = 15; + private int currentPage; + private int previousTotalItemCount; + private boolean loading; + private int startingPageIndex; private LinearLayoutManager layoutManager; - public EndlessOnScrollListener(LinearLayoutManager layoutManager) { + EndlessOnScrollListener(LinearLayoutManager layoutManager) { this.layoutManager = layoutManager; + currentPage = 0; + previousTotalItemCount = 0; + loading = true; + startingPageIndex = 0; } @Override @@ -45,14 +49,14 @@ public abstract class EndlessOnScrollListener extends RecyclerView.OnScrollListe loading = false; previousTotalItemCount = totalItemCount; } - if (!loading && lastVisibleItemPosition + visibleThreshold > totalItemCount) { + if (!loading && lastVisibleItemPosition + VISIBLE_THRESHOLD > totalItemCount) { currentPage++; onLoadMore(currentPage, totalItemCount, view); loading = true; } } - public void reset() { + void reset() { currentPage = startingPageIndex; previousTotalItemCount = 0; loading = true; diff --git a/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java b/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java index 58759233..c2844cdd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java +++ b/app/src/main/java/com/keylesspalace/tusky/FlowLayout.java @@ -45,7 +45,7 @@ public class FlowLayout extends ViewGroup { @Override 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 height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom(); int count = getChildCount(); diff --git a/app/src/main/java/com/keylesspalace/tusky/FooterViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/FooterViewHolder.java index cd47c139..d285d8a8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/FooterViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/FooterViewHolder.java @@ -21,7 +21,7 @@ import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; -public class FooterViewHolder extends RecyclerView.ViewHolder { +class FooterViewHolder extends RecyclerView.ViewHolder { private View retryBar; private TextView retryMessage; private Button retry; @@ -34,7 +34,7 @@ public class FooterViewHolder extends RecyclerView.ViewHolder { END_OF_TIMELINE, } - public FooterViewHolder(View itemView) { + FooterViewHolder(View itemView) { super(itemView); retryBar = itemView.findViewById(R.id.footer_retry_bar); 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); } - public void setupButton(final FooterActionListener listener) { + void setupButton(final FooterActionListener listener) { retry.setOnClickListener(new View.OnClickListener() { @Override 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); } - public void setEndOfTimelineMessage(int messageId) { + void setEndOfTimelineMessage(int messageId) { endOfTimelineMessage.setText(messageId); } - public void setState(State state) { + void setState(State state) { switch (state) { case LOADING: { retryBar.setVisibility(View.GONE); diff --git a/app/src/main/java/com/keylesspalace/tusky/HtmlUtils.java b/app/src/main/java/com/keylesspalace/tusky/HtmlUtils.java index 7d62b464..029cc333 100644 --- a/app/src/main/java/com/keylesspalace/tusky/HtmlUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/HtmlUtils.java @@ -19,7 +19,7 @@ import android.os.Build; import android.text.Html; import android.text.Spanned; -public class HtmlUtils { +class HtmlUtils { private static CharSequence trimTrailingWhitespace(CharSequence s) { int i = s.length(); do { @@ -28,7 +28,7 @@ public class HtmlUtils { return s.subSequence(0, i + 1); } - public static Spanned fromHtml(String html) { + static Spanned fromHtml(String html) { Spanned result; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY); diff --git a/app/src/main/java/com/keylesspalace/tusky/IOUtils.java b/app/src/main/java/com/keylesspalace/tusky/IOUtils.java index 5e54aeef..82c98c66 100644 --- a/app/src/main/java/com/keylesspalace/tusky/IOUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/IOUtils.java @@ -20,8 +20,8 @@ import android.support.annotation.Nullable; import java.io.IOException; import java.io.InputStream; -public class IOUtils { - public static void closeQuietly(@Nullable InputStream stream) { +class IOUtils { + static void closeQuietly(@Nullable InputStream stream) { try { if (stream != null) { stream.close(); diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index afab447a..360cd62e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -63,7 +63,7 @@ public class MainActivity extends BaseActivity { setSupportActionBar(toolbar); // Setup the tabs and timeline pager. - TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager(), this); + TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager()); String[] pageTitles = { getString(R.string.title_home), getString(R.string.title_notifications), diff --git a/app/src/main/java/com/keylesspalace/tusky/MultipartRequest.java b/app/src/main/java/com/keylesspalace/tusky/MultipartRequest.java index c9bcbafa..41dd05e7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MultipartRequest.java +++ b/app/src/main/java/com/keylesspalace/tusky/MultipartRequest.java @@ -29,14 +29,14 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; -public class MultipartRequest extends Request { +class MultipartRequest extends Request { private static final String CHARSET = "utf-8"; private final String boundary = "something-" + System.currentTimeMillis(); private JSONObject parameters; private Response.Listener listener; - public MultipartRequest(int method, String url, JSONObject parameters, + MultipartRequest(int method, String url, JSONObject parameters, Response.Listener listener, Response.ErrorListener errorListener) { super(method, url, errorListener); this.parameters = parameters; @@ -108,10 +108,10 @@ public class MultipartRequest extends Request { return null; } - public static class DataItem { - public String name; - public String filename; - public String mimeType; - public byte[] content; + static class DataItem { + String name; + String filename; + String mimeType; + byte[] content; } } diff --git a/app/src/main/java/com/keylesspalace/tusky/Notification.java b/app/src/main/java/com/keylesspalace/tusky/Notification.java index 6dce737c..83aee6c4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/Notification.java +++ b/app/src/main/java/com/keylesspalace/tusky/Notification.java @@ -24,8 +24,8 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.List; -public class Notification { - public enum Type { +class Notification { + enum Type { MENTION, REBLOG, FAVOURITE, @@ -37,39 +37,39 @@ public class Notification { /** Which of the user's statuses has been mentioned, reblogged, or favourited. */ private Status status; - public Notification(Type type, String id, String displayName) { + private Notification(Type type, String id, String displayName) { this.type = type; this.id = id; this.displayName = displayName; } - public Type getType() { + Type getType() { return type; } - public String getId() { + String getId() { return id; } - public String getDisplayName() { + String getDisplayName() { return displayName; } - public @Nullable Status getStatus() { + @Nullable Status getStatus() { return status; } - public void setStatus(Status status) { + void setStatus(Status status) { this.status = status; } - public boolean hasStatusType() { + private boolean hasStatusType() { return type == Type.MENTION || type == Type.FAVOURITE || type == Type.REBLOG; } - public static List parse(JSONArray array) throws JSONException { + static List parse(JSONArray array) throws JSONException { List notifications = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java index ca306433..9e1e1390 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationsAdapter.java @@ -28,7 +28,7 @@ import java.util.ArrayList; import java.util.Date; 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_FOOTER = 1; 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 FooterViewHolder.State footerState; - public NotificationsAdapter(StatusActionListener statusListener, + NotificationsAdapter(StatusActionListener statusListener, FooterActionListener footerListener) { super(); notifications = new ArrayList<>(); @@ -143,7 +143,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte return null; } - public int update(List new_notifications) { + int update(List new_notifications) { int scrollToPosition; if (notifications == null || notifications.isEmpty()) { notifications = new_notifications; @@ -162,7 +162,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte return scrollToPosition; } - public void addItems(List new_notifications) { + void addItems(List new_notifications) { int end = notifications.size(); notifications.addAll(new_notifications); notifyItemRangeInserted(end, new_notifications.size()); @@ -173,19 +173,19 @@ public class NotificationsAdapter extends RecyclerView.Adapter implements Adapte notifyItemChanged(position); } - public void setFooterState(FooterViewHolder.State state) { + void setFooterState(FooterViewHolder.State state) { footerState = state; } - public static class FollowViewHolder extends RecyclerView.ViewHolder { + private static class FollowViewHolder extends RecyclerView.ViewHolder { private TextView message; - public FollowViewHolder(View itemView) { + FollowViewHolder(View itemView) { super(itemView); message = (TextView) itemView.findViewById(R.id.notification_text); } - public void setMessage(String displayName) { + void setMessage(String displayName) { Context context = message.getContext(); String format = context.getString(R.string.notification_follow_format); 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 ImageView icon; private TextView statusContent; - public StatusNotificationViewHolder(View itemView) { + StatusNotificationViewHolder(View itemView) { super(itemView); message = (TextView) itemView.findViewById(R.id.notification_text); icon = (ImageView) itemView.findViewById(R.id.notification_icon); 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(); String format; switch (type) { diff --git a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java index 22187c71..53b29cea 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java @@ -33,11 +33,7 @@ public class PreferencesActivity extends AppCompatActivity themeSwitched = savedInstanceState.getBoolean("themeSwitched"); } else { Bundle extras = getIntent().getExtras(); - if (extras != null) { - themeSwitched = extras.getBoolean("themeSwitched"); - } else { - themeSwitched = false; - } + themeSwitched = extras != null && extras.getBoolean("themeSwitched"); } SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); diff --git a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java index 63fa2a3f..13d75e75 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java +++ b/app/src/main/java/com/keylesspalace/tusky/PullNotificationService.java @@ -140,9 +140,9 @@ public class PullNotificationService extends IntentService { } private static class MentionResult { - public String displayName; - public String content; - public String avatarUrl; + String displayName; + String content; + String avatarUrl; } private String truncateWithEllipses(String string, int limit) { diff --git a/app/src/main/java/com/keylesspalace/tusky/Status.java b/app/src/main/java/com/keylesspalace/tusky/Status.java index 6d018b3f..34c8ba64 100644 --- a/app/src/main/java/com/keylesspalace/tusky/Status.java +++ b/app/src/main/java/com/keylesspalace/tusky/Status.java @@ -56,7 +56,7 @@ public class Status { private MediaAttachment[] attachments; 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, String avatar, Date createdAt, boolean reblogged, boolean favourited, @@ -76,87 +76,87 @@ public class Status { this.mentions = new Mention[0]; } - public String getId() { + String getId() { return id; } - public String getAccountId() { + String getAccountId() { return accountId; } - public String getDisplayName() { + String getDisplayName() { return displayName; } - public String getUsername() { + String getUsername() { return username; } - public Spanned getContent() { + Spanned getContent() { return content; } - public String getAvatar() { + String getAvatar() { return avatar; } - public Date getCreatedAt() { + Date getCreatedAt() { return createdAt; } - public String getRebloggedByDisplayName() { + String getRebloggedByDisplayName() { return rebloggedByDisplayName; } - public boolean getReblogged() { + boolean getReblogged() { return reblogged; } - public boolean getFavourited() { + boolean getFavourited() { return favourited; } - public boolean getSensitive() { + boolean getSensitive() { return sensitive; } - public String getSpoilerText() { + String getSpoilerText() { return spoilerText; } - public Visibility getVisibility() { + Visibility getVisibility() { return visibility; } - public MediaAttachment[] getAttachments() { + MediaAttachment[] getAttachments() { return attachments; } - public Mention[] getMentions() { + Mention[] getMentions() { return mentions; } - public void setRebloggedByDisplayName(String name) { + private void setRebloggedByDisplayName(String name) { rebloggedByDisplayName = name; } - public void setReblogged(boolean reblogged) { + void setReblogged(boolean reblogged) { this.reblogged = reblogged; } - public void setFavourited(boolean favourited) { + void setFavourited(boolean favourited) { this.favourited = favourited; } - public void setSpoilerText(String spoilerText) { + private void setSpoilerText(String spoilerText) { this.spoilerText = spoilerText; } - public void setMentions(Mention[] mentions) { + private void setMentions(Mention[] mentions) { this.mentions = mentions; } - public void setAttachments(MediaAttachment[] attachments, boolean sensitive) { + private void setAttachments(MediaAttachment[] attachments, boolean sensitive) { this.attachments = attachments; this.sensitive = sensitive; } @@ -285,7 +285,7 @@ public class Status { return statuses; } - public static class MediaAttachment { + static class MediaAttachment { enum Type { IMAGE, VIDEO, @@ -295,45 +295,45 @@ public class Status { private String previewUrl; private Type type; - public MediaAttachment(String url, String previewUrl, Type type) { + MediaAttachment(String url, String previewUrl, Type type) { this.url = url; this.previewUrl = previewUrl; this.type = type; } - public String getUrl() { + String getUrl() { return url; } - public String getPreviewUrl() { + String getPreviewUrl() { return previewUrl; } - public Type getType() { + Type getType() { return type; } } - public static class Mention { + static class Mention { private String url; private String username; private String id; - public Mention(String url, String username, String id) { + Mention(String url, String username, String id) { this.url = url; this.username = username; this.id = id; } - public String getUrl() { + String getUrl() { return url; } - public String getUsername() { + String getUsername() { return username; } - public String getId() { + String getId() { return id; } } diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusActionListener.java b/app/src/main/java/com/keylesspalace/tusky/StatusActionListener.java index dabdf0e3..b8baf0d3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusActionListener.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusActionListener.java @@ -17,7 +17,7 @@ package com.keylesspalace.tusky; import android.view.View; -public interface StatusActionListener { +interface StatusActionListener { void onReply(int position); void onReblog(final boolean reblog, final int position); void onFavourite(final boolean favourite, final int position); diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index 249b3837..2c0a6ace 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -34,7 +34,7 @@ import com.android.volley.toolbox.NetworkImageView; import java.util.Date; -public class StatusViewHolder extends RecyclerView.ViewHolder { +class StatusViewHolder extends RecyclerView.ViewHolder { private View container; private TextView displayName; private TextView username; @@ -58,7 +58,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { private TextView contentWarningDescription; private ToggleButton contentWarningButton; - public StatusViewHolder(View itemView) { + StatusViewHolder(View itemView) { super(itemView); container = itemView.findViewById(R.id.status_container); 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); } - public void setDisplayName(String name) { + private void setDisplayName(String name) { displayName.setText(name); } - public void setUsername(String name) { + void setUsername(String name) { Context context = username.getContext(); String format = context.getString(R.string.status_username_format); String usernameText = String.format(format, name); username.setText(usernameText); } - public void setContent(Spanned content, Status.Mention[] mentions, + private void setContent(Spanned content, Status.Mention[] mentions, final StatusActionListener listener) { /* Redirect URLSpan's in the status content to the listener for viewing tag pages and * account pages. */ @@ -154,7 +154,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { this.content.setMovementMethod(LinkMovementMethod.getInstance()); } - public void setAvatar(String url) { + private void setAvatar(String url) { if (url.isEmpty()) { return; } @@ -163,7 +163,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { avatar.setImageUrl(url, imageLoader); } - public void setCreatedAt(@Nullable Date createdAt) { + private void setCreatedAt(@Nullable Date createdAt) { String readout; if (createdAt != null) { long then = createdAt.getTime(); @@ -175,7 +175,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { sinceCreated.setText(readout); } - public void setRebloggedByDisplayName(String name) { + private void setRebloggedByDisplayName(String name) { Context context = rebloggedByDisplayName.getContext(); String format = context.getString(R.string.status_boosted_format); String boostedText = String.format(format, name); @@ -183,11 +183,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { rebloggedBar.setVisibility(View.VISIBLE); } - public void hideRebloggedByDisplayName() { + private void hideRebloggedByDisplayName() { rebloggedBar.setVisibility(View.GONE); } - public void setReblogged(boolean reblogged) { + private void setReblogged(boolean reblogged) { this.reblogged = reblogged; int attribute; 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. */ - public void setRebloggingEnabled(boolean enabled) { + private void setRebloggingEnabled(boolean enabled) { reblogButton.setEnabled(enabled); if (enabled) { 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; int attribute; if (favourited) { @@ -220,7 +220,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { ThemeUtils.setImageViewTint(favouriteButton, attribute); } - public void setMediaPreviews(final Status.MediaAttachment[] attachments, + private void setMediaPreviews(final Status.MediaAttachment[] attachments, boolean sensitive, final StatusActionListener listener) { final NetworkImageView[] previews = { mediaPreview0, @@ -268,11 +268,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { } } - public void hideSensitiveMediaWarning() { + private void hideSensitiveMediaWarning() { sensitiveMediaWarning.setVisibility(View.GONE); } - public void setSpoilerText(String spoilerText) { + private void setSpoilerText(String spoilerText) { contentWarningDescription.setText(spoilerText); contentWarningBar.setVisibility(View.VISIBLE); content.setVisibility(View.GONE); @@ -289,12 +289,12 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { }); } - public void hideSpoilerText() { + private void hideSpoilerText() { contentWarningBar.setVisibility(View.GONE); 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() { @Override public void onClick(View v) { @@ -339,7 +339,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder { container.setOnClickListener(viewThreadListener); } - public void setupWithStatus(Status status, StatusActionListener listener, int position) { + void setupWithStatus(Status status, StatusActionListener listener, int position) { setDisplayName(status.getDisplayName()); setUsername(status.getUsername()); setCreatedAt(status.getCreatedAt()); diff --git a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java index 8db45fac..1d3cb82e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/ThemeUtils.java @@ -22,8 +22,8 @@ import android.support.v4.content.ContextCompat; import android.util.TypedValue; import android.widget.ImageView; -public class ThemeUtils { - public static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) { +class ThemeUtils { + static Drawable getDrawable(Context context, int attribute, int fallbackDrawable) { TypedValue value = new TypedValue(); int resourceId; if (context.getTheme().resolveAttribute(attribute, value, true)) { @@ -34,7 +34,7 @@ public class ThemeUtils { 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(); if (context.getTheme().resolveAttribute(attribute, value, true)) { 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(); if (context.getTheme().resolveAttribute(attribute, value, true)) { 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); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java b/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java index cbbd7e48..a53e2b66 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/ThreadAdapter.java @@ -23,12 +23,12 @@ import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; -public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover { +class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRemover { private List statuses; private StatusActionListener statusActionListener; private int statusIndex; - public ThreadAdapter(StatusActionListener listener) { + ThreadAdapter(StatusActionListener listener) { this.statusActionListener = listener; this.statuses = new ArrayList<>(); this.statusIndex = 0; @@ -53,7 +53,7 @@ public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRe return statuses.size(); } - public Status getItem(int position) { + Status getItem(int position) { return statuses.get(position); } @@ -62,20 +62,20 @@ public class ThreadAdapter extends RecyclerView.Adapter implements AdapterItemRe notifyItemRemoved(position); } - public int insertStatus(Status status) { + int insertStatus(Status status) { int i = statusIndex; statuses.add(i, status); notifyItemInserted(i); return i; } - public void addAncestors(List ancestors) { + void addAncestors(List ancestors) { statusIndex = ancestors.size(); statuses.addAll(0, ancestors); notifyItemRangeInserted(0, statusIndex); } - public void addDescendants(List descendants) { + void addDescendants(List descendants) { int end = statuses.size(); statuses.addAll(descendants); notifyItemRangeInserted(end, descendants.size()); diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java b/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java index 0fe360de..f0598d89 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineAdapter.java @@ -24,7 +24,7 @@ import android.view.ViewGroup; import java.util.ArrayList; 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_FOOTER = 1; @@ -33,7 +33,7 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem private FooterActionListener footerListener; private FooterViewHolder.State footerState; - public TimelineAdapter(StatusActionListener statusListener, + TimelineAdapter(StatusActionListener statusListener, FooterActionListener footerListener) { super(); statuses = new ArrayList<>(); @@ -88,7 +88,7 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem } } - public int update(List newStatuses) { + int update(List newStatuses) { int scrollToPosition; if (statuses == null || statuses.isEmpty()) { statuses = newStatuses; @@ -107,7 +107,7 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem return scrollToPosition; } - public void addItems(List newStatuses) { + void addItems(List newStatuses) { int end = statuses.size(); statuses.addAll(newStatuses); notifyItemRangeInserted(end, newStatuses.size()); @@ -118,14 +118,14 @@ public class TimelineAdapter extends RecyclerView.Adapter implements AdapterItem notifyItemRemoved(position); } - public @Nullable Status getItem(int position) { + @Nullable Status getItem(int position) { if (position >= 0 && position < statuses.size()) { return statuses.get(position); } return null; } - public void setFooterState(FooterViewHolder.State state) { + void setFooterState(FooterViewHolder.State state) { footerState = state; } } diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java index 0c2d6983..f4e48da4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java @@ -314,8 +314,11 @@ public class TimelineFragment extends SFragment implements public void onViewAccount(int position) { Status status = adapter.getItem(position); - String id = status.getAccountId(); - String username = status.getUsername(); - super.viewAccount(id, username); + Assert.expect(status != null); + if (status != null) { + String id = status.getAccountId(); + String username = status.getUsername(); + super.viewAccount(id, username); + } } } diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java b/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java index fdea632b..7cf0642d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java @@ -15,24 +15,18 @@ package com.keylesspalace.tusky; -import android.content.Context; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; 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 Context context; - public TimelinePagerAdapter(FragmentManager manager, Context context) { + TimelinePagerAdapter(FragmentManager manager) { super(manager); - this.context = context; } - public void setPageTitles(String[] titles) { + void setPageTitles(String[] titles) { pageTitles = titles; } diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index 72b77de1..d3aeebb3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -36,6 +36,8 @@ import org.json.JSONObject; import java.util.List; public class ViewThreadFragment extends SFragment implements StatusActionListener { + private static final String TAG = "ViewThread"; // logging tag + private RecyclerView recyclerView; private ThreadAdapter adapter; @@ -113,8 +115,8 @@ public class ViewThreadFragment extends SFragment implements StatusActionListene } private void onThreadRequestFailure() { + Log.e(TAG, "The request to fetch the thread has failed."); //TODO: no - assert(false); } public void onReply(int position) { diff --git a/app/src/main/java/com/keylesspalace/tusky/VolleySingleton.java b/app/src/main/java/com/keylesspalace/tusky/VolleySingleton.java index c0bb215e..7ef7ee94 100644 --- a/app/src/main/java/com/keylesspalace/tusky/VolleySingleton.java +++ b/app/src/main/java/com/keylesspalace/tusky/VolleySingleton.java @@ -56,7 +56,7 @@ public class VolleySingleton { return instance; } - public RequestQueue getRequestQueue() { + private RequestQueue getRequestQueue() { if (requestQueue == null) { /* getApplicationContext() is key, it keeps you from leaking the * Activity or BroadcastReceiver if someone passes one in. */ @@ -65,15 +65,15 @@ public class VolleySingleton { return requestQueue; } - public void addToRequestQueue(Request request) { + void addToRequestQueue(Request request) { getRequestQueue().add(request); } - public void cancelAll(String tag) { + void cancelAll(String tag) { getRequestQueue().cancelAll(tag); } - public ImageLoader getImageLoader() { + ImageLoader getImageLoader() { return imageLoader; } }