cancel spinning wheel on muclumbus error
This commit is contained in:
parent
2ec1d0cc09
commit
4c92d1b755
|
@ -1,11 +1,10 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.cache.LoadingCache;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -32,12 +31,12 @@ public class ChannelDiscoveryService {
|
||||||
|
|
||||||
private final Cache<String, List<MuclumbusService.Room>> cache;
|
private final Cache<String, List<MuclumbusService.Room>> cache;
|
||||||
|
|
||||||
public ChannelDiscoveryService(XmppConnectionService service) {
|
ChannelDiscoveryService(XmppConnectionService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
|
this.cache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeMuclumbusService() {
|
void initializeMuclumbusService() {
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
if (service.useTorToConnect()) {
|
if (service.useTorToConnect()) {
|
||||||
try {
|
try {
|
||||||
|
@ -55,7 +54,7 @@ public class ChannelDiscoveryService {
|
||||||
this.muclumbusService = retrofit.create(MuclumbusService.class);
|
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();
|
final boolean all = query == null || query.trim().isEmpty();
|
||||||
Log.d(Config.LOGTAG, "discover channels. query=" + query);
|
Log.d(Config.LOGTAG, "discover channels. query=" + query);
|
||||||
List<MuclumbusService.Room> result = cache.getIfPresent(all ? "" : query);
|
List<MuclumbusService.Room> result = cache.getIfPresent(all ? "" : query);
|
||||||
|
@ -75,9 +74,11 @@ public class ChannelDiscoveryService {
|
||||||
try {
|
try {
|
||||||
call.enqueue(new Callback<MuclumbusService.Rooms>() {
|
call.enqueue(new Callback<MuclumbusService.Rooms>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<MuclumbusService.Rooms> call, Response<MuclumbusService.Rooms> response) {
|
public void onResponse(@NonNull Call<MuclumbusService.Rooms> call, @NonNull Response<MuclumbusService.Rooms> response) {
|
||||||
final MuclumbusService.Rooms body = response.body();
|
final MuclumbusService.Rooms body = response.body();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
|
Log.d(Config.LOGTAG, "code from muclumbus=" + response.code());
|
||||||
|
listener.onChannelSearchResultsFound(Collections.emptyList());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cache.put("", body.items);
|
cache.put("", body.items);
|
||||||
|
@ -85,8 +86,8 @@ public class ChannelDiscoveryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<MuclumbusService.Rooms> call, Throwable throwable) {
|
public void onFailure(@NonNull Call<MuclumbusService.Rooms> call, @NonNull Throwable throwable) {
|
||||||
Log.d(Config.LOGTAG, "Unable to query muclumbus on "+Config.CHANNEL_DISCOVERY, throwable);
|
Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable);
|
||||||
listener.onChannelSearchResultsFound(Collections.emptyList());
|
listener.onChannelSearchResultsFound(Collections.emptyList());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -100,10 +101,11 @@ public class ChannelDiscoveryService {
|
||||||
|
|
||||||
searchResultCall.enqueue(new Callback<MuclumbusService.SearchResult>() {
|
searchResultCall.enqueue(new Callback<MuclumbusService.SearchResult>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<MuclumbusService.SearchResult> call, Response<MuclumbusService.SearchResult> response) {
|
public void onResponse(@NonNull Call<MuclumbusService.SearchResult> call, @NonNull Response<MuclumbusService.SearchResult> response) {
|
||||||
System.out.println(response.message());
|
final MuclumbusService.SearchResult body = response.body();
|
||||||
MuclumbusService.SearchResult body = response.body();
|
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
|
Log.d(Config.LOGTAG, "code from muclumbus=" + response.code());
|
||||||
|
listener.onChannelSearchResultsFound(Collections.emptyList());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cache.put(query, body.result.items);
|
cache.put(query, body.result.items);
|
||||||
|
@ -111,8 +113,8 @@ public class ChannelDiscoveryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<MuclumbusService.SearchResult> call, Throwable throwable) {
|
public void onFailure(@NonNull Call<MuclumbusService.SearchResult> call, @NonNull Throwable throwable) {
|
||||||
Log.d(Config.LOGTAG, "Unable to query muclumbus on "+Config.CHANNEL_DISCOVERY, throwable);
|
Log.d(Config.LOGTAG, "Unable to query muclumbus on " + Config.CHANNEL_DISCOVERY, throwable);
|
||||||
listener.onChannelSearchResultsFound(Collections.emptyList());
|
listener.onChannelSearchResultsFound(Collections.emptyList());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue