Skip to content

Commit

Permalink
Remove unnecessary style changes and AppCompatActivity casting
Browse files Browse the repository at this point in the history
  • Loading branch information
proletarius101 committed Apr 7, 2021
1 parent 9032306 commit d416590
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 257 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.gaulupeau.apps.Poche.data;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.view.ContextMenu;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -67,7 +66,7 @@ public int getItemCount() {
return articles.size();
}

public boolean handleContextItemSelected(AppCompatActivity activity, MenuItem item) {
public boolean handleContextItemSelected(Activity activity, MenuItem item) {
return articleWithContextMenu != null && articleActionsHelper
.handleContextItemSelected(activity, articleWithContextMenu, item);
}
Expand Down Expand Up @@ -141,9 +140,7 @@ public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
articleWithContextMenu = article;

if (article == null) {
return;
}
if (article == null) return;

new MenuInflater(context) // not sure about this
.inflate(R.menu.article_list_context_menu, menu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public Themes.Theme getTheme() {
} catch(IllegalArgumentException ignored) {}
}

return theme != null ? theme : Themes.Theme.DEFAULT;
return theme != null ? theme : Themes.Theme.LIGHT;
}

public void setTheme(Themes.Theme theme) {
Expand Down
40 changes: 11 additions & 29 deletions app/src/main/java/fr/gaulupeau/apps/Poche/tts/TtsFragment.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.gaulupeau.apps.Poche.tts;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
Expand Down Expand Up @@ -97,7 +96,7 @@ public class TtsFragment extends Fragment {

private boolean dontStopTtsService;

private AppCompatActivity activity;
private Activity activity;
private TtsHost ttsHost;

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

activity = (AppCompatActivity) context;
activity = (Activity) context;
ttsHost = ((ReadArticleActivity) activity).getTtsHost();

if (webViewText != null) {
webViewText.setTtsHost(ttsHost);
}
if (webViewText != null) webViewText.setTtsHost(ttsHost);

activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);

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

ttsHost = null;
if (webViewText != null) {
webViewText.setTtsHost(null);
}
if (webViewText != null) webViewText.setTtsHost(null);
}

@Override
Expand Down Expand Up @@ -365,7 +360,6 @@ public void onNothingSelected(AdapterView<?> parentView) {}
});

mediaCallback = new MediaControllerCompat.Callback() {
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
switch (state.getState()) {
case PlaybackStateCompat.STATE_BUFFERING:
Expand Down Expand Up @@ -406,9 +400,7 @@ public void onPlaybackStateChanged(PlaybackStateCompat state) {
private void initMediaController() {
destroyMediaController();

if (mediaSessionToken == null) {
return;
}
if (mediaSessionToken == null) return;

mediaController = new MediaControllerCompat(activity, mediaSessionToken);

Expand Down Expand Up @@ -610,9 +602,7 @@ public void onDocumentLoadFinished() {
Log.v(TAG, "onDocumentLoadFinished() documentParsed="
+ documentParsed + ", reinitDocument=" + reinitDocument);

if (documentParsed && !reinitDocument) {
return;
}
if (documentParsed && !reinitDocument) return;

reinitDocument = false;
documentParsed = false;
Expand Down Expand Up @@ -674,9 +664,7 @@ private void updateVolumeDisplay() {
}

private void showToastMessage(@StringRes int text) {
if (activity != null) {
Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
}
if (activity != null) Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
}

@Override
Expand Down Expand Up @@ -708,16 +696,12 @@ private void setLanguageIfNeeded() {
private void selectLanguage(String language) {
Log.d(TAG, "selectLanguage() " + language);

if (TextUtils.isEmpty(language)) {
return;
}
if (TextUtils.isEmpty(language)) return;

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

if (TextUtils.isEmpty(language)) {
return;
}
if (TextUtils.isEmpty(language)) return;

if (!TTS_DATA.isInitialized()) {
// The list of TTS engines has not yet be fully obtained,
Expand All @@ -741,9 +725,7 @@ private void selectLanguage(String language) {
break;
}
}
if (voiceInfo == null && !voiceInfos.isEmpty()) {
voiceInfo = voiceInfos.get(0);
}
if (voiceInfo == null && !voiceInfos.isEmpty()) voiceInfo = voiceInfos.get(0);

if (voiceInfo != null) {
setVoiceInfo(voiceInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package fr.gaulupeau.apps.Poche.ui;

import android.annotation.SuppressLint;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ClipData;
import android.content.ClipboardManager;
Expand Down Expand Up @@ -48,7 +46,7 @@ public void initMenu(Menu menu, Article article) {
unfavoriteItem.setVisible(favorite);
}

public boolean handleContextItemSelected(AppCompatActivity activity, Article article, MenuItem item) {
public boolean handleContextItemSelected(Activity activity, Article article, MenuItem item) {
switch (item.getItemId()) {
case R.id.menuArticleMarkAsRead:
case R.id.menuArticleMarkAsUnread:
Expand Down Expand Up @@ -102,26 +100,22 @@ public void favorite(Context context, Article article, boolean favorite) {

public void shareArticle(Context context, String articleTitle, String articleUrl) {
String shareText = articleUrl;
if (!TextUtils.isEmpty(articleTitle)) {
shareText = articleTitle + " " + shareText;
}
if (!TextUtils.isEmpty(articleTitle)) shareText = articleTitle + " " + shareText;

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

Intent send = new Intent(Intent.ACTION_SEND);
send.setType("text/plain");
if (!TextUtils.isEmpty(articleTitle)) {
send.putExtra(Intent.EXTRA_SUBJECT, articleTitle);
}
if (!TextUtils.isEmpty(articleTitle)) send.putExtra(Intent.EXTRA_SUBJECT, articleTitle);
send.putExtra(Intent.EXTRA_TEXT, shareText);

context.startActivity(Intent.createChooser(send,
context.getString(R.string.share_article_title)));
}

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

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

if (okCallback != null) {
okCallback.run();
}
if (okCallback != null) okCallback.run();
});
b.setNegativeButton(R.string.negative_answer, null);

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

public void openUrl(Context context, String url) {
Log.d(TAG, "openUrl() url: " + url);
if (TextUtils.isEmpty(url)) {
return;
}
if (TextUtils.isEmpty(url)) return;

Uri uri = Uri.parse(url);
if (uri.getScheme() == null) {
Expand Down Expand Up @@ -199,9 +189,7 @@ public void openUrl(Context context, String url) {
}
}

if (rethrow) {
throw e;
}
if (rethrow) throw e;
}

if (errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.gaulupeau.apps.Poche.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.DatabaseUtils;
Expand Down Expand Up @@ -141,7 +140,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public boolean handleContextItemSelected(AppCompatActivity activity, MenuItem item) {
public boolean handleContextItemSelected(Activity activity, MenuItem item) {
return listAdapter.handleContextItemSelected(activity, item);
}

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

if (host != null) {
host.onRecyclerViewListSwipeUpdate();
}
if (host != null) host.onRecyclerViewListSwipeUpdate();
}

@Override
Expand All @@ -279,7 +276,7 @@ private void openRandomArticle() {

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

@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
if (forceContentUpdate) {
return false;
}
if (forceContentUpdate) return false;

Article oldArticle = oldList.get(oldItemPosition);
Article newArticle = newList.get(newItemPosition);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.gaulupeau.apps.Poche.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -88,9 +87,7 @@ public void onCreate(Bundle savedInstanceState) {
searchQuery = savedInstanceState.getString(STATE_SEARCH_QUERY);
}
}
if (sortOrder == null) {
sortOrder = SortOrder.DESC;
}
if (sortOrder == null) sortOrder = SortOrder.DESC;
}

@Override
Expand All @@ -102,9 +99,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
getChildFragmentManager().registerFragmentLifecycleCallbacks(new FragmentManager.FragmentLifecycleCallbacks() {
@Override
public void onFragmentCreated(@NonNull FragmentManager fm, @NonNull Fragment f, @Nullable Bundle savedInstanceState) {
if (f instanceof ArticleListFragment) {
if (f instanceof ArticleListFragment)
setParametersToFragment((ArticleListFragment) f);
}
}
}, false);

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

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

if (sortOrder != null) {
outState.putInt(STATE_SORT_ORDER, sortOrder.ordinal());
}
if (searchQuery != null) {
outState.putString(STATE_SEARCH_QUERY, searchQuery);
}
if (sortOrder != null) outState.putInt(STATE_SORT_ORDER, sortOrder.ordinal());
if (searchQuery != null) outState.putString(STATE_SEARCH_QUERY, searchQuery);
}

@Override
Expand All @@ -156,7 +148,7 @@ public void setSearchQuery(String searchQuery) {
}

@Override
public boolean handleContextItemSelected(AppCompatActivity activity, MenuItem item) {
public boolean handleContextItemSelected(Activity activity, MenuItem item) {
ArticleListFragment fragment = getCurrentFragment();
return fragment != null && fragment.handleContextItemSelected(activity, item);
}
Expand All @@ -169,25 +161,19 @@ public void onFeedsChangedEvent(FeedsChangedEvent event) {

private void setParametersToFragment(ArticleListFragment fragment) {
Log.v(TAG, "setParametersToFragment() started");
if (fragment == null) {
return;
}
if (fragment == null) return;

setSortOrder(fragment, sortOrder);
setSearchQueryOnFragment(fragment, searchQuery);
}

private void setSortOrder(ArticleListFragment fragment,
Sortable.SortOrder sortOrder) {
if (fragment != null) {
fragment.setSortOrder(sortOrder);
}
if (fragment != null) fragment.setSortOrder(sortOrder);
}

private void setSearchQueryOnFragment(ArticleListFragment fragment, String searchQuery) {
if (fragment != null) {
fragment.setSearchQuery(searchQuery);
}
if (fragment != null) fragment.setSearchQuery(searchQuery);
}

private ArticleListFragment getCurrentFragment() {
Expand Down Expand Up @@ -225,9 +211,7 @@ private void updateAllLists(boolean forceContentUpdate) {
for (int i = 0; i < ArticleListsPagerAdapter.PAGES.length; i++) {
ArticleListFragment f = getFragment(i);
if (f != null) {
if (forceContentUpdate) {
f.forceContentUpdate();
}
if (forceContentUpdate) f.forceContentUpdate();
f.invalidateList();
} else {
Log.w(TAG, "updateAllLists() fragment is null; position: " + i);
Expand All @@ -242,9 +226,7 @@ private void updateList(int position, boolean forceContentUpdate) {
if (position != -1) {
ArticleListFragment f = getFragment(position);
if (f != null) {
if (forceContentUpdate) {
f.forceContentUpdate();
}
if (forceContentUpdate) f.forceContentUpdate();
f.invalidateList();
} else {
Log.w(TAG, "updateList() fragment is null");
Expand Down
Loading

0 comments on commit d416590

Please sign in to comment.