Commit c39b5aa4 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Refactor UI making it closer to the iOS app

parent 0a913c38
...@@ -44,7 +44,7 @@ public class RocketChatCache { ...@@ -44,7 +44,7 @@ public class RocketChatCache {
setString(KEY_SELECTED_SERVER_HOSTNAME, hostname.toLowerCase()); setString(KEY_SELECTED_SERVER_HOSTNAME, hostname.toLowerCase());
} }
public void addHostname(@NonNull String hostname, @Nullable String hostnameAvatarUri) { public void addHostname(@NonNull String hostname, @Nullable String hostnameAvatarUri, String siteName) {
String hostnameList = getString(KEY_HOSTNAME_LIST, null); String hostnameList = getString(KEY_HOSTNAME_LIST, null);
try { try {
JSONObject json; JSONObject json;
...@@ -53,25 +53,31 @@ public class RocketChatCache { ...@@ -53,25 +53,31 @@ public class RocketChatCache {
} else { } else {
json = new JSONObject(hostnameList); json = new JSONObject(hostnameList);
} }
JSONObject serverInfoJson = new JSONObject();
serverInfoJson.put("hostname", hostnameAvatarUri);
serverInfoJson.put("sitename", siteName);
// Replace server avatar uri if exists. // Replace server avatar uri if exists.
json.put(hostname, hostnameAvatarUri == null ? JSONObject.NULL : hostnameAvatarUri); json.put(hostname, hostnameAvatarUri == null ? JSONObject.NULL : serverInfoJson);
setString(KEY_HOSTNAME_LIST, json.toString()); setString(KEY_HOSTNAME_LIST, json.toString());
} catch (JSONException e) { } catch (JSONException e) {
RCLog.e(e); RCLog.e(e);
} }
} }
public List<Pair<String, String>> getServerList() { public List<Pair<String, Pair<String, String>>> getServerList() {
String json = getString(KEY_HOSTNAME_LIST, null); String json = getString(KEY_HOSTNAME_LIST, null);
if (json == null) { if (json == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
try { try {
JSONObject jsonObj = new JSONObject(json); JSONObject jsonObj = new JSONObject(json);
List<Pair<String, String>> serverList = new ArrayList<>(); List<Pair<String, Pair<String, String>>> serverList = new ArrayList<>();
for (Iterator<String> iter = jsonObj.keys(); iter.hasNext();) { for (Iterator<String> iter = jsonObj.keys(); iter.hasNext();) {
String hostname = iter.next(); String hostname = iter.next();
serverList.add(new Pair<>(hostname,"http://" + hostname + "/" + jsonObj.getString(hostname))); JSONObject serverInfoJson = jsonObj.getJSONObject(hostname);
serverList.add(new Pair<>(hostname, new Pair<>(
"http://" + hostname + "/" + serverInfoJson.getString("hostname"),
serverInfoJson.getString("sitename"))));
} }
return serverList; return serverList;
} catch (JSONException e) { } catch (JSONException e) {
......
package chat.rocket.android.activity; package chat.rocket.android.activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
...@@ -197,32 +196,37 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -197,32 +196,37 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
} }
@Override @Override
public void showSignedInServers(List<Pair<String, String>> serverList) { public void showSignedInServers(List<Pair<String, Pair<String, String>>> serverList) {
final SlidingPaneLayout subPane = (SlidingPaneLayout) findViewById(R.id.sub_sliding_pane); final SlidingPaneLayout subPane = (SlidingPaneLayout) findViewById(R.id.sub_sliding_pane);
if (subPane != null) { if (subPane != null) {
LinearLayout serverListContainer = subPane.findViewById(R.id.server_list_bar); LinearLayout serverListContainer = subPane.findViewById(R.id.server_list_bar);
for (Pair<String, String> server : serverList) { View addServerButton = subPane.findViewById(R.id.btn_add_server);
addServerButton.setOnClickListener(view -> showAddServerActivity());
for (Pair<String, Pair<String, String>> server : serverList) {
String serverHostname = server.first; String serverHostname = server.first;
String serverLogoUrl = server.second; Pair<String, String> serverInfoPair = server.second;
String logoUrl = serverInfoPair.first;
String siteName = serverInfoPair.second;
if (serverListContainer.findViewWithTag(serverHostname) == null) { if (serverListContainer.findViewWithTag(serverHostname) == null) {
int serverCount = serverListContainer.getChildCount(); int serverCount = serverListContainer.getChildCount();
View serverRow = LayoutInflater.from(this).inflate(R.layout.server_row, serverListContainer, false); View serverRow = LayoutInflater.from(this).inflate(R.layout.server_row, serverListContainer, false);
SimpleDraweeView serverButton = serverRow.findViewById(R.id.drawee_server_button); SimpleDraweeView serverButton = serverRow.findViewById(R.id.drawee_server_button);
TextView serverLabel = serverRow.findViewById(R.id.text_view_server_label); TextView hostnameLabel = serverRow.findViewById(R.id.text_view_server_label);
TextView siteNameLabel = serverRow.findViewById(R.id.text_view_site_name_label);
serverButton.setTag(serverHostname); serverButton.setTag(serverHostname);
serverLabel.setText(serverHostname); hostnameLabel.setText(serverHostname);
siteNameLabel.setText(siteName);
// Currently selected server // Currently selected server
if (serverHostname.equalsIgnoreCase(hostname)) { if (serverHostname.equalsIgnoreCase(hostname)) {
serverLabel.setSelected(true); hostnameLabel.setSelected(true);
serverLabel.setTypeface(Typeface.DEFAULT_BOLD);
} }
serverRow.setOnClickListener(view -> changeServerIfNeeded(serverHostname)); serverRow.setOnClickListener(view -> changeServerIfNeeded(serverHostname));
FrescoHelper.INSTANCE.loadImage(serverButton, serverLogoUrl, ContextCompat.getDrawable(this, R.mipmap.ic_launcher)); FrescoHelper.INSTANCE.loadImage(serverButton, logoUrl, ContextCompat.getDrawable(this, R.mipmap.ic_launcher));
serverListContainer.addView(serverRow, serverCount - 1); serverListContainer.addView(serverRow, serverCount - 1);
} }
......
...@@ -25,7 +25,7 @@ public interface MainContract { ...@@ -25,7 +25,7 @@ public interface MainContract {
void showConnectionOk(); void showConnectionOk();
void showSignedInServers(List<Pair<String, String>> serverList); void showSignedInServers(List<Pair<String, Pair<String, String>>> serverList);
} }
interface Presenter extends BaseContract.Presenter<View> { interface Presenter extends BaseContract.Presenter<View> {
......
...@@ -69,9 +69,9 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -69,9 +69,9 @@ public class MainPresenter extends BasePresenter<MainContract.View>
@Override @Override
public void loadSignedInServers(@NonNull String hostname) { public void loadSignedInServers(@NonNull String hostname) {
final Disposable disposable = publicSettingRepository.getById(PublicSettingsConstants.Assets.LOGO) final Disposable disposable = publicSettingRepository.getById(PublicSettingsConstants.Assets.LOGO)
.filter(Optional::isPresent) .zipWith(publicSettingRepository.getById(PublicSettingsConstants.General.SITE_NAME), Pair::new)
.map(Optional::get) .map(this::getLogoAndSiteNamePair)
.map(setting -> getServerList(hostname, setting)) .map(settings -> getServerList(hostname, settings))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
...@@ -133,11 +133,24 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -133,11 +133,24 @@ public class MainPresenter extends BasePresenter<MainContract.View>
addSubscription(subscription); addSubscription(subscription);
} }
private List<Pair<String, String>> getServerList(String hostname, PublicSetting publicSetting) throws JSONException { private Pair<String, String> getLogoAndSiteNamePair(Pair<Optional<PublicSetting>, Optional<PublicSetting>> settingsPair) {
JSONObject jsonObject = new JSONObject(publicSetting.getValue()); String logoUrl = "";
String siteName = "";
if (settingsPair.first.isPresent()) {
logoUrl = settingsPair.first.get().getValue();
}
if (settingsPair.second.isPresent()) {
siteName = settingsPair.second.get().getValue();
}
return new Pair<>(logoUrl, siteName);
}
private List<Pair<String, Pair<String, String>>> getServerList(String hostname, Pair<String, String> serverInfoPair) throws JSONException {
JSONObject jsonObject = new JSONObject(serverInfoPair.first);
String logoUrl = (jsonObject.has("url")) ? String logoUrl = (jsonObject.has("url")) ?
jsonObject.optString("url") : jsonObject.optString("defaultUrl"); jsonObject.optString("url") : jsonObject.optString("defaultUrl");
rocketChatCache.addHostname(hostname.toLowerCase(), logoUrl); String siteName = serverInfoPair.second;
rocketChatCache.addHostname(hostname.toLowerCase(), logoUrl, siteName);
return rocketChatCache.getServerList(); return rocketChatCache.getServerList();
} }
......
...@@ -22,14 +22,19 @@ ...@@ -22,14 +22,19 @@
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
android:id="@+id/btn_add_server" android:id="@+id/btn_add_server"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp"> android:layout_height="80dp"
android:background="?selectableItemBackground"
android:descendantFocusability="afterDescendants">
<io.github.yusukeiwaki.android.widget.FontAwesomeButton <io.github.yusukeiwaki.android.widget.FontAwesomeTextView
android:id="@+id/fa_add_server" android:id="@+id/fa_add_server"
style="@style/Base.Widget.AppCompat.Button.Borderless" style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="80dp" android:layout_height="80dp"
android:layout_margin="@dimen/margin_8" android:layout_margin="@dimen/margin_8"
android:background="@null"
android:clickable="false"
android:duplicateParentState="true"
android:text="@string/fa_plus" android:text="@string/fa_plus"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -40,12 +45,13 @@ ...@@ -40,12 +45,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:duplicateParentState="true"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"
android:text="@string/add_new_team" android:text="@string/add_new_team"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
......
...@@ -4,13 +4,15 @@ ...@@ -4,13 +4,15 @@
xmlns:fresco="http://schemas.android.com/apk/res-auto" xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="80dp"> android:layout_height="80dp"
tools:background="#044b76">
<com.facebook.drawee.view.SimpleDraweeView <com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/drawee_server_button" android:id="@+id/drawee_server_button"
style="@style/Base.Widget.AppCompat.Button.Borderless" style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="80dp" android:layout_height="80dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
...@@ -19,21 +21,40 @@ ...@@ -19,21 +21,40 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
fresco:actualImageScaleType="fitXY" /> fresco:actualImageScaleType="fitXY" />
<TextView
android:id="@+id/text_view_site_name_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ellipsize="end"
android:gravity="bottom"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white"
app:layout_constraintEnd_toEndOf="@+id/text_view_server_label"
app:layout_constraintStart_toStartOf="@+id/text_view_server_label"
app:layout_constraintTop_toTopOf="@+id/drawee_server_button"
tools:text="Rocket.Chat" />
<TextView <TextView
android:id="@+id/text_view_server_label" android:id="@+id/text_view_server_label"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="top"
android:maxLines="1" android:maxLines="1"
android:textColor="@color/selector_text_color_multiserver" android:textAllCaps="false"
android:textColor="@color/color_embed_hostname"
android:textSize="16sp" android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/drawee_server_button" app:layout_constraintStart_toEndOf="@+id/drawee_server_button"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toBottomOf="@+id/text_view_site_name_label"
tools:text="demo.rocket.chat" /> tools:text="demo.rocket.chat" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
\ No newline at end of file
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