diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2018-01-21 22:50:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-21 22:50:47 +0100 |
commit | 5526937698c6d45188ff273a3b18866da443c29c (patch) | |
tree | 5895b61960ac96cd966ae60e1a7857f58123c74d /app/src/main/java/de/danoeh | |
parent | 06113b089190f9a4ccfac685b17e38f03964a71e (diff) | |
parent | 34a5d7eb17d2074d746107abcdc6872ae7ad285c (diff) | |
download | AntennaPod-5526937698c6d45188ff273a3b18866da443c29c.zip |
Merge branch 'develop' into picture-in-picture
Diffstat (limited to 'app/src/main/java/de/danoeh')
66 files changed, 633 insertions, 680 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java index f6a8db5fb..3abf7557a 100644 --- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java +++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java @@ -41,10 +41,8 @@ public class PodcastApp extends Application { .detectLeakedSqlLiteObjects() .penaltyLog() .penaltyDropBox(); - if (Build.VERSION.SDK_INT >= 11) { - builder.detectActivityLeaks(); - builder.detectLeakedClosableObjects(); - } + builder.detectActivityLeaks(); + builder.detectLeakedClosableObjects(); if(Build.VERSION.SDK_INT >= 16) { builder.detectLeakedRegistrationObjects(); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 1b42b274c..041053a25 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -75,53 +75,50 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.create(new Observable.OnSubscribe<String>() { - @Override - public void call(Subscriber<? super String> subscriber) { - InputStream input = null; - try { - TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( - new int[] { android.R.attr.textColorPrimary }); - int colorResource = res.getColor(0, 0); - String colorString = String.format("#%06X", 0xFFFFFF & colorResource); - res.recycle(); - input = getAssets().open(filename); - String webViewData = IOUtils.toString(input, Charset.defaultCharset()); - if(!webViewData.startsWith("<!DOCTYPE html>")) { - //webViewData = webViewData.replace("\n\n", "</p><p>"); - webViewData = webViewData.replace("%", "%"); - webViewData = - "<!DOCTYPE html>" + - "<html>" + - "<head>" + - " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + - " <style type=\"text/css\">" + - " @font-face {" + - " font-family: 'Roboto-Light';" + - " src: url('file:///android_asset/Roboto-Light.ttf');" + - " }" + - " * {" + - " color: %s;" + - " font-family: roboto-Light;" + - " font-size: 8pt;" + - " }" + - " </style>" + - "</head><body><p>" + webViewData + "</p></body></html>"; - webViewData = webViewData.replace("\n", "<br/>"); - depth++; - } else { - depth = 0; - } - webViewData = String.format(webViewData, colorString); - subscriber.onNext(webViewData); - } catch (IOException e) { - subscriber.onError(e); - } finally { - IOUtils.closeQuietly(input); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> { + InputStream input = null; + try { + TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( + new int[] { android.R.attr.textColorPrimary }); + int colorResource = res.getColor(0, 0); + String colorString = String.format("#%06X", 0xFFFFFF & colorResource); + res.recycle(); + input = getAssets().open(filename); + String webViewData = IOUtils.toString(input, Charset.defaultCharset()); + if(!webViewData.startsWith("<!DOCTYPE html>")) { + //webViewData = webViewData.replace("\n\n", "</p><p>"); + webViewData = webViewData.replace("%", "%"); + webViewData = + "<!DOCTYPE html>" + + "<html>" + + "<head>" + + " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + + " <style type=\"text/css\">" + + " @font-face {" + + " font-family: 'Roboto-Light';" + + " src: url('file:///android_asset/Roboto-Light.ttf');" + + " }" + + " * {" + + " color: %s;" + + " font-family: roboto-Light;" + + " font-size: 8pt;" + + " }" + + " </style>" + + "</head><body><p>" + webViewData + "</p></body></html>"; + webViewData = webViewData.replace("\n", "<br/>"); + depth++; + } else { + depth = 0; + } + webViewData = String.format(webViewData, colorString); + subscriber.onNext(webViewData); + } catch (IOException e) { + subscriber.onError(e); + } finally { + IOUtils.closeQuietly(input); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index ca214de9e..123f66661 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -6,6 +6,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; +import java.text.DecimalFormat; import java.util.concurrent.atomic.AtomicBoolean; import de.danoeh.antennapod.core.feed.MediaType; @@ -18,15 +19,18 @@ import de.danoeh.antennapod.dialog.VariableSpeedDialog; * Activity for playing audio files. */ public class AudioplayerActivity extends MediaplayerInfoActivity { - public static final String TAG = "AudioPlayerActivity"; + private static final String TAG = "AudioPlayerActivity"; - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); @Override protected void onResume() { super.onResume(); if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { Intent intent = getIntent(); + if (intent.getData() == null) { + return; + } Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath()); ExternalMedia media = new ExternalMedia(intent.getData().getPath(), MediaType.AUDIO); @@ -40,7 +44,8 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { startService(launchIntent); } else if (PlaybackService.isCasting()) { Intent intent = PlaybackService.getPlayerActivityIntent(this); - if (!intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { + if (intent.getComponent() != null && + !intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { saveCurrentFragment(); finish(); startActivity(intent); @@ -95,7 +100,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { UserPreferences.setPlaybackSpeed(String.valueOf(speed)); } } - String speedStr = String.format("%.2fx", speed); + String speedStr = new DecimalFormat("0.00x").format(speed); butPlaybackSpeed.setText(speedStr); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java index a7e9b1e70..871e9c279 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java @@ -13,9 +13,9 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService; * Activity for controlling the remote playback on a Cast device. */ public class CastplayerActivity extends MediaplayerInfoActivity { - public static final String TAG = "CastPlayerActivity"; + private static final String TAG = "CastPlayerActivity"; - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java index 41b2debdc..e726afaec 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -3,15 +3,14 @@ package de.danoeh.antennapod.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; -import android.util.Log; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.apache.commons.lang3.Validate; -import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadRequest; @@ -23,8 +22,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; * Other arguments are optional. * The activity's result will be the same DownloadRequest with the entered username and password. */ -public class DownloadAuthenticationActivity extends ActionBarActivity { - private static final String TAG = "DownloadAuthenticationActivity"; +public class DownloadAuthenticationActivity extends AppCompatActivity { /** * The download request object that contains information about the resource that requires a username and a password @@ -36,47 +34,39 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { */ public static final String ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL = "send_to_downloadrequester"; - public static final String RESULT_REQUEST = "request"; + private static final String RESULT_REQUEST = "request"; private EditText etxtUsername; private EditText etxtPassword; - private Button butConfirm; - private Button butCancel; - private TextView txtvDescription; - - private DownloadRequest request; - private boolean sendToDownloadRequester; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - getSupportActionBar().hide(); - setContentView(R.layout.download_authentication_activity); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } + setContentView(R.layout.download_authentication_activity); + TextView txtvDescription = (TextView) findViewById(R.id.txtvDescription); etxtUsername = (EditText) findViewById(R.id.etxtUsername); etxtPassword = (EditText) findViewById(R.id.etxtPassword); - butConfirm = (Button) findViewById(R.id.butConfirm); - butCancel = (Button) findViewById(R.id.butCancel); - txtvDescription = (TextView) findViewById(R.id.txtvDescription); + Button butConfirm = (Button) findViewById(R.id.butConfirm); + Button butCancel = (Button) findViewById(R.id.butCancel); Validate.isTrue(getIntent().hasExtra(ARG_DOWNLOAD_REQUEST), "Download request missing"); + DownloadRequest request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); + boolean sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); - request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); - sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); + String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle(); + txtvDescription.setText(newDescription); if (savedInstanceState != null) { etxtUsername.setText(savedInstanceState.getString("username")); etxtPassword.setText(savedInstanceState.getString("password")); } - txtvDescription.setText(txtvDescription.getText() + ":\n\n" + request.getTitle()); - - butCancel.setOnClickListener(v -> { - setResult(Activity.RESULT_CANCELED); - finish(); - }); - butConfirm.setOnClickListener(v -> { String username = etxtUsername.getText().toString(); String password = etxtPassword.getText().toString(); @@ -87,11 +77,16 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { setResult(Activity.RESULT_OK, result); if (sendToDownloadRequester) { - if (BuildConfig.DEBUG) Log.d(TAG, "Sending request to DownloadRequester"); DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); } finish(); }); + + butCancel.setOnClickListener(v -> { + setResult(Activity.RESULT_CANCELED); + finish(); + }); + } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java index 2a58d5104..8dea41b7c 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java @@ -88,16 +88,10 @@ public class FeedInfoActivity extends AppCompatActivity { public void onClick(View v) { if(feed != null && feed.getDownload_url() != null) { String url = feed.getDownload_url(); - if (android.os.Build.VERSION.SDK_INT >= 11) { - ClipData clipData = ClipData.newPlainText(url, url); - android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedInfoActivity.this - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(clipData); - } else { - android.text.ClipboardManager cm = (android.text.ClipboardManager) FeedInfoActivity.this - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setText(url); - } + ClipData clipData = ClipData.newPlainText(url, url); + android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedInfoActivity.this + .getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(clipData); Toast t = Toast.makeText(FeedInfoActivity.this, R.string.copied_url_msg, Toast.LENGTH_SHORT); t.show(); } @@ -106,7 +100,7 @@ public class FeedInfoActivity extends AppCompatActivity { private boolean authInfoChanged = false; - private TextWatcher authTextWatcher = new TextWatcher() { + private final TextWatcher authTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -123,7 +117,7 @@ public class FeedInfoActivity extends AppCompatActivity { private boolean filterTextChanged = false; - private TextWatcher filterTextWatcher = new TextWatcher() { + private final TextWatcher filterTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -385,7 +379,7 @@ public class FeedInfoActivity extends AppCompatActivity { } } - private class ApplyToEpisodesDialog extends ConfirmationDialog { + private static class ApplyToEpisodesDialog extends ConfirmationDialog { private final Feed feed; private final boolean autoDownload; diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java index be1c9f9e6..d9c250b38 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java @@ -18,7 +18,6 @@ import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.flattr.FlattrUtils; -import de.danoeh.antennapod.preferences.PreferenceController; /** Guides the user through the authentication process */ @@ -104,7 +103,7 @@ public class FlattrAuthActivity extends ActionBarActivity { switch (item.getItemId()) { case android.R.id.home: if (authSuccessful) { - Intent intent = new Intent(this, PreferenceController.getPreferenceActivity()); + Intent intent = new Intent(this, PreferenceActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/ImportExportActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/ImportExportActivity.java new file mode 100644 index 000000000..6a97adcc3 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/activity/ImportExportActivity.java @@ -0,0 +1,185 @@ +package de.danoeh.antennapod.activity; + +import android.content.ComponentName; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.os.ParcelFileDescriptor; +import android.support.design.widget.Snackbar; +import android.support.v4.content.IntentCompat; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.MenuItem; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.storage.PodDBAdapter; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.channels.FileChannel; + +/** + * Displays the 'import/export' screen + */ +public class ImportExportActivity extends AppCompatActivity { + private static final int REQUEST_CODE_RESTORE = 43; + private static final int REQUEST_CODE_BACKUP_DOCUMENT = 44; + private static final String EXPORT_FILENAME = "AntennaPodBackup.db"; + private static final String TAG = ImportExportActivity.class.getSimpleName(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + setTheme(UserPreferences.getTheme()); + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayShowHomeEnabled(true); + setContentView(R.layout.import_export_activity); + + findViewById(R.id.button_export).setOnClickListener(view -> backup()); + findViewById(R.id.button_import).setOnClickListener(view -> restore()); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } else { + return super.onOptionsItemSelected(item); + } + } + + private void backup() { + if (Build.VERSION.SDK_INT >= 19) { + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT) + .addCategory(Intent.CATEGORY_OPENABLE) + .setType("application/x-sqlite3") + .putExtra(Intent.EXTRA_TITLE, EXPORT_FILENAME); + + startActivityForResult(intent, REQUEST_CODE_BACKUP_DOCUMENT); + } else { + try { + File sd = Environment.getExternalStorageDirectory(); + File backupDB = new File(sd, EXPORT_FILENAME); + writeBackupTo(new FileOutputStream(backupDB)); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } + } + } + + private void restore() { + if (Build.VERSION.SDK_INT >= 19) { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.setType("*/*"); + startActivityForResult(intent, REQUEST_CODE_RESTORE); + } else { + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("*/*"); + startActivityForResult(Intent.createChooser(intent, + getString(R.string.import_select_file)), REQUEST_CODE_RESTORE); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent resultData) { + if (resultCode != RESULT_OK || resultData == null) { + return; + } + Uri uri = resultData.getData(); + + if (requestCode == REQUEST_CODE_RESTORE) { + restoreFrom(uri); + } else if (requestCode == REQUEST_CODE_BACKUP_DOCUMENT) { + backupToDocument(uri); + } + } + + private void restoreFrom(Uri inputUri) { + File currentDB = getDatabasePath(PodDBAdapter.DATABASE_NAME); + InputStream inputStream = null; + try { + inputStream = getContentResolver().openInputStream(inputUri); + FileUtils.copyInputStreamToFile(inputStream, currentDB); + displayImportSuccessDialog(); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } finally { + IOUtils.closeQuietly(inputStream); + } + } + + private void displayImportSuccessDialog() { + AlertDialog.Builder d = new AlertDialog.Builder(ImportExportActivity.this); + d.setMessage(R.string.import_ok); + d.setCancelable(false); + d.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> { + Intent intent = new Intent(getApplicationContext(), SplashActivity.class); + ComponentName cn = intent.getComponent(); + Intent mainIntent = IntentCompat.makeRestartActivityTask(cn); + startActivity(mainIntent); + }); + d.show(); + } + + private void backupToDocument(Uri uri) { + ParcelFileDescriptor pfd = null; + FileOutputStream fileOutputStream = null; + try { + pfd = getContentResolver().openFileDescriptor(uri, "w"); + fileOutputStream = new FileOutputStream(pfd.getFileDescriptor()); + writeBackupTo(fileOutputStream); + + Snackbar.make(findViewById(R.id.import_export_layout), + R.string.export_ok, Snackbar.LENGTH_SHORT).show(); + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } finally { + IOUtils.closeQuietly(fileOutputStream); + + if (pfd != null) { + try { + pfd.close(); + } catch (IOException e) { + Log.d(TAG, "Unable to close ParcelFileDescriptor"); + } + } + } + } + + private void writeBackupTo(FileOutputStream outFileStream) { + FileChannel src = null; + FileChannel dst = null; + try { + File currentDB = getDatabasePath(PodDBAdapter.DATABASE_NAME); + + if (currentDB.exists()) { + src = new FileInputStream(currentDB).getChannel(); + dst = outFileStream.getChannel(); + dst.transferFrom(src, 0, src.size()); + + Snackbar.make(findViewById(R.id.import_export_layout), + R.string.export_ok, Snackbar.LENGTH_SHORT).show(); + } else { + Snackbar.make(findViewById(R.id.import_export_layout), + "Can not access current database", Snackbar.LENGTH_SHORT).show(); + } + } catch (IOException e) { + Log.e(TAG, Log.getStackTraceString(e)); + Snackbar.make(findViewById(R.id.import_export_layout), e.getLocalizedMessage(), Snackbar.LENGTH_SHORT).show(); + } finally { + IOUtils.closeQuietly(src); + IOUtils.closeQuietly(dst); + } + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index f0fcdca90..f56dca173 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -64,7 +64,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -83,7 +82,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String PREF_NAME = "MainActivityPrefs"; public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; - public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; + private static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; public static final String EXTRA_NAV_TYPE = "nav_type"; public static final String EXTRA_NAV_INDEX = "nav_index"; @@ -91,8 +90,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String EXTRA_FRAGMENT_ARGS = "fragment_args"; public static final String EXTRA_FEED_ID = "fragment_feed_id"; - public static final String SAVE_BACKSTACK_COUNT = "backstackCount"; - public static final String SAVE_TITLE = "title"; + private static final String SAVE_BACKSTACK_COUNT = "backstackCount"; + private static final String SAVE_TITLE = "title"; public static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, @@ -173,7 +172,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi findViewById(R.id.nav_settings).setOnClickListener(v -> { drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity())); + startActivity(new Intent(MainActivity.this, PreferenceActivity.class)); }); FragmentTransaction transaction = fm.beginTransaction(); @@ -236,7 +235,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } - public void showDrawerPreferencesDialog() { + private void showDrawerPreferencesDialog() { final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); String[] navLabels = new String[NAV_DRAWER_TAGS.length]; final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; @@ -270,7 +269,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi return (navDrawerData != null) ? navDrawerData.feeds : null; } - public void loadFragment(int index, Bundle args) { + private void loadFragment(int index, Bundle args) { Log.d(TAG, "loadFragment(index: " + index + ", args: " + args + ")"); if (index < navAdapter.getSubscriptionOffset()) { String tag = navAdapter.getTags().get(index); @@ -399,7 +398,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } - private AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() { + private final AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int viewType = parent.getAdapter().getItemViewType(position); @@ -410,7 +409,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } }; - private AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() { + private final AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if(position < navAdapter.getTags().size()) { @@ -631,7 +630,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi private DBReader.NavDrawerData navDrawerData; private int selectedNavListIndex = 0; - private NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { + private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { @Override public int getCount() { if (navDrawerData != null) { @@ -744,14 +743,12 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi View parentLayout = findViewById(R.id.drawer_layout); Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT); if(event.action != null) { - snackbar.setAction(getString(R.string.undo), v -> { - event.action.run(); - }); + snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } snackbar.show(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index ffc33eb1a..f3c0760f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -67,19 +67,19 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements private static final String PREFS = "MediaPlayerActivityPreferences"; private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft"; - protected PlaybackController controller; + PlaybackController controller; - protected TextView txtvPosition; - protected TextView txtvLength; - protected SeekBar sbPosition; - protected ImageButton butRev; - protected TextView txtvRev; - protected ImageButton butPlay; - protected ImageButton butFF; - protected TextView txtvFF; - protected ImageButton butSkip; + private TextView txtvPosition; + private TextView txtvLength; + SeekBar sbPosition; + private ImageButton butRev; + private TextView txtvRev; + private ImageButton butPlay; + private ImageButton butFF; + private TextView txtvFF; + private ImageButton butSkip; - protected boolean showTimeLeft = false; + private boolean showTimeLeft = false; private boolean isFavorite = false; @@ -184,31 +184,31 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements }; } - protected static TextView getTxtvFFFromActivity(MediaplayerActivity activity) { + private static TextView getTxtvFFFromActivity(MediaplayerActivity activity) { return activity.txtvFF; } - protected static TextView getTxtvRevFromActivity(MediaplayerActivity activity) { + private static TextView getTxtvRevFromActivity(MediaplayerActivity activity) { return activity.txtvRev; } - protected void onSetSpeedAbilityChanged() { + private void onSetSpeedAbilityChanged() { Log.d(TAG, "onSetSpeedAbilityChanged()"); updatePlaybackSpeedButton(); } - protected void onPlaybackSpeedChange() { + private void onPlaybackSpeedChange() { updatePlaybackSpeedButtonText(); } - protected void onServiceQueried() { + private void onServiceQueried() { supportInvalidateOptionsMenu(); } - protected void chooseTheme() { + void chooseTheme() { setTheme(UserPreferences.getTheme()); } - protected void setScreenOn(boolean enable) { + void setScreenOn(boolean enable) { } @Override @@ -251,7 +251,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements */ protected abstract void onBufferEnd(); - protected void onBufferUpdate(float progress) { + private void onBufferUpdate(float progress) { if (sbPosition != null) { sbPosition.setSecondaryProgress((int) progress * sbPosition.getMax()); } @@ -260,7 +260,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements /** * Current screen orientation. */ - protected int orientation; + private int orientation; @Override protected void onStart() { @@ -622,7 +622,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements protected abstract void clearStatusMsg(); - protected void onPositionObserverUpdate() { + void onPositionObserverUpdate() { if (controller == null || txtvPosition == null || txtvLength == null) { return; } @@ -658,7 +658,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements * to the PlaybackService to ensure that the activity has the right * FeedMedia object. */ - protected boolean loadMediaInfo() { + boolean loadMediaInfo() { Log.d(TAG, "loadMediaInfo()"); if(controller == null || controller.getMedia() == null) { return false; @@ -672,18 +672,18 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements return true; } - protected void updatePlaybackSpeedButton() { + void updatePlaybackSpeedButton() { // Only meaningful on AudioplayerActivity, where it is overridden. } - protected void updatePlaybackSpeedButtonText() { + void updatePlaybackSpeedButtonText() { // Only meaningful on AudioplayerActivity, where it is overridden. } /** * Abstract directions to skip forward or back (rewind) and encapsulates behavior to get or set preference (including update of UI on the skip buttons). */ - static public enum SkipDirection { + public enum SkipDirection { SKIP_FORWARD( UserPreferences::getFastForwardSecs, MediaplayerActivity::getTxtvFFFromActivity, @@ -766,7 +766,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements builder.create().show(); } - protected void setupGUI() { + void setupGUI() { setContentView(getContentViewResourceId()); sbPosition = (SeekBar) findViewById(R.id.sbPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition); @@ -840,7 +840,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } } - protected void onRewind() { + void onRewind() { if (controller == null) { return; } @@ -848,14 +848,14 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements controller.seekTo(curr - UserPreferences.getRewindSecs() * 1000); } - protected void onPlayPause() { + void onPlayPause() { if(controller == null) { return; } controller.playPause(); } - protected void onFastForward() { + void onFastForward() { if (controller == null) { return; } @@ -865,7 +865,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements protected abstract int getContentViewResourceId(); - void handleError(int errorCode) { + private void handleError(int errorCode) { final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this); errorDialog.setTitle(R.string.error_label); errorDialog.setMessage(MediaPlayerError.getErrorString(this, errorCode)); @@ -878,7 +878,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements errorDialog.create().show(); } - float prog; + private float prog; @Override public void onProgressChanged (SeekBar seekBar,int progress, boolean fromUser) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java index cc7d83e0c..f3ed1cb62 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -61,7 +61,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -73,16 +72,17 @@ import rx.schedulers.Schedulers; */ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implements NavDrawerActivity { + private static final String TAG = "MediaplayerInfoActivity"; + private static final int POS_COVER = 0; private static final int POS_DESCR = 1; private static final int POS_CHAPTERS = 2; private static final int NUM_CONTENT_FRAGMENTS = 3; - final String TAG = "MediaplayerInfoActivity"; private static final String PREFS = "AudioPlayerActivityPreferences"; private static final String PREF_KEY_SELECTED_FRAGMENT_POSITION = "selectedFragmentPosition"; - public static final String[] NAV_DRAWER_TAGS = { + private static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, EpisodesFragment.TAG, SubscriptionFragment.TAG, @@ -92,8 +92,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem NavListAdapter.SUBSCRIPTION_LIST_TAG }; - protected Button butPlaybackSpeed; - protected ImageButton butCastDisconnect; + Button butPlaybackSpeed; + ImageButton butCastDisconnect; private DrawerLayout drawerLayout; private NavListAdapter navAdapter; private ListView navList; @@ -152,7 +152,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem setTheme(UserPreferences.getNoTitleTheme()); } - protected void saveCurrentFragment() { + void saveCurrentFragment() { if(pager == null) { return; } @@ -160,7 +160,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); prefs.edit() .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, pager.getCurrentItem()) - .commit(); + .apply(); } @Override @@ -242,7 +242,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); drawerToggle.setDrawerIndicatorEnabled(false); - drawerLayout.setDrawerListener(drawerToggle); + drawerLayout.addDrawerListener(drawerToggle); navAdapter = new NavListAdapter(itemAccess, this); navList.setAdapter(navAdapter); @@ -270,7 +270,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem findViewById(R.id.nav_settings).setOnClickListener(v -> { drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceController.getPreferenceActivity())); + startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceActivity.class)); }); butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed); @@ -306,7 +306,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem return true; } - public void notifyMediaPositionChanged() { + private void notifyMediaPositionChanged() { if(pagerAdapter == null) { return; } @@ -396,12 +396,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem new RenameFeedDialog(this, feed).show(); return true; case R.id.remove_item: - final FeedRemover remover = new FeedRemover(this, feed) { - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - } - }; + final FeedRemover remover = new FeedRemover(this, feed); ConfirmationDialog conDialog = new ConfirmationDialog(this, R.string.remove_feed_label, getString(R.string.feed_delete_confirmation_msg, feed.getTitle())) { @@ -413,7 +408,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem Playable playable = controller.getMedia(); if (playable != null && playable instanceof FeedMedia) { FeedMedia media = (FeedMedia) playable; - if (media.getItem().getFeed().getId() == feed.getId()) { + if (media.getItem() != null && media.getItem().getFeed() != null && + media.getItem().getFeed().getId() == feed.getId()) { Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); remover.skipOnCompletion = true; if(controller.getStatus() == PlayerStatus.PLAYING) { @@ -447,7 +443,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem } } - public void showDrawerPreferencesDialog() { + private void showDrawerPreferencesDialog() { final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); String[] navLabels = new String[NAV_DRAWER_TAGS.length]; final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; @@ -492,14 +488,12 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem View parentLayout = findViewById(R.id.drawer_layout); Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT); if (event.action != null) { - snackbar.setAction(getString(R.string.undo), v -> { - event.action.run(); - }); + snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } snackbar.show(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index f6bf11e66..f859f5466 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -5,8 +5,9 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.os.Looper; +import android.support.annotation.UiThread; import android.support.v4.app.NavUtils; +import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; @@ -55,7 +56,6 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.syndication.handler.FeedHandler; -import de.danoeh.antennapod.core.syndication.handler.FeedHandlerResult; import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.FileNameGenerator; @@ -66,7 +66,6 @@ import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.greenrobot.event.EventBus; import rx.Observable; -import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -84,7 +83,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { public static final String ARG_FEEDURL = "arg.feedurl"; // Optional argument: specify a title for the actionbar. public static final String ARG_TITLE = "title"; - public static final int RESULT_ERROR = 2; + private static final int RESULT_ERROR = 2; private static final String TAG = "OnlineFeedViewActivity"; private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; private volatile List<Feed> feeds; @@ -101,7 +100,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private Subscription download; private Subscription parser; private Subscription updater; - private EventDistributor.EventListener listener = new EventDistributor.EventListener() { + private final EventDistributor.EventListener listener = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) { @@ -112,9 +111,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { feeds -> { OnlineFeedViewActivity.this.feeds = feeds; setSubscribeButtonState(feed); - }, error -> { - Log.e(TAG, Log.getStackTraceString(error)); - } + }, error -> Log.e(TAG, Log.getStackTraceString(error)) ); } else if ((arg & EVENTS) != 0) { setSubscribeButtonState(feed); @@ -131,10 +128,13 @@ public class OnlineFeedViewActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + } - if (getIntent() != null && getIntent().hasExtra(ARG_TITLE)) { - getSupportActionBar().setTitle(getIntent().getStringExtra(ARG_TITLE)); + if (actionBar != null && getIntent() != null && getIntent().hasExtra(ARG_TITLE)) { + actionBar.setTitle(getIntent().getStringExtra(ARG_TITLE)); } StorageUtils.checkStorageAvailability(this); @@ -146,7 +146,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity { || TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { feedUrl = (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)) ? getIntent().getStringExtra(Intent.EXTRA_TEXT) : getIntent().getDataString(); - getSupportActionBar().setTitle(R.string.add_feed_label); + if (actionBar != null) { + actionBar.setTitle(R.string.add_feed_label); + } } else { throw new IllegalArgumentException("Activity must be started with feedurl argument!"); } @@ -265,16 +267,11 @@ public class OnlineFeedViewActivity extends AppCompatActivity { feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password, true, null); - download = Observable.create(new Observable.OnSubscribe<DownloadStatus>() { - @Override - public void call(Subscriber<? super DownloadStatus> subscriber) { - feeds = DBReader.getFeedList(); - downloader = new HttpDownloader(request); - downloader.call(); - Log.d(TAG, "Download was completed"); - subscriber.onNext(downloader.getResult()); - subscriber.onCompleted(); - } + download = Observable.fromCallable(() -> { + feeds = DBReader.getFeedList(); + downloader = new HttpDownloader(request); + downloader.call(); + return downloader.getResult(); }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -286,6 +283,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { if (status == null) { Log.wtf(TAG, "DownloadStatus returned by Downloader was null"); finish(); + return; } if (status.isCancelled()) { return; @@ -300,7 +298,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } } else { String errorMsg = status.getReason().getErrorString(OnlineFeedViewActivity.this); - if (errorMsg != null && status.getReasonDetailed() != null) { + if (status.getReasonDetailed() != null) { errorMsg += " (" + status.getReasonDetailed() + ")"; } showErrorDialog(errorMsg); @@ -313,35 +311,33 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } Log.d(TAG, "Parsing feed"); - parser = Observable.create(new Observable.OnSubscribe<FeedHandlerResult>() { - @Override - public void call(Subscriber<? super FeedHandlerResult> subscriber) { - FeedHandler handler = new FeedHandler(); - try { - FeedHandlerResult result = handler.parseFeed(feed); - subscriber.onNext(result); - } catch (UnsupportedFeedtypeException e) { - Log.d(TAG, "Unsupported feed type detected"); - if (TextUtils.equals("html", e.getRootElement().toLowerCase())) { - showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); - } else { - subscriber.onError(e); - } - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - subscriber.onError(e); - } finally { - boolean rc = new File(feed.getFile_url()).delete(); - Log.d(TAG, "Deleted feed source file. Result: " + rc); - subscriber.onCompleted(); + parser = Observable.fromCallable(() -> { + FeedHandler handler = new FeedHandler(); + try { + return handler.parseFeed(feed); + } catch (UnsupportedFeedtypeException e) { + Log.d(TAG, "Unsupported feed type detected"); + if (TextUtils.equals("html", e.getRootElement().toLowerCase())) { + showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); + return null; + } else { + throw e; } + } catch (Exception e) { + Log.e(TAG, Log.getStackTraceString(e)); + throw e; + } finally { + boolean rc = new File(feed.getFile_url()).delete(); + Log.d(TAG, "Deleted feed source file. Result: " + rc); } }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - beforeShowFeedInformation(result.feed); - showFeedInformation(result.feed, result.alternateFeedUrls); + if(result != null) { + beforeShowFeedInformation(result.feed); + showFeedInformation(result.feed, result.alternateFeedUrls); + } }, error -> { String errorMsg = DownloadError.ERROR_PARSER_EXCEPTION.getErrorString( OnlineFeedViewActivity.this) + " (" + error.getMessage() + ")"; @@ -383,8 +379,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { this.selectedDownloadUrl = feed.getDownload_url(); EventDistributor.getInstance().register(listener); ListView listView = (ListView) findViewById(R.id.listview); - LayoutInflater inflater = (LayoutInflater) - getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = LayoutInflater.from(this); View header = inflater.inflate(R.layout.onlinefeedview_header, listView, false); listView.addHeaderView(header); @@ -414,7 +409,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { description.setText(feed.getDescription()); subscribeButton.setOnClickListener(v -> { - if(feed != null && feedInFeedlist(feed)) { + if(feedInFeedlist(feed)) { Intent intent = new Intent(OnlineFeedViewActivity.this, MainActivity.class); // feed.getId() is always 0, we have to retrieve the id from the feed list from // the database @@ -508,8 +503,8 @@ public class OnlineFeedViewActivity extends AppCompatActivity { return 0; } + @UiThread private void showErrorDialog(String errorMsg) { - assert(Looper.myLooper() == Looper.getMainLooper()); // run on UI thread if (!isFinishing() && !isPaused) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.error_label); @@ -586,7 +581,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private class FeedViewAuthenticationDialog extends AuthenticationDialog { - private String feedUrl; + private final String feedUrl; FeedViewAuthenticationDialog(Context context, int titleRes, String feedUrl) { super(context, titleRes, true, false, null, null); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java index 355e0f372..cd375a65a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java @@ -97,7 +97,7 @@ public class OpmlFeedChooserActivity extends AppCompatActivity { } private List<String> getTitleList() { - List<String> result = new ArrayList<String>(); + List<String> result = new ArrayList<>(); if (OpmlImportHolder.getReadElements() != null) { for (OpmlElement element : OpmlImportHolder.getReadElements()) { result.add(element.getText()); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java index 07b0b3cdb..c04ae051e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java @@ -68,7 +68,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } } - protected void importUri(@Nullable Uri uri) { + void importUri(@Nullable Uri uri) { if(uri == null) { new MaterialDialog.Builder(this) .content(R.string.opml_import_error_no_file) @@ -114,7 +114,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } /** Starts the import process. */ - protected void startImport() { + private void startImport() { try { Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8); importWorker = new OpmlImportWorker(this, mReader) { @@ -144,7 +144,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } } - protected boolean finishWhenCanceled() { + boolean finishWhenCanceled() { return false; } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index dd932814f..12d918a76 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -1,9 +1,7 @@ package de.danoeh.antennapod.activity; -import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; @@ -30,7 +28,6 @@ public class PreferenceActivity extends AppCompatActivity { private PreferenceController preferenceController; private MainFragment prefFragment; private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public Preference findPreference(CharSequence key) { return prefFragment.findPreference(key); @@ -42,7 +39,6 @@ public class PreferenceActivity extends AppCompatActivity { } }; - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected void onCreate(Bundle savedInstanceState) { // This must be the FIRST thing we do, otherwise other code may not have the @@ -95,7 +91,6 @@ public class PreferenceActivity extends AppCompatActivity { } } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static class MainFragment extends PreferenceFragment { @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java deleted file mode 100644 index 390bec15c..000000000 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java +++ /dev/null @@ -1,97 +0,0 @@ -package de.danoeh.antennapod.activity; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.content.res.Resources.Theme; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceScreen; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.preferences.PreferenceController; - -/** - * PreferenceActivity for API 10. In order to change the behavior of the preference UI, see - * PreferenceController. - */ -public class PreferenceActivityGingerbread extends android.preference.PreferenceActivity { - private static final String TAG = "PreferenceActivity"; - private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - - @SuppressWarnings("deprecation") - @Override - public Preference findPreference(CharSequence key) { - return PreferenceActivityGingerbread.this.findPreference(key); - } - - @Override - public Activity getActivity() { - return PreferenceActivityGingerbread.this; - } - }; - private PreferenceController preferenceController; - - @SuppressLint("NewApi") - @SuppressWarnings("deprecation") - @Override - public void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - - addPreferencesFromResource(R.xml.preferences); - preferenceController = new PreferenceController(preferenceUI); - preferenceController.onCreate(); - } - - - @Override - protected void onResume() { - super.onResume(); - preferenceController.onResume(); - } - - @Override - protected void onPause() { - preferenceController.onPause(); - super.onPause(); - } - - @Override - protected void onStop() { - preferenceController.onStop(); - super.onStop(); - } - - @Override - protected void onApplyThemeResource(Theme theme, int resid, boolean first) { - theme.applyStyle(UserPreferences.getTheme(), true); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - preferenceController.onActivityResult(requestCode, resultCode, data); - } - - @SuppressWarnings("deprecation") - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, - Preference preference) { - super.onPreferenceTreeClick(preferenceScreen, preference); - if (preference != null) - if (preference instanceof PreferenceScreen) - if (((PreferenceScreen) preference).getDialog() != null) - ((PreferenceScreen) preference) - .getDialog() - .getWindow() - .getDecorView() - .setBackgroundDrawable( - this.getWindow().getDecorView() - .getBackground().getConstantState() - .newDrawable() - ); - return false; - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java index d104a9e93..a2a49f54e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java @@ -164,7 +164,7 @@ public class StorageErrorActivity extends AppCompatActivity { startActivity(new Intent(this, MainActivity.class)); } - private BroadcastReceiver mediaUpdate = new BroadcastReceiver() { + private final BroadcastReceiver mediaUpdate = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index 90b4c72ea..be5107d75 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -7,6 +7,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.WindowCompat; +import android.support.v7.app.ActionBar; import android.util.Log; import android.util.Pair; import android.view.Menu; @@ -47,7 +48,7 @@ public class VideoplayerActivity extends MediaplayerActivity { private VideoControlsHider videoControlsHider = new VideoControlsHider(this); - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); private LinearLayout controls; private LinearLayout videoOverlay; @@ -182,7 +183,7 @@ public class VideoplayerActivity extends MediaplayerActivity { progressIndicator.setVisibility(View.INVISIBLE); } - private View.OnTouchListener onVideoviewTouched = (v, event) -> { + private final View.OnTouchListener onVideoviewTouched = (v, event) -> { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode()) { @@ -200,7 +201,7 @@ public class VideoplayerActivity extends MediaplayerActivity { }; @SuppressLint("NewApi") - void setupVideoControlsToggler() { + private void setupVideoControlsToggler() { videoControlsHider.stop(); videoControlsHider.start(); } @@ -400,18 +401,21 @@ public class VideoplayerActivity extends MediaplayerActivity { private WeakReference<VideoplayerActivity> activity; - public VideoControlsHider(VideoplayerActivity activity) { + VideoControlsHider(VideoplayerActivity activity) { this.activity = new WeakReference<>(activity); } private final Runnable hideVideoControls = () -> { - VideoplayerActivity vpa = activity.get(); + VideoplayerActivity vpa = activity != null ? activity.get() : null; if (vpa == null) { return; } if (vpa.videoControlsShowing) { Log.d(TAG, "Hiding video controls"); - vpa.getSupportActionBar().hide(); + ActionBar actionBar = vpa.getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } vpa.hideVideoControls(); vpa.videoControlsShowing = false; } @@ -421,7 +425,7 @@ public class VideoplayerActivity extends MediaplayerActivity { this.postDelayed(hideVideoControls, DELAY); } - public void stop() { + void stop() { this.removeCallbacks(hideVideoControls); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java index 8ede947c5..8f447ac90 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java @@ -61,7 +61,7 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity { private volatile String password; private volatile GpodnetDevice selectedDevice; - View[] views; + private View[] views; @Override protected void onCreate(Bundle savedInstanceState) { @@ -171,11 +171,7 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity { return null; } }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - authTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, service); - } else { - authTask.execute(); - } + authTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, service); } }); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java index c18564351..e6b42efcb 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonCallback.java @@ -3,7 +3,7 @@ package de.danoeh.antennapod.adapter; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.util.LongList; -public interface ActionButtonCallback { +interface ActionButtonCallback { /** Is called when the action button of a list item has been pressed. */ void onActionButtonPressed(FeedItem item, LongList queueIds); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java index f0210f983..a915692d1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ActionButtonUtils.java @@ -16,7 +16,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; * Utility methods for the action button that is displayed on the right hand side * of a listitem. */ -public class ActionButtonUtils { +class ActionButtonUtils { private final int[] labels; private final TypedArray drawables; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index f12c8285a..715318db1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -21,7 +21,6 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.joanzapata.iconify.Iconify; -import com.nineoldandroids.view.ViewHelper; import java.lang.ref.WeakReference; @@ -101,7 +100,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR holder.txtvDuration = (TextView) view.findViewById(R.id.txtvDuration); holder.item = null; holder.mainActivityRef = mainActivityRef; - holder.position = -1; // so we can grab this later view.setTag(holder); @@ -113,11 +111,10 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR final FeedItem item = itemAccess.getItem(position); if (item == null) return; holder.itemView.setOnLongClickListener(v -> { - this.position = position; + this.position = holder.getAdapterPosition(); return false; }); holder.item = item; - holder.position = position; holder.placeholder.setVisibility(View.VISIBLE); holder.placeholder.setText(item.getFeed().getTitle()); holder.title.setText(item.getTitle()); @@ -129,9 +126,9 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR holder.statusUnread.setVisibility(View.VISIBLE); } if(item.isPlayed()) { - ViewHelper.setAlpha(holder.content, 0.5f); + holder.content.setAlpha(0.5f); } else { - ViewHelper.setAlpha(holder.content, 1.0f); + holder.content.setAlpha(1.0f); } FeedMedia media = item.getMedia(); @@ -228,7 +225,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR return pos; } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { + private final View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); @@ -253,7 +250,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR ImageButton butSecondary; FeedItem item; WeakReference<MainActivity> mainActivityRef; - int position; public Holder(View itemView) { super(itemView); @@ -266,18 +262,18 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR MainActivity mainActivity = mainActivityRef.get(); if (mainActivity != null) { long[] ids = itemAccess.getItemsIds().toArray(); - mainActivity.loadChildFragment(ItemFragment.newInstance(ids, position)); + mainActivity.loadChildFragment(ItemFragment.newInstance(ids, getAdapterPosition())); } } @Override public void onItemSelected() { - ViewHelper.setAlpha(itemView, 0.5f); + itemView.setAlpha(0.5f); } @Override public void onItemClear() { - ViewHelper.setAlpha(itemView, 1.0f); + itemView.setAlpha(1.0f); } public FeedItem getFeedItem() { return item; } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java index e271b5eed..7c0be47b6 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java @@ -29,11 +29,11 @@ import de.danoeh.antennapod.core.storage.DownloadRequestException; /** Displays a list of DownloadStatus entries. */ public class DownloadLogAdapter extends BaseAdapter { - private final String TAG = "DownloadLogAdapter"; + private static final String TAG = "DownloadLogAdapter"; - private Context context; + private final Context context; - private ItemAccess itemAccess; + private final ItemAccess itemAccess; public DownloadLogAdapter(Context context, ItemAccess itemAccess) { super(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java index 6907e467b..c62c30c90 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java @@ -12,7 +12,6 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.nineoldandroids.view.ViewHelper; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItem; @@ -87,9 +86,9 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter { .into(holder.imageView); if(item.isPlayed()) { - ViewHelper.setAlpha(convertView, 0.5f); + convertView.setAlpha(0.5f); } else { - ViewHelper.setAlpha(convertView, 1.0f); + convertView.setAlpha(1.0f); } holder.title.setText(item.getTitle()); @@ -111,7 +110,7 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter { return convertView; } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { + private final View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java index e1efdaa7b..5bc67a95a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadlistAdapter.java @@ -19,11 +19,11 @@ import de.danoeh.antennapod.core.util.ThemeUtils; public class DownloadlistAdapter extends BaseAdapter { - public static final int SELECTION_NONE = -1; + private static final int SELECTION_NONE = -1; private int selectedItemIndex; - private ItemAccess itemAccess; - private Context context; + private final ItemAccess itemAccess; + private final Context context; public DownloadlistAdapter(Context context, ItemAccess itemAccess) { @@ -105,7 +105,7 @@ public class DownloadlistAdapter extends BaseAdapter { return convertView; } - private View.OnClickListener butSecondaryListener = new View.OnClickListener() { + private final View.OnClickListener butSecondaryListener = new View.OnClickListener() { @Override public void onClick(View v) { Downloader downloader = (Downloader) v.getTag(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java index f843ddb94..e29781be1 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -17,8 +17,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import com.nineoldandroids.view.ViewHelper; - import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; @@ -34,16 +32,16 @@ import de.danoeh.antennapod.core.util.ThemeUtils; */ public class FeedItemlistAdapter extends BaseAdapter { - private ActionButtonCallback callback; + private final ActionButtonCallback callback; private final ItemAccess itemAccess; private final Context context; - private boolean showFeedtitle; - private int selectedItemIndex; + private final boolean showFeedtitle; + private final int selectedItemIndex; /** true if played items should be made partially transparent */ - private boolean makePlayedItemsTransparent; + private final boolean makePlayedItemsTransparent; private final ActionButtonUtils actionButtonUtils; - public static final int SELECTION_NONE = -1; + private static final int SELECTION_NONE = -1; private final int playingBackGroundColor; private final int normalBackGroundColor; @@ -145,9 +143,9 @@ public class FeedItemlistAdapter extends BaseAdapter { holder.statusUnread.setVisibility(View.INVISIBLE); } if(item.isPlayed() && makePlayedItemsTransparent) { - ViewHelper.setAlpha(convertView, 0.5f); + convertView.setAlpha(0.5f); } else { - ViewHelper.setAlpha(convertView, 1.0f); + convertView.setAlpha(1.0f); } String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate()); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 465497b55..2daa5e70f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -48,10 +48,10 @@ import de.danoeh.antennapod.fragment.SubscriptionFragment; public class NavListAdapter extends BaseAdapter implements SharedPreferences.OnSharedPreferenceChangeListener { - public static final int VIEW_TYPE_COUNT = 3; + private static final int VIEW_TYPE_COUNT = 3; public static final int VIEW_TYPE_NAV = 0; public static final int VIEW_TYPE_SECTION_DIVIDER = 1; - public static final int VIEW_TYPE_SUBSCRIPTION = 2; + private static final int VIEW_TYPE_SUBSCRIPTION = 2; /** * a tag used as a placeholder to indicate if the subscription list should be displayed or not @@ -62,8 +62,8 @@ public class NavListAdapter extends BaseAdapter private static List<String> tags; private static String[] titles; - private ItemAccess itemAccess; - private WeakReference<Activity> activity; + private final ItemAccess itemAccess; + private final WeakReference<Activity> activity; private boolean showSubscriptionList = true; public NavListAdapter(ItemAccess itemAccess, Activity context) { @@ -86,9 +86,7 @@ public class NavListAdapter extends BaseAdapter private void loadItems() { List<String> newTags = new ArrayList<>(Arrays.asList(MainActivity.NAV_DRAWER_TAGS)); List<String> hiddenFragments = UserPreferences.getHiddenDrawerItems(); - for(String hidden : hiddenFragments) { - newTags.remove(hidden); - } + newTags.removeAll(hiddenFragments); if (newTags.contains(SUBSCRIPTION_LIST_TAG)) { // we never want SUBSCRIPTION_LIST_TAG to be in 'tags' diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 2684dcccd..01dd4c2de 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -24,7 +24,6 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.joanzapata.iconify.Iconify; -import com.nineoldandroids.view.ViewHelper; import org.apache.commons.lang3.ArrayUtils; @@ -51,7 +50,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap private static final String TAG = QueueRecyclerAdapter.class.getSimpleName(); - private WeakReference<MainActivity> mainActivity; + private final WeakReference<MainActivity> mainActivity; private final ItemAccess itemAccess; private final ActionButtonCallback actionButtonCallback; private final ActionButtonUtils actionButtonUtils; @@ -198,12 +197,12 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap @Override public void onItemSelected() { - ViewHelper.setAlpha(itemView, 0.5f); + itemView.setAlpha(0.5f); } @Override public void onItemClear() { - ViewHelper.setAlpha(itemView, 1.0f); + itemView.setAlpha(1.0f); } public void bind(FeedItem item) { @@ -305,7 +304,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap } - private View.OnClickListener secondaryActionListener = new View.OnClickListener() { + private final View.OnClickListener secondaryActionListener = new View.OnClickListener() { @Override public void onClick(View v) { FeedItem item = (FeedItem) v.getTag(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java index 8e1aa24e0..beb62b3bb 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java @@ -11,7 +11,6 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.nineoldandroids.view.ViewHelper; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.Feed; @@ -97,7 +96,7 @@ public class SearchlistAdapter extends BaseAdapter { holder.subtitle.setText(result.getSubtitle()); } - ViewHelper.setAlpha(convertView, item.isPlayed() ? 0.5f : 1.0f); + convertView.setAlpha(item.isPlayed() ? 0.5f : 1.0f); Glide.with(context) .load(item.getFeed().getImageLocation()) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java index c060083a6..50255c11f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/StatisticsListAdapter.java @@ -23,8 +23,8 @@ import de.danoeh.antennapod.core.util.Converter; * Adapter for the statistics list */ public class StatisticsListAdapter extends BaseAdapter { - private Context context; - List<DBReader.StatisticsItem> feedTime = new ArrayList<>(); + private final Context context; + private List<DBReader.StatisticsItem> feedTime = new ArrayList<>(); private boolean countAll = true; public StatisticsListAdapter(Context context) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index 6d19bfa6c..bb76ab501 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -50,7 +50,6 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI } private int getAdjustedPosition(int origPosition) { - assert(origPosition != getAddTilePosition()); return origPosition < getAddTilePosition() ? origPosition : origPosition - 1; } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java index f1f8be559..e493a2ecc 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java @@ -124,7 +124,7 @@ public class ItunesAdapter extends ArrayAdapter<ItunesAdapter.Podcast> { * @param json object holding the podcast information * @throws JSONException */ - public static Podcast fromSearch(JSONObject json) throws JSONException { + public static Podcast fromSearch(JSONObject json) { String title = json.optString("collectionName", ""); String imageUrl = json.optString("artworkUrl100", null); String feedUrl = json.optString("feedUrl", null); @@ -162,7 +162,7 @@ public class ItunesAdapter extends ArrayAdapter<ItunesAdapter.Podcast> { /** * View holder object for the GridView */ - class PodcastViewHolder { + static class PodcastViewHolder { /** * ImageView holding the Podcast image diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java b/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java index 192df8ca5..b6cf5cb84 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/ExportWorker.java @@ -23,15 +23,15 @@ public class ExportWorker { private static final String TAG = "ExportWorker"; private static final String DEFAULT_OUTPUT_NAME = "antennapod-feeds"; - private ExportWriter exportWriter; - private File output; + private final ExportWriter exportWriter; + private final File output; public ExportWorker(ExportWriter exportWriter) { this(exportWriter, new File(UserPreferences.getDataFolder(EXPORT_DIR), DEFAULT_OUTPUT_NAME + "." + exportWriter.fileExtension())); } - public ExportWorker(ExportWriter exportWriter, @NonNull File output) { + private ExportWorker(ExportWriter exportWriter, @NonNull File output) { this.exportWriter = exportWriter; this.output = output; } diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java index 4449d82c2..ea5128102 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlFeedQueuer.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.asynctask; -import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; @@ -16,9 +15,9 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; /** Queues items for download in the background. */ public class OpmlFeedQueuer extends AsyncTask<Void, Void, Void> { - private Context context; + private final Context context; private ProgressDialog progDialog; - private int[] selection; + private final int[] selection; public OpmlFeedQueuer(Context context, int[] selection) { super(); @@ -56,13 +55,8 @@ public class OpmlFeedQueuer extends AsyncTask<Void, Void, Void> { return null; } - @SuppressLint("NewApi") public void executeAsync() { - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - executeOnExecutor(THREAD_POOL_EXECUTOR); - } else { - execute(); - } + executeOnExecutor(THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java index 62ea85811..13b95907f 100644 --- a/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java +++ b/app/src/main/java/de/danoeh/antennapod/asynctask/OpmlImportWorker.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.asynctask; -import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; @@ -21,12 +20,12 @@ public class OpmlImportWorker extends AsyncTask<Void, Void, ArrayList<OpmlElement>> { private static final String TAG = "OpmlImportWorker"; - private Context context; + private final Context context; private Exception exception; private ProgressDialog progDialog; - private Reader mReader; + private final Reader mReader; public OpmlImportWorker(Context context, Reader reader) { super(); @@ -93,13 +92,8 @@ public class OpmlImportWorker extends return exception != null; } - @SuppressLint("NewApi") public void executeAsync() { - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - executeOnExecutor(THREAD_POOL_EXECUTOR); - } else { - execute(); - } + executeOnExecutor(THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java index f26f2ea76..d2498955c 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java +++ b/app/src/main/java/de/danoeh/antennapod/config/ClientConfigurator.java @@ -6,7 +6,7 @@ import de.danoeh.antennapod.core.ClientConfig; /** * Configures the ClientConfig class of the core package. */ -public class ClientConfigurator { +class ClientConfigurator { static { ClientConfig.USER_AGENT = "AntennaPod/" + BuildConfig.VERSION_NAME; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java index ac073141d..10ce12771 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodesApplyActionFragment.java @@ -32,14 +32,14 @@ import de.danoeh.antennapod.core.util.LongList; public class EpisodesApplyActionFragment extends Fragment { - public String TAG = "EpisodeActionFragment"; + public static final String TAG = "EpisodeActionFragment"; - public static final int ACTION_QUEUE = 1; - public static final int ACTION_MARK_PLAYED = 2; - public static final int ACTION_MARK_UNPLAYED = 4; - public static final int ACTION_DOWNLOAD = 8; + private static final int ACTION_QUEUE = 1; + private static final int ACTION_MARK_PLAYED = 2; + private static final int ACTION_MARK_UNPLAYED = 4; + private static final int ACTION_DOWNLOAD = 8; public static final int ACTION_REMOVE = 16; - public static final int ACTION_ALL = ACTION_QUEUE | ACTION_MARK_PLAYED | ACTION_MARK_UNPLAYED + private static final int ACTION_ALL = ACTION_QUEUE | ACTION_MARK_PLAYED | ACTION_MARK_UNPLAYED | ACTION_DOWNLOAD | ACTION_REMOVE; private ListView mListView; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java index 0bd75b5b0..b9276982a 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java @@ -43,7 +43,7 @@ public class ProxyDialog { private static final String TAG = "ProxyDialog"; - private Context context; + private final Context context; private MaterialDialog dialog; @@ -243,47 +243,44 @@ public class ProxyDialog { txtvMessage.setTextColor(textColorPrimary); txtvMessage.setText("{fa-circle-o-notch spin} " + checking); txtvMessage.setVisibility(View.VISIBLE); - subscription = Observable.create(new Observable.OnSubscribe<Response>() { - @Override - public void call(Subscriber<? super Response> subscriber) { - String type = (String) spType.getSelectedItem(); - String host = etHost.getText().toString(); - String port = etPort.getText().toString(); - String username = etUsername.getText().toString(); - String password = etPassword.getText().toString(); - int portValue = 8080; - if(!TextUtils.isEmpty(port)) { - portValue = Integer.valueOf(port); - } - SocketAddress address = InetSocketAddress.createUnresolved(host, portValue); - Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase()); - Proxy proxy = new Proxy(proxyType, address); - OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .proxy(proxy); - builder.interceptors().clear(); - OkHttpClient client = builder.build(); - if(!TextUtils.isEmpty(username)) { - String credentials = Credentials.basic(username, password); - client.interceptors().add(chain -> { - Request request = chain.request().newBuilder() - .header("Proxy-Authorization", credentials).build(); - return chain.proceed(request); - }); - } - Request request = new Request.Builder() - .url("http://www.google.com") - .head() - .build(); - try { - Response response = client.newCall(request).execute(); - subscriber.onNext(response); - } catch(IOException e) { - subscriber.onError(e); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<Response>) subscriber -> { + String type = (String) spType.getSelectedItem(); + String host = etHost.getText().toString(); + String port = etPort.getText().toString(); + String username = etUsername.getText().toString(); + String password = etPassword.getText().toString(); + int portValue = 8080; + if(!TextUtils.isEmpty(port)) { + portValue = Integer.valueOf(port); + } + SocketAddress address = InetSocketAddress.createUnresolved(host, portValue); + Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase()); + Proxy proxy = new Proxy(proxyType, address); + OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder() + .connectTimeout(10, TimeUnit.SECONDS) + .proxy(proxy); + builder.interceptors().clear(); + OkHttpClient client = builder.build(); + if(!TextUtils.isEmpty(username)) { + String credentials = Credentials.basic(username, password); + client.interceptors().add(chain -> { + Request request = chain.request().newBuilder() + .header("Proxy-Authorization", credentials).build(); + return chain.proceed(request); + }); + } + Request request = new Request.Builder() + .url("http://www.google.com") + .head() + .build(); + try { + Response response = client.newCall(request).execute(); + subscriber.onNext(response); + } catch(IOException e) { + subscriber.onError(e); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java index 64fc1fda4..72000170e 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/RatingDialog.java @@ -54,7 +54,7 @@ public class RatingDialog { } } - public static void rateNow() { + private static void rateNow() { Context context = mContext.get(); if(context == null) { return; @@ -67,11 +67,11 @@ public class RatingDialog { saveRated(); } - public static boolean rated() { + private static boolean rated() { return mPreferences.getBoolean(KEY_RATED, false); } - public static void saveRated() { + private static void saveRated() { mPreferences .edit() .putBoolean(KEY_RATED, true) diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index 5bb3f09c3..be7850495 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -24,7 +24,7 @@ public abstract class SleepTimerDialog { private static final String TAG = SleepTimerDialog.class.getSimpleName(); - private Context context; + private final Context context; private MaterialDialog dialog; private EditText etxtTime; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java index f14ebbdaf..c050221e1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java @@ -25,7 +25,7 @@ public class AddFeedFragment extends Fragment { /** * Preset value for url text field. */ - public static final String ARG_FEED_URL = "feedurl"; + private static final String ARG_FEED_URL = "feedurl"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index bbfd1688d..f3846c8a4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -69,24 +69,24 @@ public class AllEpisodesFragment extends Fragment { private static final String PREF_SCROLL_POSITION = "scroll_position"; private static final String PREF_SCROLL_OFFSET = "scroll_offset"; - protected RecyclerView recyclerView; - protected AllEpisodesRecycleAdapter listAdapter; + RecyclerView recyclerView; + AllEpisodesRecycleAdapter listAdapter; private ProgressBar progLoading; - protected List<FeedItem> episodes; + List<FeedItem> episodes; private List<Downloader> downloaderList; private boolean itemsLoaded = false; private boolean viewsCreated = false; private boolean isUpdatingFeeds; - protected boolean isMenuInvalidationAllowed = false; + boolean isMenuInvalidationAllowed = false; - protected Subscription subscription; + Subscription subscription; private LinearLayoutManager layoutManager; - protected boolean showOnlyNewEpisodes() { return false; } - protected String getPrefName() { return DEFAULT_PREF_NAME; } + boolean showOnlyNewEpisodes() { return false; } + String getPrefName() { return DEFAULT_PREF_NAME; } @Override public void onCreate(Bundle savedInstanceState) { @@ -165,7 +165,7 @@ public class AllEpisodesFragment extends Fragment { } } - protected void resetViewState() { + void resetViewState() { viewsCreated = false; listAdapter = null; } @@ -284,13 +284,7 @@ public class AllEpisodesFragment extends Fragment { return super.onContextItemSelected(item); } - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } @Override @@ -299,10 +293,10 @@ public class AllEpisodesFragment extends Fragment { R.layout.all_episodes_fragment); } - protected View onCreateViewHelper(LayoutInflater inflater, - ViewGroup container, - Bundle savedInstanceState, - int fragmentResource) { + View onCreateViewHelper(LayoutInflater inflater, + ViewGroup container, + Bundle savedInstanceState, + int fragmentResource) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(fragmentResource, container, false); @@ -346,7 +340,7 @@ public class AllEpisodesFragment extends Fragment { updateShowOnlyEpisodesListViewState(); } - protected AllEpisodesRecycleAdapter.ItemAccess itemAccess = new AllEpisodesRecycleAdapter.ItemAccess() { + private final AllEpisodesRecycleAdapter.ItemAccess itemAccess = new AllEpisodesRecycleAdapter.ItemAccess() { @Override public int getCount() { @@ -444,7 +438,7 @@ public class AllEpisodesFragment extends Fragment { } } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { @@ -459,7 +453,7 @@ public class AllEpisodesFragment extends Fragment { private void updateShowOnlyEpisodesListViewState() { } - protected void loadItems() { + void loadItems() { if(subscription != null) { subscription.unsubscribe(); } @@ -483,7 +477,7 @@ public class AllEpisodesFragment extends Fragment { }, error -> Log.e(TAG, Log.getStackTraceString(error))); } - protected List<FeedItem> loadData() { + List<FeedItem> loadData() { return DBReader.getRecentlyPublishedEpisodes(RECENT_EPISODES_LIMIT); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index 1ba7ed557..f37ecd5e7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -168,7 +168,7 @@ public class CompletedDownloadsFragment extends ListFragment { } } - private DownloadedEpisodesListAdapter.ItemAccess itemAccess = new DownloadedEpisodesListAdapter.ItemAccess() { + private final DownloadedEpisodesListAdapter.ItemAccess itemAccess = new DownloadedEpisodesListAdapter.ItemAccess() { @Override public int getCount() { return (items != null) ? items.size() : 0; @@ -189,7 +189,7 @@ public class CompletedDownloadsFragment extends ListFragment { } }; - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java index 0a710196a..9a4c9e030 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadLogFragment.java @@ -82,7 +82,7 @@ public class DownloadLogFragment extends ListFragment { getActivity().supportInvalidateOptionsMenu(); } - private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() { + private final DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() { @Override public int getCount() { @@ -99,7 +99,7 @@ public class DownloadLogFragment extends ListFragment { } }; - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java index 52a38ccb9..9c4d00e31 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/DownloadsFragment.java @@ -25,7 +25,7 @@ public class DownloadsFragment extends Fragment { public static final String ARG_SELECTED_TAB = "selected_tab"; public static final int POS_RUNNING = 0; - public static final int POS_COMPLETED = 1; + private static final int POS_COMPLETED = 1; public static final int POS_LOG = 2; private static final String PREF_LAST_TAB_POSITION = "tab_position"; @@ -78,9 +78,9 @@ public class DownloadsFragment extends Fragment { viewPager.setCurrentItem(lastPosition); } - public class DownloadsPagerAdapter extends FragmentPagerAdapter { + public static class DownloadsPagerAdapter extends FragmentPagerAdapter { - Resources resources; + final Resources resources; public DownloadsPagerAdapter(FragmentManager fm, Resources resources) { super(fm); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java index e2fbd91f3..8928d2bf3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -21,10 +21,10 @@ public class EpisodesFragment extends Fragment { public static final String TAG = "EpisodesFragment"; private static final String PREF_LAST_TAB_POSITION = "tab_position"; - public static final int POS_NEW_EPISODES = 0; - public static final int POS_ALL_EPISODES = 1; - public static final int POS_FAV_EPISODES = 2; - public static final int TOTAL_COUNT = 3; + private static final int POS_NEW_EPISODES = 0; + private static final int POS_ALL_EPISODES = 1; + private static final int POS_FAV_EPISODES = 2; + private static final int TOTAL_COUNT = 3; private TabLayout tabLayout; @@ -79,7 +79,7 @@ public class EpisodesFragment extends Fragment { public static class EpisodesPagerAdapter extends FragmentPagerAdapter { private final Resources resources; - private AllEpisodesFragment[] fragments = { + private final AllEpisodesFragment[] fragments = { new NewEpisodesFragment(), new AllEpisodesFragment(), new FavoriteEpisodesFragment() diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index 5bb8e0a2d..a9bf39632 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -208,7 +208,7 @@ public class ExternalPlayerFragment extends Fragment { return controller; } - public void onPositionObserverUpdate() { + private void onPositionObserverUpdate() { mProgressBar.setProgress((int) ((double) controller.getPosition() / controller.getDuration() * 100)); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java index 234c8377d..76d19d61c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java @@ -26,7 +26,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; public class FavoriteEpisodesFragment extends AllEpisodesFragment { - public static final String TAG = "FavoriteEpisodesFrag"; + private static final String TAG = "FavoriteEpisodesFrag"; private static final String PREF_NAME = "PrefFavoriteEpisodesFragment"; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java index 7c1ec5ec1..6ee9ce467 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FyydSearchFragment.java @@ -49,7 +49,7 @@ public class FyydSearchFragment extends Fragment { private Button butRetry; private TextView txtvEmpty; - private FyydClient client = new FyydClient(AntennapodHttpClient.getHttpClient()); + private final FyydClient client = new FyydClient(AntennapodHttpClient.getHttpClient()); /** * List of podcasts retreived from the search @@ -169,7 +169,7 @@ public class FyydSearchFragment extends Fragment { progressBar.setVisibility(View.VISIBLE); } - void processSearchResult(FyydResponse response) { + private void processSearchResult(FyydResponse response) { adapter.clear(); if (!response.getData().isEmpty()) { adapter.clear(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index a0586fe16..935fd7898 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -10,7 +10,6 @@ import android.content.SharedPreferences; import android.content.res.TypedArray; import android.graphics.Color; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; @@ -112,9 +111,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo Bundle savedInstanceState) { Log.d(TAG, "Creating view"); webvDescription = new WebView(getActivity().getApplicationContext()); - if (Build.VERSION.SDK_INT >= 11) { - webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } + webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); TypedArray ta = getActivity().getTheme().obtainStyledAttributes(new int[] {android.R.attr.colorBackground}); int backgroundColor = ta.getColor(0, UserPreferences.getTheme() == @@ -203,7 +200,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo } - private View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { + private final View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @@ -238,17 +235,11 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo ShareUtils.shareLink(getActivity(), selectedURL); break; case R.id.copy_url_item: - if (android.os.Build.VERSION.SDK_INT >= 11) { - ClipData clipData = ClipData.newPlainText(selectedURL, - selectedURL); - android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(clipData); - } else { - android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setText(selectedURL); - } + ClipData clipData = ClipData.newPlainText(selectedURL, + selectedURL); + android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() + .getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(clipData); Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT); t.show(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index 7939dcb23..4ae6b97ee 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -184,8 +184,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } webvDescription = (WebView) layout.findViewById(R.id.webvDescription); if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) { - if (Build.VERSION.SDK_INT >= 11 - && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } webvDescription.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black)); @@ -335,13 +334,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { openPodcast(); return true; default: - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), menuItem.getItemId(), item); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), menuItem.getItemId(), item); } } @@ -450,7 +443,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } } - private View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { + private final View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @@ -483,17 +476,11 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { ShareUtils.shareLink(getActivity(), selectedURL); break; case R.id.copy_url_item: - if (android.os.Build.VERSION.SDK_INT >= 11) { - ClipData clipData = ClipData.newPlainText(selectedURL, - selectedURL); - android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setPrimaryClip(clipData); - } else { - android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity() - .getSystemService(Context.CLIPBOARD_SERVICE); - cm.setText(selectedURL); - } + ClipData clipData = ClipData.newPlainText(selectedURL, + selectedURL); + android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity() + .getSystemService(Context.CLIPBOARD_SERVICE); + cm.setPrimaryClip(clipData); Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT); t.show(); @@ -558,7 +545,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index a118673a6..890f31f57 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.LightingColorFilter; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.view.MenuItemCompat; @@ -22,7 +21,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ImageButton; import android.widget.ImageView; -import android.widget.ListAdapter; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; @@ -89,9 +87,9 @@ public class ItemlistFragment extends ListFragment { | EventDistributor.PLAYER_STATUS_UPDATE; public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.danoeh.antennapod.activity.selected_feeditem"; - public static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; + private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; - protected FeedItemlistAdapter adapter; + private FeedItemlistAdapter adapter; private ContextMenu contextMenu; private AdapterView.AdapterContextMenuInfo lastMenuInfo = null; @@ -342,22 +340,7 @@ public class ItemlistFragment extends ListFragment { return super.onContextItemSelected(item); } - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - // context menu doesn't contain download functionality - return true; - } - } - - - @Override - public void setListAdapter(ListAdapter adapter) { - // This workaround prevents the ListFragment from setting a list adapter when its state is restored. - // This is only necessary on API 10 because addFooterView throws an internal exception in this case. - if (Build.VERSION.SDK_INT > 10 || insideOnFragmentLoaded) { - super.setListAdapter(adapter); - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } @Override @@ -417,7 +400,7 @@ public class ItemlistFragment extends ListFragment { } } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { @@ -583,7 +566,7 @@ public class ItemlistFragment extends ListFragment { } } - private FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { + private final FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { @Override public FeedItem getItem(int position) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java index 43dedad25..08610c1f3 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItunesSearchFragment.java @@ -75,7 +75,7 @@ public class ItunesSearchFragment extends Fragment { * Replace adapter data with provided search results from SearchTask. * @param result List of Podcast objects containing search results */ - void updateData(List<Podcast> result) { + private void updateData(List<Podcast> result) { this.searchResults = result; adapter.clear(); if (result != null && result.size() > 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 441f0096c..fb6280021 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -199,7 +199,7 @@ public class PlaybackHistoryFragment extends ListFragment { } } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { @@ -224,7 +224,7 @@ public class PlaybackHistoryFragment extends ListFragment { getActivity().supportInvalidateOptionsMenu(); } - private FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { + private final FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { @Override public int getItemDownloadProgressPercent(FeedItem item) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index fccb86076..bf22e71f5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -363,13 +363,7 @@ public class QueueFragment extends Fragment { DBWriter.moveQueueItemToBottom(selectedItem.getId(), true); return true; default: - try { - return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); - } catch (DownloadRequestException e) { - e.printStackTrace(); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); - return true; - } + return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem); } } @@ -519,7 +513,7 @@ public class QueueFragment extends Fragment { infoBar.setText(info); } - private QueueRecyclerAdapter.ItemAccess itemAccess = new QueueRecyclerAdapter.ItemAccess() { + private final QueueRecyclerAdapter.ItemAccess itemAccess = new QueueRecyclerAdapter.ItemAccess() { @Override public int getCount() { return queue != null ? queue.size() : 0; @@ -579,7 +573,7 @@ public class QueueFragment extends Fragment { } }; - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EVENTS) != 0) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java index ba526edb3..66c59b7f7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/RunningDownloadsFragment.java @@ -75,7 +75,7 @@ public class RunningDownloadsFragment extends ListFragment { } - private DownloadlistAdapter.ItemAccess itemAccess = new DownloadlistAdapter.ItemAccess() { + private final DownloadlistAdapter.ItemAccess itemAccess = new DownloadlistAdapter.ItemAccess() { @Override public int getCount() { return (downloaderList != null) ? downloaderList.size() : 0; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 9626e6c2e..c834b7ea7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -210,7 +210,7 @@ public class SubscriptionFragment extends Fragment { loadSubscriptions(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((EVENTS & arg) != 0) { @@ -220,7 +220,7 @@ public class SubscriptionFragment extends Fragment { } }; - private SubscriptionsAdapter.ItemAccess itemAccess = new SubscriptionsAdapter.ItemAccess() { + private final SubscriptionsAdapter.ItemAccess itemAccess = new SubscriptionsAdapter.ItemAccess() { @Override public int getCount() { if (navDrawerData != null) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java index aff5069c6..b48027668 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/GpodnetMainFragment.java @@ -20,7 +20,7 @@ import de.danoeh.antennapod.R; */ public class GpodnetMainFragment extends Fragment { - public static final String TAG = "GpodnetMainFragment"; + private static final String TAG = "GpodnetMainFragment"; private static final String PREF_LAST_TAB_POSITION = "tab_position"; private TabLayout tabLayout; @@ -71,7 +71,7 @@ public class GpodnetMainFragment extends Fragment { private static final int POS_TAGS = 1; private static final int POS_SUGGESTIONS = 2; - Resources resources; + final Resources resources; public GpodnetPagerAdapter(FragmentManager fm, Resources resources) { super(fm); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java index 15e9c9943..055358c64 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/PodcastListFragment.java @@ -91,7 +91,7 @@ public abstract class PodcastListFragment extends Fragment { return root; } - protected void onPodcastSelected(GpodnetPodcast selection) { + private void onPodcastSelected(GpodnetPodcast selection) { Log.d(TAG, "Selected podcast: " + selection.toString()); Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, selection.getUrl()); @@ -101,7 +101,7 @@ public abstract class PodcastListFragment extends Fragment { protected abstract List<GpodnetPodcast> loadPodcastData(GpodnetService service) throws GpodnetServiceException; - protected final void loadData() { + final void loadData() { AsyncTask<Void, Void, List<GpodnetPodcast>> loaderTask = new AsyncTask<Void, Void, List<GpodnetPodcast>>() { volatile Exception exception = null; @@ -160,10 +160,6 @@ public abstract class PodcastListFragment extends Fragment { } }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - loaderTask.execute(); - } + loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java index 613e06805..10bd636dd 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/SearchListFragment.java @@ -73,7 +73,7 @@ public class SearchListFragment extends PodcastListFragment { return service.searchPodcasts(query, 0); } - public void changeQuery(String query) { + private void changeQuery(String query) { Validate.notNull(query); this.query = query; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java index d2c7f32dd..1e46b1ac5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java @@ -135,11 +135,7 @@ public class TagListFragment extends ListFragment { } } }; - if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { - loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - loadTask.execute(); - } + loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 57b7c359c..f6f73e017 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -17,7 +17,6 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; @@ -155,7 +154,7 @@ public class FeedItemMenuHandler { } public static boolean onMenuItemClicked(Context context, int menuItemId, - FeedItem selectedItem) throws DownloadRequestException { + FeedItem selectedItem) { switch (menuItemId) { case R.id.skip_episode_item: context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 3b5a68f7f..b5e0f1e99 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -38,6 +38,7 @@ import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; +import de.danoeh.antennapod.activity.ImportExportActivity; import org.apache.commons.lang3.ArrayUtils; import java.io.File; @@ -45,7 +46,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; -import java.util.Comparator; import java.util.GregorianCalendar; import java.util.List; import java.util.concurrent.TimeUnit; @@ -56,8 +56,6 @@ import de.danoeh.antennapod.activity.AboutActivity; import de.danoeh.antennapod.activity.DirectoryChooserActivity; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MediaplayerActivity; -import de.danoeh.antennapod.activity.PreferenceActivity; -import de.danoeh.antennapod.activity.PreferenceActivityGingerbread; import de.danoeh.antennapod.activity.StatisticsActivity; import de.danoeh.antennapod.asynctask.ExportWorker; import de.danoeh.antennapod.core.export.ExportWriter; @@ -93,12 +91,13 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private static final String PREF_OPML_EXPORT = "prefOpmlExport"; private static final String PREF_HTML_EXPORT = "prefHtmlExport"; private static final String STATISTICS = "statistics"; + private static final String IMPORT_EXPORT = "importExport"; private static final String PREF_ABOUT = "prefAbout"; private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir"; private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings"; private static final String PREF_PLAYBACK_SPEED_LAUNCHER = "prefPlaybackSpeedLauncher"; - public static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher"; - public static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher"; + private static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher"; + private static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher"; private static final String PREF_GPODNET_LOGIN = "pref_gpodnet_authenticate"; private static final String PREF_GPODNET_SETLOGIN_INFORMATION = "pref_gpodnet_setlogin_information"; private static final String PREF_GPODNET_SYNC = "pref_gpodnet_sync"; @@ -132,19 +131,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc .registerOnSharedPreferenceChangeListener(this); } - /** - * Returns the preference activity that should be used on this device. - * - * @return PreferenceActivity if the API level is greater than 10, PreferenceActivityGingerbread otherwise. - */ - public static Class<? extends Activity> getPreferenceActivity() { - if (Build.VERSION.SDK_INT > 10) { - return PreferenceActivity.class; - } else { - return PreferenceActivityGingerbread.class; - } - } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if(key.equals(UserPreferences.PREF_SONIC)) { @@ -189,6 +175,12 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc return true; } ); + ui.findPreference(PreferenceController.IMPORT_EXPORT).setOnPreferenceClickListener( + preference -> { + activity.startActivity(new Intent(activity, ImportExportActivity.class)); + return true; + } + ); ui.findPreference(PreferenceController.PREF_OPML_EXPORT).setOnPreferenceClickListener( preference -> export(new OpmlWriter())); ui.findPreference(PreferenceController.PREF_HTML_EXPORT).setOnPreferenceClickListener( @@ -230,12 +222,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc .setOnPreferenceChangeListener( (preference, newValue) -> { Intent i = new Intent(activity, MainActivity.class); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_ACTIVITY_NEW_TASK); - } else { - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_NEW_TASK); activity.finish(); activity.startActivity(i); return true; @@ -513,7 +501,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc alert.setTitle(R.string.export_error_label); alert.setMessage(error.getMessage()); alert.show(); - }, () -> progressDialog.dismiss()); + }, progressDialog::dismiss); return true; } @@ -786,61 +774,56 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); - if (networks != null) { - Collections.sort(networks, new Comparator<WifiConfiguration>() { - @Override - public int compare(WifiConfiguration x, WifiConfiguration y) { - return x.SSID.compareTo(y.SSID); + if (networks == null) { + Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); + return; + } + Collections.sort(networks, (x, y) -> x.SSID.compareTo(y.SSID)); + selectedNetworks = new CheckBoxPreference[networks.size()]; + List<String> prefValues = Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()); + PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); + Preference.OnPreferenceClickListener clickListener = preference -> { + if (preference instanceof CheckBoxPreference) { + String key = preference.getKey(); + List<String> prefValuesList = new ArrayList<>( + Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()) + ); + boolean newValue = ((CheckBoxPreference) preference) + .isChecked(); + Log.d(TAG, "Selected network " + key + ". New state: " + newValue); + + int index = prefValuesList.indexOf(key); + if (index >= 0 && !newValue) { + // remove network + prefValuesList.remove(index); + } else if (index < 0 && newValue) { + prefValuesList.add(key); } - }); - selectedNetworks = new CheckBoxPreference[networks.size()]; - List<String> prefValues = Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()); - PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); - Preference.OnPreferenceClickListener clickListener = preference -> { - if (preference instanceof CheckBoxPreference) { - String key = preference.getKey(); - List<String> prefValuesList = new ArrayList<>( - Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()) - ); - boolean newValue = ((CheckBoxPreference) preference) - .isChecked(); - Log.d(TAG, "Selected network " + key + ". New state: " + newValue); - - int index = prefValuesList.indexOf(key); - if (index >= 0 && !newValue) { - // remove network - prefValuesList.remove(index); - } else if (index < 0 && newValue) { - prefValuesList.add(key); - } - UserPreferences.setAutodownloadSelectedNetworks( - prefValuesList.toArray(new String[prefValuesList.size()]) - ); - return true; - } else { - return false; - } - }; - // create preference for each known network. attach listener and set - // value - for (int i = 0; i < networks.size(); i++) { - WifiConfiguration config = networks.get(i); - - CheckBoxPreference pref = new CheckBoxPreference(activity); - String key = Integer.toString(config.networkId); - pref.setTitle(config.SSID); - pref.setKey(key); - pref.setOnPreferenceClickListener(clickListener); - pref.setPersistent(false); - pref.setChecked(prefValues.contains(key)); - selectedNetworks[i] = pref; - prefScreen.addPreference(pref); + UserPreferences.setAutodownloadSelectedNetworks( + prefValuesList.toArray(new String[prefValuesList.size()]) + ); + return true; + } else { + return false; } - } else { - Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); + }; + // create preference for each known network. attach listener and set + // value + for (int i = 0; i < networks.size(); i++) { + WifiConfiguration config = networks.get(i); + + CheckBoxPreference pref = new CheckBoxPreference(activity); + String key = Integer.toString(config.networkId); + pref.setTitle(config.SSID); + pref.setKey(key); + pref.setOnPreferenceClickListener(clickListener); + pref.setPersistent(false); + pref.setChecked(prefValues.contains(key)); + selectedNetworks[i] = pref; + prefScreen.addPreference(pref); } } diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java index a373c5353..c9bd973cb 100644 --- a/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java +++ b/app/src/main/java/de/danoeh/antennapod/receiver/SPAReceiver.java @@ -22,8 +22,8 @@ public class SPAReceiver extends BroadcastReceiver{ private static final String TAG = "SPAReceiver"; public static final String ACTION_SP_APPS_QUERY_FEEDS = "de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS"; - public static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE = "de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS_RESPONSE"; - public static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA = "feeds"; + private static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE = "de.danoeh.antennapdsp.intent.SP_APPS_QUERY_FEEDS_RESPONSE"; + private static final String ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA = "feeds"; @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java index b5bfb1ae4..d5141bd37 100644 --- a/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java +++ b/app/src/main/java/de/danoeh/antennapod/service/PlayerWidgetService.java @@ -38,7 +38,7 @@ public class PlayerWidgetService extends Service { /** * Controls write access to playbackservice reference */ - private Object psLock; + private final Object psLock = new Object(); /** * True while service is updating the widget @@ -53,7 +53,6 @@ public class PlayerWidgetService extends Service { super.onCreate(); Log.d(TAG, "Service created"); isUpdating = false; - psLock = new Object(); } @Override @@ -194,7 +193,7 @@ public class PlayerWidgetService extends Service { } } - private ServiceConnection mConnection = new ServiceConnection() { + private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.d(TAG, "Connection to service established"); synchronized (psLock) { @@ -224,7 +223,7 @@ public class PlayerWidgetService extends Service { class ViewUpdater extends Thread { private static final String THREAD_NAME = "ViewUpdater"; - private PlayerWidgetService service; + private final PlayerWidgetService service; public ViewUpdater(PlayerWidgetService service) { super(); diff --git a/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java b/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java index 27b6ee2bc..7ce33e11f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/SquareImageView.java @@ -1,13 +1,13 @@ package de.danoeh.antennapod.view; import android.content.Context; +import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; -import android.widget.ImageView; /** * From http://stackoverflow.com/a/19449488/6839 */ -public class SquareImageView extends ImageView { +public class SquareImageView extends AppCompatImageView { public SquareImageView(Context context) { super(context); @@ -26,6 +26,7 @@ public class SquareImageView extends ImageView { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); + //noinspection SuspiciousNameCombination setMeasuredDimension(width, width); } |