diff --git a/src/main/java/eu/siacs/conversations/services/ChannelDiscoveryService.java b/src/main/java/eu/siacs/conversations/services/ChannelDiscoveryService.java index 306f8e189..24aa7bdac 100644 --- a/src/main/java/eu/siacs/conversations/services/ChannelDiscoveryService.java +++ b/src/main/java/eu/siacs/conversations/services/ChannelDiscoveryService.java @@ -1,11 +1,10 @@ package eu.siacs.conversations.services; +import android.support.annotation.NonNull; import android.util.Log; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import java.io.IOException; import java.util.Collections; @@ -32,12 +31,12 @@ public class ChannelDiscoveryService { private final Cache> cache; - public ChannelDiscoveryService(XmppConnectionService service) { + ChannelDiscoveryService(XmppConnectionService service) { this.service = service; this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); } - public void initializeMuclumbusService() { + void initializeMuclumbusService() { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (service.useTorToConnect()) { try { @@ -55,7 +54,7 @@ public class ChannelDiscoveryService { this.muclumbusService = retrofit.create(MuclumbusService.class); } - public void discover(String query, OnChannelSearchResultsFound onChannelSearchResultsFound) { + void discover(String query, OnChannelSearchResultsFound onChannelSearchResultsFound) { final boolean all = query == null || query.trim().isEmpty(); Log.d(Config.LOGTAG, "discover channels. query=" + query); List result = cache.getIfPresent(all ? "" : query); @@ -75,9 +74,11 @@ public class ChannelDiscoveryService { try { call.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(@NonNull Call call, @NonNull Response response) { final MuclumbusService.Rooms body = response.body(); if (body == null) { + Log.d(Config.LOGTAG, "code from muclumbus=" + response.code()); + listener.onChannelSearchResultsFound(Collections.emptyList()); return; } cache.put("", body.items); @@ -85,8 +86,8 @@ public class ChannelDiscoveryService { } @Override - public void onFailure(Call call, Throwable throwable) { - Log.d(Config.LOGTAG, "Unable to query muclumbus on "+Config.CHANNEL_DISCOVERY, throwable); + public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { + Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable); listener.onChannelSearchResultsFound(Collections.emptyList()); } }); @@ -100,10 +101,11 @@ public class ChannelDiscoveryService { searchResultCall.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { - System.out.println(response.message()); - MuclumbusService.SearchResult body = response.body(); + public void onResponse(@NonNull Call call, @NonNull Response response) { + final MuclumbusService.SearchResult body = response.body(); if (body == null) { + Log.d(Config.LOGTAG, "code from muclumbus=" + response.code()); + listener.onChannelSearchResultsFound(Collections.emptyList()); return; } cache.put(query, body.result.items); @@ -111,8 +113,8 @@ public class ChannelDiscoveryService { } @Override - public void onFailure(Call call, Throwable throwable) { - Log.d(Config.LOGTAG, "Unable to query muclumbus on "+Config.CHANNEL_DISCOVERY, throwable); + public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { + Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable); listener.onChannelSearchResultsFound(Collections.emptyList()); } });