Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-01-01 16:35:30 +01:00
parent e55f5ca325
commit 1880a9f481
4 changed files with 54 additions and 37 deletions

View File

@ -7,7 +7,7 @@ import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
/**
* Instrumented test, which will execute on an Android device.

View File

@ -24,6 +24,8 @@ import android.accounts.Account;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
@ -113,21 +115,34 @@ public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.User
holder.serverUrl.setText(userEntity.getBaseUrl());
GlideUrl glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(),
participant.getUserId()), new LazyHeaders.Builder()
.setHeader("Accept", "image/*")
.setHeader("User-Agent", ApiHelper.getUserAgent())
.build());
if (userEntity.getBaseUrl().startsWith("http://") || userEntity.getBaseUrl().startsWith("https://")) {
holder.avatarImageView.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.linearLayout.getLayoutParams();
layoutParams.setMarginStart(0);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_START);
holder.linearLayout.setLayoutParams(layoutParams);
GlideUrl glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(),
participant.getUserId()), new LazyHeaders.Builder()
.setHeader("Accept", "image/*")
.setHeader("User-Agent", ApiHelper.getUserAgent())
.build());
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(glideUrl)
.centerInside()
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.into(holder.avatarImageView)
;
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(glideUrl)
.centerInside()
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.into(holder.avatarImageView);
} else {
holder.avatarImageView.setVisibility(View.GONE);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.linearLayout.getLayoutParams();
layoutParams.setMarginStart((int) NextcloudTalkApplication.getSharedApplication().getApplicationContext()
.getResources().getDimension(R.dimen.activity_horizontal_margin));
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
holder.linearLayout.setLayoutParams(layoutParams);
}
}
@Override
@ -145,6 +160,8 @@ public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.User
public TextView serverUrl;
@BindView(R.id.avatar_image)
public ImageView avatarImageView;
@BindView(R.id.linear_layout)
LinearLayout linearLayout;
/**
* Default constructor.

View File

@ -303,6 +303,10 @@ public class ServerSelectionController extends BaseController {
.equals(ErrorMessageHolder.ErrorMessageType.SERVER_WITHOUT_TALK)) {
textFieldBoxes.setError(getResources().getString(R.string.nc_settings_no_talk_installed),
false);
} else if (ErrorMessageHolder.getInstance().getMessageType()
.equals(ErrorMessageHolder.ErrorMessageType.FAILED_TO_IMPORT_ACCOUNT)) {
textFieldBoxes.setError(getResources().getString(R.string.nc_server_failed_to_import_account),
false);
}
ErrorMessageHolder.getInstance().setMessageType(null);
}

View File

@ -36,7 +36,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.models.ImportAccount;
import com.nextcloud.talk.persistence.entities.UserEntity;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@ -61,10 +60,22 @@ public class AccountUtils {
for (int i = 0; i < userEntitiesList.size(); i++) {
internalUserEntity = userEntitiesList.get(i);
importAccount = getInformationFromAccount(account, null);
if (internalUserEntity.getUsername().equals(importAccount.getUsername()) &&
internalUserEntity.getBaseUrl().equals(importAccount.getBaseUrl())) {
accountFound = true;
break;
if (importAccount.getBaseUrl().startsWith("http://") ||
importAccount.getBaseUrl().startsWith("https://")) {
if (internalUserEntity.getUsername().equals(importAccount.getUsername()) &&
internalUserEntity.getBaseUrl().equals(importAccount.getBaseUrl())) {
accountFound = true;
break;
}
} else {
if (internalUserEntity.getUsername().equals(importAccount.getUsername()) &&
(internalUserEntity.getBaseUrl().equals("http://" + importAccount.getBaseUrl()) ||
internalUserEntity.getBaseUrl().equals("https://" +
importAccount.getBaseUrl()))) {
accountFound = true;
break;
}
}
}
@ -95,29 +106,14 @@ public class AccountUtils {
String urlString = account.name.substring(lastAtPos + 1);
String username = account.name.substring(0, lastAtPos);
if (!urlString.startsWith("http")) {
urlString = "http://" + urlString;
}
String password = null;
if (data != null) {
password = data.getString(AccountManager.KEY_AUTHTOKEN);
}
try {
final String urlStringOrig = urlString;
URL url = new URL(urlStringOrig);
urlString = url.getProtocol() + "://" + url.getHost();
if (url.getPath().contains("/owncloud")) {
urlString += url.getPath().substring(0, url.getPath().indexOf("/owncloud") + 9);
} else if (url.getPath().contains("/nextcloud")) {
urlString += url.getPath().substring(0, url.getPath().indexOf("/nextcloud") + 10);
} else if (url.getPath().contains("/")) {
urlString += url.getPath().substring(0, url.getPath().indexOf("/"));
}
} catch (Exception ex) {
Log.e(TAG, "Something went wrong while trying to create url string");
if (urlString.endsWith("/")) {
urlString = urlString.substring(0, urlString.length() - 1);
}
return new ImportAccount(username, password, urlString);