diff --git a/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java b/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java index b5e79392..28c5c068 100644 --- a/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/fragment/ListFragment.java @@ -32,6 +32,8 @@ public abstract class ListFragment extends Fragment implements OnRefreshListener private SwipeRefreshLayout reload; private GlobalSettings settings; + private boolean isRefreshing = false; + @Override public final View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle param) { @@ -56,11 +58,12 @@ public abstract class ListFragment extends Fragment implements OnRefreshListener * @param enable true to enable swipe view delayed, false to stop immediately */ protected void setRefresh(boolean enable) { + isRefreshing = enable; if (enable) { reload.postDelayed(new Runnable() { @Override public void run() { - if (!reload.isRefreshing()) { + if (isRefreshing) { reload.setRefreshing(true); } } diff --git a/app/src/main/java/org/nuclearfog/twidda/fragment/MessageFragment.java b/app/src/main/java/org/nuclearfog/twidda/fragment/MessageFragment.java index e3557fa0..ff050485 100644 --- a/app/src/main/java/org/nuclearfog/twidda/fragment/MessageFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/fragment/MessageFragment.java @@ -153,7 +153,7 @@ public class MessageFragment extends ListFragment implements OnRefreshListener, @Override public void onConfirm(DialogBuilder.DialogType type) { - messageTask = new MessageListLoader(MessageFragment.this, MessageListLoader.Action.DEL); + messageTask = new MessageListLoader(this, MessageListLoader.Action.DEL); messageTask.execute(deleteId); } diff --git a/app/src/main/java/org/nuclearfog/twidda/fragment/TrendFragment.java b/app/src/main/java/org/nuclearfog/twidda/fragment/TrendFragment.java index 6662535b..ffb169f8 100644 --- a/app/src/main/java/org/nuclearfog/twidda/fragment/TrendFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/fragment/TrendFragment.java @@ -77,7 +77,7 @@ public class TrendFragment extends ListFragment implements OnRefreshListener, Tr @Override public void onTrendClick(TwitterTrend trend) { if (!isRefreshing()) { - Intent intent = new Intent(getContext(), SearchPage.class); + Intent intent = new Intent(requireContext(), SearchPage.class); intent.putExtra(KEY_SEARCH_QUERY, trend.getSearchString()); startActivity(intent); } @@ -108,8 +108,8 @@ public class TrendFragment extends ListFragment implements OnRefreshListener, Tr * @param error Twitter exception */ public void onError(EngineException error) { - if (getContext() != null) - ErrorHandler.handleFailure(getContext(), error); + if (error != null) + ErrorHandler.handleFailure(requireContext(), error); setRefresh(false); } diff --git a/app/src/main/java/org/nuclearfog/twidda/fragment/TweetFragment.java b/app/src/main/java/org/nuclearfog/twidda/fragment/TweetFragment.java index b2faee82..1f8db98d 100644 --- a/app/src/main/java/org/nuclearfog/twidda/fragment/TweetFragment.java +++ b/app/src/main/java/org/nuclearfog/twidda/fragment/TweetFragment.java @@ -128,10 +128,10 @@ public class TweetFragment extends ListFragment implements OnRefreshListener, Tw @Override public void onTweetClick(Tweet tweet) { - if (getContext() != null && !isRefreshing()) { + if (!isRefreshing()) { if (tweet.getEmbeddedTweet() != null) tweet = tweet.getEmbeddedTweet(); - Intent tweetIntent = new Intent(getContext(), TweetActivity.class); + Intent tweetIntent = new Intent(requireContext(), TweetActivity.class); tweetIntent.putExtra(KEY_TWEET_ID, tweet.getId()); tweetIntent.putExtra(KEY_TWEET_NAME, tweet.getUser().getScreenname()); startActivityForResult(tweetIntent, REQUEST_TWEET_CHANGED); @@ -169,8 +169,8 @@ public class TweetFragment extends ListFragment implements OnRefreshListener, Tw * @param error Twitter exception */ public void onError(@Nullable EngineException error) { - if (getContext() != null && error != null) - ErrorHandler.handleFailure(getContext(), error); + if (error != null) + ErrorHandler.handleFailure(requireContext(), error); adapter.disableLoading(); setRefresh(false); }