Skip to content

Commit d416590

Browse files
Remove unnecessary style changes and AppCompatActivity casting
1 parent 9032306 commit d416590

16 files changed

+126
-257
lines changed

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/data/ListAdapter.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.gaulupeau.apps.Poche.data;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
3+
import android.app.Activity;
54
import android.content.Context;
65
import android.view.ContextMenu;
76
import android.view.LayoutInflater;
@@ -67,7 +66,7 @@ public int getItemCount() {
6766
return articles.size();
6867
}
6968

70-
public boolean handleContextItemSelected(AppCompatActivity activity, MenuItem item) {
69+
public boolean handleContextItemSelected(Activity activity, MenuItem item) {
7170
return articleWithContextMenu != null && articleActionsHelper
7271
.handleContextItemSelected(activity, articleWithContextMenu, item);
7372
}
@@ -141,9 +140,7 @@ public void onCreateContextMenu(ContextMenu menu, View v,
141140
ContextMenu.ContextMenuInfo menuInfo) {
142141
articleWithContextMenu = article;
143142

144-
if (article == null) {
145-
return;
146-
}
143+
if (article == null) return;
147144

148145
new MenuInflater(context) // not sure about this
149146
.inflate(R.menu.article_list_context_menu, menu);

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public Themes.Theme getTheme() {
441441
} catch(IllegalArgumentException ignored) {}
442442
}
443443

444-
return theme != null ? theme : Themes.Theme.DEFAULT;
444+
return theme != null ? theme : Themes.Theme.LIGHT;
445445
}
446446

447447
public void setTheme(Themes.Theme theme) {

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/tts/TtsFragment.java

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.gaulupeau.apps.Poche.tts;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
3+
import android.app.Activity;
54
import android.app.PendingIntent;
65
import android.content.BroadcastReceiver;
76
import android.content.ComponentName;
@@ -97,7 +96,7 @@ public class TtsFragment extends Fragment {
9796

9897
private boolean dontStopTtsService;
9998

100-
private AppCompatActivity activity;
99+
private Activity activity;
101100
private TtsHost ttsHost;
102101

103102
private MediaSessionCompat.Token mediaSessionToken;
@@ -152,12 +151,10 @@ public void onAttach(@NonNull Context context) {
152151
super.onAttach(context);
153152
Log.d(TAG, "onAttach()");
154153

155-
activity = (AppCompatActivity) context;
154+
activity = (Activity) context;
156155
ttsHost = ((ReadArticleActivity) activity).getTtsHost();
157156

158-
if (webViewText != null) {
159-
webViewText.setTtsHost(ttsHost);
160-
}
157+
if (webViewText != null) webViewText.setTtsHost(ttsHost);
161158

162159
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
163160

@@ -173,9 +170,7 @@ public void onDetach() {
173170
activity = null;
174171

175172
ttsHost = null;
176-
if (webViewText != null) {
177-
webViewText.setTtsHost(null);
178-
}
173+
if (webViewText != null) webViewText.setTtsHost(null);
179174
}
180175

181176
@Override
@@ -365,7 +360,6 @@ public void onNothingSelected(AdapterView<?> parentView) {}
365360
});
366361

367362
mediaCallback = new MediaControllerCompat.Callback() {
368-
@Override
369363
public void onPlaybackStateChanged(PlaybackStateCompat state) {
370364
switch (state.getState()) {
371365
case PlaybackStateCompat.STATE_BUFFERING:
@@ -406,9 +400,7 @@ public void onPlaybackStateChanged(PlaybackStateCompat state) {
406400
private void initMediaController() {
407401
destroyMediaController();
408402

409-
if (mediaSessionToken == null) {
410-
return;
411-
}
403+
if (mediaSessionToken == null) return;
412404

413405
mediaController = new MediaControllerCompat(activity, mediaSessionToken);
414406

@@ -610,9 +602,7 @@ public void onDocumentLoadFinished() {
610602
Log.v(TAG, "onDocumentLoadFinished() documentParsed="
611603
+ documentParsed + ", reinitDocument=" + reinitDocument);
612604

613-
if (documentParsed && !reinitDocument) {
614-
return;
615-
}
605+
if (documentParsed && !reinitDocument) return;
616606

617607
reinitDocument = false;
618608
documentParsed = false;
@@ -674,9 +664,7 @@ private void updateVolumeDisplay() {
674664
}
675665

676666
private void showToastMessage(@StringRes int text) {
677-
if (activity != null) {
678-
Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
679-
}
667+
if (activity != null) Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
680668
}
681669

682670
@Override
@@ -708,16 +696,12 @@ private void setLanguageIfNeeded() {
708696
private void selectLanguage(String language) {
709697
Log.d(TAG, "selectLanguage() " + language);
710698

711-
if (TextUtils.isEmpty(language)) {
712-
return;
713-
}
699+
if (TextUtils.isEmpty(language)) return;
714700

715701
language = new Locale(language).getISO3Language();
716702
Log.v(TAG, "selectLanguage() ISO3: " + language);
717703

718-
if (TextUtils.isEmpty(language)) {
719-
return;
720-
}
704+
if (TextUtils.isEmpty(language)) return;
721705

722706
if (!TTS_DATA.isInitialized()) {
723707
// The list of TTS engines has not yet be fully obtained,
@@ -741,9 +725,7 @@ private void selectLanguage(String language) {
741725
break;
742726
}
743727
}
744-
if (voiceInfo == null && !voiceInfos.isEmpty()) {
745-
voiceInfo = voiceInfos.get(0);
746-
}
728+
if (voiceInfo == null && !voiceInfos.isEmpty()) voiceInfo = voiceInfos.get(0);
747729

748730
if (voiceInfo != null) {
749731
setVoiceInfo(voiceInfo);

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/ui/ArticleActionsHelper.java

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package fr.gaulupeau.apps.Poche.ui;
22

33
import android.annotation.SuppressLint;
4-
5-
import androidx.appcompat.app.AppCompatActivity;
6-
4+
import android.app.Activity;
75
import android.content.ActivityNotFoundException;
86
import android.content.ClipData;
97
import android.content.ClipboardManager;
@@ -48,7 +46,7 @@ public void initMenu(Menu menu, Article article) {
4846
unfavoriteItem.setVisible(favorite);
4947
}
5048

51-
public boolean handleContextItemSelected(AppCompatActivity activity, Article article, MenuItem item) {
49+
public boolean handleContextItemSelected(Activity activity, Article article, MenuItem item) {
5250
switch (item.getItemId()) {
5351
case R.id.menuArticleMarkAsRead:
5452
case R.id.menuArticleMarkAsUnread:
@@ -102,26 +100,22 @@ public void favorite(Context context, Article article, boolean favorite) {
102100

103101
public void shareArticle(Context context, String articleTitle, String articleUrl) {
104102
String shareText = articleUrl;
105-
if (!TextUtils.isEmpty(articleTitle)) {
106-
shareText = articleTitle + " " + shareText;
107-
}
103+
if (!TextUtils.isEmpty(articleTitle)) shareText = articleTitle + " " + shareText;
108104

109105
if (App.getSettings().isAppendWallabagMentionEnabled()) {
110106
shareText += context.getString(R.string.share_text_extra);
111107
}
112108

113109
Intent send = new Intent(Intent.ACTION_SEND);
114110
send.setType("text/plain");
115-
if (!TextUtils.isEmpty(articleTitle)) {
116-
send.putExtra(Intent.EXTRA_SUBJECT, articleTitle);
117-
}
111+
if (!TextUtils.isEmpty(articleTitle)) send.putExtra(Intent.EXTRA_SUBJECT, articleTitle);
118112
send.putExtra(Intent.EXTRA_TEXT, shareText);
119113

120114
context.startActivity(Intent.createChooser(send,
121115
context.getString(R.string.share_article_title)));
122116
}
123117

124-
public void showChangeTitleDialog(AppCompatActivity activity, Article article) {
118+
public void showChangeTitleDialog(Activity activity, Article article) {
125119
@SuppressLint("InflateParams") // ok for dialogs
126120
final View view = activity.getLayoutInflater().inflate(R.layout.dialog_change_title, null);
127121

@@ -156,9 +150,7 @@ public void showDeleteArticleDialog(Context context, Article article, Runnable o
156150
b.setPositiveButton(R.string.positive_answer, (dialog, which) -> {
157151
OperationsHelper.deleteArticle(context, article.getArticleId());
158152

159-
if (okCallback != null) {
160-
okCallback.run();
161-
}
153+
if (okCallback != null) okCallback.run();
162154
});
163155
b.setNegativeButton(R.string.negative_answer, null);
164156

@@ -167,9 +159,7 @@ public void showDeleteArticleDialog(Context context, Article article, Runnable o
167159

168160
public void openUrl(Context context, String url) {
169161
Log.d(TAG, "openUrl() url: " + url);
170-
if (TextUtils.isEmpty(url)) {
171-
return;
172-
}
162+
if (TextUtils.isEmpty(url)) return;
173163

174164
Uri uri = Uri.parse(url);
175165
if (uri.getScheme() == null) {
@@ -199,9 +189,7 @@ public void openUrl(Context context, String url) {
199189
}
200190
}
201191

202-
if (rethrow) {
203-
throw e;
204-
}
192+
if (rethrow) throw e;
205193
}
206194

207195
if (errorMessage) {

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/ui/ArticleListFragment.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.gaulupeau.apps.Poche.ui;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
3+
import android.app.Activity;
54
import android.content.Context;
65
import android.content.Intent;
76
import android.database.DatabaseUtils;
@@ -141,7 +140,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
141140
}
142141

143142
@Override
144-
public boolean handleContextItemSelected(AppCompatActivity activity, MenuItem item) {
143+
public boolean handleContextItemSelected(Activity activity, MenuItem item) {
145144
return listAdapter.handleContextItemSelected(activity, item);
146145
}
147146

@@ -253,9 +252,7 @@ private List<Article> detachObjects(List<Article> articles) {
253252
protected void onSwipeRefresh() {
254253
super.onSwipeRefresh();
255254

256-
if (host != null) {
257-
host.onRecyclerViewListSwipeUpdate();
258-
}
255+
if (host != null) host.onRecyclerViewListSwipeUpdate();
259256
}
260257

261258
@Override
@@ -279,7 +276,7 @@ private void openRandomArticle() {
279276

280277
// TODO: include more info (order, search query, tag)
281278
private void openArticle(long id) {
282-
AppCompatActivity activity = (AppCompatActivity) getActivity();
279+
Activity activity = getActivity();
283280
if (activity != null) {
284281
Intent intent = new Intent(activity, ReadArticleActivity.class);
285282
intent.putExtra(ReadArticleActivity.EXTRA_ID, id);
@@ -330,9 +327,7 @@ public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
330327

331328
@Override
332329
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
333-
if (forceContentUpdate) {
334-
return false;
335-
}
330+
if (forceContentUpdate) return false;
336331

337332
Article oldArticle = oldList.get(oldItemPosition);
338333
Article newArticle = newList.get(newItemPosition);

Diff for: app/src/main/java/fr/gaulupeau/apps/Poche/ui/ArticleListsFragment.java

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fr.gaulupeau.apps.Poche.ui;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
3+
import android.app.Activity;
54
import android.os.Bundle;
65
import android.util.Log;
76
import android.view.LayoutInflater;
@@ -88,9 +87,7 @@ public void onCreate(Bundle savedInstanceState) {
8887
searchQuery = savedInstanceState.getString(STATE_SEARCH_QUERY);
8988
}
9089
}
91-
if (sortOrder == null) {
92-
sortOrder = SortOrder.DESC;
93-
}
90+
if (sortOrder == null) sortOrder = SortOrder.DESC;
9491
}
9592

9693
@Override
@@ -102,9 +99,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
10299
getChildFragmentManager().registerFragmentLifecycleCallbacks(new FragmentManager.FragmentLifecycleCallbacks() {
103100
@Override
104101
public void onFragmentCreated(@NonNull FragmentManager fm, @NonNull Fragment f, @Nullable Bundle savedInstanceState) {
105-
if (f instanceof ArticleListFragment) {
102+
if (f instanceof ArticleListFragment)
106103
setParametersToFragment((ArticleListFragment) f);
107-
}
108104
}
109105
}, false);
110106

@@ -133,12 +129,8 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
133129

134130
Log.v(TAG, "onSaveInstanceState()");
135131

136-
if (sortOrder != null) {
137-
outState.putInt(STATE_SORT_ORDER, sortOrder.ordinal());
138-
}
139-
if (searchQuery != null) {
140-
outState.putString(STATE_SEARCH_QUERY, searchQuery);
141-
}
132+
if (sortOrder != null) outState.putInt(STATE_SORT_ORDER, sortOrder.ordinal());
133+
if (searchQuery != null) outState.putString(STATE_SEARCH_QUERY, searchQuery);
142134
}
143135

144136
@Override
@@ -156,7 +148,7 @@ public void setSearchQuery(String searchQuery) {
156148
}
157149

158150
@Override
159-
public boolean handleContextItemSelected(AppCompatActivity activity, MenuItem item) {
151+
public boolean handleContextItemSelected(Activity activity, MenuItem item) {
160152
ArticleListFragment fragment = getCurrentFragment();
161153
return fragment != null && fragment.handleContextItemSelected(activity, item);
162154
}
@@ -169,25 +161,19 @@ public void onFeedsChangedEvent(FeedsChangedEvent event) {
169161

170162
private void setParametersToFragment(ArticleListFragment fragment) {
171163
Log.v(TAG, "setParametersToFragment() started");
172-
if (fragment == null) {
173-
return;
174-
}
164+
if (fragment == null) return;
175165

176166
setSortOrder(fragment, sortOrder);
177167
setSearchQueryOnFragment(fragment, searchQuery);
178168
}
179169

180170
private void setSortOrder(ArticleListFragment fragment,
181171
Sortable.SortOrder sortOrder) {
182-
if (fragment != null) {
183-
fragment.setSortOrder(sortOrder);
184-
}
172+
if (fragment != null) fragment.setSortOrder(sortOrder);
185173
}
186174

187175
private void setSearchQueryOnFragment(ArticleListFragment fragment, String searchQuery) {
188-
if (fragment != null) {
189-
fragment.setSearchQuery(searchQuery);
190-
}
176+
if (fragment != null) fragment.setSearchQuery(searchQuery);
191177
}
192178

193179
private ArticleListFragment getCurrentFragment() {
@@ -225,9 +211,7 @@ private void updateAllLists(boolean forceContentUpdate) {
225211
for (int i = 0; i < ArticleListsPagerAdapter.PAGES.length; i++) {
226212
ArticleListFragment f = getFragment(i);
227213
if (f != null) {
228-
if (forceContentUpdate) {
229-
f.forceContentUpdate();
230-
}
214+
if (forceContentUpdate) f.forceContentUpdate();
231215
f.invalidateList();
232216
} else {
233217
Log.w(TAG, "updateAllLists() fragment is null; position: " + i);
@@ -242,9 +226,7 @@ private void updateList(int position, boolean forceContentUpdate) {
242226
if (position != -1) {
243227
ArticleListFragment f = getFragment(position);
244228
if (f != null) {
245-
if (forceContentUpdate) {
246-
f.forceContentUpdate();
247-
}
229+
if (forceContentUpdate) f.forceContentUpdate();
248230
f.invalidateList();
249231
} else {
250232
Log.w(TAG, "updateList() fragment is null");

0 commit comments

Comments
 (0)