Commit dd508b7a authored by Leonardo Aramaki's avatar Leonardo Aramaki

Cleaned up code and change the asset url from where to fetch the logo

for the server button
parent d21901cb
......@@ -11,7 +11,6 @@ import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.List;
......@@ -27,6 +26,7 @@ import chat.rocket.android.helper.KeyboardHelper;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.widget.RoomToolbar;
import chat.rocket.android.widget.helper.AvatarHelper;
import chat.rocket.android.widget.helper.FrescoHelper;
import chat.rocket.core.interactors.CanCreateRoomInteractor;
import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.interactors.SessionInteractor;
......@@ -271,8 +271,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
Drawable drawable = AvatarHelper.INSTANCE.getTextDrawable(server.first,this);
serverButton.getHierarchy().setPlaceholderImage(drawable);
serverButton.setController(Fresco.newDraweeControllerBuilder().setUri(server.second).setAutoPlayAnimations(true).build());
FrescoHelper.INSTANCE.loadImage(serverButton, server.second, drawable);
serverListContainer.addView(serverButton, serverCount - 1);
serverListContainer.requestLayout();
}
......
......@@ -4,9 +4,11 @@ import android.support.annotation.NonNull;
import com.hadisatrio.optional.Optional;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.RocketChatCache;
import chat.rocket.android.api.MethodCallHelper;
......@@ -20,6 +22,7 @@ import chat.rocket.core.PublicSettingsConstants;
import chat.rocket.core.interactors.CanCreateRoomInteractor;
import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.interactors.SessionInteractor;
import chat.rocket.core.models.PublicSetting;
import chat.rocket.core.models.Session;
import chat.rocket.core.models.User;
import chat.rocket.core.repositories.PublicSettingRepository;
......@@ -64,15 +67,11 @@ public class MainPresenter extends BasePresenter<MainContract.View>
}
@Override
public void loadSignedInServers(@NotNull String hostname) {
final Disposable disposable = publicSettingRepository.getById(PublicSettingsConstants.Assets.TILE_144)
public void loadSignedInServers(@NonNull String hostname) {
final Disposable disposable = publicSettingRepository.getById(PublicSettingsConstants.Assets.LOGO)
.filter(Optional::isPresent)
.map(Optional::get)
.map(publicSetting -> {
JSONObject jsonObject = new JSONObject(publicSetting.getValue());
rocketChatCache.addHostname(hostname, jsonObject.optString("defaultUrl"));
return rocketChatCache.getServerList();
})
.map(setting -> getServerList(hostname, setting))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
......@@ -134,6 +133,14 @@ public class MainPresenter extends BasePresenter<MainContract.View>
addSubscription(subscription);
}
private List<Pair<String, String>> getServerList(String hostname, PublicSetting publicSetting) throws JSONException {
JSONObject jsonObject = new JSONObject(publicSetting.getValue());
String logoUrl = (jsonObject.has("url")) ?
jsonObject.optString("url") : jsonObject.optString("defaultUrl");
rocketChatCache.addHostname(hostname, logoUrl);
return rocketChatCache.getServerList();
}
private void openRoom() {
String hostname = rocketChatCache.getSelectedServerHostname();
String roomId = rocketChatCache.getSelectedRoomId();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment