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 {
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);
try {
JSONObject json;
......@@ -53,25 +53,31 @@ public class RocketChatCache {
} else {
json = new JSONObject(hostnameList);
}
JSONObject serverInfoJson = new JSONObject();
serverInfoJson.put("hostname", hostnameAvatarUri);
serverInfoJson.put("sitename", siteName);
// 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());
} catch (JSONException 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);
if (json == null) {
return Collections.emptyList();
}
try {
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();) {
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;
} catch (JSONException e) {
......
package chat.rocket.android.activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
......@@ -197,32 +196,37 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
@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);
if (subPane != null) {
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 serverLogoUrl = server.second;
Pair<String, String> serverInfoPair = server.second;
String logoUrl = serverInfoPair.first;
String siteName = serverInfoPair.second;
if (serverListContainer.findViewWithTag(serverHostname) == null) {
int serverCount = serverListContainer.getChildCount();
View serverRow = LayoutInflater.from(this).inflate(R.layout.server_row, serverListContainer, false);
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);
serverLabel.setText(serverHostname);
hostnameLabel.setText(serverHostname);
siteNameLabel.setText(siteName);
// Currently selected server
if (serverHostname.equalsIgnoreCase(hostname)) {
serverLabel.setSelected(true);
serverLabel.setTypeface(Typeface.DEFAULT_BOLD);
hostnameLabel.setSelected(true);
}
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);
}
......
......@@ -25,7 +25,7 @@ public interface MainContract {
void showConnectionOk();
void showSignedInServers(List<Pair<String, String>> serverList);
void showSignedInServers(List<Pair<String, Pair<String, String>>> serverList);
}
interface Presenter extends BaseContract.Presenter<View> {
......
......@@ -69,9 +69,9 @@ public class MainPresenter extends BasePresenter<MainContract.View>
@Override
public void loadSignedInServers(@NonNull String hostname) {
final Disposable disposable = publicSettingRepository.getById(PublicSettingsConstants.Assets.LOGO)
.filter(Optional::isPresent)
.map(Optional::get)
.map(setting -> getServerList(hostname, setting))
.zipWith(publicSettingRepository.getById(PublicSettingsConstants.General.SITE_NAME), Pair::new)
.map(this::getLogoAndSiteNamePair)
.map(settings -> getServerList(hostname, settings))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
......@@ -133,11 +133,24 @@ 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());
private Pair<String, String> getLogoAndSiteNamePair(Pair<Optional<PublicSetting>, Optional<PublicSetting>> settingsPair) {
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")) ?
jsonObject.optString("url") : jsonObject.optString("defaultUrl");
rocketChatCache.addHostname(hostname.toLowerCase(), logoUrl);
String siteName = serverInfoPair.second;
rocketChatCache.addHostname(hostname.toLowerCase(), logoUrl, siteName);
return rocketChatCache.getServerList();
}
......
......@@ -22,14 +22,19 @@
<android.support.constraint.ConstraintLayout
android:id="@+id/btn_add_server"
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"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="@dimen/margin_8"
android:background="@null"
android:clickable="false"
android:duplicateParentState="true"
android:text="@string/fa_plus"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -40,12 +45,13 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:duplicateParentState="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:text="@string/add_new_team"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
......
......@@ -4,13 +4,15 @@
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp">
android:layout_height="80dp"
tools:background="#044b76">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/drawee_server_button"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
......@@ -19,21 +21,40 @@
app:layout_constraintTop_toTopOf="parent"
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
android:id="@+id/text_view_server_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ellipsize="end"
android:gravity="center_vertical"
android:gravity="top"
android:maxLines="1"
android:textColor="@color/selector_text_color_multiserver"
android:textAllCaps="false"
android:textColor="@color/color_embed_hostname"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
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" />
</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