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