Checkstyle fixes

This commit is contained in:
ByteHamster 2020-03-30 14:24:55 +02:00
parent 6e3d012a8a
commit 6d3cc1a9da
9 changed files with 73 additions and 72 deletions

View File

@ -52,7 +52,7 @@ public class GPodnetServiceTest {
ArrayList<String> l = new ArrayList<>(); ArrayList<String> l = new ArrayList<>();
l.add("http://bitsundso.de/feed"); l.add("http://bitsundso.de/feed");
l.add("http://gamesundso.de/feed"); l.add("http://gamesundso.de/feed");
service.uploadSubscriptions( "radio", l); service.uploadSubscriptions("radio", l);
} }
@Test @Test

View File

@ -116,9 +116,9 @@ public abstract class PodcastListFragment extends Fragment {
@Override @Override
protected List<GpodnetPodcast> doInBackground(Void... params) { protected List<GpodnetPodcast> doInBackground(Void... params) {
GpodnetService service = null;
try { try {
service = new GpodnetService(AntennapodHttpClient.getHttpClient(), GpodnetPreferences.getHostname()); GpodnetService service = new GpodnetService(AntennapodHttpClient.getHttpClient(),
GpodnetPreferences.getHostname());
return loadPodcastData(service); return loadPodcastData(service);
} catch (GpodnetServiceException e) { } catch (GpodnetServiceException e) {
exception = e; exception = e;

View File

@ -92,7 +92,8 @@ public class TagListFragment extends ListFragment {
@Override @Override
protected List<GpodnetTag> doInBackground(Void... params) { protected List<GpodnetTag> doInBackground(Void... params) {
GpodnetService service = new GpodnetService(AntennapodHttpClient.getHttpClient(), GpodnetPreferences.getHostname()); GpodnetService service = new GpodnetService(AntennapodHttpClient.getHttpClient(),
GpodnetPreferences.getHostname());
try { try {
return service.getTopTags(COUNT); return service.getTopTags(COUNT);
} catch (GpodnetServiceException e) { } catch (GpodnetServiceException e) {

View File

@ -82,25 +82,25 @@ public class GpodderPreferencesFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
findPreference(PREF_GPODNET_SYNC).setOnPreferenceClickListener(preference -> { findPreference(PREF_GPODNET_SYNC).setOnPreferenceClickListener(preference -> {
SyncService.syncImmediately(getActivity().getApplicationContext()); SyncService.syncImmediately(getActivity().getApplicationContext());
return true; return true;
}); });
findPreference(PREF_GPODNET_FORCE_FULL_SYNC).setOnPreferenceClickListener(preference -> { findPreference(PREF_GPODNET_FORCE_FULL_SYNC).setOnPreferenceClickListener(preference -> {
SyncService.fullSync(getContext()); SyncService.fullSync(getContext());
return true; return true;
}); });
findPreference(PREF_GPODNET_LOGOUT).setOnPreferenceClickListener(preference -> { findPreference(PREF_GPODNET_LOGOUT).setOnPreferenceClickListener(preference -> {
GpodnetPreferences.logout(); GpodnetPreferences.logout();
Toast toast = Toast.makeText(activity, R.string.pref_gpodnet_logout_toast, Toast.LENGTH_SHORT); Toast toast = Toast.makeText(activity, R.string.pref_gpodnet_logout_toast, Toast.LENGTH_SHORT);
toast.show(); toast.show();
updateGpodnetPreferenceScreen(); updateGpodnetPreferenceScreen();
return true; return true;
}); });
findPreference(PREF_GPODNET_HOSTNAME).setOnPreferenceClickListener(preference -> { findPreference(PREF_GPODNET_HOSTNAME).setOnPreferenceClickListener(preference -> {
GpodnetSetHostnameDialog.createDialog(activity).setOnDismissListener( GpodnetSetHostnameDialog.createDialog(activity).setOnDismissListener(
dialog -> updateGpodnetPreferenceScreen()); dialog -> updateGpodnetPreferenceScreen());
return true; return true;
}); });
} }
private void updateGpodnetPreferenceScreen() { private void updateGpodnetPreferenceScreen() {

View File

@ -176,7 +176,6 @@
<property name="ignoreFinal" value="false"/> <property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/> <property name="allowedAbbreviationLength" value="1"/>
</module> </module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/> <module name="VariableDeclarationUsageDistance"/>
<module name="MethodParamPad"/> <module name="MethodParamPad"/>
<module name="WhitespaceAfter"/> <module name="WhitespaceAfter"/>

View File

@ -148,7 +148,7 @@ public class SyncService extends Worker {
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
String json = prefs.getString(PREF_QUEUED_EPISODE_ACTIONS, "[]"); String json = prefs.getString(PREF_QUEUED_EPISODE_ACTIONS, "[]");
JSONArray queue = new JSONArray(json); JSONArray queue = new JSONArray(json);
queue.put(action.writeToJSONObject()); queue.put(action.writeToJsonObject());
prefs.edit().putString(PREF_QUEUED_EPISODE_ACTIONS, queue.toString()).apply(); prefs.edit().putString(PREF_QUEUED_EPISODE_ACTIONS, queue.toString()).apply();
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -217,7 +217,7 @@ public class SyncService extends Worker {
String json = prefs.getString(PREF_QUEUED_EPISODE_ACTIONS, "[]"); String json = prefs.getString(PREF_QUEUED_EPISODE_ACTIONS, "[]");
JSONArray queue = new JSONArray(json); JSONArray queue = new JSONArray(json);
for (int i = 0; i < queue.length(); i++) { for (int i = 0; i < queue.length(); i++) {
actions.add(EpisodeAction.readFromJSONObject(queue.getJSONObject(i))); actions.add(EpisodeAction.readFromJsonObject(queue.getJSONObject(i)));
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -297,7 +297,7 @@ public class SyncService extends Worker {
synchronized (lock) { synchronized (lock) {
UploadChangesResponse uploadResponse = syncServiceImpl UploadChangesResponse uploadResponse = syncServiceImpl
.uploadSubscriptionChanges(queuedAddedFeeds, queuedRemovedFeeds); .uploadSubscriptionChanges(queuedAddedFeeds, queuedRemovedFeeds);
getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit() getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit()
.putString(PREF_QUEUED_FEEDS_ADDED, "[]").apply(); .putString(PREF_QUEUED_FEEDS_ADDED, "[]").apply();
getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit() getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit()
@ -406,6 +406,9 @@ public class SyncService extends Worker {
case DELETE: case DELETE:
// NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop // NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop
break; break;
default:
Log.e(TAG, "Unknown action: " + action);
break;
} }
} }

View File

@ -109,7 +109,7 @@ public class GpodnetService implements ISyncService {
String response = executeRequest(request); String response = executeRequest(request);
JSONArray jsonArray = new JSONArray(response); JSONArray jsonArray = new JSONArray(response);
return readPodcastListFromJSONArray(jsonArray); return readPodcastListFromJsonArray(jsonArray);
} catch (JSONException | MalformedURLException | URISyntaxException e) { } catch (JSONException | MalformedURLException | URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
@ -134,7 +134,7 @@ public class GpodnetService implements ISyncService {
String response = executeRequest(request); String response = executeRequest(request);
JSONArray jsonArray = new JSONArray(response); JSONArray jsonArray = new JSONArray(response);
return readPodcastListFromJSONArray(jsonArray); return readPodcastListFromJsonArray(jsonArray);
} catch (JSONException | MalformedURLException | URISyntaxException e) { } catch (JSONException | MalformedURLException | URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
@ -165,7 +165,7 @@ public class GpodnetService implements ISyncService {
String response = executeRequest(request); String response = executeRequest(request);
JSONArray jsonArray = new JSONArray(response); JSONArray jsonArray = new JSONArray(response);
return readPodcastListFromJSONArray(jsonArray); return readPodcastListFromJsonArray(jsonArray);
} catch (JSONException | MalformedURLException | URISyntaxException e) { } catch (JSONException | MalformedURLException | URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
throw new GpodnetServiceException(e); throw new GpodnetServiceException(e);
@ -191,7 +191,7 @@ public class GpodnetService implements ISyncService {
String response = executeRequest(request); String response = executeRequest(request);
JSONArray jsonArray = new JSONArray(response); JSONArray jsonArray = new JSONArray(response);
return readPodcastListFromJSONArray(jsonArray); return readPodcastListFromJsonArray(jsonArray);
} catch (JSONException | MalformedURLException e) { } catch (JSONException | MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
@ -216,7 +216,7 @@ public class GpodnetService implements ISyncService {
Request.Builder request = new Request.Builder().url(url); Request.Builder request = new Request.Builder().url(url);
String response = executeRequest(request); String response = executeRequest(request);
JSONArray devicesArray = new JSONArray(response); JSONArray devicesArray = new JSONArray(response);
return readDeviceListFromJSONArray(devicesArray); return readDeviceListFromJsonArray(devicesArray);
} catch (JSONException | MalformedURLException | URISyntaxException e) { } catch (JSONException | MalformedURLException | URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
throw new GpodnetServiceException(e); throw new GpodnetServiceException(e);
@ -393,7 +393,7 @@ public class GpodnetService implements ISyncService {
String response = executeRequest(request); String response = executeRequest(request);
JSONObject changes = new JSONObject(response); JSONObject changes = new JSONObject(response);
return readSubscriptionChangesFromJSONObject(changes); return readSubscriptionChangesFromJsonObject(changes);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
throw new IllegalStateException(e); throw new IllegalStateException(e);
@ -436,7 +436,7 @@ public class GpodnetService implements ISyncService {
final JSONArray list = new JSONArray(); final JSONArray list = new JSONArray();
for (int i = from; i < to; i++) { for (int i = from; i < to; i++) {
EpisodeAction episodeAction = episodeActions.get(i); EpisodeAction episodeAction = episodeActions.get(i);
JSONObject obj = episodeAction.writeToJSONObject(); JSONObject obj = episodeAction.writeToJsonObject();
if (obj != null) { if (obj != null) {
obj.put("device", GpodnetPreferences.getDeviceID()); obj.put("device", GpodnetPreferences.getDeviceID());
list.put(obj); list.put(obj);
@ -474,7 +474,7 @@ public class GpodnetService implements ISyncService {
String response = executeRequest(request); String response = executeRequest(request);
JSONObject json = new JSONObject(response); JSONObject json = new JSONObject(response);
return readEpisodeActionsFromJSONObject(json); return readEpisodeActionsFromJsonObject(json);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); e.printStackTrace();
throw new IllegalStateException(e); throw new IllegalStateException(e);
@ -570,15 +570,15 @@ public class GpodnetService implements ISyncService {
} }
} }
private List<GpodnetPodcast> readPodcastListFromJSONArray(@NonNull JSONArray array) throws JSONException { private List<GpodnetPodcast> readPodcastListFromJsonArray(@NonNull JSONArray array) throws JSONException {
List<GpodnetPodcast> result = new ArrayList<>(array.length()); List<GpodnetPodcast> result = new ArrayList<>(array.length());
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
result.add(readPodcastFromJSONObject(array.getJSONObject(i))); result.add(readPodcastFromJsonObject(array.getJSONObject(i)));
} }
return result; return result;
} }
private GpodnetPodcast readPodcastFromJSONObject(JSONObject object) throws JSONException { private GpodnetPodcast readPodcastFromJsonObject(JSONObject object) throws JSONException {
String url = object.getString("url"); String url = object.getString("url");
String title; String title;
@ -623,15 +623,15 @@ public class GpodnetService implements ISyncService {
return new GpodnetPodcast(url, title, description, subscribers, logoUrl, website, mygpoLink, author); return new GpodnetPodcast(url, title, description, subscribers, logoUrl, website, mygpoLink, author);
} }
private List<GpodnetDevice> readDeviceListFromJSONArray(@NonNull JSONArray array) throws JSONException { private List<GpodnetDevice> readDeviceListFromJsonArray(@NonNull JSONArray array) throws JSONException {
List<GpodnetDevice> result = new ArrayList<>(array.length()); List<GpodnetDevice> result = new ArrayList<>(array.length());
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
result.add(readDeviceFromJSONObject(array.getJSONObject(i))); result.add(readDeviceFromJsonObject(array.getJSONObject(i)));
} }
return result; return result;
} }
private GpodnetDevice readDeviceFromJSONObject(JSONObject object) throws JSONException { private GpodnetDevice readDeviceFromJsonObject(JSONObject object) throws JSONException {
String id = object.getString("id"); String id = object.getString("id");
String caption = object.getString("caption"); String caption = object.getString("caption");
String type = object.getString("type"); String type = object.getString("type");
@ -639,7 +639,7 @@ public class GpodnetService implements ISyncService {
return new GpodnetDevice(id, caption, type, subscriptions); return new GpodnetDevice(id, caption, type, subscriptions);
} }
private SubscriptionChanges readSubscriptionChangesFromJSONObject(@NonNull JSONObject object) private SubscriptionChanges readSubscriptionChangesFromJsonObject(@NonNull JSONObject object)
throws JSONException { throws JSONException {
List<String> added = new LinkedList<>(); List<String> added = new LinkedList<>();
@ -664,7 +664,7 @@ public class GpodnetService implements ISyncService {
return new SubscriptionChanges(added, removed, timestamp); return new SubscriptionChanges(added, removed, timestamp);
} }
private EpisodeActionChanges readEpisodeActionsFromJSONObject(@NonNull JSONObject object) private EpisodeActionChanges readEpisodeActionsFromJsonObject(@NonNull JSONObject object)
throws JSONException { throws JSONException {
List<EpisodeAction> episodeActions = new ArrayList<>(); List<EpisodeAction> episodeActions = new ArrayList<>();
@ -673,7 +673,7 @@ public class GpodnetService implements ISyncService {
JSONArray jsonActions = object.getJSONArray("actions"); JSONArray jsonActions = object.getJSONArray("actions");
for (int i = 0; i < jsonActions.length(); i++) { for (int i = 0; i < jsonActions.length(); i++) {
JSONObject jsonAction = jsonActions.getJSONObject(i); JSONObject jsonAction = jsonActions.getJSONObject(i);
EpisodeAction episodeAction = EpisodeAction.readFromJSONObject(jsonAction); EpisodeAction episodeAction = EpisodeAction.readFromJsonObject(jsonAction);
if (episodeAction != null) { if (episodeAction != null) {
episodeActions.add(episodeAction); episodeActions.add(episodeAction);
} }

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.sync.model;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.core.util.ObjectsCompat;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.DateUtils;
import org.json.JSONException; import org.json.JSONException;
@ -45,7 +46,7 @@ public class EpisodeAction {
* @param object JSON representation * @param object JSON representation
* @return episode action object, or null if mandatory values are missing * @return episode action object, or null if mandatory values are missing
*/ */
public static EpisodeAction readFromJSONObject(JSONObject object) { public static EpisodeAction readFromJsonObject(JSONObject object) {
String podcast = object.optString("podcast", null); String podcast = object.optString("podcast", null);
String episode = object.optString("episode", null); String episode = object.optString("episode", null);
String actionString = object.optString("action", null); String actionString = object.optString("action", null);
@ -98,7 +99,7 @@ public class EpisodeAction {
} }
/** /**
* Returns the position (in seconds) at which the client started playback * Returns the position (in seconds) at which the client started playback.
* *
* @return start position (in seconds) * @return start position (in seconds)
*/ */
@ -107,7 +108,7 @@ public class EpisodeAction {
} }
/** /**
* Returns the position (in seconds) at which the client stopped playback * Returns the position (in seconds) at which the client stopped playback.
* *
* @return stop position (in seconds) * @return stop position (in seconds)
*/ */
@ -126,21 +127,18 @@ public class EpisodeAction {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || !(o instanceof EpisodeAction)) return false; return true;
}
if (!(o instanceof EpisodeAction)) {
return false;
}
EpisodeAction that = (EpisodeAction) o; EpisodeAction that = (EpisodeAction) o;
return started == that.started && position == that.position && total == that.total && action != that.action
if (started != that.started) return false; && ObjectsCompat.equals(podcast, that.podcast)
if (position != that.position) return false; && ObjectsCompat.equals(episode, that.episode)
if (total != that.total) return false; && ObjectsCompat.equals(timestamp, that.timestamp);
if (podcast != null ? !podcast.equals(that.podcast) : that.podcast != null) return false;
if (episode != null ? !episode.equals(that.episode) : that.episode != null) return false;
//if (deviceId != null ? !deviceId.equals(that.deviceId) : that.deviceId != null)
// return false;
if (action != that.action) return false;
return !(timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null);
} }
@Override @Override
@ -156,11 +154,11 @@ public class EpisodeAction {
} }
/** /**
* Returns a JSON object representation of this object * Returns a JSON object representation of this object.
* *
* @return JSON object representation, or null if the object is invalid * @return JSON object representation, or null if the object is invalid
*/ */
public JSONObject writeToJSONObject() { public JSONObject writeToJsonObject() {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
try { try {
obj.putOpt("podcast", this.podcast); obj.putOpt("podcast", this.podcast);
@ -183,15 +181,15 @@ public class EpisodeAction {
@Override @Override
public String toString() { public String toString() {
return "EpisodeAction{" + return "EpisodeAction{"
"podcast='" + podcast + '\'' + + "podcast='" + podcast + '\''
", episode='" + episode + '\'' + + ", episode='" + episode + '\''
", action=" + action + + ", action=" + action
", timestamp=" + timestamp + + ", timestamp=" + timestamp
", started=" + started + + ", started=" + started
", position=" + position + + ", position=" + position
", total=" + total + + ", total=" + total
'}'; + '}';
} }
public enum Action { public enum Action {

View File

@ -25,9 +25,9 @@ public class EpisodeActionChanges {
@Override @Override
public String toString() { public String toString() {
return "EpisodeActionGetResponse{" + return "EpisodeActionGetResponse{"
"episodeActions=" + episodeActions + + "episodeActions=" + episodeActions
", timestamp=" + timestamp + + ", timestamp=" + timestamp
'}'; + '}';
} }
} }